Browse Source

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

tags/alpha-0.4.1
Manos Pitsidianakis 2 years ago
parent
commit
bb486ca9d8
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 21
      melib/src/email/address.rs
  2. 12
      melib/src/email/parser.rs

21
melib/src/email/address.rs

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

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

Loading…
Cancel
Save