use std::fs;
use anyhow::Result;
use log::{debug, info, warn, error};
use serde_derive::{Deserialize, Serialize};
use toml;
use email_address::EmailAddress;
use chrono::TimeDelta;
use crate::utils::EmailAddressList;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Cfg {
pub imap: ImapCfg,
pub archive: ArchiveCfg,
pub run: RuntimeCfg,
}
impl Cfg {
pub fn load(path: &str) -> Result<Cfg> {
info!("loading configuration from {}...", path);
let cfg_data = fs::read_to_string(path)?;
let cfg: Cfg = toml::from_str(&cfg_data)?;
info!("loaded");
Ok(cfg)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImapCfg {
pub host: String,
pub port: u16,
pub username: EmailAddress,
pub password: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArchiveCfg {
pub letter_dir: String, pub rstdoc_dir: String, pub create_dirs: Option<bool>,
pub letter_managed_by_git: Option<bool>, pub rstdoc_managed_by_git: Option<bool>, pub git_no_push: Option<bool>,
pub allowed_from_addrs: EmailAddressList,
pub allowed_to_addrs: EmailAddressList,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RuntimeCfg {
pub interval_seconds: u32,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cfg_load() {
let _ = Cfg::load("./test_data/config.toml").unwrap();
}
}