Skip to content

Commit

Permalink
fix: Truncate messages at 104_448 to prevent OOM error on SplitBody
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyDL-Infomaniak authored and KevinBoulongne committed Oct 22, 2024
1 parent e987197 commit 7518dcd
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ object MessageBodyUtils {

private const val QUOTE_DETECTION_TIMEOUT = 1_500L

private const val MESSAGE_LENGTH_LIMIT = 104_448

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 +72,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)
return@executeWithTimeoutOrDefault SplitBody(content)
}

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

0 comments on commit 7518dcd

Please sign in to comment.