Skip to content

Commit

Permalink
use himalaya shared config from pimalaya-tui
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Oct 9, 2024
1 parent 30cc5e9 commit c080678
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 336 deletions.
36 changes: 19 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ rustdoc-args = ["--cfg", "docsrs"]
default = [
"imap",
"maildir",
# "notmuch",
#"notmuch",
"smtp",
"sendmail",

# "keyring",
# "oauth2",
#"keyring",
#"oauth2",
"wizard",

# "pgp-commands",
# "pgp-gpg",
# "pgp-native",
#"pgp-commands",
#"pgp-gpg",
#"pgp-native",
]

imap = ["email-lib/imap", "pimalaya-tui/imap"]
Expand Down Expand Up @@ -63,7 +63,7 @@ mml-lib = { version = "=1.0.14", default-features = false, features = ["derive"]
oauth-lib = { version = "=0.1.1", optional = true }
once_cell = "1.16"
petgraph = "0.6"
pimalaya-tui = { version = "=0.1.0", default-features = false, features = ["email", "path", "cli", "config", "tracing"] }
pimalaya-tui = { version = "=0.1.0", default-features = false, features = ["email", "path", "cli", "config", "tracing", "himalaya"] }
process-lib = { version = "=0.4.2", features = ["derive"] }
reedline = "0.35.0"
secret-lib = { version = "=0.4.6", default-features = false, features = ["command", "derive"], optional = true }
Expand All @@ -82,5 +82,6 @@ imap-next = { git = "https://github.com/duesee/imap-next" }
imap-client = { git = "https://github.com/pimalaya/imap-client" }
oauth-lib = { git = "https://github.com/pimalaya/core" }
process-lib = { git = "https://github.com/pimalaya/core" }
pgp-lib = { git = "https://github.com/pimalaya/core" }
email-lib = { git = "https://github.com/pimalaya/core" }
pimalaya-tui = { git = "https://github.com/pimalaya/tui" }
123 changes: 80 additions & 43 deletions src/account/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ use email::notmuch::config::NotmuchConfig;
use email::sendmail::config::SendmailConfig;
#[cfg(feature = "smtp")]
use email::smtp::config::SmtpConfig;
use process::Command;
use email::{account::config::AccountConfig, template::config::TemplateConfig};
use pimalaya_tui::config::toml::himalaya::{
BackendKind, EnvelopeConfig, FolderConfig, MessageConfig,
};
use serde::{Deserialize, Serialize};

use crate::backend::BackendKind;

// use crate::{
// backend::BackendKind, envelope::config::EnvelopeConfig, flag::config::FlagConfig,
// folder::config::FolderConfig, message::config::MessageConfig,
// };

/// Represents all existing kind of account config.
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
Expand All @@ -43,11 +39,11 @@ pub struct TomlAccountConfig {
#[cfg(feature = "pgp")]
pub pgp: Option<PgpConfig>,

// pub folder: Option<FolderConfig>,
// pub envelope: Option<EnvelopeConfig>,
// pub flag: Option<FlagConfig>,
pub folder: Option<FolderConfig>,
pub envelope: Option<EnvelopeConfig>,
pub message: Option<MessageConfig>,
// pub template: Option<TemplateConfig>,
pub template: Option<TemplateConfig>,

#[cfg(feature = "imap")]
pub imap: Option<ImapConfig>,
#[cfg(feature = "maildir")]
Expand All @@ -60,41 +56,82 @@ pub struct TomlAccountConfig {
pub sendmail: Option<SendmailConfig>,
}

#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct MessageConfig {
pub send: Option<MessageSendConfig>,
}
impl From<TomlAccountConfig> for AccountConfig {
fn from(config: TomlAccountConfig) -> Self {
Self {
name: String::new(),
email: config.email,
display_name: config.display_name,
signature: config.signature,
signature_delim: config.signature_delim,
downloads_dir: config.downloads_dir,

#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct MessageSendConfig {
pub backend: Option<BackendKind>,
pub save_copy: Option<bool>,
pub pre_hook: Option<Command>,
}
#[cfg(feature = "pgp")]
pgp: config.pgp,

#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct ListAccountsTableConfig {
pub preset: Option<String>,
pub name_color: Option<Color>,
pub backends_color: Option<Color>,
pub default_color: Option<Color>,
folder: config.folder.map(Into::into),
envelope: config.envelope.map(Into::into),
flag: None,
message: config.message.map(Into::into),
template: config.template,
}
}
}

// impl ListAccountsTableConfig {
// pub fn preset(&self) -> &str {
// self.preset.as_deref().unwrap_or(presets::ASCII_MARKDOWN)
// }
impl TomlAccountConfig {
pub fn envelope_list_table_preset(&self) -> Option<String> {
self.envelope.as_ref().and_then(|c| c.list_table_preset())
}

pub fn envelope_list_table_unseen_char(&self) -> Option<char> {
self.envelope
.as_ref()
.and_then(|c| c.list_table_unseen_char())
}

pub fn envelope_list_table_replied_char(&self) -> Option<char> {
self.envelope
.as_ref()
.and_then(|c| c.list_table_replied_char())
}

pub fn envelope_list_table_flagged_char(&self) -> Option<char> {
self.envelope
.as_ref()
.and_then(|c| c.list_table_flagged_char())
}

// pub fn name_color(&self) -> comfy_table::Color {
// map_color(self.name_color.unwrap_or(Color::Green))
// }
pub fn envelope_list_table_attachment_char(&self) -> Option<char> {
self.envelope
.as_ref()
.and_then(|c| c.list_table_attachment_char())
}

// pub fn backends_color(&self) -> comfy_table::Color {
// map_color(self.backends_color.unwrap_or(Color::Blue))
// }
pub fn envelope_list_table_id_color(&self) -> Option<Color> {
self.envelope.as_ref().and_then(|c| c.list_table_id_color())
}

// pub fn default_color(&self) -> comfy_table::Color {
// map_color(self.default_color.unwrap_or(Color::Reset))
// }
// }
pub fn envelope_list_table_flags_color(&self) -> Option<Color> {
self.envelope
.as_ref()
.and_then(|c| c.list_table_flags_color())
}

pub fn envelope_list_table_subject_color(&self) -> Option<Color> {
self.envelope
.as_ref()
.and_then(|c| c.list_table_subject_color())
}

pub fn envelope_list_table_sender_color(&self) -> Option<Color> {
self.envelope
.as_ref()
.and_then(|c| c.list_table_sender_color())
}

pub fn envelope_list_table_date_color(&self) -> Option<Color> {
self.envelope
.as_ref()
.and_then(|c| c.list_table_date_color())
}
}
18 changes: 1 addition & 17 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use email::{
},
AnyResult,
};
use serde::{Deserialize, Serialize};
use pimalaya_tui::config::toml::himalaya::BackendKind;

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum BackendConfig {
Expand All @@ -38,22 +38,6 @@ pub enum BackendConfig {
Sendmail(SendmailConfig),
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum BackendKind {
None,
#[cfg(feature = "imap")]
Imap,
#[cfg(feature = "maildir")]
Maildir,
#[cfg(feature = "notmuch")]
Notmuch,
#[cfg(feature = "smtp")]
Smtp,
#[cfg(feature = "sendmail")]
Sendmail,
}

#[derive(BackendContext)]
pub struct Context {
#[cfg(feature = "imap")]
Expand Down
Loading

0 comments on commit c080678

Please sign in to comment.