diff --git a/Cargo.lock b/Cargo.lock index 21a119e35..bfc1f5489 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,6 +116,31 @@ dependencies = [ "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "async-smtp" +version = "0.1.0" +source = "git+https://github.com/async-email/async-smtp#f6bf23d29fa0a09db2bce557a0e2c13c3d851f2f" +dependencies = [ + "async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "async-tls 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "async-trait 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "fast_chemail 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", + "hostname 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "nom 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rustls 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustls-connector 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "snafu 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki-roots 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "async-std" version = "1.2.0" @@ -161,6 +186,16 @@ dependencies = [ "webpki-roots 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "async-trait" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.13" @@ -610,6 +645,7 @@ name = "deltachat" version = "1.0.0-beta.12" dependencies = [ "async-imap 0.1.1 (git+https://github.com/async-email/async-imap)", + "async-smtp 0.1.0 (git+https://github.com/async-email/async-smtp)", "async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "async-tls 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -628,7 +664,6 @@ dependencies = [ "image-meta 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lettre 0.9.2 (git+https://github.com/deltachat/lettre?branch=feat/mail)", "lettre_email 0.9.2 (git+https://github.com/deltachat/lettre?branch=feat/mail)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "mailparse 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -760,6 +795,11 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "doc-comment" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "dtoa" version = "0.4.4" @@ -1198,11 +1238,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hostname" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "match_cfg 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1415,17 +1456,9 @@ name = "lettre" version = "0.9.2" source = "git+https://github.com/deltachat/lettre?branch=feat/mail#00ba9db544059ddd60048f0b85d5052e4bf605da" dependencies = [ - "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "fast_chemail 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "nom 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustls 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustls-connector 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", "webpki-roots 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1521,6 +1554,11 @@ dependencies = [ "quoted_printable 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "matches" version = "0.1.8" @@ -2607,6 +2645,25 @@ name = "smallvec" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "snafu" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "doc-comment 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "snafu-derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "snafu-derive" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sourcefile" version = "0.1.4" @@ -3324,14 +3381,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "winutil" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" @@ -3393,9 +3442,11 @@ dependencies = [ "checksum async-attributes 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "efd3d156917d94862e779f356c5acae312b08fd3121e792c857d7928c8088423" "checksum async-imap 0.1.1 (git+https://github.com/async-email/async-imap)" = "" "checksum async-macros 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "644a5a8de80f2085a1e7e57cd1544a2a7438f6e003c0790999bd43b92a77cdb2" +"checksum async-smtp 0.1.0 (git+https://github.com/async-email/async-smtp)" = "" "checksum async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "513ee3c49800679a319912340f5601afda9e72848d7dea3a48bab489e8c1a46f" "checksum async-task 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de6bd58f7b9cc49032559422595c81cbfcf04db2f2133592f70af19e258a1ced" "checksum async-tls 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce6977f57fa68da77ffe5542950d47e9c23d65f5bc7cb0a9f8700996913eec7" +"checksum async-trait 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "8b6dd385bb33043b833ba049048d57bdbb4d654a121ed68c71871ca51ff67070" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" @@ -3457,6 +3508,7 @@ dependencies = [ "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +"checksum doc-comment 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "923dea538cea0aa3025e8685b20d6ee21ef99c4f77e954a30febbaac5ec73a97" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum ed25519-dalek 1.0.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)" = "845aaacc16f01178f33349e7c992ecd0cee095aa5e577f0f4dee35971bd36455" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" @@ -3510,7 +3562,7 @@ dependencies = [ "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" "checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" -"checksum hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "21ceb46a83a85e824ef93669c8b390009623863b5c195d1ba747292c0c72f94e" +"checksum hostname 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc5260e6c63877196b6fca5a7fb4eaff751134045ad3415716192baa36f5b9a0" "checksum http 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" "checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" @@ -3544,6 +3596,7 @@ dependencies = [ "checksum lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" "checksum mach 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1" "checksum mailparse 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c00eb97cc18f08aaadd02808328dcc9be94948d8e5b54adbfd3414d2f87f7bf1" +"checksum match_cfg 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" "checksum md-5 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a18af3dcaf2b0219366cdb4e2af65a6101457b415c3d1a5c71dd9c2b7c77b9c8" @@ -3657,6 +3710,8 @@ dependencies = [ "checksum slice-deque 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ffddf594f5f597f63533d897427a570dbaa9feabaaa06595b74b71b7014507d7" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecf3b85f68e8abaa7555aa5abdb1153079387e60b718283d732f03897fcfc86" +"checksum snafu 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41207ca11f96a62cd34e6b7fdf73d322b25ae3848eb9d38302169724bb32cf27" +"checksum snafu-derive 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4c5e338c8b0577457c9dda8e794b6ad7231c96e25b1b0dd5842d52249020c1c0" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" @@ -3743,7 +3798,6 @@ dependencies = [ "checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767" "checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" "checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" -"checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" "checksum yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d" diff --git a/Cargo.toml b/Cargo.toml index b33b0c821..1d87af162 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ smallvec = "0.6.9" reqwest = { version = "0.9.15", default-features = false, features = ["rustls-tls"] } num-derive = "0.2.5" num-traits = "0.2.6" -lettre = { git = "https://github.com/deltachat/lettre", branch = "feat/mail" } +async-smtp = { git = "https://github.com/async-email/async-smtp" } lettre_email = { git = "https://github.com/deltachat/lettre", branch = "feat/mail" } async-imap = { git = "https://github.com/async-email/async-imap", branch="master" } async-tls = "0.6" diff --git a/src/job.rs b/src/job.rs index d80a0f365..49a109169 100644 --- a/src/job.rs +++ b/src/job.rs @@ -167,13 +167,15 @@ impl Job { if let Some(recipients) = self.param.get(Param::Recipients) { let recipients_list = recipients .split('\x1e') - .filter_map(|addr| match lettre::EmailAddress::new(addr.to_string()) { - Ok(addr) => Some(addr), - Err(err) => { - warn!(context, "invalid recipient: {} {:?}", addr, err); - None - } - }) + .filter_map( + |addr| match async_smtp::EmailAddress::new(addr.to_string()) { + Ok(addr) => Some(addr), + Err(err) => { + warn!(context, "invalid recipient: {} {:?}", addr, err); + None + } + }, + ) .collect::>(); /* if there is a msg-id and it does not exist in the db, cancel sending. diff --git a/src/smtp/mod.rs b/src/smtp/mod.rs index f714e185c..20cad417c 100644 --- a/src/smtp/mod.rs +++ b/src/smtp/mod.rs @@ -2,8 +2,10 @@ pub mod send; -use lettre::smtp::client::net::*; -use lettre::*; +use async_smtp::smtp::client::net::*; +use async_smtp::*; + +use async_std::task; use crate::constants::*; use crate::context::Context; @@ -19,12 +21,12 @@ pub enum Error { InvalidLoginAddress { address: String, #[cause] - error: lettre::error::Error, + error: async_smtp::error::Error, }, #[fail(display = "SMTP failed to connect: {:?}", _0)] - ConnectionFailure(#[cause] lettre::smtp::error::Error), + ConnectionFailure(#[cause] async_smtp::smtp::error::Error), #[fail(display = "SMTP: failed to setup connection {:?}", _0)] - ConnectionSetupFailure(#[cause] lettre::smtp::error::Error), + ConnectionSetupFailure(#[cause] async_smtp::smtp::error::Error), #[fail(display = "SMTP: oauth2 error {:?}", _0)] Oauth2Error { address: String }, } @@ -34,7 +36,7 @@ pub type Result = std::result::Result; #[derive(Default, DebugStub)] pub struct Smtp { #[debug_stub(some = "SmtpTransport")] - transport: Option, + transport: Option, transport_connected: bool, /// Email address we are sending from. from: Option, @@ -99,21 +101,21 @@ impl Smtp { } let user = &lp.send_user; ( - lettre::smtp::authentication::Credentials::new( + async_smtp::smtp::authentication::Credentials::new( user.to_string(), access_token.unwrap_or_default(), ), - vec![lettre::smtp::authentication::Mechanism::Xoauth2], + vec![async_smtp::smtp::authentication::Mechanism::Xoauth2], ) } else { // plain let user = lp.send_user.clone(); let pw = lp.send_pw.clone(); ( - lettre::smtp::authentication::Credentials::new(user, pw), + async_smtp::smtp::authentication::Credentials::new(user, pw), vec![ - lettre::smtp::authentication::Mechanism::Plain, - lettre::smtp::authentication::Mechanism::Login, + async_smtp::smtp::authentication::Mechanism::Plain, + async_smtp::smtp::authentication::Mechanism::Login, ], ) }; @@ -121,21 +123,24 @@ impl Smtp { let security = if 0 != lp.server_flags & (DC_LP_SMTP_SOCKET_STARTTLS | DC_LP_SMTP_SOCKET_PLAIN) as i32 { - lettre::smtp::ClientSecurity::Opportunistic(tls_parameters) + async_smtp::smtp::ClientSecurity::Opportunistic(tls_parameters) } else { - lettre::smtp::ClientSecurity::Wrapper(tls_parameters) + async_smtp::smtp::ClientSecurity::Wrapper(tls_parameters) }; - let client = lettre::smtp::SmtpClient::new((domain.as_str(), port), security) - .map_err(Error::ConnectionSetupFailure)?; + let client = task::block_on(async_smtp::smtp::SmtpClient::with_security( + (domain.as_str(), port), + security, + )) + .map_err(Error::ConnectionSetupFailure)?; let client = client .smtp_utf8(true) .credentials(creds) .authentication_mechanism(mechanism) - .connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited); - let mut trans = client.transport(); - trans.connect().map_err(Error::ConnectionFailure)?; + .connection_reuse(async_smtp::smtp::ConnectionReuseParameters::ReuseUnlimited); + let mut trans = client.into_transport(); + task::block_on(trans.connect()).map_err(Error::ConnectionFailure)?; self.transport = Some(trans); self.transport_connected = true; diff --git a/src/smtp/send.rs b/src/smtp/send.rs index 6d3a3213b..fcfbf2d68 100644 --- a/src/smtp/send.rs +++ b/src/smtp/send.rs @@ -1,7 +1,9 @@ //! # SMTP message sending use super::Smtp; -use lettre::*; +use async_smtp::*; + +use async_std::task; use crate::context::Context; use crate::events::Event; @@ -11,9 +13,9 @@ pub type Result = std::result::Result; #[derive(Debug, Fail)] pub enum Error { #[fail(display = "Envelope error: {}", _0)] - EnvelopeError(#[cause] lettre::error::Error), + EnvelopeError(#[cause] async_smtp::error::Error), #[fail(display = "Send error: {}", _0)] - SendError(#[cause] lettre::smtp::error::Error), + SendError(#[cause] async_smtp::smtp::error::Error), #[fail(display = "SMTP has no transport")] NoTransport, } @@ -45,7 +47,7 @@ impl Smtp { message, ); - transport.send(mail).map_err(Error::SendError)?; + task::block_on(transport.send(mail)).map_err(Error::SendError)?; context.call_cb(Event::SmtpMessageSent(format!( "Message len={} was smtp-sent to {}",