mirror of
https://github.com/stalwartlabs/mail-parser.git
synced 2026-11-29 00:01:49 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77fe8cd0d1 | ||
|
|
b4478f74e2 | ||
|
|
da1e6180db | ||
|
|
cf8de086c7 | ||
|
|
c7ae90b3bf |
+10
-1
@@ -1,3 +1,12 @@
|
||||
mail-parser 0.8.2
|
||||
================================
|
||||
- Fix: Parsing address name with \ characters (#41)
|
||||
- Fix: Missing space when folded header begins with RFC2047 word (#43)
|
||||
|
||||
mail-parser 0.8.1
|
||||
================================
|
||||
- Added `raw_message()` function.
|
||||
|
||||
mail-parser 0.8.0
|
||||
================================
|
||||
- Removed get_() prefixes (#31).
|
||||
@@ -21,7 +30,7 @@ mail-parser 0.6.1
|
||||
mail-parser 0.6.0
|
||||
================================
|
||||
- Maildir parsing support.
|
||||
- Headers and attributes are now stored in a `Vec` instead of a `HashMap` for tiny performance enhancement.
|
||||
- Headers and attributes are now stored in a `Vec` instead of a `HashMap` for a tiny performance enhancement.
|
||||
- Support for Content-Type attributes spanning multiple lines.
|
||||
- Support for malformed Thunderbird messages (#27).
|
||||
- Fixed raw offset range for body parts.
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "mail-parser"
|
||||
description = "Fast and robust e-mail parsing library for Rust"
|
||||
version = "0.8.0"
|
||||
version = "0.8.2"
|
||||
edition = "2018"
|
||||
authors = [ "Stalwart Labs <hello@stalw.art>"]
|
||||
license = "Apache-2.0 OR MIT"
|
||||
@@ -19,7 +19,7 @@ serde = { version = "1.0", features = ["derive"], optional=true }
|
||||
[dev-dependencies]
|
||||
mail-parser = { path = ".", features = ["serde_support", "full_encoding"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_yaml = "0.8" # Version 0.9 fails to parse certain inputs
|
||||
serde_yaml = "0.8"
|
||||
serde_json = "1.0"
|
||||
bincode = "1.3.3"
|
||||
chrono = "0.4"
|
||||
|
||||
@@ -325,8 +325,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
super::base64_decode(encoded_str.as_bytes()).unwrap_or_default(),
|
||||
expected_result.as_bytes(),
|
||||
"Failed for {:?}",
|
||||
encoded_str
|
||||
"Failed for {encoded_str:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -357,8 +356,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
result,
|
||||
expected_result.as_bytes(),
|
||||
"Failed for {:?}",
|
||||
encoded_str
|
||||
"Failed for {encoded_str:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -376,8 +374,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
s.decode_base64_word().unwrap(),
|
||||
expected_result.as_bytes(),
|
||||
"Failed for {:?}",
|
||||
encoded_str
|
||||
"Failed for {encoded_str:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ mod tests {
|
||||
use super::charset_decoder;
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::uninlined_format_args)]
|
||||
fn decoder_charset() {
|
||||
let inputs = [
|
||||
"l8",
|
||||
@@ -100,7 +101,7 @@ mod tests {
|
||||
for input in inputs {
|
||||
assert!(
|
||||
charset_decoder(input.as_bytes()).is_some(),
|
||||
"Failed for '{}'",
|
||||
"Failed for {}",
|
||||
input
|
||||
);
|
||||
}
|
||||
|
||||
@@ -331,8 +331,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
super::quoted_printable_decode(encoded_str.as_bytes()).unwrap_or_default(),
|
||||
expected_result.as_bytes(),
|
||||
"Failed for {:?}",
|
||||
encoded_str
|
||||
"Failed for {encoded_str:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -394,8 +393,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
result,
|
||||
expected_result.as_bytes(),
|
||||
"Failed for {:?}",
|
||||
encoded_str
|
||||
"Failed for {encoded_str:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -423,8 +421,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
s.decode_quoted_printable_word().unwrap_or_default(),
|
||||
expected_result.as_bytes(),
|
||||
"Failed for {:?}",
|
||||
encoded_str
|
||||
"Failed for {encoded_str:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -983,6 +983,14 @@ impl<'x> Message<'x> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the raw message
|
||||
pub fn raw_message(&self) -> &[u8] {
|
||||
let part = &self.parts[0];
|
||||
self.raw_message
|
||||
.get(part.offset_header..part.offset_end)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Returns the BCC header field
|
||||
pub fn bcc(&self) -> &HeaderValue {
|
||||
self.parts[0]
|
||||
|
||||
@@ -231,7 +231,7 @@ impl<'x> MessageStream<'x> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
b'\\' if parser.state != AddressState::Name => {
|
||||
b'\\' if parser.state != AddressState::Name && !parser.is_escaped => {
|
||||
if parser.token_start > 0 {
|
||||
if parser.state == AddressState::Quote {
|
||||
parser.token_end = self.offset() - 1;
|
||||
@@ -989,6 +989,15 @@ mod tests {
|
||||
" address: \"mailto:listmom@host.com\"\n"
|
||||
),
|
||||
),
|
||||
(
|
||||
r#""\\\\\\\\S. NIG\\\\\\\\" <first.last@host.com>"#,
|
||||
concat!(
|
||||
"---\n",
|
||||
"Address:\n",
|
||||
" name: \"\\\\\\\\\\\\\\\\S. NIG\\\\\\\\\\\\\\\\\"\n",
|
||||
" address: first.last@host.com\n",
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
for input in inputs {
|
||||
|
||||
@@ -243,7 +243,7 @@ impl<'x> ContentTypeParser<'x> {
|
||||
for (key, _, value) in continuations.drain(..) {
|
||||
if let Some((_, old_value)) = self.attributes.iter_mut().find(|(name, _)| name == &key)
|
||||
{
|
||||
*old_value = format!("{}{}", old_value, value).into();
|
||||
*old_value = format!("{old_value}{value}").into();
|
||||
} else {
|
||||
self.attributes.push((key, value));
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ impl<'x> MessageStream<'x> {
|
||||
parts[2]
|
||||
} as u16,
|
||||
month: if month_pos == 3 && month_hash <= 30 {
|
||||
MONTH_MAP[month_hash] as u8
|
||||
MONTH_MAP[month_hash]
|
||||
} else {
|
||||
parts[1] as u8
|
||||
},
|
||||
|
||||
@@ -275,7 +275,7 @@ mod tests {
|
||||
];
|
||||
|
||||
for (input, expected) in tests {
|
||||
assert_eq!(thread_name(input), expected, "{:?}", input);
|
||||
assert_eq!(thread_name(input), expected, "{input:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ mod tests {
|
||||
];
|
||||
|
||||
for (input, expected) in tests {
|
||||
assert_eq!(trim_trailing_fwd(input), expected, "{:?}", input);
|
||||
assert_eq!(trim_trailing_fwd(input), expected, "{input:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ struct UnstructuredParser<'x> {
|
||||
token_start: usize,
|
||||
token_end: usize,
|
||||
tokens: Vec<Cow<'x, str>>,
|
||||
last_is_encoded: bool,
|
||||
}
|
||||
|
||||
impl<'x> UnstructuredParser<'x> {
|
||||
fn add_token(&mut self, stream: &MessageStream<'x>, add_space: bool) {
|
||||
fn add_token(&mut self, stream: &MessageStream<'x>) {
|
||||
if self.token_start > 0 {
|
||||
if !self.tokens.is_empty() {
|
||||
self.tokens.push(" ".into());
|
||||
@@ -28,13 +29,18 @@ impl<'x> UnstructuredParser<'x> {
|
||||
stream.bytes(self.token_start - 1..self.token_end),
|
||||
));
|
||||
|
||||
if add_space {
|
||||
self.tokens.push(" ".into());
|
||||
}
|
||||
|
||||
self.token_start = 0;
|
||||
self.last_is_encoded = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn add_rfc2047(&mut self, token: String) {
|
||||
if !self.last_is_encoded {
|
||||
self.tokens.push(" ".into());
|
||||
}
|
||||
self.tokens.push(token.into());
|
||||
self.last_is_encoded = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'x> MessageStream<'x> {
|
||||
@@ -43,12 +49,13 @@ impl<'x> MessageStream<'x> {
|
||||
token_start: 0,
|
||||
token_end: 0,
|
||||
tokens: Vec::new(),
|
||||
last_is_encoded: true,
|
||||
};
|
||||
|
||||
while let Some(ch) = self.next() {
|
||||
match ch {
|
||||
b'\n' => {
|
||||
parser.add_token(self, false);
|
||||
parser.add_token(self);
|
||||
|
||||
if !self.try_next_is_space() {
|
||||
return match parser.tokens.len() {
|
||||
@@ -66,8 +73,8 @@ impl<'x> MessageStream<'x> {
|
||||
b'=' if self.peek_char(b'?') => {
|
||||
self.checkpoint();
|
||||
if let Some(token) = self.decode_rfc2047() {
|
||||
parser.add_token(self, true);
|
||||
parser.tokens.push(token.into());
|
||||
parser.add_token(self);
|
||||
parser.add_rfc2047(token);
|
||||
continue;
|
||||
}
|
||||
self.restore();
|
||||
@@ -187,6 +194,11 @@ mod tests {
|
||||
"[SUSPECTED SPAM] This is the original subject",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"Les Communs - =?utf-8?Q?R=C3=A9capitulatif?= de la\r\n =?utf-8?Q?r=C3=A9servation?= 13510164434879\r\n",
|
||||
"Les Communs - Récapitulatif de la réservation 13510164434879",
|
||||
true,
|
||||
),
|
||||
];
|
||||
|
||||
for (input, expected_result, _) in inputs {
|
||||
@@ -195,8 +207,7 @@ mod tests {
|
||||
.parse_unstructured()
|
||||
.unwrap_text(),
|
||||
expected_result,
|
||||
"Failed to parse '{:?}'",
|
||||
input
|
||||
"Failed to parse '{input:?}'",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,8 +254,7 @@ mod tests {
|
||||
MessageStream::new(input.as_bytes())
|
||||
.parse_header_name()
|
||||
.unwrap(),
|
||||
"Failed to parse '{:?}'",
|
||||
input
|
||||
"Failed to parse '{input:?}'",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ use std::borrow::Cow;
|
||||
|
||||
use crate::decoders::html::html_to_text;
|
||||
|
||||
pub fn preview_html<'x, 'y>(html: Cow<'y, str>, max_len: usize) -> Cow<'x, str> {
|
||||
pub fn preview_html<'x>(html: Cow<'_, str>, max_len: usize) -> Cow<'x, str> {
|
||||
preview_text(html_to_text(html.as_ref()).into(), max_len)
|
||||
}
|
||||
|
||||
pub fn preview_text<'x, 'y>(text: Cow<'y, str>, mut max_len: usize) -> Cow<'x, str> {
|
||||
pub fn preview_text<'x>(text: Cow<'_, str>, mut max_len: usize) -> Cow<'x, str> {
|
||||
if text.len() > max_len {
|
||||
let add_dots = max_len > 6;
|
||||
if add_dots {
|
||||
@@ -39,11 +39,11 @@ pub fn preview_text<'x, 'y>(text: Cow<'y, str>, mut max_len: usize) -> Cow<'x, s
|
||||
}
|
||||
}
|
||||
|
||||
pub fn truncate_text<'x, 'y>(text: Cow<'y, str>, max_len: usize) -> Cow<'x, str> {
|
||||
pub fn truncate_text<'x>(text: Cow<'_, str>, max_len: usize) -> Cow<'x, str> {
|
||||
preview_text(text, max_len)
|
||||
}
|
||||
|
||||
pub fn truncate_html<'x, 'y>(html: Cow<'y, str>, mut max_len: usize) -> Cow<'x, str> {
|
||||
pub fn truncate_html<'x>(html: Cow<'_, str>, mut max_len: usize) -> Cow<'x, str> {
|
||||
if html.len() > max_len {
|
||||
let add_dots = max_len > 6;
|
||||
if add_dots {
|
||||
|
||||
Reference in New Issue
Block a user