Remove obsolete crate::components::mail::get_display_name()
parent
77020e0c19
commit
428f752b20
|
@ -1366,7 +1366,7 @@ impl ImapType {
|
|||
timeout,
|
||||
};
|
||||
let account_hash = AccountHash::from_bytes(s.name.as_bytes());
|
||||
let account_name = Arc::new(s.name().to_string());
|
||||
let account_name = Arc::new(s.name.to_string());
|
||||
let uid_store: Arc<UIDStore> = Arc::new(UIDStore {
|
||||
keep_offline_cache,
|
||||
..UIDStore::new(
|
||||
|
|
|
@ -1187,17 +1187,17 @@ impl MaildirType {
|
|||
}
|
||||
Ok(children)
|
||||
}
|
||||
let root_mailbox = PathBuf::from(settings.root_mailbox()).expand();
|
||||
let root_mailbox = PathBuf::from(&settings.root_mailbox).expand();
|
||||
if !root_mailbox.exists() {
|
||||
return Err(Error::new(format!(
|
||||
"Configuration error ({}): root_mailbox `{}` is not a valid directory.",
|
||||
settings.name(),
|
||||
settings.name,
|
||||
settings.root_mailbox.as_str()
|
||||
)));
|
||||
} else if !root_mailbox.is_dir() {
|
||||
return Err(Error::new(format!(
|
||||
"Configuration error ({}): root_mailbox `{}` is not a directory.",
|
||||
settings.name(),
|
||||
settings.name,
|
||||
settings.root_mailbox.as_str()
|
||||
)));
|
||||
}
|
||||
|
@ -1255,7 +1255,7 @@ impl MaildirType {
|
|||
);
|
||||
}
|
||||
Ok(Box::new(MaildirType {
|
||||
name: settings.name().to_string(),
|
||||
name: settings.name.to_string(),
|
||||
mailboxes,
|
||||
hash_indexes: Arc::new(Mutex::new(hash_indexes)),
|
||||
mailbox_index: Default::default(),
|
||||
|
@ -1335,17 +1335,17 @@ impl MaildirType {
|
|||
}
|
||||
|
||||
pub fn validate_config(s: &mut AccountSettings) -> Result<()> {
|
||||
let root_mailbox = PathBuf::from(s.root_mailbox()).expand();
|
||||
let root_mailbox = PathBuf::from(&s.root_mailbox).expand();
|
||||
if !root_mailbox.exists() {
|
||||
return Err(Error::new(format!(
|
||||
"Configuration error ({}): root_mailbox `{}` is not a valid directory.",
|
||||
s.name(),
|
||||
s.name,
|
||||
s.root_mailbox.as_str()
|
||||
)));
|
||||
} else if !root_mailbox.is_dir() {
|
||||
return Err(Error::new(format!(
|
||||
"Configuration error ({}): root_mailbox `{}` is not a directory.",
|
||||
s.name(),
|
||||
s.name,
|
||||
s.root_mailbox.as_str()
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -1315,12 +1315,12 @@ impl MboxType {
|
|||
return Err(Error::new(format!(
|
||||
"\"root_mailbox\" {} for account {} is not a valid path.",
|
||||
s.root_mailbox.as_str(),
|
||||
s.name()
|
||||
s.name
|
||||
)));
|
||||
}
|
||||
let prefer_mbox_type: String = get_conf_val!(s["prefer_mbox_type"], "auto".to_string())?;
|
||||
let ret = MboxType {
|
||||
account_name: s.name().to_string(),
|
||||
account_name: s.name.to_string(),
|
||||
event_consumer,
|
||||
path,
|
||||
prefer_mbox_type: match prefer_mbox_type.as_str() {
|
||||
|
@ -1332,8 +1332,7 @@ impl MboxType {
|
|||
_ => {
|
||||
return Err(Error::new(format!(
|
||||
"{} invalid `prefer_mbox_type` value: `{}`",
|
||||
s.name(),
|
||||
prefer_mbox_type,
|
||||
s.name, prefer_mbox_type,
|
||||
)))
|
||||
}
|
||||
},
|
||||
|
@ -1469,7 +1468,7 @@ impl MboxType {
|
|||
return Err(Error::new(format!(
|
||||
"\"root_mailbox\" {} for account {} is not a valid path.",
|
||||
s.root_mailbox.as_str(),
|
||||
s.name()
|
||||
s.name
|
||||
)));
|
||||
}
|
||||
let prefer_mbox_type: Result<String> =
|
||||
|
|
|
@ -607,7 +607,7 @@ impl NntpType {
|
|||
},
|
||||
};
|
||||
let account_hash = AccountHash::from_bytes(s.name.as_bytes());
|
||||
let account_name = Arc::new(s.name().to_string());
|
||||
let account_name = Arc::new(s.name.to_string());
|
||||
let mut mailboxes = HashMap::default();
|
||||
for (k, _f) in s.mailboxes.iter() {
|
||||
let mailbox_hash = MailboxHash(get_path_hash!(&k));
|
||||
|
|
|
@ -326,8 +326,7 @@ impl NotmuchDb {
|
|||
return Err(Error::new(format!(
|
||||
"Notmuch `library_file_path` setting value `{}` for account {} does \
|
||||
not exist or is a directory or not a valid library file.",
|
||||
dlpath,
|
||||
s.name()
|
||||
dlpath, s.name
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration)
|
||||
.set_source(Some(Arc::new(err))));
|
||||
|
@ -344,7 +343,7 @@ impl NotmuchDb {
|
|||
return Err(Error::new(format!(
|
||||
"Notmuch `root_mailbox` {} for account {} does not exist.",
|
||||
s.root_mailbox.as_str(),
|
||||
s.name()
|
||||
s.name
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration));
|
||||
}
|
||||
|
@ -352,7 +351,7 @@ impl NotmuchDb {
|
|||
return Err(Error::new(format!(
|
||||
"Notmuch `root_mailbox` {} for account {} is not a directory.",
|
||||
s.root_mailbox.as_str(),
|
||||
s.name()
|
||||
s.name
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration));
|
||||
}
|
||||
|
@ -362,7 +361,7 @@ impl NotmuchDb {
|
|||
"Notmuch `root_mailbox` {} for account {} does not contain a `.notmuch` \
|
||||
subdirectory.",
|
||||
s.root_mailbox.as_str(),
|
||||
s.name()
|
||||
s.name
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration));
|
||||
}
|
||||
|
@ -394,8 +393,7 @@ impl NotmuchDb {
|
|||
return Err(Error::new(format!(
|
||||
"notmuch mailbox configuration entry `{}` for account {} should have a \
|
||||
`query` value set.",
|
||||
k,
|
||||
s.name(),
|
||||
k, s.name,
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration));
|
||||
}
|
||||
|
@ -423,7 +421,7 @@ impl NotmuchDb {
|
|||
}
|
||||
}
|
||||
|
||||
let account_hash = AccountHash::from_bytes(s.name().as_bytes());
|
||||
let account_hash = AccountHash::from_bytes(s.name.as_bytes());
|
||||
Ok(Box::new(NotmuchDb {
|
||||
lib,
|
||||
revision_uuid: Arc::new(RwLock::new(0)),
|
||||
|
@ -434,7 +432,7 @@ impl NotmuchDb {
|
|||
|
||||
mailboxes: Arc::new(RwLock::new(mailboxes)),
|
||||
save_messages_to: None,
|
||||
_account_name: Arc::new(s.name().to_string()),
|
||||
_account_name: Arc::new(s.name.to_string()),
|
||||
account_hash,
|
||||
event_consumer,
|
||||
}))
|
||||
|
@ -446,7 +444,7 @@ impl NotmuchDb {
|
|||
return Err(Error::new(format!(
|
||||
"Notmuch `root_mailbox` {} for account {} does not exist.",
|
||||
s.root_mailbox.as_str(),
|
||||
s.name()
|
||||
s.name
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration));
|
||||
}
|
||||
|
@ -454,7 +452,7 @@ impl NotmuchDb {
|
|||
return Err(Error::new(format!(
|
||||
"Notmuch `root_mailbox` {} for account {} is not a directory.",
|
||||
s.root_mailbox.as_str(),
|
||||
s.name()
|
||||
s.name
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration));
|
||||
}
|
||||
|
@ -464,20 +462,19 @@ impl NotmuchDb {
|
|||
"Notmuch `root_mailbox` {} for account {} does not contain a `.notmuch` \
|
||||
subdirectory.",
|
||||
s.root_mailbox.as_str(),
|
||||
s.name()
|
||||
s.name
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration));
|
||||
}
|
||||
path.pop();
|
||||
|
||||
let account_name = s.name().to_string();
|
||||
let account_name = s.name.to_string();
|
||||
if let Some(lib_path) = s.extra.remove("library_file_path") {
|
||||
if !Path::new(&lib_path).exists() || Path::new(&lib_path).is_dir() {
|
||||
return Err(Error::new(format!(
|
||||
"Notmuch `library_file_path` setting value `{}` for account {} does not exist \
|
||||
or is a directory.",
|
||||
&lib_path,
|
||||
s.name()
|
||||
&lib_path, s.name
|
||||
))
|
||||
.set_kind(ErrorKind::Configuration));
|
||||
}
|
||||
|
|
|
@ -52,33 +52,18 @@ pub struct AccountSettings {
|
|||
}
|
||||
|
||||
impl AccountSettings {
|
||||
pub fn format(&self) -> &str {
|
||||
&self.format
|
||||
}
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
pub fn set_name(&mut self, s: String) {
|
||||
self.name = s;
|
||||
}
|
||||
pub fn root_mailbox(&self) -> &str {
|
||||
&self.root_mailbox
|
||||
}
|
||||
pub fn identity(&self) -> &str {
|
||||
&self.identity
|
||||
}
|
||||
pub fn read_only(&self) -> bool {
|
||||
self.read_only
|
||||
}
|
||||
pub fn display_name(&self) -> Option<&String> {
|
||||
self.display_name.as_ref()
|
||||
}
|
||||
pub fn order(&self) -> Option<(SortField, SortOrder)> {
|
||||
Some(self.order)
|
||||
/// Create the account's display name from fields
|
||||
/// [`AccountSettings::identity`] and [`AccountSettings::display_name`].
|
||||
pub fn make_display_name(&self) -> String {
|
||||
if let Some(d) = self.display_name.as_ref() {
|
||||
format!("{} <{}>", d, self.identity)
|
||||
} else {
|
||||
self.identity.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subscribed_mailboxes(&self) -> &Vec<String> {
|
||||
&self.subscribed_mailboxes
|
||||
pub fn order(&self) -> Option<(SortField, SortOrder)> {
|
||||
Some(self.order)
|
||||
}
|
||||
|
||||
#[cfg(feature = "vcard")]
|
||||
|
|
|
@ -41,12 +41,3 @@ pub mod pgp;
|
|||
|
||||
mod status;
|
||||
pub use self::status::*;
|
||||
|
||||
fn get_display_name(context: &Context, account_hash: AccountHash) -> String {
|
||||
let settings = context.accounts[&account_hash].settings.account();
|
||||
if let Some(d) = settings.display_name.as_ref() {
|
||||
format!("{} <{}>", d, settings.identity)
|
||||
} else {
|
||||
settings.identity.to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,7 +337,11 @@ impl Composer {
|
|||
}
|
||||
to.extend(envelope.to().iter().cloned());
|
||||
if let Ok(ours) = TryInto::<Address>::try_into(
|
||||
crate::components::mail::get_display_name(context, coordinates.0).as_str(),
|
||||
context.accounts[&coordinates.0]
|
||||
.settings
|
||||
.account()
|
||||
.make_display_name()
|
||||
.as_str(),
|
||||
) {
|
||||
to.remove(&ours);
|
||||
}
|
||||
|
@ -558,17 +562,7 @@ To: {}
|
|||
c.accounts
|
||||
.values()
|
||||
.map(|acc| {
|
||||
let addr = if let Some(display_name) =
|
||||
acc.settings.account.display_name()
|
||||
{
|
||||
format!(
|
||||
"{} <{}>",
|
||||
display_name,
|
||||
acc.settings.account.identity()
|
||||
)
|
||||
} else {
|
||||
acc.settings.account.identity().to_string()
|
||||
};
|
||||
let addr = acc.settings.account.make_display_name();
|
||||
let desc =
|
||||
match account_settings!(c[acc.hash()].composing.send_mail) {
|
||||
crate::conf::composing::SendMail::ShellCommand(ref cmd) => {
|
||||
|
@ -805,7 +799,10 @@ impl Component for Composer {
|
|||
{
|
||||
self.draft.set_header(
|
||||
"From",
|
||||
crate::components::mail::get_display_name(context, self.account_hash),
|
||||
context.accounts[&self.account_hash]
|
||||
.settings
|
||||
.account()
|
||||
.make_display_name(),
|
||||
);
|
||||
}
|
||||
self.pager.update_from_str(self.draft.body(), Some(77));
|
||||
|
|
|
@ -2664,10 +2664,10 @@ impl Component for MailView {
|
|||
let mut draft: Draft = mailto.into();
|
||||
draft.set_header(
|
||||
"From",
|
||||
crate::components::mail::get_display_name(
|
||||
context,
|
||||
self.coordinates.0,
|
||||
),
|
||||
context.accounts[&self.coordinates.0]
|
||||
.settings
|
||||
.account()
|
||||
.make_display_name(),
|
||||
);
|
||||
/* Manually drop stuff because borrowck doesn't do it
|
||||
* on its own */
|
||||
|
|
|
@ -621,7 +621,7 @@ impl Settings {
|
|||
|
||||
for (id, x) in fs.accounts {
|
||||
let mut ac = AccountConf::from(x);
|
||||
ac.account.set_name(id.clone());
|
||||
ac.account.name = id.clone();
|
||||
|
||||
s.insert(id, ac);
|
||||
}
|
||||
|
|
|
@ -438,7 +438,7 @@ impl Account {
|
|||
event_consumer: BackendEventConsumer,
|
||||
) -> Result<Self> {
|
||||
let s = settings.clone();
|
||||
let backend = map.get(settings.account().format())(
|
||||
let backend = map.get(&settings.account().format)(
|
||||
settings.account(),
|
||||
Box::new(move |path: &str| {
|
||||
s.account.subscribed_mailboxes.is_empty()
|
||||
|
@ -1251,7 +1251,7 @@ impl Account {
|
|||
mailbox_hash: MailboxHash,
|
||||
flags: Option<Flag>,
|
||||
) -> Result<()> {
|
||||
if self.settings.account.read_only() {
|
||||
if self.settings.account.read_only {
|
||||
return Err(Error::new(format!(
|
||||
"Account {} is read-only.",
|
||||
self.name.as_str()
|
||||
|
@ -1453,7 +1453,7 @@ impl Account {
|
|||
}
|
||||
pub fn operation(&self, h: EnvelopeHash) -> Result<Box<dyn BackendOp>> {
|
||||
let operation = self.backend.read().unwrap().operation(h)?;
|
||||
Ok(if self.settings.account.read_only() {
|
||||
Ok(if self.settings.account.read_only {
|
||||
ReadOnlyOp::new(operation)
|
||||
} else {
|
||||
operation
|
||||
|
@ -1465,7 +1465,7 @@ impl Account {
|
|||
op: crate::command::actions::MailboxOperation,
|
||||
) -> Result<()> {
|
||||
use crate::command::actions::MailboxOperation;
|
||||
if self.settings.account.read_only() {
|
||||
if self.settings.account.read_only {
|
||||
return Err(Error::new("Account is read-only."));
|
||||
}
|
||||
match op {
|
||||
|
|
Loading…
Reference in New Issue