diff --git a/Cargo.lock b/Cargo.lock index 4b7c711..0e6b861 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2859,7 +2859,7 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "relayer-utils" -version = "0.4.0" +version = "0.4.1" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 464f751..fc10f1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/command_templates.rs b/src/command_templates.rs index 7fb3ff4..5e9bb2d 100644 --- a/src/command_templates.rs +++ b/src/command_templates.rs @@ -94,6 +94,11 @@ pub fn extract_template_vals_from_command( input: &str, templates: Vec, ) -> Result, 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() diff --git a/src/parse_email.rs b/src/parse_email.rs index 016899b..8178a72 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 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() { @@ -289,28 +289,11 @@ pub(crate) fn remove_quoted_printable_soft_breaks(body: Vec) -> Vec { // 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 }