Skip to content

Commit e032acf

Browse files
committed
view: pass filtered body to Composer as reply text
When replying to an e-mail, pass the filtered e-mail text to the composer. This way, processed text like decrypted PGP e-mail is shown in the reply context of a reply as the user expects. Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent e0cfe8e commit e032acf

File tree

2 files changed

+31
-144
lines changed

2 files changed

+31
-144
lines changed

meli/src/mail/view.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use std::{
2323
collections::HashSet,
2424
convert::TryFrom,
25-
fmt::Write as _,
2625
io::Write,
2726
process::{Command, Stdio},
2827
};
@@ -199,25 +198,27 @@ impl MailView {
199198
ref env,
200199
ref env_view,
201200
..
202-
} => (
203-
bytes,
204-
EnvelopeView::attachment_displays_to_text(&env_view.display, false),
205-
env,
206-
),
201+
} => (bytes, env_view.body_text(), env),
207202
MailViewState::Error { .. } => {
208203
return;
209204
}
210205
};
211206
let composer = match action {
212-
PendingReplyAction::Reply => {
213-
Box::new(Composer::reply_to_select(coordinates, reply_body, context))
214-
}
215-
PendingReplyAction::ReplyToAuthor => {
216-
Box::new(Composer::reply_to_author(coordinates, reply_body, context))
217-
}
218-
PendingReplyAction::ReplyToAll => {
219-
Box::new(Composer::reply_to_all(coordinates, reply_body, context))
220-
}
207+
PendingReplyAction::Reply => Box::new(Composer::reply_to_select(
208+
coordinates,
209+
reply_body.to_string(),
210+
context,
211+
)),
212+
PendingReplyAction::ReplyToAuthor => Box::new(Composer::reply_to_author(
213+
coordinates,
214+
reply_body.to_string(),
215+
context,
216+
)),
217+
PendingReplyAction::ReplyToAll => Box::new(Composer::reply_to_all(
218+
coordinates,
219+
reply_body.to_string(),
220+
context,
221+
)),
221222
PendingReplyAction::ForwardAttachment => {
222223
Box::new(Composer::forward(coordinates, bytes, env, true, context))
223224
}

meli/src/mail/view/envelope.rs

Lines changed: 15 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -379,125 +379,6 @@ impl EnvelopeView {
379379
self.display = display;
380380
self.attachment_tree = attachment_tree;
381381
self.attachment_paths = attachment_paths;
382-
self.regenerate_body_text();
383-
}
384-
385-
pub fn regenerate_body_text(&mut self) {
386-
self.body_text = Self::attachment_displays_to_text(&self.display, true);
387-
}
388-
389-
pub fn attachment_displays_to_text(
390-
displays: &[AttachmentDisplay],
391-
show_comments: bool,
392-
) -> String {
393-
let mut acc = String::new();
394-
for d in displays {
395-
use AttachmentDisplay::*;
396-
match d {
397-
Alternative {
398-
inner: _,
399-
shown_display,
400-
display,
401-
} => {
402-
acc.push_str(&Self::attachment_displays_to_text(
403-
&display[*shown_display..(*shown_display + 1)],
404-
show_comments,
405-
));
406-
}
407-
InlineText {
408-
inner: _,
409-
text,
410-
comment: Some(comment),
411-
} if show_comments => {
412-
acc.push_str(comment);
413-
if !acc.ends_with("\n\n") {
414-
acc.push_str("\n\n");
415-
}
416-
acc.push_str(text);
417-
}
418-
InlineText {
419-
inner: _,
420-
text,
421-
comment: _,
422-
} => acc.push_str(text),
423-
InlineOther { inner } => {
424-
if !acc.ends_with("\n\n") {
425-
acc.push_str("\n\n");
426-
}
427-
acc.push_str(&inner.to_string());
428-
if !acc.ends_with("\n\n") {
429-
acc.push_str("\n\n");
430-
}
431-
}
432-
Attachment { inner: _ } => {}
433-
SignedPending {
434-
inner: _,
435-
display,
436-
handle: _,
437-
job_id: _,
438-
} => {
439-
if show_comments {
440-
acc.push_str("Waiting for signature verification.\n\n");
441-
}
442-
acc.push_str(&Self::attachment_displays_to_text(display, show_comments));
443-
}
444-
SignedUnverified { inner: _, display } => {
445-
if show_comments {
446-
acc.push_str("Unverified signature.\n\n");
447-
}
448-
acc.push_str(&Self::attachment_displays_to_text(display, show_comments))
449-
}
450-
SignedFailed {
451-
inner: _,
452-
display,
453-
error,
454-
} => {
455-
if show_comments {
456-
let _ = writeln!(acc, "Failed to verify signature: {}.\n", error);
457-
}
458-
acc.push_str(&Self::attachment_displays_to_text(display, show_comments));
459-
}
460-
SignedVerified {
461-
inner: _,
462-
display,
463-
description,
464-
} => {
465-
if show_comments {
466-
if description.is_empty() {
467-
acc.push_str("Verified signature.\n\n");
468-
} else {
469-
acc.push_str(description);
470-
acc.push_str("\n\n");
471-
}
472-
}
473-
acc.push_str(&Self::attachment_displays_to_text(display, show_comments));
474-
}
475-
EncryptedPending { .. } => acc.push_str("Waiting for decryption result."),
476-
EncryptedFailed { inner: _, error } => {
477-
let _ = write!(acc, "Decryption failed: {}.", &error);
478-
}
479-
EncryptedSuccess {
480-
inner: _,
481-
plaintext: _,
482-
plaintext_display,
483-
description,
484-
} => {
485-
if show_comments {
486-
if description.is_empty() {
487-
acc.push_str("Successfully decrypted.\n\n");
488-
} else {
489-
acc.push_str(description);
490-
acc.push_str("\n\n");
491-
}
492-
}
493-
acc.push_str(&Self::attachment_displays_to_text(
494-
plaintext_display,
495-
show_comments,
496-
));
497-
}
498-
}
499-
}
500-
acc
501382
}
502383

503384
fn attachment_displays_to_tree(
@@ -720,6 +601,10 @@ impl EnvelopeView {
720601
))));
721602
None
722603
}
604+
605+
pub fn body_text(&self) -> &str {
606+
&self.body_text
607+
}
723608
}
724609

