Skip to content

Commit

Permalink
fix: remove quoted printable soft breaks fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisht13 committed Oct 21, 2024
1 parent 957b16f commit aa1ab83
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
23 changes: 20 additions & 3 deletions src/parse_email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,36 @@ impl ParsedEmail {
///
/// A `Vec<u8>` with all quoted-printable soft line breaks removed.
pub(crate) fn remove_quoted_printable_soft_breaks(body: Vec<u8>) -> Vec<u8> {
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() {
if byte == b'=' && body.get(i + 1..i + 3) == Some(&[b'\r', b'\n']) {
// 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
}
Expand Down

0 comments on commit aa1ab83

Please sign in to comment.