himalaya/src/config/config.rs

577 lines
17 KiB
Rust
Raw Normal View History

2022-09-22 14:38:38 +00:00
//! Deserialized config module.
//!
//! This module contains the raw deserialized representation of the
//! user configuration file.
use anyhow::{anyhow, Context, Result};
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
use dirs::{config_dir, home_dir};
2022-09-22 14:38:38 +00:00
use log::{debug, trace};
2023-04-20 10:12:33 +00:00
use pimalaya_email::{AccountConfig, BackendConfig, EmailHooks, EmailTextPlainFormat};
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fs, path::PathBuf};
2022-09-22 14:38:38 +00:00
use toml;
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
use crate::{
account::DeserializedAccountConfig,
config::{prelude::*, wizard::wizard},
};
2022-09-22 14:38:38 +00:00
/// Represents the user config file.
2023-02-18 20:12:47 +00:00
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
2022-09-22 14:38:38 +00:00
#[serde(rename_all = "kebab-case")]
pub struct DeserializedConfig {
#[serde(alias = "name")]
pub display_name: Option<String>,
pub signature_delim: Option<String>,
pub signature: Option<String>,
pub downloads_dir: Option<PathBuf>,
pub folder_listing_page_size: Option<usize>,
pub folder_aliases: Option<HashMap<String, String>>,
pub email_listing_page_size: Option<usize>,
pub email_reading_headers: Option<Vec<String>>,
2023-02-18 20:12:47 +00:00
#[serde(default, with = "EmailTextPlainFormatDef")]
pub email_reading_format: EmailTextPlainFormat,
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
pub email_reading_verify_cmd: Option<String>,
2022-09-22 14:38:38 +00:00
pub email_reading_decrypt_cmd: Option<String>,
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
pub email_writing_headers: Option<Vec<String>>,
pub email_writing_sign_cmd: Option<String>,
2022-09-22 14:38:38 +00:00
pub email_writing_encrypt_cmd: Option<String>,
#[serde(
default,
2023-02-18 20:12:47 +00:00
with = "EmailHooksDef",
skip_serializing_if = "EmailHooks::is_empty"
)]
2023-02-18 20:12:47 +00:00
pub email_hooks: EmailHooks,
2022-09-22 14:38:38 +00:00
#[serde(flatten)]
pub accounts: HashMap<String, DeserializedAccountConfig>,
}
impl DeserializedConfig {
/// Tries to create a config from an optional path.
pub fn from_opt_path(path: Option<&str>) -> Result<Self> {
debug!("path: {:?}", path);
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
let config: Self = match path.map(|s| s.into()).or_else(Self::path) {
Some(path) => {
let content = fs::read_to_string(path).context("cannot read config file")?;
toml::from_str(&content).context("cannot parse config file")?
}
None => wizard()?,
};
2022-09-22 14:38:38 +00:00
if config.accounts.is_empty() {
return Err(anyhow!("config file must contain at least one account"));
}
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
trace!("config: {:#?}", config);
2022-09-22 14:38:38 +00:00
Ok(config)
}
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
/// Tries to return a config path from a few default settings.
///
/// Tries paths in this order:
///
/// - `"$XDG_CONFIG_DIR/himalaya/config.toml"` (or equivalent to `$XDG_CONFIG_DIR` in other
/// OSes.)
/// - `"$HOME/.config/himalaya/config.toml"`
/// - `"$HOME/.himalayarc"`
///
/// Returns `Some(path)` if the path exists, otherwise `None`.
pub fn path() -> Option<PathBuf> {
config_dir()
.map(|p| p.join("himalaya").join("config.toml"))
.filter(|p| p.exists())
.or_else(|| home_dir().map(|p| p.join(".config").join("himalaya").join("config.toml")))
.filter(|p| p.exists())
.or_else(|| home_dir().map(|p| p.join(".himalayarc")))
.filter(|p| p.exists())
2022-09-22 14:38:38 +00:00
}
pub fn to_configs(&self, account_name: Option<&str>) -> Result<(AccountConfig, BackendConfig)> {
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
let (account_name, deserialized_account_config) = match account_name {
2022-09-22 14:38:38 +00:00
Some("default") | Some("") | None => self
.accounts
.iter()
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
.find_map(|(name, account)| {
2022-09-22 14:38:38 +00:00
if account.is_default() {
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
Some((name.clone(), account))
2022-09-22 14:38:38 +00:00
} else {
None
}
})
.ok_or_else(|| anyhow!("cannot find default account")),
Some(name) => self
.accounts
.get(name)
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
.map(|account| (name.to_string(), account))
2022-09-22 14:38:38 +00:00
.ok_or_else(|| anyhow!(format!("cannot find account {}", name))),
release v0.7.0 (#433) * update codebase with email lib changes (#431) update himalaya-lib, rename remaining mbox vars add missing methods from lib update changelog * fixed missing folder aliases #430 * improve README links * fix README repology link * fix README repology table * fix README repology table 2 * center README repology table * fix README cosmetic issues * fix README cosmetic issues 2 * fix README title * fix README wiki links * fix lock file * prepare v0.6.2 * fix ci * try some musl builds #356 * add musl build to artifact #356 * add musl build to deployment pipeline #356 * migrate clap v4, add man command #419 * add option to choose color manually #407 * update links and badges * update matrix badge * add github release version badge * update badges links * fix code bloc type * fix tests * fix cargo lock * generate all man pages for all subcommands #419 * fix query and headers arg parsers * fix invalid flags and options due to clap v4 migration * fix tests * remove -l|--log-level option * refactor contributing guide * update lib * fix flags string printer * make commands read, attachments, copy, move and delete accept multiple ids * fix ids arg parser * fix flags subcommands conflicts between ids and flags * flip back copy and move arguments * add issue template (#439) * update lib, prepare for sync feature * update himalaya lib, fix senders and config * update lock file himalaya lib * fix sync enabling issues * fix wrong imap backend init in main file * fix notmuch backend post sync feature * configuration wizard (#432) * make DeserializedConfig::path more robust With this change, himalaya uses the crate `dirs` in order to follow XDG specifications on Unix, Known Folder on Windows and Standard Directories on MacOS. This gives us much smoother cross-platform support. It still has the same fallbacks (`$HOME/.config/himalaya/config.toml` and `$HOME/.himalayarc`.) Additionally, this commit removes a bit of in-house code-bloat. * add wizard entrypoint and basic structure * wip * feat: impl Serialize for all DeserializedConfigs * feat: select default account and write to file * feat: add SMTP part of wizard * build: update lockfile * refactor: separate out multiple files for wizard * style: friendlier and prettier messages * feat: add maildir part of wizard * feat: add notmuch part of wizard * chore: clippy lints and reorder prompts * fix: contrived solution to serializing None values * fix: allow empty Option field when deserializing * style: address PR review comments * fix: utilize notmuch lib in finding database path * fix notmuch wizard --------- Co-authored-by: Clément DOUIN <clement.douin@posteo.net> * add account sync progress bar * improve sync spinner * make the sync dry run flag show patches without applying them * update himalaya lib, increase imap session pool size * add disable cache flag * add nlnet logo in readme * update himalaya lib deps, make use of sync reports * prepare v0.7.0 * bump rustc v1.67.0 and clap v4.1.4 * bump himalaya lib v0.5.1, fix flake lock file --------- Co-authored-by: janabhumi <dmitriy@ideascup.me> Co-authored-by: Knut Magnus Aasrud <km@aasrud.com>
2023-02-08 15:03:45 +00:00
}?;
let (account_config, backend_config) =
deserialized_account_config.to_configs(account_name, self);
2022-09-22 14:38:38 +00:00
Ok((account_config, backend_config))
}
}
#[cfg(test)]
mod tests {
2023-04-20 10:12:33 +00:00
use pimalaya_email::{EmailSender, MaildirConfig, SendmailConfig, SmtpConfig};
2022-09-28 22:44:31 +00:00
#[cfg(feature = "imap-backend")]
2023-04-20 10:12:33 +00:00
use pimalaya_email::ImapConfig;
2022-09-28 22:44:31 +00:00
#[cfg(feature = "notmuch-backend")]
2023-04-20 10:12:33 +00:00
use pimalaya_email::NotmuchConfig;
2022-09-28 22:44:31 +00:00
2022-09-22 14:38:38 +00:00
use std::io::Write;
use tempfile::NamedTempFile;
2022-09-28 22:44:31 +00:00
use crate::account::DeserializedBaseAccountConfig;
#[cfg(feature = "imap-backend")]
use crate::account::DeserializedImapAccountConfig;
use crate::account::DeserializedMaildirAccountConfig;
#[cfg(feature = "notmuch-backend")]
use crate::account::DeserializedNotmuchAccountConfig;
2022-09-22 14:38:38 +00:00
use super::*;
fn make_config(config: &str) -> Result<DeserializedConfig> {
let mut file = NamedTempFile::new().unwrap();
write!(file, "{}", config).unwrap();
DeserializedConfig::from_opt_path(file.into_temp_path().to_str())
}
#[test]
fn empty_config() {
let config = make_config("");
assert_eq!(
config.unwrap_err().root_cause().to_string(),
"config file must contain at least one account"
);
}
#[test]
fn account_missing_backend_field() {
let config = make_config("[account]");
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `backend`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn account_invalid_backend_field() {
let config = make_config(
"[account]
backend = \"bad\"",
);
2022-09-28 22:44:31 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
2023-02-20 16:47:40 +00:00
.contains("unknown variant `bad`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn account_missing_email_field() {
let config = make_config(
"[account]
backend = \"none\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `email`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn imap_account_missing_host_field() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"imap\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `imap-host`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn account_backend_imap_missing_port_field() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"imap\"
imap-host = \"localhost\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `imap-port`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn account_backend_imap_missing_login_field() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"imap\"
imap-host = \"localhost\"
imap-port = 993",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `imap-login`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn account_backend_imap_missing_passwd_cmd_field() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"imap\"
imap-host = \"localhost\"
imap-port = 993
imap-login = \"login\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `imap-passwd-cmd`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn account_backend_maildir_missing_root_dir_field() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"maildir\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `maildir-root-dir`"));
2022-09-22 14:38:38 +00:00
}
2022-09-28 22:44:31 +00:00
#[cfg(feature = "notmuch-backend")]
2022-09-22 14:38:38 +00:00
#[test]
fn account_backend_notmuch_missing_db_path_field() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"notmuch\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `notmuch-db-path`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn account_missing_sender_field() {
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `sender`"));
2022-09-22 14:38:38 +00:00
}
#[test]
fn account_invalid_sender_field() {
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"
sender = \"bad\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("unknown variant `bad`, expected one of `none`, `smtp`, `sendmail`"),);
2022-09-22 14:38:38 +00:00
}
#[test]
2022-10-10 16:06:13 +00:00
fn account_smtp_sender_missing_host_field() {
2022-09-22 14:38:38 +00:00
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"
2022-10-10 16:06:13 +00:00
sender = \"smtp\"",
2022-09-22 14:38:38 +00:00
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `smtp-host`"));
2022-09-22 14:38:38 +00:00
}
#[test]
2022-10-10 16:06:13 +00:00
fn account_smtp_sender_missing_port_field() {
2022-09-22 14:38:38 +00:00
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"
2022-10-10 16:06:13 +00:00
sender = \"smtp\"
2022-09-22 14:38:38 +00:00
smtp-host = \"localhost\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `smtp-port`"));
2022-09-22 14:38:38 +00:00
}
#[test]
2022-10-10 16:06:13 +00:00
fn account_smtp_sender_missing_login_field() {
2022-09-22 14:38:38 +00:00
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"
2022-10-10 16:06:13 +00:00
sender = \"smtp\"
2022-09-22 14:38:38 +00:00
smtp-host = \"localhost\"
smtp-port = 25",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `smtp-login`"));
2022-09-22 14:38:38 +00:00
}
#[test]
2022-10-10 16:06:13 +00:00
fn account_smtp_sender_missing_passwd_cmd_field() {
2022-09-22 14:38:38 +00:00
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"
2022-10-10 16:06:13 +00:00
sender = \"smtp\"
2022-09-22 14:38:38 +00:00
smtp-host = \"localhost\"
smtp-port = 25
smtp-login = \"login\"",
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `smtp-passwd-cmd`"));
2022-09-22 14:38:38 +00:00
}
#[test]
2022-10-10 16:06:13 +00:00
fn account_sendmail_sender_missing_cmd_field() {
2022-09-22 14:38:38 +00:00
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"
2022-10-10 16:06:13 +00:00
sender = \"sendmail\"",
2022-09-22 14:38:38 +00:00
);
2023-02-20 16:47:40 +00:00
assert!(config
.unwrap_err()
.root_cause()
.to_string()
.contains("missing field `sendmail-cmd`"));
2022-09-22 14:38:38 +00:00
}
#[test]
2022-10-10 16:06:13 +00:00
fn account_smtp_sender_minimum_config() {
2022-09-22 14:38:38 +00:00
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"
2022-10-10 16:06:13 +00:00
sender = \"smtp\"
2022-09-22 14:38:38 +00:00
smtp-host = \"localhost\"
smtp-port = 25
smtp-login = \"login\"
smtp-passwd-cmd = \"echo password\"",
);
assert_eq!(
config.unwrap(),
DeserializedConfig {
accounts: HashMap::from_iter([(
"account".into(),
DeserializedAccountConfig::None(DeserializedBaseAccountConfig {
email: "test@localhost".into(),
2022-10-10 16:06:13 +00:00
email_sender: EmailSender::Smtp(SmtpConfig {
2022-09-22 14:38:38 +00:00
host: "localhost".into(),
port: 25,
login: "login".into(),
passwd_cmd: "echo password".into(),
..SmtpConfig::default()
}),
..DeserializedBaseAccountConfig::default()
})
)]),
..DeserializedConfig::default()
}
);
}
#[test]
2022-10-10 16:06:13 +00:00
fn account_sendmail_sender_minimum_config() {
2022-09-22 14:38:38 +00:00
let config = make_config(
"[account]
email = \"test@localhost\"
backend = \"none\"
2022-10-10 16:06:13 +00:00
sender = \"sendmail\"
sendmail-cmd = \"echo send\"",
2022-09-22 14:38:38 +00:00
);
assert_eq!(
config.unwrap(),
DeserializedConfig {
accounts: HashMap::from_iter([(
"account".into(),
DeserializedAccountConfig::None(DeserializedBaseAccountConfig {
email: "test@localhost".into(),
2022-10-10 16:06:13 +00:00
email_sender: EmailSender::Sendmail(SendmailConfig {
2022-09-22 14:38:38 +00:00
cmd: "echo send".into(),
}),
..DeserializedBaseAccountConfig::default()
})
)]),
..DeserializedConfig::default()
}
);
}
#[test]
fn account_backend_imap_minimum_config() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"imap\"
imap-host = \"localhost\"
imap-port = 993
imap-login = \"login\"
imap-passwd-cmd = \"echo password\"",
);
assert_eq!(
config.unwrap(),
DeserializedConfig {
accounts: HashMap::from_iter([(
"account".into(),
DeserializedAccountConfig::Imap(DeserializedImapAccountConfig {
base: DeserializedBaseAccountConfig {
email: "test@localhost".into(),
..DeserializedBaseAccountConfig::default()
},
backend: ImapConfig {
host: "localhost".into(),
port: 993,
login: "login".into(),
passwd_cmd: "echo password".into(),
..ImapConfig::default()
}
})
)]),
..DeserializedConfig::default()
}
);
}
#[test]
fn account_backend_maildir_minimum_config() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"maildir\"
maildir-root-dir = \"/tmp/maildir\"",
);
assert_eq!(
config.unwrap(),
DeserializedConfig {
accounts: HashMap::from_iter([(
"account".into(),
DeserializedAccountConfig::Maildir(DeserializedMaildirAccountConfig {
base: DeserializedBaseAccountConfig {
email: "test@localhost".into(),
..DeserializedBaseAccountConfig::default()
},
backend: MaildirConfig {
root_dir: "/tmp/maildir".into(),
}
})
)]),
..DeserializedConfig::default()
}
);
}
2022-09-28 22:44:31 +00:00
#[cfg(feature = "notmuch-backend")]
2022-09-22 14:38:38 +00:00
#[test]
fn account_backend_notmuch_minimum_config() {
let config = make_config(
"[account]
email = \"test@localhost\"
sender = \"none\"
backend = \"notmuch\"
notmuch-db-path = \"/tmp/notmuch.db\"",
);
assert_eq!(
config.unwrap(),
DeserializedConfig {
accounts: HashMap::from_iter([(
"account".into(),
DeserializedAccountConfig::Notmuch(DeserializedNotmuchAccountConfig {
base: DeserializedBaseAccountConfig {
email: "test@localhost".into(),
..DeserializedBaseAccountConfig::default()
},
backend: NotmuchConfig {
db_path: "/tmp/notmuch.db".into(),
}
})
)]),
..DeserializedConfig::default()
}
);
}
}