Skip to content

Commit

Permalink
feat: Handle signatures containing +xxx in the answering email (#2212)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne authored Mar 4, 2025
2 parents 189c4de + 9b8458a commit 139a988
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.infomaniak.mail.data.models.thread.Thread
import com.infomaniak.mail.data.models.thread.Thread.ThreadFilter
import com.infomaniak.mail.utils.AccountUtils
import com.infomaniak.mail.utils.LocalStorageUtils.deleteDraftUploadDir
import com.infomaniak.mail.utils.extensions.getStartAndEndOfPlusEmail
import io.realm.kotlin.MutableRealm
import io.realm.kotlin.Realm
import io.realm.kotlin.TypedRealm
Expand Down Expand Up @@ -59,10 +60,17 @@ class MessageController @Inject constructor(private val mailboxContentRealm: Rea
fun getLastMessageToExecuteAction(thread: Thread): Message = with(thread) {

val isNotScheduledDraft = "${Message::isScheduledDraft.name} == false"
val isNotFromMe = "SUBQUERY(${Message::from.name}, \$recipient, " +

val isNotFromRealMe = "SUBQUERY(${Message::from.name}, \$recipient, " +
"\$recipient.${Recipient::email.name} != '${AccountUtils.currentMailboxEmail}').@count > 0"

return messages.query("$isNotDraft AND $isNotScheduledDraft AND $isNotFromMe").find().lastOrNull()
val (start, end) = AccountUtils.currentMailboxEmail.getStartAndEndOfPlusEmail()
val isNotFromPlusMe = "SUBQUERY(${Message::from.name}, \$recipient," +
" \$recipient.${Recipient::email.name} BEGINSWITH '${start}'" +
" AND \$recipient.${Recipient::email.name} ENDSWITH '${end}'" +
").@count < 1"

return messages.query("$isNotDraft AND $isNotScheduledDraft AND $isNotFromRealMe AND $isNotFromPlusMe").find().lastOrNull()
?: messages.query("$isNotDraft AND $isNotScheduledDraft").find().lastOrNull()
?: messages.query(isNotScheduledDraft).find().lastOrNull()
?: messages.last()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.os.Parcelable
import com.infomaniak.lib.core.utils.firstOrEmpty
import com.infomaniak.mail.R
import com.infomaniak.mail.utils.AccountUtils
import com.infomaniak.mail.utils.extensions.getStartAndEndOfPlusEmail
import io.sentry.Sentry

interface Correspondent : Parcelable {
Expand All @@ -30,7 +31,17 @@ interface Correspondent : Parcelable {

val initials: String

fun isMe(): Boolean = AccountUtils.currentMailboxEmail?.lowercase() == email.lowercase()
fun isMe(): Boolean {
val userEmail = AccountUtils.currentMailboxEmail?.lowercase()
val correspondentEmail = email.lowercase()

val isRealMe = userEmail == correspondentEmail

val (start, end) = userEmail.getStartAndEndOfPlusEmail()
val isPlusMe = correspondentEmail.startsWith(start) && correspondentEmail.endsWith(end)

return isRealMe || isPlusMe
}

fun shouldDisplayUserAvatar(): Boolean = isMe() && email.lowercase() == AccountUtils.currentUser?.email?.lowercase()

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ class MainViewModel @Inject constructor(
message != null -> {
message.folder.role
}
threads?.firstOrNull()?.folder?.id == FolderController.SEARCH_FOLDER_ID -> {
threads?.firstOrNull()?.folderId == FolderController.SEARCH_FOLDER_ID -> {
folderController.getFolder(threads.first().folderId)?.role
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ fun String.removeLineBreaksFromHtml(): Document = jsoupParseWithLog(replace("\r"

fun String.htmlToText(): String = removeLineBreaksFromHtml().wholeText()

fun String?.getStartAndEndOfPlusEmail(): Pair<String, String> {
val splittedEmail = this?.split("@")
val fromStartToPlus = splittedEmail?.first() + "+"
val fromArobaseToEnd = "@" + splittedEmail?.last()
return fromStartToPlus to fromArobaseToEnd
}

//region Date
fun RealmInstant.toDate(): Date = Date(epochSeconds * 1_000L + nanosecondsOfSecond / 1_000L)

Expand Down

0 comments on commit 139a988

Please sign in to comment.