Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate messages at 104_448 to prevent OOM error on SplitBody #2082

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/src/main/java/com/infomaniak/mail/utils/MessageBodyUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ object MessageBodyUtils {

private const val QUOTE_DETECTION_TIMEOUT = 1_500L

// Arbitrary maximum length that a Message's body can reach without provoking
// a crash when opened in a Thread with other equally long Messages.
private const val MESSAGE_LENGTH_LIMIT = 104_448
TommyDL-Infomaniak marked this conversation as resolved.
Show resolved Hide resolved

private val quoteDescriptors = arrayOf(
"blockquote[type=cite]", // macOS and iOS mail client
// The reply and forward #divRplyFwdMsg div only contains the header, the previous message body is written right next to
Expand Down Expand Up @@ -70,6 +74,12 @@ object MessageBodyUtils {
block = {
// Do not nest jsoupParseWithLog and measureAndLogMemoryUsage so logs are independent from one another
val htmlDocument = jsoupParseWithLog(bodyContent)

if (htmlDocument.text().length > MESSAGE_LENGTH_LIMIT) {
val content = bodyContent.substring(0, MESSAGE_LENGTH_LIMIT)
TommyDL-Infomaniak marked this conversation as resolved.
Show resolved Hide resolved
return@executeWithTimeoutOrDefault SplitBody(content)
}

val (content, quotes) = measureAndLogMemoryUsage(
tag = "Split signature and quote memory usage",
actionName = "splitting",
Expand Down
Loading