make notmuch optional via cargo features (#303)

This commit is contained in:
Clément DOUIN 2022-02-26 09:56:26 +01:00
parent 00e2524640
commit a2616fc1bd
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
5 changed files with 18 additions and 2 deletions

View file

@ -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"] }

View file

@ -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.

View file

@ -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

View file

@ -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::*;

View file

@ -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)