pub struct Maildir { /* private fields */ }
Expand description
The main entry point for this library. This struct can be
instantiated from a path using the from
implementations.
The path passed in to the from
should be the root of the
maildir (the folder containing cur
, new
, and tmp
).
Implementations§
source§impl Maildir
impl Maildir
sourcepub fn with_path<P: Into<PathBuf>>(p: P) -> Self
pub fn with_path<P: Into<PathBuf>>(p: P) -> Self
Create a Maildir from a path-compatible parameter
sourcepub fn set_dir_mode(&mut self, dir_mode: Option<u32>)
pub fn set_dir_mode(&mut self, dir_mode: Option<u32>)
Set the directory permission mode. By default this is left unspecified, which causes directories to be created with permissions suitable for the owner, obeying the standard unix umask semantics. If you choose to assign the permission modes here, the umask will be ignored and the explicit modes that you set will be used on any directories that are created by Maildir. This will NOT change modes on existing directories they will only be applied to directores created by this instance of Maildir
sourcepub fn set_file_mode(&mut self, file_mode: Option<u32>)
pub fn set_file_mode(&mut self, file_mode: Option<u32>)
Set the file permission mode. By default this is left unspecified, which causes files to be created with permissions suitable for the owner, obeying the standard unix umask semantics. If you choose to assign the permission modes here, the umask will be ignored and the explicit modes that you set will be used on any files that are created by Maildir. This will NOT change modes on existing files they will only be applied to files created by this instance of Maildir
sourcepub fn count_new(&self) -> usize
pub fn count_new(&self) -> usize
Returns the number of messages found inside the new
maildir folder.
sourcepub fn count_cur(&self) -> usize
pub fn count_cur(&self) -> usize
Returns the number of messages found inside the cur
maildir folder.
sourcepub fn list_new(&self) -> MailEntries ⓘ
pub fn list_new(&self) -> MailEntries ⓘ
Returns an iterator over the messages inside the new
maildir folder. The order of messages in the iterator
is not specified, and is not guaranteed to be stable
over multiple invocations of this method.
sourcepub fn list_cur(&self) -> MailEntries ⓘ
pub fn list_cur(&self) -> MailEntries ⓘ
Returns an iterator over the messages inside the cur
maildir folder. The order of messages in the iterator
is not specified, and is not guaranteed to be stable
over multiple invocations of this method.
sourcepub fn list_subdirs(&self) -> MaildirEntries ⓘ
pub fn list_subdirs(&self) -> MaildirEntries ⓘ
Returns an iterator over the maildir subdirectories. The order of subdirectories in the iterator is not specified, and is not guaranteed to be stable over multiple invocations of this method.
sourcepub fn move_new_to_cur(&self, id: &str) -> Result<()>
pub fn move_new_to_cur(&self, id: &str) -> Result<()>
Moves a message from the new
maildir folder to the
cur
maildir folder. The id passed in should be
obtained from the iterator produced by list_new
.
sourcepub fn move_new_to_cur_with_flags(&self, id: &str, flags: &str) -> Result<()>
pub fn move_new_to_cur_with_flags(&self, id: &str, flags: &str) -> Result<()>
Moves a message from the new
maildir folder to the cur
maildir folder, and sets the
given flags. The id passed in should be obtained from the iterator produced by list_new
.
The possible flags are described e.g. at https://cr.yp.to/proto/maildir.html or http://www.courier-mta.org/maildir.html.
sourcepub fn copy_to(&self, id: &str, target: &Maildir) -> Result<()>
pub fn copy_to(&self, id: &str, target: &Maildir) -> Result<()>
Copies a message from the current maildir to the targetted maildir.
sourcepub fn move_to(&self, id: &str, target: &Maildir) -> Result<()>
pub fn move_to(&self, id: &str, target: &Maildir) -> Result<()>
Moves a message from the current maildir to the targetted maildir.
sourcepub fn find(&self, id: &str) -> Option<MailEntry>
pub fn find(&self, id: &str) -> Option<MailEntry>
Tries to find the message with the given id in the
maildir. This searches both the new
and the cur
folders.
sourcepub fn set_flags(&self, id: &str, flags: &str) -> Result<()>
pub fn set_flags(&self, id: &str, flags: &str) -> Result<()>
Updates the flags for the message with the given id in the
maildir. This only searches the cur
folder, because that’s
the folder where messages have flags. Returns an error if the
message was not found. All existing flags are overwritten with
the new flags provided.
sourcepub fn add_flags(&self, id: &str, flags: &str) -> Result<()>
pub fn add_flags(&self, id: &str, flags: &str) -> Result<()>
Adds the given flags to the message with the given id in the maildir.
This only searches the cur
folder, because that’s the folder where
messages have flags. Returns an error if the message was not found.
Flags are deduplicated, so setting a already-set flag has no effect.
sourcepub fn remove_flags(&self, id: &str, flags: &str) -> Result<()>
pub fn remove_flags(&self, id: &str, flags: &str) -> Result<()>
Removes the given flags to the message with the given id in the maildir.
This only searches the cur
folder, because that’s the folder where
messages have flags. Returns an error if the message was not found.
If the message doesn’t have the flag(s) to be removed, those flags are
ignored.
sourcepub fn delete(&self, id: &str) -> Result<()>
pub fn delete(&self, id: &str) -> Result<()>
Deletes the message with the given id in the maildir.
This searches both the new
and the cur
folders,
and deletes the file from the filesystem. Returns an
error if no message was found with the given id.
sourcepub fn create_dirs(&self) -> Result<()>
pub fn create_dirs(&self) -> Result<()>
Creates all neccessary directories if they don’t exist yet. It is the library user’s
responsibility to call this before using store_new
.
sourcepub fn store_new(&self, data: &[u8]) -> Result<String, MaildirError>
pub fn store_new(&self, data: &[u8]) -> Result<String, MaildirError>
Stores the given message data as a new message file in the Maildir new
folder. Does not
create the neccessary directories, so if in doubt call create_dirs
before using
store_new
.
Returns the Id of the inserted message on success.
sourcepub fn store_cur_with_flags(
&self,
data: &[u8],
flags: &str,
) -> Result<String, MaildirError>
pub fn store_cur_with_flags( &self, data: &[u8], flags: &str, ) -> Result<String, MaildirError>
Stores the given message data as a new message file in the Maildir cur
folder, adding the
given flags
to it. The possible flags are explained e.g. at
https://cr.yp.to/proto/maildir.html or http://www.courier-mta.org/maildir.html.
Returns the Id of the inserted message on success.