You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
meli/melib/src/notmuch/config.rs

64 lines
1.7 KiB
Rust

//
// melib
//
// Copyright 2024 Emmanouil Pitsidianakis <manos@pitsidianak.is>
//
// This file is part of melib.
//
// melib is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// melib is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with melib. If not, see <http://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: EUPL-1.2 OR GPL-3.0-or-later
use crate::{email::Address, SpecialUsageMailbox};
use indexmap::IndexMap;
use regex::bytes::Regex;
use std::path::PathBuf;
#[derive(Serialize, Deserialize)]
pub struct FccDirEntry {
pattern: Box<str>,
folder: Option<Box<str>>,
//tags: Vec<FlagOp>,
}
impl FccDirEntry {
pub fn matches<'fcc>(&'fcc self, from: &Address) -> Option<&'fcc str> {
let reg = Regex::new(&self.pattern).ok()?;
if reg.is_match(from.raw()) {
return self.folder.as_ref().map(|s| s.as_ref());
}
None
}
}
#[derive(Serialize, Deserialize)]
pub enum FccDirs {
None,
Folder(Box<str>),
SpecialFolder(SpecialUsageMailbox),
Map(Vec<FccDirEntry>),
}
impl Default for FccDirs {
fn default() -> Self {
Self::SpecialFolder(SpecialUsageMailbox::Sent)
}
}
#[derive(Default, Serialize, Deserialize)]
pub struct Configuration {
pub library_file_path: Option<PathBuf>,
pub fcc_dirs: FccDirs,
}