-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6618 from thundernest/message-view-redesign
Add the redesigned message view screen
- Loading branch information
Showing
127 changed files
with
3,657 additions
and
1,147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/core/src/main/java/com/fsck/k9/helper/AddressFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.fsck.k9.helper | ||
|
||
import android.text.Spannable.SPAN_EXCLUSIVE_EXCLUSIVE | ||
import android.text.SpannableString | ||
import android.text.style.ForegroundColorSpan | ||
import com.fsck.k9.Account | ||
import com.fsck.k9.Identity | ||
import com.fsck.k9.mail.Address | ||
|
||
/** | ||
* Get the display name for an email address. | ||
*/ | ||
interface AddressFormatter { | ||
fun getDisplayName(address: Address): CharSequence | ||
} | ||
|
||
class RealAddressFormatter( | ||
private val contactNameProvider: ContactNameProvider, | ||
private val account: Account, | ||
private val showCorrespondentNames: Boolean, | ||
private val showContactNames: Boolean, | ||
private val contactNameColor: Int?, | ||
private val meText: String | ||
) : AddressFormatter { | ||
override fun getDisplayName(address: Address): CharSequence { | ||
val identity = account.findIdentity(address) | ||
if (identity != null) { | ||
return getIdentityName(identity) | ||
} | ||
|
||
return if (!showCorrespondentNames) { | ||
address.address | ||
} else if (showContactNames) { | ||
getContactName(address) | ||
} else { | ||
buildDisplayName(address) | ||
} | ||
} | ||
|
||
private fun getIdentityName(identity: Identity): String { | ||
return if (account.identities.size == 1) { | ||
meText | ||
} else { | ||
identity.description ?: identity.name ?: identity.email ?: meText | ||
} | ||
} | ||
|
||
private fun getContactName(address: Address): CharSequence { | ||
val contactName = contactNameProvider.getNameForAddress(address.address) ?: return buildDisplayName(address) | ||
|
||
return if (contactNameColor != null) { | ||
SpannableString(contactName).apply { | ||
setSpan(ForegroundColorSpan(contactNameColor), 0, contactName.length, SPAN_EXCLUSIVE_EXCLUSIVE) | ||
} | ||
} else { | ||
contactName | ||
} | ||
} | ||
|
||
private fun buildDisplayName(address: Address): CharSequence { | ||
return address.personal?.takeIf { | ||
it.isNotBlank() && !it.equals(meText, ignoreCase = true) && !isSpoofAddress(it) | ||
} ?: address.address | ||
} | ||
|
||
private fun isSpoofAddress(displayName: String): Boolean { | ||
val atIndex = displayName.indexOf('@') | ||
return if (atIndex > 0) { | ||
displayName[atIndex - 1] != '(' | ||
} else { | ||
false | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/core/src/main/java/com/fsck/k9/helper/ContactNameProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.fsck.k9.helper | ||
|
||
interface ContactNameProvider { | ||
fun getNameForAddress(address: String): String? | ||
} | ||
|
||
class RealContactNameProvider(private val contacts: Contacts) : ContactNameProvider { | ||
override fun getNameForAddress(address: String): String? { | ||
return contacts.getNameForAddress(address) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/core/src/main/java/com/fsck/k9/mailstore/MessageDetails.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.fsck.k9.mailstore | ||
|
||
import com.fsck.k9.mail.Address | ||
import java.util.Date | ||
|
||
data class MessageDetails( | ||
val date: MessageDate, | ||
val from: List<Address>, | ||
val sender: Address?, | ||
val replyTo: List<Address>, | ||
val to: List<Address>, | ||
val cc: List<Address>, | ||
val bcc: List<Address> | ||
) | ||
|
||
sealed interface MessageDate { | ||
data class ValidDate(val date: Date) : MessageDate | ||
|
||
data class InvalidDate(val dateHeader: String) : MessageDate | ||
|
||
object MissingDate : MessageDate | ||
} |
58 changes: 58 additions & 0 deletions
58
app/core/src/main/java/com/fsck/k9/mailstore/MessageRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,69 @@ | ||
package com.fsck.k9.mailstore | ||
|
||
import com.fsck.k9.controller.MessageReference | ||
import com.fsck.k9.mail.Address | ||
import com.fsck.k9.mail.Header | ||
import com.fsck.k9.mail.internet.MimeUtility | ||
import org.apache.james.mime4j.dom.field.DateTimeField | ||
import org.apache.james.mime4j.field.DefaultFieldParser | ||
|
||
class MessageRepository(private val messageStoreManager: MessageStoreManager) { | ||
fun getHeaders(messageReference: MessageReference): List<Header> { | ||
val messageStore = messageStoreManager.getMessageStore(messageReference.accountUuid) | ||
return messageStore.getHeaders(messageReference.folderId, messageReference.uid) | ||
} | ||
|
||
fun getMessageDetails(messageReference: MessageReference): MessageDetails { | ||
val messageStore = messageStoreManager.getMessageStore(messageReference.accountUuid) | ||
val headers = messageStore.getHeaders(messageReference.folderId, messageReference.uid, MESSAGE_DETAILS_HEADERS) | ||
|
||
val messageDate = headers.parseDate("date") | ||
val fromAddresses = headers.parseAddresses("from") | ||
val senderAddresses = headers.parseAddresses("sender") | ||
val replyToAddresses = headers.parseAddresses("reply-to") | ||
val toAddresses = headers.parseAddresses("to") | ||
val ccAddresses = headers.parseAddresses("cc") | ||
val bccAddresses = headers.parseAddresses("bcc") | ||
|
||
return MessageDetails( | ||
date = messageDate, | ||
from = fromAddresses, | ||
sender = senderAddresses.firstOrNull(), | ||
replyTo = replyToAddresses, | ||
to = toAddresses, | ||
cc = ccAddresses, | ||
bcc = bccAddresses | ||
) | ||
} | ||
|
||
private fun List<Header>.firstHeaderOrNull(name: String): String? { | ||
return firstOrNull { it.name.equals(name, ignoreCase = true) }?.value | ||
} | ||
|
||
private fun List<Header>.parseAddresses(headerName: String): List<Address> { | ||
return Address.parse(MimeUtility.unfold(firstHeaderOrNull(headerName))).toList() | ||
} | ||
|
||
private fun List<Header>.parseDate(headerName: String): MessageDate { | ||
val dateHeader = firstHeaderOrNull(headerName) ?: return MessageDate.MissingDate | ||
|
||
return try { | ||
val dateTimeField = DefaultFieldParser.parse("Date: $dateHeader") as DateTimeField | ||
return MessageDate.ValidDate(date = dateTimeField.date) | ||
} catch (e: Exception) { | ||
MessageDate.InvalidDate(dateHeader) | ||
} | ||
} | ||
|
||
companion object { | ||
private val MESSAGE_DETAILS_HEADERS = setOf( | ||
"date", | ||
"from", | ||
"sender", | ||
"reply-to", | ||
"to", | ||
"cc", | ||
"bcc", | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.