@@ -23,18 +23,16 @@ import com.infomaniak.mail.data.models.thread.Thread
23
23
import com.infomaniak.mail.utils.extensions.MergedContactDictionary
24
24
25
25
object ExternalUtils {
26
+
26
27
/* *
27
28
* Only returns a quantity of at most 2, used to differentiate between the singular or plural form of the dialog messages
28
29
*/
29
- fun Thread.findExternalRecipients (
30
- emailDictionary : MergedContactDictionary ,
31
- aliases : List <String >,
32
- ): Pair <String ?, Int > {
30
+ fun Thread.findExternalRecipients (externalData : ExternalData ): Pair <String ?, Int > {
33
31
var externalRecipientEmail: String? = null
34
32
var externalRecipientQuantity = 0
35
33
36
34
messages.forEach { message ->
37
- val (singleEmail, quantityForThisMessage) = findExternalRecipientInIterables(emailDictionary, aliases , message.from)
35
+ val (singleEmail, quantityForThisMessage) = findExternalRecipientInIterables(externalData , message.from)
38
36
39
37
externalRecipientQuantity + = quantityForThisMessage
40
38
if (externalRecipientQuantity > 1 ) return null to 2
@@ -45,14 +43,12 @@ object ExternalUtils {
45
43
return externalRecipientEmail to externalRecipientQuantity
46
44
}
47
45
48
- fun Draft.findExternalRecipientForNewMessage (
49
- aliases : List <String >,
50
- emailDictionary : MergedContactDictionary ,
51
- ): Pair <String ?, Int > {
46
+ fun Draft.findExternalRecipientForNewMessage (externalData : ExternalData ): Pair <String ?, Int > {
52
47
val to = to.onlyAutomaticallyAddedOnes()
53
48
val cc = cc.onlyAutomaticallyAddedOnes()
54
49
val bcc = bcc.onlyAutomaticallyAddedOnes()
55
- return findExternalRecipientInIterables(emailDictionary, aliases, to, cc, bcc)
50
+
51
+ return findExternalRecipientInIterables(externalData, to, cc, bcc)
56
52
}
57
53
58
54
private fun List<Recipient>.onlyAutomaticallyAddedOnes (): List <Recipient > = filter { ! it.isManuallyEntered }
@@ -61,16 +57,15 @@ object ExternalUtils {
61
57
* Only returns a quantity of at most 2, used to differentiate between the singular or plural form of the dialog messages
62
58
*/
63
59
private fun findExternalRecipientInIterables (
64
- emailDictionary : MergedContactDictionary ,
65
- aliases : List <String >,
60
+ externalData : ExternalData ,
66
61
vararg recipientLists : Iterable <Recipient >,
67
62
): Pair <String ?, Int > {
68
63
var externalRecipientEmail: String? = null
69
64
var externalRecipientQuantity = 0
70
65
71
66
recipientLists.forEach { recipientList ->
72
67
recipientList.forEach { recipient ->
73
- if (recipient.isExternal(emailDictionary, aliases )) {
68
+ if (recipient.isExternal(externalData )) {
74
69
if (externalRecipientQuantity++ == 0 ) {
75
70
externalRecipientEmail = recipient.email
76
71
} else {
@@ -82,4 +77,10 @@ object ExternalUtils {
82
77
83
78
return externalRecipientEmail to externalRecipientQuantity
84
79
}
80
+
81
+ data class ExternalData (
82
+ val emailDictionary : MergedContactDictionary ,
83
+ val aliases : List <String >,
84
+ val trustedDomains : List <String >,
85
+ )
85
86
}
0 commit comments