Skip to content

Fix NPE in EmailAndNameWorker #3040

@DenBond7

Description

@DenBond7
Patch
Index: FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt
--- a/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt	(revision dba834d5ebf5b5e4e1c3811fb10a9540b12383b1)
+++ b/FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/workmanager/EmailAndNameWorker.kt	(revision 2be717e30e68225fc95cc92ca4dbd45b3f5166a2)
@@ -41,7 +41,7 @@

   for (i in emails.indices) {
     val email = emails[i].lowercase()
-      val name = names[i]
+      val name = names[i].takeIf { it.isNotEmpty() }
     val recipientEntity = recipientDao.getRecipientByEmailSuspend(email)
     if (recipientEntity != null) {
       if (recipientEntity.name.isNullOrEmpty()) {
@@ -60,7 +60,7 @@
   const val EXTRA_KEY_NAMES = BuildConfig.APPLICATION_ID + ".EXTRA_KEY_NAMES"
   const val GROUP_UNIQUE_TAG = BuildConfig.APPLICATION_ID + ".UPDATE_EMAIL_AND_NAME"

-    fun enqueue(context: Context, emailAndNamePairs: List<Pair<String, String?>>) {
+    fun enqueue(context: Context, emailAndNamePairs: List<Pair<String, String>>) {
     var i = 0
     val stepValue = 50
     while (i < emailAndNamePairs.size) {
Index: FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt
--- a/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt	(revision dba834d5ebf5b5e4e1c3811fb10a9540b12383b1)
+++ b/FlowCrypt/src/main/java/com/flowcrypt/email/util/GeneralUtil.kt	(revision 2be717e30e68225fc95cc92ca4dbd45b3f5166a2)
@@ -597,7 +597,7 @@
       val isSentFolder = imapFolder?.attributes?.contains("\\Sent") != false

       if (isSentFolder) {
-          val emailAndNamePairs = mutableListOf<Pair<String, String?>>()
+          val emailAndNamePairs = mutableListOf<Pair<String, String>>()
         for (message in messages) {
           emailAndNamePairs.addAll(getEmailAndNamePairs(message))
         }
@@ -616,8 +616,7 @@
    *
    * @param msg The input [jakarta.mail.Message].
    * @return <tt>[List]</tt> of [Pair] objects, which contains information
-     * about
-     * emails and names.
+     * about emails and names.
    * @throws MessagingException when retrieve information about recipients.
    */
   private fun getEmailAndNamePairs(msg: Message): List<Pair<String, String>> {
@@ -627,7 +626,7 @@
     if (addressesTo != null) {
       for (address in addressesTo) {
         val internetAddress = address as InternetAddress
-          pairs.add(Pair(internetAddress.address, internetAddress.personal))
+          pairs.add(Pair(internetAddress.address, internetAddress.personal ?: ""))
       }
     }

@@ -635,7 +634,7 @@
     if (addressesCC != null) {
       for (address in addressesCC) {
         val internetAddress = address as InternetAddress
-          pairs.add(Pair(internetAddress.address, internetAddress.personal))
+          pairs.add(Pair(internetAddress.address, internetAddress.personal ?: ""))
       }
     }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions