/*
* meli - configuration module.
*
* Copyright 2017 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli 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.
*
* meli 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 meli. If not, see <http://www.gnu.org/licenses/>.
*/
/*! Configuration logic and `config.toml` interfaces. */
extern crate bincode;
extern crate serde;
extern crate toml;
extern crate xdg;
use crate::conf::deserializers::non_empty_string;
use crate::terminal::Color;
use melib::search::Query;
use std::collections::HashSet;
mod overrides;
pub use overrides::*;
pub mod composing;
pub mod notifications;
pub mod pager;
pub mod pgp;
pub mod tags;
#[macro_use]
pub mod shortcuts;
mod listing;
pub mod terminal;
mod themes;
pub use themes::*;
pub mod accounts;
pub use self::accounts::Account;
pub use self::composing::*;
pub use self::pgp::*;
pub use self::shortcuts::*;
pub use self::tags::*;
use self::default_vals::*;
use self::listing::ListingSettings;
use self::notifications::NotificationsSettings;
use self::terminal::TerminalSettings;
use crate::pager::PagerSettings;
use melib::conf::{AccountSettings, MailboxConf, ToggleFlag};
use melib::error::*;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use indexmap::IndexMap;
use std::collections::HashMap;
use std::env;
use std::fs::OpenOptions;
use std::io::{self, BufRead, Write};
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
#[macro_export]
macro_rules! split_command {
($cmd:expr) => {{
$cmd.split_whitespace().collect::<Vec<&str>>()
}};
}
#[macro_export]
macro_rules! account_settings {
($context:ident[$account_hash:expr].$setting:ident.$field:ident) => {{
$context.accounts[&$account_hash]
.settings
.conf_override
.$setting
.$field
.as_ref()
.unwrap_or(&$context.settings.$setting.$field)
}};
}
#[macro_export]
macro_rules! mailbox_settings {
($context:ident[$account_hash:expr][$mailbox_path:expr].$setting:ident.$field:ident) => {{
$context.accounts[&$account_hash][$mailbox_path]
.conf
.conf_override
.$setting
.$field
.as_ref()
.or($context.accounts[&$account_hash]
.settings
.conf_override
.$setting
.$field
.as_ref())
.unwrap_or(&$context.settings.$setting.$field)
}};
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct MailUIConf {
#[serde(default)]
pub pager: PagerSettingsOverride,
#[serde(default)]
pub listing: ListingSettingsOverride,
#[serde(default)]
pub notifications: NotificationsSettingsOverride,
#[serde(default)]
pub shortcuts: ShortcutsOverride,
#[serde(default)]
pub composing: ComposingSettingsOverride,
#[serde(default)]
pub identity: Option<String>,
#[serde(default)]
pub tags: TagsSettingsOverride,
#[serde(default)]
pub themes: Option<Themes>,
#[serde(default)]
pub pgp: PGPSettingsOverride,
}
#[serde(default)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct FileMailboxConf {
#[serde(flatten)]
pub conf_override: MailUIConf,
#[serde(flatten)]
pub mailbox_conf: MailboxConf,
}
impl FileMailboxConf {
pub fn conf_override(&self) -> &MailUIConf {
&self.conf_override
}
pub fn mailbox_conf(&self) -> &MailboxConf {
&self.mailbox_conf
}
}
use crate::conf::deserializers::extra_settings;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct FileAccount {
root_mailbox: String,
format: String,
identity: String,
#[serde(default = "none")]
display_name: Option<String>,
#[serde(default = "false_val")]
read_only: bool,
#[serde(default)]
subscribed_mailboxes: Vec<String>,
#[serde(default)]
mailboxes: IndexMap<String, FileMailboxConf>