From bb486ca9d867079e3be940465fcee16029629348 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 28 Nov 2019 22:15:32 +0200 Subject: [PATCH] melib: Remove quotes from addresses in email/parser.rs --- melib/src/email/address.rs | 21 +++++++++++++++++++++ melib/src/email/parser.rs | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/melib/src/email/address.rs b/melib/src/email/address.rs index 9bfc1940..bdf9a96f 100644 --- a/melib/src/email/address.rs +++ b/melib/src/email/address.rs @@ -29,6 +29,27 @@ pub struct GroupAddress { } #[derive(Clone, Debug, Serialize, Deserialize)] +/** + * Container for an address. + * + * > raw: Vec + * > ┌──────────┴────────────┐ + * > Name + * > └─┬┘ └──────────┬─────┘ + * > display_name │ + * > │ + * > address_spec + * + * + * > raw: Vec + * > ┌──────────┴────────────────────┐ + * > "Name Name2" + * > └─────┬──┘ └──────────┬─────┘ + * > display_name │ + * > │ + * > address_spec + * + */ pub struct MailboxAddress { pub raw: Vec, pub display_name: StrBuilder, 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; fn rfind(&self, needle: &[u8]) -> Option; fn replace(&self, from: &[u8], to: &[u8]) -> Vec; + 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 {