Browse Source

melib/email/address: return Option in get_display_name

master
Manos Pitsidianakis 2 years ago
parent
commit
d57dd9c98e
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 13
      melib/src/email/address.rs
  2. 4
      src/components/mail/view.rs

13
melib/src/email/address.rs

@ -87,8 +87,8 @@ impl PartialEq for MailboxAddress {
/// ```rust
/// let (rest_bytes, addr) = melib::email::parser::address::address("=?utf-8?q?J=C3=B6rg_Doe?= <joerg@example.com>".as_bytes()).unwrap();
/// assert!(rest_bytes.is_empty());
/// assert_eq!(addr.get_display_name(), "Jörg Doe");
/// assert_eq!(addr.get_email(), "joerg@example.com");
/// assert_eq!(addr.get_display_name(), Some("Jörg Doe".to_string()));
/// assert_eq!(addr.get_email(), "joerg@example.com".to_string());
/// ```
#[derive(Clone, Serialize, Deserialize)]
pub enum Address {
@ -167,10 +167,15 @@ impl Address {
/// │ │
/// address_spec address_spec
///```
pub fn get_display_name(&self) -> String {
match self {
pub fn get_display_name(&self) -> Option<String> {
let ret = match self {
Address::Mailbox(m) => m.display_name.display(&m.raw),
Address::Group(g) => g.display_name.display(&g.raw),
};
if ret.is_empty() {
None
} else {
Some(ret)
}
}

4
src/components/mail/view.rs

@ -1212,7 +1212,9 @@ impl Component for MailView {
for addr in envelope.from().iter().chain(envelope.to().iter()) {
let mut new_card: Card = Card::new();
new_card.set_email(addr.get_email());
new_card.set_name(addr.get_display_name());
if let Some(display_name) = addr.get_display_name() {
new_card.set_name(display_name);
}
entries.push((new_card, format!("{}", addr)));
}
drop(envelope);

Loading…
Cancel
Save