mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 09:05:13 +00:00
add insecure tls option for testing purpose (#103)
This commit is contained in:
parent
aad74add52
commit
f4cc584716
|
@ -25,12 +25,14 @@ pub struct Account {
|
|||
pub imap_host: String,
|
||||
pub imap_port: u16,
|
||||
pub imap_starttls: Option<bool>,
|
||||
pub imap_insecure: Option<bool>,
|
||||
pub imap_login: String,
|
||||
pub imap_passwd_cmd: String,
|
||||
|
||||
pub smtp_host: String,
|
||||
pub smtp_port: u16,
|
||||
pub smtp_starttls: Option<bool>,
|
||||
pub smtp_insecure: Option<bool>,
|
||||
pub smtp_login: String,
|
||||
pub smtp_passwd_cmd: String,
|
||||
}
|
||||
|
@ -54,6 +56,13 @@ impl Account {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn imap_insecure(&self) -> bool {
|
||||
match self.imap_insecure {
|
||||
Some(true) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn smtp_creds(&self) -> Result<SmtpCredentials> {
|
||||
let passwd = run_cmd(&self.smtp_passwd_cmd).chain_err(|| "Cannot run SMTP passwd cmd")?;
|
||||
let passwd = passwd.trim_end_matches("\n").to_owned();
|
||||
|
@ -67,6 +76,13 @@ impl Account {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn smtp_insecure(&self) -> bool {
|
||||
match self.smtp_insecure {
|
||||
Some(true) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Config
|
||||
|
|
|
@ -24,7 +24,12 @@ pub struct ImapConnector<'a> {
|
|||
|
||||
impl<'ic> ImapConnector<'ic> {
|
||||
pub fn new(account: &'ic Account) -> Result<Self> {
|
||||
let tls = TlsConnector::new().chain_err(|| "Cannot create TLS connector")?;
|
||||
let tls = TlsConnector::builder()
|
||||
.danger_accept_invalid_certs(account.imap_insecure())
|
||||
.danger_accept_invalid_hostnames(account.imap_insecure())
|
||||
.build()
|
||||
.chain_err(|| "Cannot create TLS connector")?;
|
||||
|
||||
let client = if account.imap_starttls() {
|
||||
imap::connect_starttls(account.imap_addr(), &account.imap_host, &tls)
|
||||
.chain_err(|| "Cannot connect using STARTTLS")
|
||||
|
|
16
src/smtp.rs
16
src/smtp.rs
|
@ -1,5 +1,12 @@
|
|||
use error_chain::error_chain;
|
||||
use lettre::{self, transport::smtp::SmtpTransport, Transport};
|
||||
use lettre::{self,
|
||||
transport::{
|
||||
smtp::SmtpTransport,
|
||||
smtp::client::Tls,
|
||||
smtp::client::TlsParameters
|
||||
},
|
||||
Transport
|
||||
};
|
||||
|
||||
use crate::config::model::Account;
|
||||
|
||||
|
@ -19,8 +26,15 @@ pub fn send(account: &Account, msg: &lettre::Message) -> Result<()> {
|
|||
SmtpTransport::relay
|
||||
};
|
||||
|
||||
let tls = TlsParameters::builder(account.smtp_host.to_string())
|
||||
.dangerous_accept_invalid_hostnames(account.smtp_insecure())
|
||||
.dangerous_accept_invalid_certs(account.smtp_insecure())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
smtp_relay(&account.smtp_host)?
|
||||
.port(account.smtp_port)
|
||||
.tls(Tls::Wrapper(tls))
|
||||
.credentials(account.smtp_creds()?)
|
||||
.build()
|
||||
.send(msg)?;
|
||||
|
|
Loading…
Reference in a new issue