diff --git a/melib/src/backends/maildir/backend.rs b/melib/src/backends/maildir/backend.rs index b30848df..1072b72b 100644 --- a/melib/src/backends/maildir/backend.rs +++ b/melib/src/backends/maildir/backend.rs @@ -1012,6 +1012,16 @@ impl MaildirType { } pub fn save_to_mailbox(mut path: PathBuf, bytes: &[u8], flags: Option) -> Result<()> { + for d in &["cur", "new", "tmp"] { + path.push(d); + if !path.is_dir() { + return Err(MeliError::new(format!( + "{} is not a valid maildir mailbox", + path.display() + ))); + } + path.pop(); + } path.push("cur"); { let mut rand_buf = [0u8; 16]; diff --git a/melib/src/backends/notmuch.rs b/melib/src/backends/notmuch.rs index 858b048b..b960afc1 100644 --- a/melib/src/backends/notmuch.rs +++ b/melib/src/backends/notmuch.rs @@ -448,24 +448,11 @@ impl MailBackend for NotmuchDb { } fn save(&self, bytes: &[u8], _mailbox: &str, flags: Option) -> Result<()> { - let mut path = self + let path = self .save_messages_to .as_ref() .unwrap_or(&self.path) .to_path_buf(); - if !(path.ends_with("cur") || path.ends_with("new") || path.ends_with("tmp")) { - for d in &["cur", "new", "tmp"] { - path.push(d); - if !path.is_dir() { - return Err(MeliError::new(format!( - "{} is not a valid maildir mailbox", - path.display() - ))); - } - path.pop(); - } - path.push("cur"); - } crate::backends::MaildirType::save_to_mailbox(path, bytes, flags) }