Skip to content

Commit

Permalink
Merge pull request #759 from Infomaniak/largeComplexMailSlowToDisplay
Browse files Browse the repository at this point in the history
Large complex mails are slow to display
  • Loading branch information
Ambrdctr committed May 25, 2023
2 parents 07a49f5 + 8c1e922 commit c0b0524
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Mail/Views/Thread/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CocoaLumberjackSwift
import InfomaniakCore
import InfomaniakCoreUI
import InfomaniakDI
Expand Down Expand Up @@ -92,11 +93,29 @@ struct MessageView: View {
private func prepareBody() {
guard let messageBody = message.body else { return }
presentableBody.body = messageBody.detached()
let bodyValue = messageBody.value ?? ""

// Heuristic to give up on mail too large for "perfect" preprocessing.
// 5 Meg looks like a fine threshold
guard bodyValue.lengthOfBytes(using: String.Encoding.utf8) < 5_000_000 else {
DDLogInfo("give up on processing, file too large")
mutate(compactBody: bodyValue, quote: nil)
return
}

Task.detached {
guard let messageBodyQuote = MessageBodyUtils.splitBodyAndQuote(messageBody: bodyValue) else {
return
}

await mutate(compactBody: messageBodyQuote.messageBody, quote: messageBodyQuote.quote)
}
}

guard let messageBodyQuote = MessageBodyUtils.splitBodyAndQuote(messageBody: messageBody.value ?? "")
else { return }
presentableBody.compactBody = messageBodyQuote.messageBody
presentableBody.quote = messageBodyQuote.quote
/// Update the DOM in the main thread
@MainActor func mutate(compactBody: String?, quote: String?) {
presentableBody.compactBody = compactBody
presentableBody.quote = quote
}

private func insertInlineAttachments() async throws {
Expand Down

0 comments on commit c0b0524

Please sign in to comment.