summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2022-08-30 12:23:25 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2022-08-30 12:23:25 +0300
commit480000ebbb67a80181fd27762ca649acf13df0f3 (patch)
tree8f7f1d18833a559cfc8e89e1dac2bdfc135ef744
parent29042aba593210f3be73010908d5092951b3b1a1 (diff)
downloadmeli-480000ebbb67a80181fd27762ca649acf13df0f3.zip
melib/notmuch: show error if account directory does not contain ".notmuch" subdirectory
Bug reported by user on mailing list.
-rw-r--r--melib/src/backends/notmuch.rs66
-rw-r--r--melib/src/error.rs17
2 files changed, 59 insertions, 24 deletions
diff --git a/melib/src/backends/notmuch.rs b/melib/src/backends/notmuch.rs
index 7a2e1a77..1661cf8d 100644
--- a/melib/src/backends/notmuch.rs
+++ b/melib/src/backends/notmuch.rs
@@ -314,14 +314,32 @@ impl NotmuchDb {
#[cfg(target_os = "macos")]
let dlpath = "libnotmuch.5.dylib";
let lib = Arc::new(unsafe { libloading::Library::new(dlpath)? });
- let path = Path::new(s.root_mailbox.as_str()).expand();
+ let mut path = Path::new(s.root_mailbox.as_str()).expand();
if !path.exists() {
return Err(MeliError::new(format!(
- "\"root_mailbox\" {} for account {} is not a valid path.",
+ "Notmuch `root_mailbox` {} for account {} does not exist.",
s.root_mailbox.as_str(),
s.name()
- )));
+ ))
+ .set_kind(ErrorKind::Configuration));
+ }
+ if !path.is_dir() {
+ return Err(MeliError::new(format!(
+ "Notmuch `root_mailbox` {} for account {} is not a directory.",
+ s.root_mailbox.as_str(),
+ s.name()
+ ))
+ .set_kind(ErrorKind::Configuration));
+ }
+ path.push(".notmuch");
+ if !path.exists() || !path.is_dir() {
+ return Err(MeliError::new(format!(
+ "Notmuch `root_mailbox` {} for account {} does not contain a `.notmuch` subdirectory.",
+ s.root_mailbox.as_str(),
+ s.name()
+ )).set_kind(ErrorKind::Configuration));
}
+ path.pop();
let mut mailboxes = HashMap::default();
for (k, f) in s.mailboxes.iter() {
@@ -347,9 +365,11 @@ impl NotmuchDb {
);
} else {
return Err(MeliError::new(format!(
- "notmuch mailbox configuration entry \"{}\" should have a \"query\" value set.",
- k
- )));
+ "notmuch mailbox configuration entry `{}` for account {} should have a `query` value set.",
+ k,
+ s.name(),
+ ))
+ .set_kind(ErrorKind::Configuration));
}
}
@@ -375,20 +395,42 @@ impl NotmuchDb {
}
pub fn validate_config(s: &mut AccountSettings) -> Result<()> {
- let path = Path::new(s.root_mailbox.as_str()).expand();
+ let mut path = Path::new(s.root_mailbox.as_str()).expand();
if !path.exists() {
return Err(MeliError::new(format!(
- "\"root_mailbox\" {} for account {} is not a valid path.",
+ "Notmuch `root_mailbox` {} for account {} does not exist.",
s.root_mailbox.as_str(),
s.name()
- )));
+ ))
+ .set_kind(ErrorKind::Configuration));
+ }
+ if !path.is_dir() {
+ return Err(MeliError::new(format!(
+ "Notmuch `root_mailbox` {} for account {} is not a directory.",
+ s.root_mailbox.as_str(),
+ s.name()
+ ))
+ .set_kind(ErrorKind::Configuration));
}
+ path.push(".notmuch");
+ if !path.exists() || !path.is_dir() {
+ return Err(MeliError::new(format!(
+ "Notmuch `root_mailbox` {} for account {} does not contain a `.notmuch` subdirectory.",
+ s.root_mailbox.as_str(),
+ s.name()
+ )).set_kind(ErrorKind::Configuration));
+ }
+ path.pop();
+
+ let account_name = s.name().to_string();
for (k, f) in s.mailboxes.iter_mut() {
if f.extra.remove("query").is_none() {
return Err(MeliError::new(format!(
- "notmuch mailbox configuration entry \"{}\" should have a \"query\" value set.",
- k
- )));
+ "notmuch mailbox configuration entry `{}` for account {} should have a `query` value set.",
+ k,
+ account_name,
+ ))
+ .set_kind(ErrorKind::Configuration));
}
}
Ok(())
diff --git a/melib/src/error.rs b/melib/src/error.rs
index aa83de73..14053fa0 100644
--- a/melib/src/error.rs
+++ b/melib/src/error.rs
@@ -39,6 +39,7 @@ pub enum ErrorKind {
None,
External,
Authentication,
+ Configuration,
Bug,
Network,
Timeout,
@@ -60,6 +61,7 @@ impl fmt::Display for ErrorKind {
ErrorKind::Network => "Network",
ErrorKind::Timeout => "Timeout",
ErrorKind::OSError => "OS Error",
+ ErrorKind::Configuration => "Configuration",
ErrorKind::NotImplemented => "Not implemented",
ErrorKind::NotSupported => "Not supported",
}
@@ -69,24 +71,15 @@ impl fmt::Display for ErrorKind {
impl ErrorKind {
pub fn is_network(&self) -> bool {
- match self {
- ErrorKind::Network => true,
- _ => false,
- }
+ matches!(self, ErrorKind::Network)
}
pub fn is_timeout(&self) -> bool {
- match self {
- ErrorKind::Timeout => true,
- _ => false,
- }
+ matches!(self, ErrorKind::Timeout)
}
pub fn is_authentication(&self) -> bool {
- match self {
- ErrorKind::Authentication => true,
- _ => false,
- }
+ matches!(self, ErrorKind::Authentication)
}
}