@@ -230,7 +230,7 @@ class NewMessageViewModel @Inject constructor(
230
230
if (draft.identityId.isNullOrBlank()) {
231
231
draft.identityId = SignatureController .getDefaultSignatureWithFallback(realm, draftMode)?.id?.toString()
232
232
}
233
- if (draft.body.isNotEmpty()) splitSignatureAndQuoteFromBody(draft)
233
+ splitSignatureAndQuoteFromBody(draft)
234
234
}
235
235
}
236
236
@@ -274,8 +274,6 @@ class NewMessageViewModel @Inject constructor(
274
274
)
275
275
276
276
populateWithExternalMailDataIfNeeded(draft = this , intent)
277
-
278
- body = getWholeBody(" " , uiSignature, uiQuote)
279
277
}
280
278
281
279
private fun saveNavArgsToSavedState (localUuid : String ) {
@@ -287,9 +285,12 @@ class NewMessageViewModel @Inject constructor(
287
285
}
288
286
289
287
private fun splitSignatureAndQuoteFromBody (draft : Draft ) {
288
+ val remoteBody = draft.body
289
+ if (remoteBody.isEmpty()) return
290
+
290
291
val (body, signature, quote) = when (draft.mimeType) {
291
- Utils .TEXT_PLAIN -> Triple (BodyContentPayload (draft.body , BodyContentType .TEXT_PLAIN_WITHOUT_HTML ), null , null )
292
- Utils .TEXT_HTML -> splitSignatureAndQuoteFromHtml(draft )
292
+ Utils .TEXT_PLAIN -> Triple (BodyContentPayload (remoteBody , BodyContentType .TEXT_PLAIN_WITHOUT_HTML ), null , null )
293
+ Utils .TEXT_HTML -> splitSignatureAndQuoteFromHtml(remoteBody )
293
294
else -> error(" Cannot load an email which is not of type text/plain or text/html" )
294
295
}
295
296
@@ -300,7 +301,7 @@ class NewMessageViewModel @Inject constructor(
300
301
}
301
302
}
302
303
303
- private fun splitSignatureAndQuoteFromHtml (draft : Draft ): Triple <BodyContentPayload , String ?, String ?> {
304
+ private fun splitSignatureAndQuoteFromHtml (draftBody : String ): Triple <BodyContentPayload , String ?, String ?> {
304
305
305
306
fun Document.split (divClassName : String , defaultValue : String ): Pair <String , String ?> {
306
307
return getElementsByClass(divClassName).firstOrNull()?.let {
@@ -316,12 +317,12 @@ class NewMessageViewModel @Inject constructor(
316
317
return if (index == - 1 ) Int .MAX_VALUE else index
317
318
}
318
319
319
- val doc = Jsoup .parse(draft.body ).also { it.outputSettings().prettyPrint(false ) }
320
+ val doc = Jsoup .parse(draftBody ).also { it.outputSettings().prettyPrint(false ) }
320
321
321
- val (bodyWithQuote, signature) = doc.split(MessageBodyUtils .INFOMANIAK_SIGNATURE_HTML_CLASS_NAME , draft.body )
322
+ val (bodyWithQuote, signature) = doc.split(MessageBodyUtils .INFOMANIAK_SIGNATURE_HTML_CLASS_NAME , draftBody )
322
323
323
- val replyPosition = draft.body .lastIndexOfOrMax(MessageBodyUtils .INFOMANIAK_REPLY_QUOTE_HTML_CLASS_NAME )
324
- val forwardPosition = draft.body .lastIndexOfOrMax(MessageBodyUtils .INFOMANIAK_FORWARD_QUOTE_HTML_CLASS_NAME )
324
+ val replyPosition = draftBody .lastIndexOfOrMax(MessageBodyUtils .INFOMANIAK_REPLY_QUOTE_HTML_CLASS_NAME )
325
+ val forwardPosition = draftBody .lastIndexOfOrMax(MessageBodyUtils .INFOMANIAK_FORWARD_QUOTE_HTML_CLASS_NAME )
325
326
val (body, quote) = if (replyPosition < forwardPosition) {
326
327
doc.split(MessageBodyUtils .INFOMANIAK_REPLY_QUOTE_HTML_CLASS_NAME , bodyWithQuote)
327
328
} else {
@@ -845,7 +846,7 @@ class NewMessageViewModel @Inject constructor(
845
846
846
847
val signature = uiSignatureLiveData.value
847
848
val quote = uiQuoteLiveData.value
848
- body = getWholeBody (uiBodyValue, signature, quote)
849
+ body = assembleWholeBody (uiBodyValue, signature, quote)
849
850
850
851
/* *
851
852
* If we are opening for the 1st time an existing Draft created somewhere else
@@ -907,7 +908,8 @@ class NewMessageViewModel @Inject constructor(
907
908
}
908
909
}
909
910
910
- private fun getWholeBody (body : String , signature : String? , quote : String? ): String = body + (signature ? : " " ) + (quote ? : " " )
911
+ private fun assembleWholeBody (body : String , signature : String? , quote : String? ): String =
912
+ body + (signature ? : " " ) + (quote ? : " " )
911
913
912
914
private fun isSnapshotTheSame (subjectValue : String? , uiBodyValue : String ): Boolean {
913
915
return snapshot?.let { draftSnapshot ->
0 commit comments