diff --git a/melib/src/conf.rs b/melib/src/conf.rs index 3b70c6a42..55d2a5e2c 100644 --- a/melib/src/conf.rs +++ b/melib/src/conf.rs @@ -25,7 +25,6 @@ pub struct AccountSettings { pub name: String, pub root_folder: String, pub format: String, - pub sent_folder: String, pub identity: String, pub read_only: bool, pub display_name: Option, diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 2a369751c..699b0b90d 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -775,10 +775,7 @@ pub fn send_draft(context: &mut Context, account_cursor: usize, draft: Draft) -> .expect("Failed to write to stdin"); if let Err(e) = context.accounts[account_cursor].save( draft.as_bytes(), - &context.accounts[account_cursor] - .settings - .conf() - .sent_folder(), + &context.accounts[account_cursor].sent_folder(), Some(Flag::SEEN), ) { debug!("{:?} could not save sent msg", e); diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 2feb7259c..9518a4e24 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -287,7 +287,7 @@ impl Component for Listing { if let Some(index_style) = context .accounts .get(self.cursor_pos.0) - .and_then(|account| account.folder_confs(folder_hash).conf_override.index) + .and_then(|account| account.folder_confs(folder_hash).conf_override.index_style) { self.component.set_style(index_style); }; @@ -332,7 +332,7 @@ impl Component for Listing { if let Some(index_style) = context .accounts .get(self.cursor_pos.0) - .and_then(|account| account.folder_confs(folder_hash).conf_override.index) + .and_then(|account| account.folder_confs(folder_hash).conf_override.index_style) { self.component.set_style(index_style); }; @@ -572,10 +572,9 @@ impl Listing { .collect(); /* Check if per-folder configuration overrides general configuration */ let component = if let Some(index_style) = accounts.get(0).and_then(|account| { - account - .folders_order - .get(0) - .and_then(|folder_hash| account.folder_confs(*folder_hash).conf_override.index) + account.folders_order.get(0).and_then(|folder_hash| { + account.folder_confs(*folder_hash).conf_override.index_style + }) }) { ListingComponent::from(index_style) } else { diff --git a/ui/src/conf.rs b/ui/src/conf.rs index 218f14587..223c737fd 100644 --- a/ui/src/conf.rs +++ b/ui/src/conf.rs @@ -96,7 +96,7 @@ pub struct MailUIConf { pub shortcuts: Option, pub mailer: Option, pub identity: Option, - pub index: Option, + pub index_style: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -137,15 +137,13 @@ impl FolderConf { pub struct FileAccount { root_folder: String, format: String, - sent_folder: String, - draft_folder: String, identity: String, #[serde(flatten)] pub extra: HashMap, #[serde(default = "none")] display_name: Option, - index: IndexStyle, + index_style: IndexStyle, /// A command to pipe html output before displaying it in a pager /// Default: None @@ -161,7 +159,6 @@ pub struct FileAccount { impl From for AccountConf { fn from(x: FileAccount) -> Self { let format = x.format.to_lowercase(); - let sent_folder = x.sent_folder.clone(); let root_folder = x.root_folder.clone(); let identity = x.identity.clone(); let display_name = x.display_name.clone(); @@ -170,7 +167,6 @@ impl From for AccountConf { name: String::new(), root_folder, format, - sent_folder, identity, read_only: x.read_only, display_name, @@ -252,15 +248,15 @@ impl FileAccount { pub fn folders(&self) -> Option<&HashMap> { self.folders.as_ref() } + pub fn folder(&self) -> &str { &self.root_folder } - pub fn index(&self) -> IndexStyle { - self.index - } - pub fn sent_folder(&self) -> &str { - self.sent_folder.as_str() + + pub fn index_style(&self) -> IndexStyle { + self.index_style } + pub fn html_filter(&self) -> Option<&str> { self.html_filter.as_ref().map(String::as_str) } diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index dd4c5a3f3..eb33a9bca 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -650,9 +650,23 @@ impl Account { self.name.as_str() ))); } + let draft_folder = self + .settings + .folder_confs + .iter() + .find(|(_, f)| f.usage == Some(SpecialUseMailbox::Drafts)); + if draft_folder.is_none() { + return Err(MeliError::new(format!( + "Account {} has no draft folder set.", + self.name.as_str() + ))); + } + + let draft_folder = draft_folder.unwrap(); + let finalize = draft.finalise()?; self.backend - .save(&finalize.as_bytes(), &self.settings.conf.draft_folder, None) + .save(&finalize.as_bytes(), draft_folder.0, None) } pub fn save(&self, bytes: &[u8], folder: &str, flags: Option) -> Result<()> { if self.settings.account.read_only() { @@ -736,6 +750,19 @@ impl Account { pub fn folder_confs(&self, folder_hash: FolderHash) -> &FolderConf { &self.folder_confs[&folder_hash] } + + pub fn sent_folder(&self) -> &str { + let sent_folder = self + .settings + .folder_confs + .iter() + .find(|(_, f)| f.usage == Some(SpecialUseMailbox::Sent)); + if let Some(sent_folder) = sent_folder.as_ref() { + sent_folder.0 + } else { + "" + } + } } impl Index for Account {