melib: Remove quotes from addresses in email/parser.rs
parent
3dfb2f4f2c
commit
bb486ca9d8
|
@ -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,
|
||||
|
|
|
@ -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…
Reference in New Issue