diff --git a/Cargo.lock b/Cargo.lock index de7d39c..4b7c711 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2859,7 +2859,7 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "relayer-utils" -version = "0.3.9" +version = "0.4.0" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index e9e46aa..464f751 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "relayer-utils" -version = "0.3.9" +version = "0.4.0" authors = ["Sora Suegami", "Aditya Bisht"] license = "MIT" edition = "2018" diff --git a/src/parse_email.rs b/src/parse_email.rs index 8178a72..016899b 100644 --- a/src/parse_email.rs +++ b/src/parse_email.rs @@ -281,7 +281,7 @@ impl ParsedEmail { /// /// A `Vec` with all quoted-printable soft line breaks removed. pub(crate) fn remove_quoted_printable_soft_breaks(body: Vec) -> Vec { - let mut result = Vec::with_capacity(body.len()); + let mut partial_result = Vec::with_capacity(body.len()); let mut iter = body.iter().enumerate(); while let Some((i, &byte)) = iter.next() { @@ -289,11 +289,28 @@ pub(crate) fn remove_quoted_printable_soft_breaks(body: Vec) -> Vec { // Skip the next two bytes (soft line break) iter.nth(1); } else { - result.push(byte); + partial_result.push(byte); } } - // Resize the result to match the original body length + // Run while loop again to remove any remaining soft line breaks + let mut result = Vec::new(); + let mut i = 0; + + while i < partial_result.len() { + if partial_result[i] == b'\r' + && i + 1 < partial_result.len() + && partial_result[i + 1] == b'\n' + { + // Skip both bytes (soft line break) + i += 2; + } else { + result.push(partial_result[i]); + i += 1; + } + } + + // Resize the partial_result to match the original body length result.resize(body.len(), 0); result }