~llndqvst/notmuch-mvrs

ref: fb4a33808e4436c4b4f91f0b11227d2c0ed8f99e notmuch-mvrs/src/mover_config.rs -rw-r--r-- 1.1 KiB
fb4a3380Lukas Lindqvist squash! Add support for Maildir cur, tmp, and new 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::movers::mover::Mover;
use std::path::PathBuf;

pub struct MoverConfig<'a, T>
where
    T: Mover<PathBuf>,
{
    mover: T,
    nm_db: &'a notmuch::Database,
    query_string: &'a str,
}

impl<'a, T> MoverConfig<'a, T>
where
    T: Mover<PathBuf>,
{
    pub fn new(nm_db_location: &'a notmuch::Database, query: &'a str, target_path: PathBuf) -> Self {
        MoverConfig {
            mover: T::new(target_path),
            nm_db: nm_db_location,
            query_string: query,
        }
    }

    pub fn dry_execute(&mut self) -> Result<i32, &str> {
        let query = self.nm_db.create_query(self.query_string).unwrap();
        let messages = query.search_messages().unwrap();
        for m in messages {
            self.mover.add_file_path(m.filename());
        }
        self.mover.dry_rename()
    }

    pub fn execute(&mut self) -> Result<i32, &str> {
        let query = self.nm_db.create_query(self.query_string).unwrap();
        let messages = query.search_messages().unwrap();
        for m in messages {
            self.mover.add_file_path(m.filename());
        }
        self.mover.rename()
    }
}