-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
288 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[cfg(feature = "imap-backend")] | ||
use email::imap::ImapConfig; | ||
#[cfg(feature = "notmuch-backend")] | ||
use email::notmuch::NotmuchConfig; | ||
#[cfg(feature = "smtp-sender")] | ||
use email::smtp::SmtpConfig; | ||
use email::{maildir::MaildirConfig, sendmail::SendmailConfig}; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub enum BackendConfig { | ||
Maildir(MaildirConfig), | ||
#[cfg(feature = "imap-backend")] | ||
Imap(ImapConfig), | ||
#[cfg(feature = "notmuch-backend")] | ||
Notmuch(NotmuchConfig), | ||
#[cfg(feature = "smtp-sender")] | ||
Smtp(SmtpConfig), | ||
Sendmail(SendmailConfig), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use anyhow::Result; | ||
use dialoguer::Select; | ||
|
||
#[cfg(feature = "imap-backend")] | ||
use crate::imap; | ||
#[cfg(feature = "notmuch-backend")] | ||
use crate::notmuch; | ||
#[cfg(feature = "smtp-sender")] | ||
use crate::smtp; | ||
use crate::{config::wizard::THEME, maildir, sendmail}; | ||
|
||
use super::{config::BackendConfig, BackendKind}; | ||
|
||
const DEFAULT_BACKEND_KINDS: &[BackendKind] = &[ | ||
BackendKind::Maildir, | ||
#[cfg(feature = "imap-backend")] | ||
BackendKind::Imap, | ||
#[cfg(feature = "notmuch-backend")] | ||
BackendKind::Notmuch, | ||
]; | ||
|
||
const SEND_MESSAGE_BACKEND_KINDS: &[BackendKind] = &[ | ||
BackendKind::Sendmail, | ||
#[cfg(feature = "smtp-sender")] | ||
BackendKind::Smtp, | ||
]; | ||
|
||
pub(crate) async fn configure(account_name: &str, email: &str) -> Result<Option<BackendConfig>> { | ||
let kind = Select::with_theme(&*THEME) | ||
.with_prompt("Default email backend") | ||
.items(DEFAULT_BACKEND_KINDS) | ||
.default(0) | ||
.interact_opt()? | ||
.and_then(|idx| DEFAULT_BACKEND_KINDS.get(idx).map(Clone::clone)); | ||
|
||
let config = match kind { | ||
Some(kind) if kind == BackendKind::Maildir => Some(maildir::wizard::configure()?), | ||
#[cfg(feature = "imap-backend")] | ||
Some(kind) if kind == BackendKind::Imap => { | ||
Some(imap::wizard::configure(account_name, email).await?) | ||
} | ||
#[cfg(feature = "notmuch-backend")] | ||
Some(kind) if kind == BackendKind::Notmuch => Some(notmuch::wizard::configure()?), | ||
_ => None, | ||
}; | ||
|
||
Ok(config) | ||
} | ||
|
||
pub(crate) async fn configure_sender( | ||
account_name: &str, | ||
email: &str, | ||
) -> Result<Option<BackendConfig>> { | ||
let kind = Select::with_theme(&*THEME) | ||
.with_prompt("Default email backend") | ||
.items(SEND_MESSAGE_BACKEND_KINDS) | ||
.default(0) | ||
.interact_opt()? | ||
.and_then(|idx| SEND_MESSAGE_BACKEND_KINDS.get(idx).map(Clone::clone)); | ||
|
||
let config = match kind { | ||
Some(kind) if kind == BackendKind::Sendmail => Some(sendmail::wizard::configure()?), | ||
#[cfg(feature = "smtp-sender")] | ||
Some(kind) if kind == BackendKind::Smtp => { | ||
Some(smtp::wizard::configure(account_name, email).await?) | ||
} | ||
_ => None, | ||
}; | ||
|
||
Ok(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.