melib/notmuch: add sent_mailbox_path conf setting

Where to store sent e-mail in the filesystem.
issue-133
Manos Pitsidianakis 2022-09-25 16:10:57 +03:00
parent 000b8feb90
commit 812533fe2e
2 changed files with 31 additions and 2 deletions

View File

@ -199,11 +199,19 @@ property to each of them.
.It Ic library_file_path Ar Path .It Ic library_file_path Ar Path
Use an arbitrary location of libnotmuch by specifying its full filesystem path. Use an arbitrary location of libnotmuch by specifying its full filesystem path.
.Pq Em optional .Pq Em optional
.It Ic sent_mailbox_path Ar Path
Where to store sent e-mail in the filesystem.
Defaults to
.Ic root_mailbox Ns
\&.
.Pq Em optional
.El .El
Example: Example:
.Bd -literal .Bd -literal
[accounts.notmuch] [accounts.notmuch]
root_mailbox = "/path/to/notmuch/folder"
format = "notmuch" format = "notmuch"
sent_mailbox_path = "/path/to/notmuch/folder/Sent/cur"
#library_file_path = "/opt/homebrew/lib/libnotmuch.5.dylib" #library_file_path = "/opt/homebrew/lib/libnotmuch.5.dylib"
\&... \&...
[accounts.notmuch.mailboxes] [accounts.notmuch.mailboxes]

View File

@ -490,6 +490,18 @@ impl NotmuchDb {
.set_kind(ErrorKind::Configuration)); .set_kind(ErrorKind::Configuration));
} }
} }
let save_messages_to = if let Some(sent_path) = s.extra.get("sent_mailbox_path") {
if !Path::new(&sent_path).exists() || !Path::new(&sent_path).is_dir() {
return Err(MeliError::new(format!(
"Notmuch `sent_mailbox_path` setting value `{}` for account {} does not exist or is not a directory.",
&sent_path,
s.name()
)).set_kind(ErrorKind::Configuration));
}
Some(Path::new(&sent_path).to_path_buf())
} else {
None
};
let account_hash = { let account_hash = {
let mut hasher = DefaultHasher::new(); let mut hasher = DefaultHasher::new();
@ -509,7 +521,7 @@ impl NotmuchDb {
account_name: account_name.clone(), account_name: account_name.clone(),
account_hash, account_hash,
event_consumer: event_consumer.clone(), event_consumer: event_consumer.clone(),
save_messages_to: None, save_messages_to: save_messages_to.clone(),
}); });
Ok(Box::new(NotmuchDb { Ok(Box::new(NotmuchDb {
lib, lib,
@ -519,7 +531,7 @@ impl NotmuchDb {
account_name, account_name,
account_hash, account_hash,
event_consumer, event_consumer,
save_messages_to: None, save_messages_to,
})) }))
} }
@ -571,6 +583,15 @@ impl NotmuchDb {
.set_kind(ErrorKind::Configuration)); .set_kind(ErrorKind::Configuration));
} }
} }
if let Some(sent_path) = s.extra.remove("sent_mailbox_path") {
if !Path::new(&sent_path).exists() || !Path::new(&sent_path).is_dir() {
return Err(MeliError::new(format!(
"Notmuch `sent_mailbox_path` setting value `{}` for account {} does not exist or is not a directory.",
&sent_path,
s.name()
)).set_kind(ErrorKind::Configuration));
}
}
Ok(()) Ok(())
} }