diff --git a/Cargo.toml b/Cargo.toml index 240dd9a..54930aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ log = "0.4.14" maildir = "0.6.0" mailparse = "0.13.6" native-tls = "0.2.8" -notmuch = "0.7.1" +notmuch = { version = "0.7.1", optional = true } regex = "1.5.4" rfc2047-decoder = "0.1.2" serde = { version = "1.0.118", features = ["derive"] } diff --git a/src/config/account_config.rs b/src/config/account_config.rs index b222abd..20c51ca 100644 --- a/src/config/account_config.rs +++ b/src/config/account_config.rs @@ -70,6 +70,7 @@ impl<'a> AccountConfig { DeserializedAccountConfig::Maildir(account) => { account.default.unwrap_or_default() } + #[cfg(feature = "notmuch")] DeserializedAccountConfig::Notmuch(account) => { account.default.unwrap_or_default() } @@ -177,6 +178,7 @@ impl<'a> AccountConfig { maildir_dir: shellexpand::full(&config.maildir_dir)?.to_string().into(), }) } + #[cfg(feature = "notmuch")] DeserializedAccountConfig::Notmuch(config) => { BackendConfig::Notmuch(NotmuchBackendConfig { notmuch_database_dir: shellexpand::full(&config.notmuch_database_dir)? @@ -311,6 +313,7 @@ impl<'a> AccountConfig { pub enum BackendConfig { Imap(ImapBackendConfig), Maildir(MaildirBackendConfig), + #[cfg(feature = "notmuch")] Notmuch(NotmuchBackendConfig), } @@ -350,6 +353,7 @@ pub struct MaildirBackendConfig { } /// Represents the Notmuch backend. +#[cfg(feature = "notmuch")] #[derive(Debug, Default, Clone)] pub struct NotmuchBackendConfig { /// Represents the Notmuch database path. diff --git a/src/config/deserialized_account_config.rs b/src/config/deserialized_account_config.rs index 4f5c440..80b59fb 100644 --- a/src/config/deserialized_account_config.rs +++ b/src/config/deserialized_account_config.rs @@ -11,6 +11,7 @@ pub trait ToDeserializedBaseAccountConfig { pub enum DeserializedAccountConfig { Imap(DeserializedImapAccountConfig), Maildir(DeserializedMaildirAccountConfig), + #[cfg(feature = "notmuch")] Notmuch(DeserializedNotmuchAccountConfig), } @@ -19,6 +20,7 @@ impl ToDeserializedBaseAccountConfig for DeserializedAccountConfig { match self { Self::Imap(config) => config.to_base(), Self::Maildir(config) => config.to_base(), + #[cfg(feature = "notmuch")] Self::Notmuch(config) => config.to_base(), } } @@ -122,6 +124,7 @@ make_account_config!( make_account_config!(DeserializedMaildirAccountConfig, maildir_dir: String); +#[cfg(feature = "notmuch")] make_account_config!( DeserializedNotmuchAccountConfig, notmuch_database_dir: String diff --git a/src/lib.rs b/src/lib.rs index 5e9a09a..48b162d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,9 @@ pub mod backends { pub use maildir_flag::*; } + #[cfg(feature = "notmuch")] pub use self::notmuch::*; + #[cfg(feature = "notmuch")] pub mod notmuch { pub mod notmuch_backend; pub use notmuch_backend::*; diff --git a/src/main.rs b/src/main.rs index f4db6b7..c99d4cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::{convert::TryFrom, env}; use url::Url; use himalaya::{ - backends::{imap_arg, imap_handler, Backend, ImapBackend, MaildirBackend, NotmuchBackend}, + backends::{imap_arg, imap_handler, Backend, ImapBackend, MaildirBackend}, compl::{compl_arg, compl_handler}, config::{ account_args, config_args, AccountConfig, BackendConfig, DeserializedConfig, @@ -15,6 +15,9 @@ use himalaya::{ smtp::LettreService, }; +#[cfg(feature = "notmuch")] +use himalaya::backends::NotmuchBackend; + fn create_app<'a>() -> clap::App<'a, 'a> { clap::App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) @@ -48,6 +51,7 @@ fn main() -> Result<()> { let mut imap; let mut maildir; + #[cfg(feature = "notmuch")] let mut notmuch; let backend: Box<&mut dyn Backend> = match backend_config { BackendConfig::Imap(ref imap_config) => { @@ -58,6 +62,7 @@ fn main() -> Result<()> { maildir = MaildirBackend::new(&account_config, maildir_config); Box::new(&mut maildir) } + #[cfg(feature = "notmuch")] BackendConfig::Notmuch(ref notmuch_config) => { notmuch = NotmuchBackend::new(&account_config, notmuch_config)?; Box::new(&mut notmuch) @@ -90,6 +95,7 @@ fn main() -> Result<()> { let mut printer = StdoutPrinter::try_from(m.value_of("output"))?; let mut imap; let mut maildir; + #[cfg(feature = "notmuch")] let mut notmuch; let backend: Box<&mut dyn Backend> = match backend_config { BackendConfig::Imap(ref imap_config) => { @@ -100,6 +106,7 @@ fn main() -> Result<()> { maildir = MaildirBackend::new(&account_config, maildir_config); Box::new(&mut maildir) } + #[cfg(feature = "notmuch")] BackendConfig::Notmuch(ref notmuch_config) => { notmuch = NotmuchBackend::new(&account_config, notmuch_config)?; Box::new(&mut notmuch)