check for absolute and relative maildir paths

This commit is contained in:
Clément DOUIN 2022-03-09 09:48:23 +01:00
parent d79c6c40a7
commit 1f01202262
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
2 changed files with 13 additions and 10 deletions

View file

@ -47,13 +47,16 @@ impl<'a> MaildirBackend<'a> {
self.validate_mdir_path(self.mdir.path().to_owned())
.map(maildir::Maildir::from)
} else {
// If the dir is a valid maildir path, creates a maildir instance from it.
// If the dir is a valid maildir path, creates a maildir
// instance from it. Checks for absolute path first,
self.validate_mdir_path(dir.into())
// then for relative path,
.or_else(|_| self.validate_mdir_path(self.mdir.path().join(dir)))
.or_else(|_| {
// Otherwise creates a maildir instance from a
// otherwise creates a maildir instance from a
// maildir subdirectory by adding a "." in front
// of the name as described in the spec:
// https://cr.yp.to/proto/maildir.html
// https://cr.yp.to/proto/maildir.html.
let dir = self
.account_config
.mailboxes

View file

@ -5,7 +5,7 @@
use anyhow::{anyhow, Context, Error, Result};
use chrono::DateTime;
use log::{debug, info, trace};
use log::trace;
use std::{
convert::{TryFrom, TryInto},
ops::{Deref, DerefMut},
@ -125,7 +125,7 @@ impl<'a> TryFrom<RawMaildirEnvelope> for MaildirEnvelope {
type Error = Error;
fn try_from(mut mail_entry: RawMaildirEnvelope) -> Result<Self, Self::Error> {
info!("begin: try building envelope from maildir parsed mail");
trace!(">> build envelope from maildir parsed mail");
let mut envelope = Self::default();
@ -139,14 +139,14 @@ impl<'a> TryFrom<RawMaildirEnvelope> for MaildirEnvelope {
.parsed()
.context("cannot parse maildir mail entry")?;
debug!("begin: parse headers");
trace!(">> parse headers");
for h in parsed_mail.get_headers() {
let k = h.get_key();
debug!("header key: {:?}", k);
trace!("header key: {:?}", k);
let v = rfc2047_decoder::decode(h.get_value_raw())
.context(format!("cannot decode value from header {:?}", k))?;
debug!("header value: {:?}", v);
trace!("header value: {:?}", v);
match k.to_lowercase().as_str() {
"date" => {
@ -182,10 +182,10 @@ impl<'a> TryFrom<RawMaildirEnvelope> for MaildirEnvelope {
_ => (),
}
}
debug!("end: parse headers");
trace!("<< parse headers");
trace!("envelope: {:?}", envelope);
info!("end: try building envelope from maildir parsed mail");
trace!("<< build envelope from maildir parsed mail");
Ok(envelope)
}
}