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 |
+6
-1
@@ -1,3 +1,8 @@
|
||||
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.
|
||||
@@ -25,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.1"
|
||||
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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user