Skip to content

Commit 26d33ce

Browse files
committed
address: add separator argument to display_slice()
Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent 394236b commit 26d33ce

File tree

7 files changed

+16
-49
lines changed

7 files changed

+16
-49
lines changed

meli/src/mail/listing/compact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ impl CompactListing {
10071007
context,
10081008
(self.cursor_pos.0, self.cursor_pos.1),
10091009
),
1010-
from: FromString(Address::display_name_slice(from)),
1010+
from: FromString(Address::display_name_slice(from, None)),
10111011
tags: TagString(tags_string, colors),
10121012
unseen: thread.unseen() > 0,
10131013
highlight_self,

meli/src/mail/listing/conversations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ impl ConversationsListing {
770770
context,
771771
(self.cursor_pos.0, self.cursor_pos.1),
772772
),
773-
from: FromString(Address::display_name_slice(from)),
773+
from: FromString(Address::display_name_slice(from, None)),
774774
tags: TagString(tags_string, colors),
775775
unseen: thread.unseen() > 0,
776776
highlight_self: false,

meli/src/mail/listing/plain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl PlainListing {
707707
context,
708708
(self.cursor_pos.0, self.cursor_pos.1),
709709
),
710-
from: FromString(Address::display_name_slice(e.from())),
710+
from: FromString(Address::display_name_slice(e.from(), None)),
711711
tags: TagString(tags, colors),
712712
unseen: !e.is_seen(),
713713
highlight_self: false,

meli/src/mail/listing/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ impl ThreadListing {
895895
context,
896896
(self.cursor_pos.0, self.cursor_pos.1),
897897
),
898-
from: FromString(Address::display_name_slice(e.from())),
898+
from: FromString(Address::display_name_slice(e.from(), None)),
899899
tags: TagString(tags, colors),
900900
unseen: !e.is_seen(),
901901
highlight_self: false,

meli/src/mail/view/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl ThreadView {
325325
.collection
326326
.get_env(e.msg_hash);
327327
let thread_node = &threads.thread_nodes()[&e.index.1];
328-
let from = Address::display_name_slice(envelope.from());
328+
let from = Address::display_name_slice(envelope.from(), None);
329329
let date = timestamp_to_string(envelope.date(), Some("%Y-%m-%d %H:%M\0"), true);
330330
e.heading = if thread_node.show_subject() {
331331
let subject = envelope.subject();

melib/src/email.rs

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -505,27 +505,15 @@ impl Envelope {
505505
.unwrap_or_default()
506506
.to_string()
507507
} else {
508-
self.bcc.iter().fold(String::new(), |mut acc, x| {
509-
if !acc.is_empty() {
510-
acc.push_str(", ");
511-
}
512-
acc.push_str(&x.to_string());
513-
acc
514-
})
508+
Address::display_slice(self.bcc(), None)
515509
}
516510
}
517511

518512
pub fn field_cc_to_string(&self) -> String {
519513
if self.cc.is_empty() {
520514
self.other_headers.get("Cc").unwrap_or_default().to_string()
521515
} else {
522-
self.cc.iter().fold(String::new(), |mut acc, x| {
523-
if !acc.is_empty() {
524-
acc.push_str(", ");
525-
}
526-
acc.push_str(&x.to_string());
527-
acc
528-
})
516+
Address::display_slice(self.cc(), None)
529517
}
530518
}
531519

@@ -536,13 +524,7 @@ impl Envelope {
536524
.unwrap_or_default()
537525
.to_string()
538526
} else {
539-
self.from.iter().fold(String::new(), |mut acc, x| {
540-
if !acc.is_empty() {
541-
acc.push_str(", ");
542-
}
543-
acc.push_str(&x.to_string());
544-
acc
545-
})
527+
Address::display_slice(self.from(), None)
546528
}
547529
}
548530

@@ -562,16 +544,7 @@ impl Envelope {
562544
if self.to.is_empty() {
563545
self.other_headers.get("To").unwrap_or_default().to_string()
564546
} else {
565-
self.to
566-
.iter()
567-
.map(|a| format!("{}", a))
568-
.fold(String::new(), |mut acc, x| {
569-
if !acc.is_empty() {
570-
acc.push_str(", ");
571-
}
572-
acc.push_str(&x);
573-
acc
574-
})
547+
Address::display_slice(self.to(), None)
575548
}
576549
}
577550

@@ -583,15 +556,7 @@ impl Envelope {
583556
.unwrap_or_default()
584557
.to_string()
585558
} else {
586-
refs.iter()
587-
.map(|a| a.to_string())
588-
.fold(String::new(), |mut acc, x| {
589-
if !acc.is_empty() {
590-
acc.push_str(", ");
591-
}
592-
acc.push_str(&x);
593-
acc
594-
})
559+
MessageID::display_slice(refs, Some("\n "))
595560
}
596561
}
597562

melib/src/email/address.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,29 +357,31 @@ impl Address {
357357

358358
/// Formats a slice of `Address`es with their `Address::display` method,
359359
/// separated by comma or `separator` if passed.
360-
pub fn display_slice(slice: &[Self]) -> String {
360+
pub fn display_slice(slice: &[Self], separator: Option<&str>) -> String {
361+
let separator = separator.unwrap_or(", ");
361362
match slice.first() {
362363
None => String::new(),
363364
Some(f) if slice.len() == 1 => f.display().to_string(),
364365
Some(_) => slice
365366
.iter()
366367
.map(|a| a.display().to_string())
367368
.collect::<Vec<String>>()
368-
.join(", "),
369+
.join(separator),
369370
}
370371
}
371372

372373
/// Formats a slice of `Address`es with their `Address::display_name`
373374
/// method, separated by comma or `separator` if passed.
374-
pub fn display_name_slice(slice: &[Self]) -> String {
375+
pub fn display_name_slice(slice: &[Self], separator: Option<&str>) -> String {
376+
let separator = separator.unwrap_or(", ");
375377
match slice.first() {
376378
None => String::new(),
377379
Some(f) if slice.len() == 1 => f.display_name().to_string(),
378380
Some(_) => slice
379381
.iter()
380382
.map(|a| a.display_name().to_string())
381383
.collect::<Vec<String>>()
382-
.join(", "),
384+
.join(separator),
383385
}
384386
}
385387
}

0 commit comments

Comments
 (0)