add new() method for Account and Config

This commit is contained in:
Clément DOUIN
2021-06-02 22:50:22 +02:00
parent 4df39b6d01
commit fa223417a0
4 changed files with 69 additions and 197 deletions
+37 -1
View File
@@ -50,6 +50,30 @@ pub struct Account {
}
impl Account {
pub fn new() -> Self {
Self {
name: None,
downloads_dir: None,
signature: None,
default_page_size: None,
default: None,
email: String::new(),
watch_cmds: None,
imap_host: String::new(),
imap_port: 0,
imap_starttls: None,
imap_insecure: None,
imap_login: String::new(),
imap_passwd_cmd: String::new(),
smtp_host: String::new(),
smtp_port: 0,
smtp_starttls: None,
smtp_insecure: None,
smtp_login: String::new(),
smtp_passwd_cmd: String::new(),
}
}
pub fn imap_addr(&self) -> (&str, u16) {
debug!("host: {}", self.imap_host);
debug!("port: {}", self.imap_port);
@@ -125,6 +149,18 @@ pub struct Config {
}
impl Config {
pub fn new() -> Self {
Self {
name: String::new(),
downloads_dir: None,
notify_cmd: None,
signature: None,
default_page_size: None,
watch_cmds: None,
accounts: HashMap::new(),
}
}
fn path_from_xdg() -> Result<PathBuf> {
let path =
env::var("XDG_CONFIG_HOME").chain_err(|| "Cannot find `XDG_CONFIG_HOME` env var")?;
@@ -165,7 +201,7 @@ impl Config {
Ok(path)
}
pub fn new(path: Option<PathBuf>) -> Result<Self> {
pub fn from_path(path: Option<PathBuf>) -> Result<Self> {
let path = match path {
Some(path) => path,
None => Self::path_from_xdg()