Skip to content

Commit

Permalink
fix: cleaned body
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisht13 committed Oct 22, 2024
1 parent aa1ab83 commit 659b12c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 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.4.0"
version = "0.4.1"
authors = ["Sora Suegami", "Aditya Bisht"]
license = "MIT"
edition = "2018"
Expand Down
5 changes: 5 additions & 0 deletions src/command_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ pub fn extract_template_vals_from_command(
input: &str,
templates: Vec<String>,
) -> Result<Vec<TemplateValue>, anyhow::Error> {
// Skip to text/html part
let re = Regex::new(r"(?s)Content-Type:\s*text/html;.*?\r?\n\r?\n(.*?)(?:--\S+|$)").unwrap();
let caps = re.captures(input).unwrap();
let input = caps.get(1).unwrap().as_str();

// Convert the template to a regex pattern, escaping necessary characters and replacing placeholders
let pattern = templates
.iter()
Expand Down
23 changes: 3 additions & 20 deletions src/parse_email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,36 +281,19 @@ 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 partial_result = Vec::with_capacity(body.len());
let mut 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 {
partial_result.push(byte);
result.push(byte);
}
}

// 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
// Resize the result to match the original body length
result.resize(body.len(), 0);
result
}
Expand Down

0 comments on commit 659b12c

Please sign in to comment.