diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d24d01..10ba00d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: rust: - stable - beta - - 1.40.0 + - 1.45.2 steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -37,7 +37,6 @@ jobs: args: --no-default-features --features=builder,smtp-transport,file-transport,sendmail-transport - run: rm target/debug/deps/liblettre-* - uses: actions-rs/cargo@v1 - if: matrix.rust != '1.40.0' with: command: test args: --features=async-std1 @@ -54,7 +53,7 @@ jobs: rust: - stable - beta - - 1.40.0 + - 1.45.2 steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 diff --git a/README.md b/README.md index 0de29d5..4373967 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Lettre does not provide (for now): ## Example -This library requires Rust 1.40 or newer. +This library requires Rust 1.45 or newer. To use this library, add the following to your `Cargo.toml`: diff --git a/src/message/utf8_b.rs b/src/message/utf8_b.rs index e1b347f..ae6d78e 100644 --- a/src/message/utf8_b.rs +++ b/src/message/utf8_b.rs @@ -16,19 +16,16 @@ pub fn encode(s: &str) -> String { } pub fn decode(s: &str) -> Option { - const PREFIX: &str = "=?utf-8?b?"; - const SUFFIX: &str = "?="; - - let s = s.trim(); - if s.starts_with(PREFIX) && s.ends_with(SUFFIX) { - let s = &s[PREFIX.len()..]; - let s = &s[..s.len() - SUFFIX.len()]; - base64::decode(s) - .ok() - .and_then(|v| String::from_utf8(v).ok()) - } else { - Some(s.into()) - } + s.strip_prefix("=?utf-8?b?") + .and_then(|stripped| stripped.strip_suffix("?=")) + .map_or_else( + || Some(s.into()), + |stripped| { + let decoded = base64::decode(stripped).ok()?; + let decoded = String::from_utf8(decoded).ok()?; + Some(decoded) + }, + ) } #[cfg(test)] diff --git a/src/transport/smtp/response.rs b/src/transport/smtp/response.rs index bd20145..c346715 100644 --- a/src/transport/smtp/response.rs +++ b/src/transport/smtp/response.rs @@ -151,10 +151,10 @@ impl Response { /// Tells if the response is positive pub fn is_positive(&self) -> bool { - match self.code.severity { - Severity::PositiveCompletion | Severity::PositiveIntermediate => true, - _ => false, - } + matches!( + self.code.severity, + Severity::PositiveCompletion | Severity::PositiveIntermediate + ) } /// Tests code equality