melib: fix two minor email parsing bugs

- windows-1250 encoding not being recognized
- spaces in Message-ID header messing up parsing '<' + msg-id + '>'
structure
async
Manos Pitsidianakis 2020-01-11 13:10:41 +02:00
parent 6835968d9a
commit 853fe14128
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 19 additions and 1 deletions

View File

@ -33,6 +33,7 @@ pub enum Charset {
ISO8859_2,
ISO8859_7,
ISO8859_15,
Windows1250,
Windows1251,
Windows1252,
Windows1253,
@ -59,6 +60,7 @@ impl<'a> From<&'a [u8]> for Charset {
b"iso-8859-2" | b"ISO-8859-2" => Charset::ISO8859_2,
b"iso-8859-7" | b"ISO-8859-7" | b"iso8859-7" => Charset::ISO8859_7,
b"iso-8859-15" | b"ISO-8859-15" => Charset::ISO8859_15,
b"windows-1250" | b"Windows-1250" => Charset::Windows1250,
b"windows-1251" | b"Windows-1251" => Charset::Windows1251,
b"windows-1252" | b"Windows-1252" => Charset::Windows1252,
b"windows-1253" | b"Windows-1253" => Charset::Windows1253,
@ -84,6 +86,7 @@ impl Display for Charset {
Charset::ISO8859_2 => write!(f, "iso-8859-2"),
Charset::ISO8859_7 => write!(f, "iso-8859-7"),
Charset::ISO8859_15 => write!(f, "iso-8859-15"),
Charset::Windows1250 => write!(f, "windows-1250"),
Charset::Windows1251 => write!(f, "windows-1251"),
Charset::Windows1252 => write!(f, "windows-1252"),
Charset::Windows1253 => write!(f, "windows-1253"),

View File

@ -391,6 +391,7 @@ pub fn decode_charset(s: &[u8], charset: Charset) -> Result<String> {
Charset::ISO8859_7 => Ok(ISO_8859_7.decode(s, DecoderTrap::Strict)?),
Charset::ISO8859_15 => Ok(ISO_8859_15.decode(s, DecoderTrap::Strict)?),
Charset::GBK => Ok(GBK.decode(s, DecoderTrap::Strict)?),
Charset::Windows1250 => Ok(WINDOWS_1250.decode(s, DecoderTrap::Strict)?),
Charset::Windows1251 => Ok(WINDOWS_1251.decode(s, DecoderTrap::Strict)?),
Charset::Windows1252 => Ok(WINDOWS_1252.decode(s, DecoderTrap::Strict)?),
Charset::Windows1253 => Ok(WINDOWS_1253.decode(s, DecoderTrap::Strict)?),
@ -667,7 +668,7 @@ pub fn date(input: &[u8]) -> Result<UnixTimestamp> {
}
named!(pub message_id<&[u8]>,
complete!(delimited!(tag!("<"), take_until1!(">"), tag!(">")))
complete!(delimited!(ws!(tag!("<")), take_until1!(">"), tag!(">")))
);
fn message_id_peek(input: &[u8]) -> IResult<&[u8], &[u8]> {
@ -1098,6 +1099,20 @@ mod tests {
"[internal] Νέος Οδηγός Συγγραφής",
std::str::from_utf8(&phrase(words.as_bytes()).to_full_result().unwrap()).unwrap()
);
let words = r#"=?UTF-8?Q?Re=3a_Climate_crisis_reality_check_=e2=80=93=c2=a0EcoHust?=
=?UTF-8?Q?ler?="#;
assert_eq!(
"Re: Climate crisis reality check \u{a0}EcoHustler",
std::str::from_utf8(&phrase(words.as_bytes()).to_full_result().unwrap()).unwrap()
);
let words = r#"Re: Climate crisis reality check =?windows-1250?B?lqBFY29IdXN0?=
=?windows-1250?B?bGVy?="#;
assert_eq!(
"Re: Climate crisis reality check \u{a0}EcoHustler",
std::str::from_utf8(&phrase(words.as_bytes()).to_full_result().unwrap()).unwrap()
);
}
#[test]