~matthiasbeyer/maildir

2d81decae89f823b29a7a9ad98da5594bf91340d — Kartikaya Gupta 2 years ago d6adbf5
Add a delete function to remove mail files
2 files changed, 31 insertions(+), 0 deletions(-)

M src/lib.rs
M tests/smoke.rs
M src/lib.rs => src/lib.rs +7 -0
@@ 378,6 378,13 @@ impl Maildir {
            .map(|e| e.unwrap())
    }

    pub fn delete(&self, id: &str) -> std::io::Result<()> {
        match self.find(id) {
            Some(m) => fs::remove_file(m.path()),
            None => Err(std::io::Error::new(std::io::ErrorKind::NotFound, "Mail entry not found")),
        }
    }

    /// Creates all neccessary directories if they don't exist yet. It is the library user's
    /// responsibility to call this before using `store_new`.
    pub fn create_dirs(&self) -> std::io::Result<()> {

M tests/smoke.rs => tests/smoke.rs +24 -0
@@ 106,6 106,30 @@ fn maildir_find() {
}

#[test]
fn check_delete() {
    with_maildir("maildir1", |maildir| {
        assert_eq!(
            maildir
                .find("1463941010.5f7fa6dd4922c183dc457d033deee9d7")
                .is_some(),
            true
        );
        assert_eq!(
            maildir
                .delete("1463941010.5f7fa6dd4922c183dc457d033deee9d7")
                .is_ok(),
            true
        );
        assert_eq!(
            maildir
                .find("1463941010.5f7fa6dd4922c183dc457d033deee9d7")
                .is_some(),
            false
        );
    })
}

#[test]
fn mark_read() {
    with_maildir("maildir1", |maildir| {
        assert_eq!(