Skip to content

Commit

Permalink
Use BASE64_MIME_PERMISSIVE to allow trailing bits in b64 data
Browse files Browse the repository at this point in the history
This uses the updated data-encoding crate that introduced
the new functionality in ia0/data-encoding#104
  • Loading branch information
wathiede authored and staktrace committed Apr 29, 2024
1 parent c51e924 commit 595888b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude = [".gitattributes", ".gitignore", ".github/**", "examples/**"]
maintenance = { status = "passively-maintained" }

[dependencies]
data-encoding = "2.3.3"
data-encoding = "2.6.0"
quoted_printable = "0.5.0"
charset = "0.1.3"

Expand Down
5 changes: 3 additions & 2 deletions src/body.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{MailParseError, ParsedContentType};
use charset::{decode_ascii, Charset};

use crate::{MailParseError, ParsedContentType};

/// Represents the body of an email (or mail subpart)
pub enum Body<'a> {
/// A body with 'base64' Content-Transfer-Encoding.
Expand Down Expand Up @@ -141,7 +142,7 @@ fn decode_base64(body: &[u8]) -> Result<Vec<u8>, MailParseError> {
.filter(|c| !c.is_ascii_whitespace())
.cloned()
.collect::<Vec<u8>>();
Ok(data_encoding::BASE64_MIME.decode(&cleaned)?)
Ok(data_encoding::BASE64_MIME_PERMISSIVE.decode(&cleaned)?)
}

fn decode_quoted_printable(body: &[u8]) -> Result<Vec<u8>, MailParseError> {
Expand Down
4 changes: 3 additions & 1 deletion src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ fn decode_word(encoded: &str) -> Option<String> {
let input = &encoded[ix_delim2 + 1..];

let decoded = match transfer_coding {
"B" | "b" => data_encoding::BASE64_MIME.decode(input.as_bytes()).ok()?,
"B" | "b" => data_encoding::BASE64_MIME_PERMISSIVE
.decode(input.as_bytes())
.ok()?,
"Q" | "q" => {
// The quoted_printable module does a trim_end on the input, so if
// that affects the output we should save and restore the trailing
Expand Down

0 comments on commit 595888b

Please sign in to comment.