725610
impl Component for EnvelopeView {
@@ -1030,7 +915,7 @@ impl Component for EnvelopeView {
1030915
}
1031916
};
1032917

1033-
if self.filters.is_empty() || self.body_text.is_empty() {
918+
if self.filters.is_empty() {
1034919
let body = self.mail.body();
1035920
if body.is_html() {
1036921
let attachment = if let Some(sub) = match body.content_type {
@@ -1081,15 +966,12 @@ impl Component for EnvelopeView {
1081966
{
1082967
self.filters.push(filter);
1083968
}
1084-
self.body_text = String::from_utf8_lossy(
1085-
&body.decode(Option::<Charset>::from(&self.force_charset).into()),
1086-
)
1087-
.to_string();
1088969
}
1089970
if !self.initialised {
1090971
self.initialised = true;
1091972
let mut text = if !self.filters.is_empty() {
1092973
let mut text = String::new();
974+
self.body_text.clear();
1093975
if let Some(last) = self.filters.last() {
1094976
let mut stack = vec![last];
1095977
while let Some(ViewFilter {
@@ -1115,10 +997,16 @@ impl Component for EnvelopeView {
1115997
if !text.is_empty() {
1116998
text.push('\n');
1117999
}
1000+
if !self.body_text.is_empty() {
1001+
self.body_text.push('\n');
1002+
}
11181003
match body_text {
1119-
ViewFilterContent::Filtered { inner } => text.push_str(
1120-
&self.options.convert(&mut self.links, &self.body, inner),
1121-
),
1004+
ViewFilterContent::Filtered { inner } => {
1005+
let payload =
1006+
self.options.convert(&mut self.links, &self.body, inner);
1007+
text.push_str(&payload);
1008+
self.body_text.push_str(&payload);
1009+
}
11221010
ViewFilterContent::Error { inner } => text.push_str(&inner.to_string()),
11231011
ViewFilterContent::Running { .. } => {
11241012
text.push_str("Filter job running in background.")
@@ -1318,7 +1206,6 @@ impl Component for EnvelopeView {
13181206
}
13191207
if caught {
13201208
self.links.clear();
1321-
self.regenerate_body_text();
13221209
self.initialised = false;
13231210
self.set_dirty(true);
13241211
}
@@ -1346,7 +1233,6 @@ impl Component for EnvelopeView {
13461233
}
13471234
}
13481235
self.links.clear();
1349-
self.regenerate_body_text();
13501236
self.initialised = false;
13511237
self.set_dirty(true);
13521238
}

0 commit comments

Comments
 (0)