show email addr when name not available (#131)

This commit is contained in:
Clément DOUIN 2021-04-27 18:10:18 +02:00
parent 754d311a05
commit 950e57acdb
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
2 changed files with 19 additions and 3 deletions

View file

@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Output redirected to `stderr` [#130]
- Refactor table system [#132]
- Editon file format on Linux [#133]
- Show email address when name not available [#131]
## [0.2.6] - 2021-04-17
@ -211,5 +212,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#125]: https://github.com/soywod/himalaya/issues/125
[#126]: https://github.com/soywod/himalaya/issues/126
[#130]: https://github.com/soywod/himalaya/issues/130
[#131]: https://github.com/soywod/himalaya/issues/131
[#132]: https://github.com/soywod/himalaya/issues/132
[#133]: https://github.com/soywod/himalaya/issues/133

View file

@ -262,9 +262,23 @@ impl<'m> From<&'m imap::types::Fetch> for Msg<'m> {
sender: envelope
.from
.as_ref()
.and_then(|addrs| addrs.first()?.name)
.and_then(|name| rfc2047_decoder::decode(name).ok())
.unwrap_or_default(),
.and_then(|addrs| addrs.first())
.and_then(|addr| {
addr.name
.and_then(|name| rfc2047_decoder::decode(name).ok())
.or_else(|| {
let mbox = addr
.mailbox
.and_then(|mbox| String::from_utf8(mbox.to_vec()).ok())
.unwrap_or(String::from("unknown"));
let host = addr
.host
.and_then(|host| String::from_utf8(host.to_vec()).ok())
.unwrap_or(String::from("unknown"));
Some(format!("{}@{}", mbox, host))
})
})
.unwrap_or(String::from("unknown")),
date: fetch
.internal_date()
.map(|date| date.naive_local().to_string())