mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-16 20:57:53 +08:00
add ability to change account vim plugin (#91)
This commit is contained in:
+5
-5
@@ -210,16 +210,16 @@ impl Config {
|
||||
|
||||
pub fn find_account_by_name(&self, name: Option<&str>) -> Result<&Account> {
|
||||
match name {
|
||||
Some(name) => self
|
||||
.accounts
|
||||
.get(name)
|
||||
.ok_or_else(|| format!("Cannot find account `{}`", name).into()),
|
||||
None => self
|
||||
Some("") | None => self
|
||||
.accounts
|
||||
.iter()
|
||||
.find(|(_, account)| account.default.unwrap_or(false))
|
||||
.map(|(_, account)| account)
|
||||
.ok_or_else(|| "Cannot find default account".into()),
|
||||
Some(name) => self
|
||||
.accounts
|
||||
.get(name)
|
||||
.ok_or_else(|| format!("Cannot find account `{}`", name).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-13
@@ -4,7 +4,7 @@ use log::warn;
|
||||
use mailparse::{self, MailHeaderMap};
|
||||
use rfc2047_decoder;
|
||||
use serde::{
|
||||
ser::{self, SerializeStruct},
|
||||
ser::{self, SerializeStruct, Serializer},
|
||||
Serialize,
|
||||
};
|
||||
use std::{borrow::Cow, fmt, fs, path::PathBuf, result};
|
||||
@@ -101,23 +101,13 @@ impl<'a> Attachments {
|
||||
// Readable message
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReadableMsg {
|
||||
pub content: String,
|
||||
#[serde(serialize_with = "bool_to_int")]
|
||||
pub has_attachment: bool,
|
||||
}
|
||||
|
||||
// impl Serialize for ReadableMsg {
|
||||
// fn serialize<S>(&self, serializer: S) -> result::Result<S::Ok, S::Error>
|
||||
// where
|
||||
// S: ser::Serializer,
|
||||
// {
|
||||
// let mut state = serializer.serialize_struct("ReadableMsg", 2)?;
|
||||
// state.serialize_field("content", &self.content)?;
|
||||
// state.serialize_field("hasAttachment", if self.has_attachment { &1 } else { &0 })?;
|
||||
// state.end()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl fmt::Display for ReadableMsg {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f, "{}", self.content)
|
||||
@@ -660,3 +650,15 @@ impl fmt::Display for Msgs<'_> {
|
||||
writeln!(f, "\n{}", Table::render(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
// Custom bool to int serializer
|
||||
|
||||
fn bool_to_int<S>(t: &bool, s: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match t {
|
||||
true => s.serialize_u8(1),
|
||||
false => s.serialize_u8(0),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user