mirror of
https://github.com/stalwartlabs/mail-parser.git
synced 2026-11-28 08:01:24 +00:00
Support for malformed unstructured fields containing encoded words
This commit is contained in:
@@ -38,8 +38,9 @@ pub fn decode_quoted_printable<'x>(
|
||||
let mut lf_pos = 0;
|
||||
|
||||
debug_assert!(boundary.is_empty() || boundary.len() >= 2);
|
||||
let mut iter = stream.data[start_pos..].iter().peekable();
|
||||
|
||||
for ch in stream.data[start_pos..].iter() {
|
||||
while let Some(ch) = iter.next() {
|
||||
bytes_read += 1;
|
||||
|
||||
// if success is false, a boundary was provided
|
||||
@@ -108,10 +109,17 @@ pub fn decode_quoted_printable<'x>(
|
||||
}
|
||||
b'\n' => {
|
||||
if is_word {
|
||||
if !matches!(stream.data.get(start_pos + bytes_read), Some(ch) if [b' ', b'\t'].contains(ch))
|
||||
{
|
||||
if !matches!(iter.peek(), Some(ch) if [b' ', b'\t'].contains(ch)) {
|
||||
success = false;
|
||||
break;
|
||||
} else {
|
||||
loop {
|
||||
iter.next();
|
||||
bytes_read += 1;
|
||||
if !matches!(iter.peek(), Some(ch) if [b' ', b'\t'].contains(ch)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if QuotedPrintableState::Eq == state {
|
||||
state = QuotedPrintableState::None;
|
||||
|
||||
@@ -175,8 +175,13 @@ mod tests {
|
||||
"abcd",
|
||||
true,
|
||||
),
|
||||
("=?utf-8?Q?Hello\n _there!?=\n", "Hello there!", true),
|
||||
("=?utf-8?Q?Hello\r\n _there!?=\r\n", "Hello there!", true),
|
||||
("=?utf-8?Q?Hello\n _there!?=\n", "Hello there!", true),
|
||||
("=?utf-8?Q?Hello\r\n _there!?=\r\n", "Hello there!", true),
|
||||
(
|
||||
"=?utf-8?Q?Hello\r\n \t _there!?=\r\n",
|
||||
"Hello there!",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"[SUSPECTED SPAM]=?utf-8?B?VGhpcyBpcyB0aGUgb\n 3JpZ2luYWwgc3ViamVjdA==?=\n",
|
||||
"[SUSPECTED SPAM] This is the original subject",
|
||||
|
||||
Reference in New Issue
Block a user