diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-11-28 22:15:32 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-11-28 22:15:32 +0200 |
commit | bb486ca9d867079e3be940465fcee16029629348 (patch) | |
tree | 310176cff669c4bd2ec1177d8920e56cdc90ecdd /melib/src/email/parser.rs | |
parent | 3dfb2f4f2cd49f3b540dd38c86afa2d211d2fa4d (diff) |
melib: Remove quotes from addresses in email/parser.rs
Diffstat (limited to 'melib/src/email/parser.rs')
-rw-r--r-- | melib/src/email/parser.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs index 193800f2..c830fa85 100644 --- a/melib/src/email/parser.rs +++ b/melib/src/email/parser.rs @@ -55,6 +55,7 @@ pub trait BytesExt { fn find(&self, needle: &[u8]) -> Option<usize>; fn rfind(&self, needle: &[u8]) -> Option<usize>; fn replace(&self, from: &[u8], to: &[u8]) -> Vec<u8>; + fn is_quoted(&self) -> bool; } impl BytesExt for [u8] { @@ -93,6 +94,10 @@ impl BytesExt for [u8] { } ret } + + fn is_quoted(&self) -> bool { + self.starts_with(b"\"") && self.ends_with(b"\"") && self.len() > 1 + } } fn quoted_printable_byte(input: &[u8]) -> IResult<&[u8], u8> { @@ -488,11 +493,18 @@ fn display_addr(input: &[u8]) -> IResult<&[u8], Address> { length: end, } }; + + if display_name.display(&raw).as_bytes().is_quoted() { + display_name.offset += 1; + display_name.length -= 2; + } + let rest_start = if input.len() > end + display_name.length + 2 { end + display_name.length + 3 } else { end + display_name.length + 2 }; + IResult::Done( &input[rest_start..], Address::Mailbox(MailboxAddress { |