diff --git a/Cargo.toml b/Cargo.toml index abcdb4c..ec9e5dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ nom = { version = "7", optional = true } hostname = { version = "0.3", optional = true } # feature socket2 = { version = "0.5.1", optional = true } url = { version = "2.4", optional = true } +percent-encoding = { version = "2.3", optional = true } ## tls native-tls = { version = "0.2.5", optional = true } # feature @@ -103,7 +104,7 @@ mime03 = ["dep:mime"] file-transport = ["dep:uuid", "tokio1_crate?/fs", "tokio1_crate?/io-util"] file-transport-envelope = ["serde", "dep:serde_json", "file-transport"] sendmail-transport = ["tokio1_crate?/process", "tokio1_crate?/io-util", "async-std?/unstable"] -smtp-transport = ["dep:base64", "dep:nom", "dep:socket2", "dep:url", "tokio1_crate?/rt", "tokio1_crate?/time", "tokio1_crate?/net"] +smtp-transport = ["dep:base64", "dep:nom", "dep:socket2", "dep:url", "dep:percent-encoding", "tokio1_crate?/rt", "tokio1_crate?/time", "tokio1_crate?/net"] pool = ["dep:futures-util"] diff --git a/src/transport/smtp/connection_url.rs b/src/transport/smtp/connection_url.rs index 6ac5ee7..571adc8 100644 --- a/src/transport/smtp/connection_url.rs +++ b/src/transport/smtp/connection_url.rs @@ -112,7 +112,16 @@ pub(crate) fn from_connection_url(connection_url: &str) -> } if let Some(password) = connection_url.password() { - let credentials = Credentials::new(connection_url.username().into(), password.into()); + let percent_decode = |s: &str| { + percent_encoding::percent_decode_str(s) + .decode_utf8() + .map(|cow| cow.into_owned()) + .map_err(error::connection) + }; + let credentials = Credentials::new( + percent_decode(connection_url.username())?, + percent_decode(password)?, + ); builder = builder.credentials(credentials); }