Support for malformed unstructured fields containing encoded words

This commit is contained in:
Mauro D
2022-09-09 08:54:56 +00:00
parent 9794de57c4
commit de4aecf9f1
2 changed files with 18 additions and 5 deletions
+11 -3
View File
@@ -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;
+7 -2
View File
@@ -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",