summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-07-24 20:31:00 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-07-24 20:31:00 +0200
commit5623e4af5c2eb7a26516e21920af1fb5ae2a5be2 (patch)
tree54fd91860d03514bfc0dac903732081a184c7216
parenta115a705984ff69394ad3ed167ee280d9d5eb43c (diff)
Use placeholder string if fetching header value fails
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/maillist_view.rs41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/maillist_view.rs b/src/maillist_view.rs
index 00ba7e0..aaf36c4 100644
--- a/src/maillist_view.rs
+++ b/src/maillist_view.rs
@@ -15,6 +15,8 @@ use cursive::views::ResizedView;
use cursive_table_view::TableView;
use cursive_table_view::TableViewItem;
use chrono::naive::NaiveDateTime;
+use notmuch::Message;
+use notmuch::MessageOwner;
pub struct MaillistView(TableView<MailListingData, MailListingColumn>);
@@ -22,6 +24,18 @@ impl MaillistView {
pub fn create_for(database_path: &PathBuf, query: &str, name: String) -> Result<Self> {
debug!("Getting '{}' from '{}'", query, database_path.display());
+ fn get_header_field_save<'o, O: MessageOwner + 'o>(msg: &Message<'o, O>, field: &str) -> String {
+ match msg.header(field) {
+ Err(e) => {
+ error!("Failed getting '{}' of '{}': {}", field, msg.id(), e);
+ String::from("---")
+ },
+
+ Ok(None) => format!("No Value for {}", field),
+ Ok(Some(f)) => f.to_string(),
+ }
+ }
+
let items = notmuch::Database::open(database_path, notmuch::DatabaseMode::ReadOnly)
.context(format!("Opening database {}", database_path.display()))?
.create_query(query)
@@ -39,30 +53,9 @@ impl MaillistView {
})
.context(format!("Getting the date of message {}", msg.id()))?;
- let from = msg.header("From")
- .context(format!("Reading Header field 'From' of {}", msg.id()))?
- .map(|f| f.to_string())
- .ok_or_else(|| {
- error!("Failed to get From for {}", msg.id());
- anyhow!("Failed to get From for {}", msg.id())
- })
- .context(format!("Getting the 'From' of message {}", msg.id()))?;
-
- let to = msg.header("To")
- .context(format!("Reading Header field 'To' of {}", msg.id()))?
- .map(|c| c.to_string())
- .unwrap_or_else(|| {
- error!("Failed to get 'To:' field for {}, using default ''", msg.id());
- String::from("")
- });
- let subject = msg.header("Subject")
- .context(format!("Reading Header field 'Subject' of {}", msg.id()))?
- .map(|s| s.to_string())
- .ok_or_else(|| {
- error!("Failed to get Subject for {}", msg.id());
- anyhow!("Failed to get Subject for {}", msg.id())
- })
- .context(format!("Getting the subject of message {}", msg.id()))?;
+ let from = get_header_field_save(&msg, "From");
+ let to = get_header_field_save(&msg, "To");
+ let subject = get_header_field_save(&msg, "Subject");
Ok(MailListingData {
mail_id,