summaryrefslogtreecommitdiffstats
path: root/ui/src/components
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-12-18 15:46:21 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-12-18 15:46:21 +0200
commit0739f80f4ba2b61eb0ce508446d0b68dcb6b869b (patch)
tree6ec04223db571056dea158ba79cbca0d0bdd60b9 /ui/src/components
parent92826f982f795d0a61fa0807c5205437c5d826f5 (diff)
ui/MailView: print attachment tree instead of list
Diffstat (limited to 'ui/src/components')
-rw-r--r--ui/src/components/mail/view.rs68
1 files changed, 60 insertions, 8 deletions
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index f8d11998..874a3906 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -219,14 +219,66 @@ impl MailView {
let mut t = body_text.to_string();
t.push('\n');
if body.count_attachments() > 1 {
- t = body
- .attachments()
- .iter()
- .enumerate()
- .fold(t, |mut s, (idx, a)| {
- s.push_str(&format!("\n[{}] {}\n", idx, a));
- s
- });
+ fn attachment_tree(
+ (idx, (depth, att)): (&mut usize, (usize, &Attachment)),
+ branches: &mut StackVec<bool>,
+ has_sibling: bool,
+ s: &mut String,
+ ) {
+ s.extend(format!("\n[{}]", idx).chars());
+ for &b in branches.iter() {
+ if b {
+ s.push('|');
+ } else {
+ s.push(' ');
+ }
+ s.push(' ');
+ }
+ if depth > 0 {
+ if has_sibling {
+ s.push('|');
+ } else {
+ s.push(' ');
+ }
+ s.push('\\');
+ s.push(' ');
+ } else {
+ if has_sibling {
+ s.push('|');
+ s.push('\\');
+ } else {
+ s.push(' ');
+ }
+ s.push(' ');
+ }
+
+ s.extend(att.to_string().chars());
+ match att.content_type {
+ ContentType::Multipart {
+ parts: ref sub_att_vec,
+ ..
+ } => {
+ let mut iter = (0..sub_att_vec.len()).peekable();
+ if has_sibling {
+ branches.push(true);
+ } else {
+ branches.push(false);
+ }
+ while let Some(i) = iter.next() {
+ *idx += 1;
+ attachment_tree(
+ (idx, (depth + 1, &sub_att_vec[i])),
+ branches,
+ !(iter.peek() == None),
+ s,
+ );
+ }
+ branches.pop();
+ }
+ _ => {}
+ }
+ }
+ attachment_tree((&mut 0, (0, &body)), &mut StackVec::new(), false, &mut t);
}
t
}