From 4a2e1897a6ebaf5014b14a4b469b84fa7dd93c97 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 16 Oct 2019 13:51:18 +0200 Subject: [PATCH] fix(smtp): use correct auth mechanisms --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- src/smtp.rs | 20 +++++++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77c8be658..02b1b0250 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -500,7 +500,7 @@ dependencies = [ "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "jetscii 0.4.4 (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)", + "lettre 0.9.2 (git+https://github.com/deltachat/lettre?branch=feat/multi-auth)", "libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)", "mmime 0.1.2", "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1081,7 +1081,7 @@ dependencies = [ [[package]] name = "lettre" version = "0.9.2" -source = "git+https://github.com/deltachat/lettre#aeec999c27a70870e4b7b149e45f24188c1ff351" +source = "git+https://github.com/deltachat/lettre?branch=feat/multi-auth#119ef8e5a003e0afb3abcbe706951cf827bdac2c" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2945,7 +2945,7 @@ dependencies = [ "checksum keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum lettre 0.9.2 (git+https://github.com/deltachat/lettre)" = "" +"checksum lettre 0.9.2 (git+https://github.com/deltachat/lettre?branch=feat/multi-auth)" = "" "checksum lexical-core 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2304bccb228c4b020f3a4835d247df0a02a7c4686098d4167762cfbbe4c5cb14" "checksum libc 0.2.64 (registry+https://github.com/rust-lang/crates.io-index)" = "74dfca3d9957906e8d1e6a0b641dc9a59848e793f1da2165889fd4f62d10d79c" "checksum libm 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" diff --git a/Cargo.toml b/Cargo.toml index b8278c687..b5cd71c1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ reqwest = "0.9.15" num-derive = "0.2.5" num-traits = "0.2.6" native-tls = "0.2.3" -lettre = { git = "https://github.com/deltachat/lettre" } +lettre = { git = "https://github.com/deltachat/lettre", branch = "feat/multi-auth" } imap = { git = "https://github.com/dignifiedquire/rust-imap", branch = "feat/expose-read-greeting" } base64 = "0.10" charset = "0.1" diff --git a/src/smtp.rs b/src/smtp.rs index 9643a583a..0532d0343 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -71,7 +71,7 @@ impl Smtp { let tls = dc_build_tls(lp.smtp_certificate_checks).unwrap(); let tls_parameters = ClientTlsParameters::new(domain.to_string(), tls); - let creds = if 0 != lp.server_flags & (DC_LP_AUTH_OAUTH2 as i32) { + let (creds, mechanism) = if 0 != lp.server_flags & (DC_LP_AUTH_OAUTH2 as i32) { // oauth2 let addr = &lp.addr; let send_pw = &lp.send_pw; @@ -81,15 +81,24 @@ impl Smtp { } let user = &lp.send_user; - lettre::smtp::authentication::Credentials::new( - user.to_string(), - access_token.unwrap_or_default(), + ( + lettre::smtp::authentication::Credentials::new( + user.to_string(), + access_token.unwrap_or_default(), + ), + vec![lettre::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) + ( + lettre::smtp::authentication::Credentials::new(user, pw), + vec![ + lettre::smtp::authentication::Mechanism::Plain, + lettre::smtp::authentication::Mechanism::Login, + ], + ) }; let security = if 0 @@ -105,6 +114,7 @@ impl Smtp { let client = client .smtp_utf8(true) .credentials(creds) + .authentication_mechanism(mechanism) .connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited); self.transport = Some(client.transport()); context.call_cb(Event::SmtpConnected(format!(