From bf56c88918d42d6d1c33c0deb7df0ca32b4956e1 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 24 Nov 2020 10:33:20 +0200 Subject: [PATCH] compose: respect auto_choose_multipart_alternative when rendering multipart/alternative attachments to text --- src/components/mail/view.rs | 39 ++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/components/mail/view.rs b/src/components/mail/view.rs index 4f72e8a46..145142165 100644 --- a/src/components/mail/view.rs +++ b/src/components/mail/view.rs @@ -688,11 +688,40 @@ impl MailView { parts.iter().position(|a| a.content_type == "text/plain") { let bytes = decode(&parts[text_attachment_pos], None); - acc.push(AttachmentDisplay::InlineText { - inner: a.clone(), - comment: None, - text: String::from_utf8_lossy(&bytes).to_string(), - }); + if bytes.trim().is_empty() + && mailbox_settings!( + context[coordinates.0][&coordinates.1] + .pager + .auto_choose_multipart_alternative + ) + .is_true() + { + if let Some(text_attachment_pos) = + parts.iter().position(|a| a.content_type == "text/html") + { + /* Select html alternative since text/plain is empty */ + rec( + &parts[text_attachment_pos], + context, + coordinates, + acc, + active_jobs, + ); + } else { + for a in parts { + rec(a, context, coordinates, acc, active_jobs); + } + } + } else { + /* Select text/plain alternative */ + rec( + &parts[text_attachment_pos], + context, + coordinates, + acc, + active_jobs, + ); + } } else { for a in parts { rec(a, context, coordinates, acc, active_jobs);