mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-20 07:01:12 +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_host: String,
|
||||||
pub imap_port: u16,
|
pub imap_port: u16,
|
||||||
pub imap_starttls: Option<bool>,
|
pub imap_starttls: Option<bool>,
|
||||||
|
pub imap_insecure: Option<bool>,
|
||||||
pub imap_login: String,
|
pub imap_login: String,
|
||||||
pub imap_passwd_cmd: String,
|
pub imap_passwd_cmd: String,
|
||||||
|
|
||||||
pub smtp_host: String,
|
pub smtp_host: String,
|
||||||
pub smtp_port: u16,
|
pub smtp_port: u16,
|
||||||
pub smtp_starttls: Option<bool>,
|
pub smtp_starttls: Option<bool>,
|
||||||
|
pub smtp_insecure: Option<bool>,
|
||||||
pub smtp_login: String,
|
pub smtp_login: String,
|
||||||
pub smtp_passwd_cmd: 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> {
|
pub fn smtp_creds(&self) -> Result<SmtpCredentials> {
|
||||||
let passwd = run_cmd(&self.smtp_passwd_cmd).chain_err(|| "Cannot run SMTP passwd cmd")?;
|
let passwd = run_cmd(&self.smtp_passwd_cmd).chain_err(|| "Cannot run SMTP passwd cmd")?;
|
||||||
let passwd = passwd.trim_end_matches("\n").to_owned();
|
let passwd = passwd.trim_end_matches("\n").to_owned();
|
||||||
|
@ -67,6 +76,13 @@ impl Account {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn smtp_insecure(&self) -> bool {
|
||||||
|
match self.smtp_insecure {
|
||||||
|
Some(true) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
|
|
|
@ -24,7 +24,12 @@ pub struct ImapConnector<'a> {
|
||||||
|
|
||||||
impl<'ic> ImapConnector<'ic> {
|
impl<'ic> ImapConnector<'ic> {
|
||||||
pub fn new(account: &'ic Account) -> Result<Self> {
|
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() {
|
let client = if account.imap_starttls() {
|
||||||
imap::connect_starttls(account.imap_addr(), &account.imap_host, &tls)
|
imap::connect_starttls(account.imap_addr(), &account.imap_host, &tls)
|
||||||
.chain_err(|| "Cannot connect using STARTTLS")
|
.chain_err(|| "Cannot connect using STARTTLS")
|
||||||
|
|
16
src/smtp.rs
16
src/smtp.rs
|
@ -1,5 +1,12 @@
|
||||||
use error_chain::error_chain;
|
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;
|
use crate::config::model::Account;
|
||||||
|
|
||||||
|
@ -19,8 +26,15 @@ pub fn send(account: &Account, msg: &lettre::Message) -> Result<()> {
|
||||||
SmtpTransport::relay
|
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)?
|
smtp_relay(&account.smtp_host)?
|
||||||
.port(account.smtp_port)
|
.port(account.smtp_port)
|
||||||
|
.tls(Tls::Wrapper(tls))
|
||||||
.credentials(account.smtp_creds()?)
|
.credentials(account.smtp_creds()?)
|
||||||
.build()
|
.build()
|
||||||
.send(msg)?;
|
.send(msg)?;
|
||||||
|
|
Loading…
Reference in a new issue