fix comment typos in maildir backend

This commit is contained in:
Clément DOUIN 2022-02-28 23:20:09 +01:00
parent 526f344c7c
commit 328da34f8d
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72

View file

@ -1,3 +1,8 @@
//! Maildir backend module.
//!
//! This module contains the definition of the maildir backend and its
//! traits implementation.
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use log::{debug, info, trace}; use log::{debug, info, trace};
use std::{convert::TryInto, fs, path::PathBuf}; use std::{convert::TryInto, fs, path::PathBuf};
@ -82,49 +87,46 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
} }
fn get_mboxes(&mut self) -> Result<Box<dyn Mboxes>> { fn get_mboxes(&mut self) -> Result<Box<dyn Mboxes>> {
info!(">> get maildir subdirs"); info!(">> get maildir dirs");
let subdirs: MaildirMboxes = self.mdir.list_subdirs().try_into().context(format!( let dirs: MaildirMboxes = self.mdir.list_subdirs().try_into().context(format!(
"cannot parse maildir subdirs from {:?}", "cannot parse maildir dirs from {:?}",
self.mdir.path() self.mdir.path()
))?; ))?;
trace!("subdirs: {:?}", subdirs); trace!("dirs: {:?}", dirs);
info!("<< get maildir subdirs"); info!("<< get maildir dirs");
Ok(Box::new(subdirs)) Ok(Box::new(dirs))
} }
fn del_mbox(&mut self, subdir: &str) -> Result<()> { fn del_mbox(&mut self, dir: &str) -> Result<()> {
info!(">> delete maildir subdir"); info!(">> delete maildir dir");
debug!("subdir: {:?}", subdir); debug!("dir: {:?}", dir);
let path = self.mdir.path().join(format!(".{}", subdir)); let path = self.mdir.path().join(format!(".{}", dir));
trace!("subdir path: {:?}", path); trace!("dir path: {:?}", path);
fs::remove_dir_all(&path).context(format!( fs::remove_dir_all(&path)
"cannot delete maildir subdir {:?} from {:?}", .context(format!("cannot delete maildir {:?} from {:?}", dir, path))?;
subdir, path
))?;
info!("<< delete maildir subdir"); info!("<< delete maildir dir");
Ok(()) Ok(())
} }
fn get_envelopes( fn get_envelopes(
&mut self, &mut self,
subdir: &str, dir: &str,
page_size: usize, page_size: usize,
page: usize, page: usize,
) -> Result<Box<dyn Envelopes>> { ) -> Result<Box<dyn Envelopes>> {
info!(">> get maildir envelopes"); info!(">> get maildir envelopes");
debug!("maildir subdir: {:?}", subdir); debug!("dir: {:?}", dir);
debug!("page size: {:?}", page_size); debug!("page size: {:?}", page_size);
debug!("page: {:?}", page); debug!("page: {:?}", page);
let mdir = self.get_mdir_from_dir(subdir).context(format!( let mdir = self
"cannot get maildir instance from subdir {:?}", .get_mdir_from_dir(dir)
subdir .context(format!("cannot get maildir instance from {:?}", dir))?;
))?;
// Reads envelopes from the "cur" folder of the selected // Reads envelopes from the "cur" folder of the selected
// maildir. // maildir.
@ -178,7 +180,7 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
fn search_envelopes( fn search_envelopes(
&mut self, &mut self,
_subdir: &str, _dir: &str,
_query: &str, _query: &str,
_sort: &str, _sort: &str,
_page_size: usize, _page_size: usize,
@ -191,18 +193,17 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
)) ))
} }
fn add_msg(&mut self, subdir: &str, msg: &[u8], flags: &str) -> Result<Box<dyn ToString>> { fn add_msg(&mut self, dir: &str, msg: &[u8], flags: &str) -> Result<Box<dyn ToString>> {
info!(">> add maildir message"); info!(">> add maildir message");
debug!("subdir: {:?}", subdir); debug!("dir: {:?}", dir);
debug!("flags: {:?}", flags); debug!("flags: {:?}", flags);
let mdir = self.get_mdir_from_dir(subdir).context(format!( let mdir = self
"cannot get maildir instance from subdir {:?}", .get_mdir_from_dir(dir)
subdir .context(format!("cannot get maildir instance from {:?}", dir))?;
))?;
let flags: MaildirFlags = flags let flags: MaildirFlags = flags
.try_into() .try_into()
.context(format!("cannot parse flags {:?}", flags))?; .context(format!("cannot parse maildir flags {:?}", flags))?;
let id = mdir let id = mdir
.store_cur_with_flags(msg, &flags.to_string()) .store_cur_with_flags(msg, &flags.to_string())
.context(format!("cannot add maildir message to {:?}", mdir.path()))?; .context(format!("cannot add maildir message to {:?}", mdir.path()))?;
@ -226,15 +227,14 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
Ok(Box::new(hash)) Ok(Box::new(hash))
} }
fn get_msg(&mut self, subdir: &str, short_hash: &str) -> Result<Msg> { fn get_msg(&mut self, dir: &str, short_hash: &str) -> Result<Msg> {
info!(">> get maildir message"); info!(">> get maildir message");
debug!("subdir: {:?}", subdir); debug!("dir: {:?}", dir);
debug!("short hash: {:?}", short_hash); debug!("short hash: {:?}", short_hash);
let mdir = self.get_mdir_from_dir(subdir).context(format!( let mdir = self
"cannot get maildir instance from subdir {:?}", .get_mdir_from_dir(dir)
subdir .context(format!("cannot get maildir instance from {:?}", dir))?;
))?;
let id = IdMapper::new(mdir.path())? let id = IdMapper::new(mdir.path())?
.find(short_hash) .find(short_hash)
.context(format!( .context(format!(
@ -266,18 +266,18 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
Ok(msg) Ok(msg)
} }
fn copy_msg(&mut self, subdir_src: &str, subdir_dst: &str, short_hash: &str) -> Result<()> { fn copy_msg(&mut self, dir_src: &str, dir_dst: &str, short_hash: &str) -> Result<()> {
info!(">> copy maildir message"); info!(">> copy maildir message");
debug!("source subdir: {:?}", subdir_src); debug!("source dir: {:?}", dir_src);
debug!("destination subdir: {:?}", subdir_dst); debug!("destination dir: {:?}", dir_dst);
let mdir_src = self.get_mdir_from_dir(subdir_src).context(format!( let mdir_src = self.get_mdir_from_dir(dir_src).context(format!(
"cannot get source maildir instance from subdir {:?}", "cannot get source maildir instance from {:?}",
subdir_src dir_src
))?; ))?;
let mdir_dst = self.get_mdir_from_dir(subdir_dst).context(format!( let mdir_dst = self.get_mdir_from_dir(dir_dst).context(format!(
"cannot get destination maildir instance from subdir {:?}", "cannot get destination maildir instance from {:?}",
subdir_dst dir_dst
))?; ))?;
let id = IdMapper::new(mdir_src.path()) let id = IdMapper::new(mdir_src.path())
.context(format!( .context(format!(
@ -316,18 +316,18 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
Ok(()) Ok(())
} }
fn move_msg(&mut self, subdir_src: &str, subdir_dst: &str, short_hash: &str) -> Result<()> { fn move_msg(&mut self, dir_src: &str, dir_dst: &str, short_hash: &str) -> Result<()> {
info!(">> move maildir message"); info!(">> move maildir message");
debug!("source subdir: {:?}", subdir_src); debug!("source dir: {:?}", dir_src);
debug!("destination subdir: {:?}", subdir_dst); debug!("destination dir: {:?}", dir_dst);
let mdir_src = self.get_mdir_from_dir(subdir_src).context(format!( let mdir_src = self.get_mdir_from_dir(dir_src).context(format!(
"cannot get source maildir instance from subdir {:?}", "cannot get source maildir instance from {:?}",
subdir_src dir_src
))?; ))?;
let mdir_dst = self.get_mdir_from_dir(subdir_dst).context(format!( let mdir_dst = self.get_mdir_from_dir(dir_dst).context(format!(
"cannot get destination maildir instance from subdir {:?}", "cannot get destination maildir instance from {:?}",
subdir_dst dir_dst
))?; ))?;
let id = IdMapper::new(mdir_src.path()) let id = IdMapper::new(mdir_src.path())
.context(format!( .context(format!(
@ -366,15 +366,14 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
Ok(()) Ok(())
} }
fn del_msg(&mut self, subdir: &str, short_hash: &str) -> Result<()> { fn del_msg(&mut self, dir: &str, short_hash: &str) -> Result<()> {
info!(">> delete maildir message"); info!(">> delete maildir message");
debug!("subdir: {:?}", subdir); debug!("dir: {:?}", dir);
debug!("short hash: {:?}", short_hash); debug!("short hash: {:?}", short_hash);
let mdir = self.get_mdir_from_dir(subdir).context(format!( let mdir = self
"cannot get maildir instance from subdir {:?}", .get_mdir_from_dir(dir)
subdir .context(format!("cannot get maildir instance from {:?}", dir))?;
))?;
let id = IdMapper::new(mdir.path()) let id = IdMapper::new(mdir.path())
.context(format!( .context(format!(
"cannot create id mapper instance for {:?}", "cannot create id mapper instance for {:?}",
@ -397,16 +396,15 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
Ok(()) Ok(())
} }
fn add_flags(&mut self, subdir: &str, short_hash: &str, flags: &str) -> Result<()> { fn add_flags(&mut self, dir: &str, short_hash: &str, flags: &str) -> Result<()> {
info!(">> add maildir message flags"); info!(">> add maildir message flags");
debug!("subdir: {:?}", subdir); debug!("dir: {:?}", dir);
debug!("short hash: {:?}", short_hash); debug!("short hash: {:?}", short_hash);
debug!("flags: {:?}", flags); debug!("flags: {:?}", flags);
let mdir = self.get_mdir_from_dir(subdir).context(format!( let mdir = self
"cannot get maildir instance from subdir {:?}", .get_mdir_from_dir(dir)
subdir .context(format!("cannot get maildir instance from {:?}", dir))?;
))?;
let flags: MaildirFlags = flags let flags: MaildirFlags = flags
.try_into() .try_into()
.context(format!("cannot parse maildir flags {:?}", flags))?; .context(format!("cannot parse maildir flags {:?}", flags))?;
@ -432,16 +430,15 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
Ok(()) Ok(())
} }
fn set_flags(&mut self, subdir: &str, short_hash: &str, flags: &str) -> Result<()> { fn set_flags(&mut self, dir: &str, short_hash: &str, flags: &str) -> Result<()> {
info!(">> set maildir message flags"); info!(">> set maildir message flags");
debug!("subdir: {:?}", subdir); debug!("dir: {:?}", dir);
debug!("short hash: {:?}", short_hash); debug!("short hash: {:?}", short_hash);
debug!("flags: {:?}", flags); debug!("flags: {:?}", flags);
let mdir = self.get_mdir_from_dir(subdir).context(format!( let mdir = self
"cannot get maildir instance from subdir {:?}", .get_mdir_from_dir(dir)
subdir .context(format!("cannot get maildir instance from {:?}", dir))?;
))?;
let flags: MaildirFlags = flags let flags: MaildirFlags = flags
.try_into() .try_into()
.context(format!("cannot parse maildir flags {:?}", flags))?; .context(format!("cannot parse maildir flags {:?}", flags))?;
@ -467,16 +464,15 @@ impl<'a> Backend<'a> for MaildirBackend<'a> {
Ok(()) Ok(())
} }
fn del_flags(&mut self, subdir: &str, short_hash: &str, flags: &str) -> Result<()> { fn del_flags(&mut self, dir: &str, short_hash: &str, flags: &str) -> Result<()> {
info!(">> delete maildir message flags"); info!(">> delete maildir message flags");
debug!("subdir: {:?}", subdir); debug!("dir: {:?}", dir);
debug!("short hash: {:?}", short_hash); debug!("short hash: {:?}", short_hash);
debug!("flags: {:?}", flags); debug!("flags: {:?}", flags);
let mdir = self.get_mdir_from_dir(subdir).context(format!( let mdir = self
"cannot get maildir instance from subdir {:?}", .get_mdir_from_dir(dir)
subdir .context(format!("cannot get maildir instance from {:?}", dir))?;
))?;
let flags: MaildirFlags = flags let flags: MaildirFlags = flags
.try_into() .try_into()
.context(format!("cannot parse maildir flags {:?}", flags))?; .context(format!("cannot parse maildir flags {:?}", flags))?;