@@ -22,7 +22,9 @@ import com.infomaniak.mail.R
22
22
import com.infomaniak.mail.data.models.Attachment
23
23
import com.infomaniak.mail.data.models.correspondent.Recipient
24
24
import com.infomaniak.mail.data.models.message.Message
25
- import com.infomaniak.mail.ui.main.thread.MessageWebViewClient
25
+ import com.infomaniak.mail.utils.HtmlUtils.CID_PROTOCOL
26
+ import com.infomaniak.mail.utils.HtmlUtils.SRC_ATTRIBUTE
27
+ import com.infomaniak.mail.utils.HtmlUtils.processCids
26
28
import com.infomaniak.mail.utils.JsoupParserUtil.jsoupParseBodyFragmentWithLog
27
29
import com.infomaniak.mail.utils.JsoupParserUtil.jsoupParseWithLog
28
30
import com.infomaniak.mail.utils.MailDateFormatUtils.formatForHeader
@@ -42,12 +44,12 @@ class ReplyForwardFooterManager @Inject constructor(private val appContext: Cont
42
44
fun createForwardFooter (message : Message , attachmentsToForward : List <Attachment >): String {
43
45
val previousBody = getHtmlDocument(message)?.let { document ->
44
46
document.processCids(
45
- message = message,
47
+ attachments = message.attachments ,
46
48
associateDataToCid = { oldAttachment ->
47
49
val newAttachment = attachmentsToForward.find { it.originalContentId == oldAttachment.contentId }
48
50
newAttachment?.contentId
49
51
},
50
- applyAssociatedDataToImage = { newContentId, imageElement ->
52
+ onCidImageFound = { newContentId, imageElement ->
51
53
imageElement.attr(SRC_ATTRIBUTE , " ${CID_PROTOCOL }$newContentId " )
52
54
},
53
55
)
@@ -66,9 +68,9 @@ class ReplyForwardFooterManager @Inject constructor(private val appContext: Cont
66
68
67
69
val previousBody = getHtmlDocument(message)?.let { document ->
68
70
document.processCids(
69
- message = message,
71
+ attachments = message.attachments ,
70
72
associateDataToCid = Attachment ::name,
71
- applyAssociatedDataToImage = { name, imageElement ->
73
+ onCidImageFound = { name, imageElement ->
72
74
imageElement.replaceWith(TextNode (" <$name >" ))
73
75
},
74
76
)
@@ -80,22 +82,6 @@ class ReplyForwardFooterManager @Inject constructor(private val appContext: Cont
80
82
return assembleReplyHtmlFooter(messageReplyHeader, previousFullBody)
81
83
}
82
84
83
- private fun Document.processCids (
84
- message : Message ,
85
- associateDataToCid : (Attachment ) -> String? ,
86
- applyAssociatedDataToImage : (String , Element ) -> Unit
87
- ) {
88
- val attachmentsMap = message.attachments.associate {
89
- it.contentId to associateDataToCid(it)
90
- }
91
-
92
- doOnHtmlImage { imageElement ->
93
- attachmentsMap[getCid(imageElement)]?.let { associatedData ->
94
- applyAssociatedDataToImage(associatedData, imageElement)
95
- }
96
- }
97
- }
98
-
99
85
private fun Message.fromName (): String = sender?.quotedDisplayName() ? : appContext.getString(R .string.unknownRecipientTitle)
100
86
101
87
private fun getHtmlDocument (message : Message ): Document ? {
@@ -109,11 +95,6 @@ class ReplyForwardFooterManager @Inject constructor(private val appContext: Cont
109
95
return html?.let (::jsoupParseWithLog)
110
96
}
111
97
112
- private fun Document.doOnHtmlImage (actionOnImage : (Element ) -> Unit ) {
113
- select(CID_IMAGE_CSS_QUERY ).forEach { imageElement -> actionOnImage(imageElement) }
114
- }
115
-
116
- private fun getCid (imageElement : Element ) = imageElement.attr(SRC_ATTRIBUTE ).removePrefix(CID_PROTOCOL )
117
98
118
99
private fun computePreviousFullBody (previousBody : String , message : Message ): String {
119
100
return message.body?.let { body ->
@@ -187,10 +168,4 @@ class ReplyForwardFooterManager @Inject constructor(private val appContext: Cont
187
168
private fun formatRecipientList (recipientList : List <Recipient >): String? {
188
169
return if (recipientList.isNotEmpty()) recipientList.joinToString { it.quotedDisplayName() } else null
189
170
}
190
-
191
- companion object {
192
- private const val CID_PROTOCOL = " ${MessageWebViewClient .CID_SCHEME } :"
193
- private const val SRC_ATTRIBUTE = " src"
194
- private const val CID_IMAGE_CSS_QUERY = " img[${SRC_ATTRIBUTE } ^='${CID_PROTOCOL } ']"
195
- }
196
171
}
0 commit comments