From 67c722958bb8053fd92212bde253df7b6093433c Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 15 Sep 2020 10:17:56 +0300 Subject: [PATCH] melib/email/parser: quoted-printable accept message ending with soft line break --- melib/src/email/parser.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs index 634db9b00..c6aef9878 100644 --- a/melib/src/email/parser.rs +++ b/melib/src/email/parser.rs @@ -1576,15 +1576,11 @@ pub mod encodings { } } - fn quoted_printable_soft_break(input: &[u8]) -> IResult<&[u8], &[u8]> { - if input.len() < 2 { - Err(nom::Err::Error( - (input, "quoted_printable_soft_break(): found EOF").into(), - )) - } else if input[0] == b'=' && input[1] == b'\n' { - Ok((&input[2..], &input[0..2])) // `=\n` is an escaped space character. - } else if input.len() > 3 && input.starts_with(b"=\r\n") { - Ok((&input[3..], &input[0..3])) // `=\r\n` is an escaped space character. + fn quoted_printable_soft_break(input: &[u8]) -> IResult<&[u8], u8> { + if input.starts_with(b"=\n") { + Ok((&input[2..], input[1])) // `=\n` is an escaped space character. + } else if input.starts_with(b"=\r\n") { + Ok((&input[3..], input[2])) // `=\r\n` is an escaped space character. } else { Err(nom::Err::Error( (input, "quoted_printable_soft_break(): invalid input").into(), @@ -1606,6 +1602,9 @@ pub mod encodings { // For atoms in Header values. pub fn quoted_printable_bytes(input: &[u8]) -> IResult<&[u8], Vec> { many0(alt(( + terminated(quoted_printable_soft_break, tag("\n")), + terminated(quoted_printable_soft_break, tag("\r\n")), + terminated(quoted_printable_soft_break, generic::eof), preceded(quoted_printable_soft_break, quoted_printable_byte), preceded(quoted_printable_soft_break, le_u8), quoted_printable_byte,