ui: small configuration fixes

- unused options were removed,
- renamed `index` conf option to `index_style`
embed
Manos Pitsidianakis 2019-09-16 14:09:08 +03:00
parent e6b7d3a855
commit 8795c2da4f
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 41 additions and 23 deletions

View File

@ -25,7 +25,6 @@ pub struct AccountSettings {
pub name: String, pub name: String,
pub root_folder: String, pub root_folder: String,
pub format: String, pub format: String,
pub sent_folder: String,
pub identity: String, pub identity: String,
pub read_only: bool, pub read_only: bool,
pub display_name: Option<String>, pub display_name: Option<String>,

View File

@ -775,10 +775,7 @@ pub fn send_draft(context: &mut Context, account_cursor: usize, draft: Draft) ->
.expect("Failed to write to stdin"); .expect("Failed to write to stdin");
if let Err(e) = context.accounts[account_cursor].save( if let Err(e) = context.accounts[account_cursor].save(
draft.as_bytes(), draft.as_bytes(),
&context.accounts[account_cursor] &context.accounts[account_cursor].sent_folder(),
.settings
.conf()
.sent_folder(),
Some(Flag::SEEN), Some(Flag::SEEN),
) { ) {
debug!("{:?} could not save sent msg", e); debug!("{:?} could not save sent msg", e);

View File

@ -287,7 +287,7 @@ impl Component for Listing {
if let Some(index_style) = context if let Some(index_style) = context
.accounts .accounts
.get(self.cursor_pos.0) .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); self.component.set_style(index_style);
}; };
@ -332,7 +332,7 @@ impl Component for Listing {
if let Some(index_style) = context if let Some(index_style) = context
.accounts .accounts
.get(self.cursor_pos.0) .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); self.component.set_style(index_style);
}; };
@ -572,10 +572,9 @@ impl Listing {
.collect(); .collect();
/* Check if per-folder configuration overrides general configuration */ /* Check if per-folder configuration overrides general configuration */
let component = if let Some(index_style) = accounts.get(0).and_then(|account| { let component = if let Some(index_style) = accounts.get(0).and_then(|account| {
account account.folders_order.get(0).and_then(|folder_hash| {
.folders_order account.folder_confs(*folder_hash).conf_override.index_style
.get(0) })
.and_then(|folder_hash| account.folder_confs(*folder_hash).conf_override.index)
}) { }) {
ListingComponent::from(index_style) ListingComponent::from(index_style)
} else { } else {

View File

@ -96,7 +96,7 @@ pub struct MailUIConf {
pub shortcuts: Option<Shortcuts>, pub shortcuts: Option<Shortcuts>,
pub mailer: Option<MailerSettings>, pub mailer: Option<MailerSettings>,
pub identity: Option<String>, pub identity: Option<String>,
pub index: Option<IndexStyle>, pub index_style: Option<IndexStyle>,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -137,15 +137,13 @@ impl FolderConf {
pub struct FileAccount { pub struct FileAccount {
root_folder: String, root_folder: String,
format: String, format: String,
sent_folder: String,
draft_folder: String,
identity: String, identity: String,
#[serde(flatten)] #[serde(flatten)]
pub extra: HashMap<String, String>, pub extra: HashMap<String, String>,
#[serde(default = "none")] #[serde(default = "none")]
display_name: Option<String>, display_name: Option<String>,
index: IndexStyle, index_style: IndexStyle,
/// A command to pipe html output before displaying it in a pager /// A command to pipe html output before displaying it in a pager
/// Default: None /// Default: None
@ -161,7 +159,6 @@ pub struct FileAccount {
impl From<FileAccount> for AccountConf { impl From<FileAccount> for AccountConf {
fn from(x: FileAccount) -> Self { fn from(x: FileAccount) -> Self {
let format = x.format.to_lowercase(); let format = x.format.to_lowercase();
let sent_folder = x.sent_folder.clone();
let root_folder = x.root_folder.clone(); let root_folder = x.root_folder.clone();
let identity = x.identity.clone(); let identity = x.identity.clone();
let display_name = x.display_name.clone(); let display_name = x.display_name.clone();
@ -170,7 +167,6 @@ impl From<FileAccount> for AccountConf {
name: String::new(), name: String::new(),
root_folder, root_folder,
format, format,
sent_folder,
identity, identity,
read_only: x.read_only, read_only: x.read_only,
display_name, display_name,
@ -252,15 +248,15 @@ impl FileAccount {
pub fn folders(&self) -> Option<&HashMap<String, FolderConf>> { pub fn folders(&self) -> Option<&HashMap<String, FolderConf>> {
self.folders.as_ref() self.folders.as_ref()
} }
pub fn folder(&self) -> &str { pub fn folder(&self) -> &str {
&self.root_folder &self.root_folder
} }
pub fn index(&self) -> IndexStyle {
self.index pub fn index_style(&self) -> IndexStyle {
} self.index_style
pub fn sent_folder(&self) -> &str {
self.sent_folder.as_str()
} }
pub fn html_filter(&self) -> Option<&str> { pub fn html_filter(&self) -> Option<&str> {
self.html_filter.as_ref().map(String::as_str) self.html_filter.as_ref().map(String::as_str)
} }

View File

@ -650,9 +650,23 @@ impl Account {
self.name.as_str() 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()?; let finalize = draft.finalise()?;
self.backend 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<Flag>) -> Result<()> { pub fn save(&self, bytes: &[u8], folder: &str, flags: Option<Flag>) -> Result<()> {
if self.settings.account.read_only() { if self.settings.account.read_only() {
@ -736,6 +750,19 @@ impl Account {
pub fn folder_confs(&self, folder_hash: FolderHash) -> &FolderConf { pub fn folder_confs(&self, folder_hash: FolderHash) -> &FolderConf {
&self.folder_confs[&folder_hash] &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<FolderHash> for Account { impl Index<FolderHash> for Account {