From 3094091c5ebbbab1954691e8d69500df3f94b053 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Thu, 4 Jul 2024 13:21:11 +0200 Subject: [PATCH] fix: Mailto with empty fields are not managed --- .../mail/ui/newMessage/NewMessageViewModel.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageViewModel.kt b/app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageViewModel.kt index 2e4dd91e41..1c5131d0e6 100644 --- a/app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageViewModel.kt +++ b/app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageViewModel.kt @@ -551,16 +551,22 @@ class NewMessageViewModel @Inject constructor( return getStringArrayExtra(recipientsFlag)?.map { Recipient().initLocalValues(it, it) } } + /** + * Each customer app is free to do what he wants, so we sometimes receive mailto fields that are empty, + * so we don't want to ignore them, so we return null. + */ + fun String.nullIfEmpty() = ifEmpty { null } + val mailToIntent = runCatching { MailTo.parse(uri!!) }.getOrNull() if (mailToIntent == null && intent?.hasExtra(Intent.EXTRA_EMAIL) != true) return - val splitTo = mailToIntent?.to?.splitToRecipientList() + val splitTo = mailToIntent?.to?.nullIfEmpty()?.splitToRecipientList() ?: intent?.getRecipientsFromIntent(Intent.EXTRA_EMAIL) ?: emptyList() - val splitCc = mailToIntent?.cc?.splitToRecipientList() + val splitCc = mailToIntent?.cc?.nullIfEmpty()?.splitToRecipientList() ?: intent?.getRecipientsFromIntent(Intent.EXTRA_CC) ?: emptyList() - val splitBcc = mailToIntent?.bcc?.splitToRecipientList() + val splitBcc = mailToIntent?.bcc?.nullIfEmpty()?.splitToRecipientList() ?: intent?.getRecipientsFromIntent(Intent.EXTRA_BCC) ?: emptyList() @@ -569,8 +575,8 @@ class NewMessageViewModel @Inject constructor( cc.addAll(splitCc) bcc.addAll(splitBcc) - subject = mailToIntent?.subject ?: intent?.getStringExtra(Intent.EXTRA_SUBJECT) - uiBody = mailToIntent?.body ?: intent?.getStringExtra(Intent.EXTRA_TEXT) ?: "" + subject = mailToIntent?.subject?.nullIfEmpty() ?: intent?.getStringExtra(Intent.EXTRA_SUBJECT) + uiBody = mailToIntent?.body?.nullIfEmpty() ?: intent?.getStringExtra(Intent.EXTRA_TEXT) ?: "" } }