melib: Remove quotes from addresses in email/parser.rs

jmap
Manos Pitsidianakis 2019-11-28 22:15:32 +02:00
parent 3dfb2f4f2c
commit bb486ca9d8
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 33 additions and 0 deletions

View File

@ -29,6 +29,27 @@ pub struct GroupAddress {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
/**
* Container for an address.
*
* > raw: Vec<u8>
* >
* > Name <address@domain.tld>
* >
* > display_name
* >
* > address_spec
*
*
* > raw: Vec<u8>
* >
* > "Name Name2" <address@domain.tld>
* >
* > display_name
* >
* > address_spec
*
*/
pub struct MailboxAddress {
pub raw: Vec<u8>,
pub display_name: StrBuilder,

View File

@ -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 {