Add address_list parser
parent
a4b8b4fd4e
commit
ea9bdd2074
|
@ -198,7 +198,7 @@ impl Envelope {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if name.eq_ignore_ascii_case("to") {
|
if name.eq_ignore_ascii_case("to") {
|
||||||
let parse_result = parser::subject(value.as_bytes());
|
let parse_result = parser::address_list(value.as_bytes());
|
||||||
let value = if parse_result.is_done() {
|
let value = if parse_result.is_done() {
|
||||||
parse_result.to_full_result().unwrap()
|
parse_result.to_full_result().unwrap()
|
||||||
} else {
|
} else {
|
||||||
|
@ -206,7 +206,7 @@ impl Envelope {
|
||||||
};
|
};
|
||||||
self.set_to(value);
|
self.set_to(value);
|
||||||
} else if name.eq_ignore_ascii_case("from") {
|
} else if name.eq_ignore_ascii_case("from") {
|
||||||
let parse_result = parser::subject(value.as_bytes());
|
let parse_result = parser::address_list(value.as_bytes());
|
||||||
let value = if parse_result.is_done() {
|
let value = if parse_result.is_done() {
|
||||||
parse_result.to_full_result().unwrap()
|
parse_result.to_full_result().unwrap()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -259,6 +259,25 @@ named!(ascii_token<String>, do_parse!(
|
||||||
String::from_utf8_lossy(word).into_owned()
|
String::from_utf8_lossy(word).into_owned()
|
||||||
} )));
|
} )));
|
||||||
|
|
||||||
|
named!(pub address_list<String>, ws!(do_parse!(
|
||||||
|
list: alt_complete!( encoded_word_list | ascii_token) >>
|
||||||
|
( {
|
||||||
|
let list: Vec<&str> = list.split(',').collect();
|
||||||
|
let string_len = list.iter().fold(0, |mut acc, x| { acc+=x.trim().len(); acc }) + list.len() - 1;
|
||||||
|
let list_len = list.len();
|
||||||
|
let mut i = 0;
|
||||||
|
list.iter().fold(String::with_capacity(string_len),
|
||||||
|
|acc, x| {
|
||||||
|
let mut acc = acc + &x.replace("\n", "").replace("\t", " ").trim();
|
||||||
|
if i != list_len - 1 {
|
||||||
|
acc.push_str(" ");
|
||||||
|
i+=1;
|
||||||
|
}
|
||||||
|
acc
|
||||||
|
})
|
||||||
|
} )
|
||||||
|
|
||||||
|
)));
|
||||||
named!(pub subject<String>, ws!(do_parse!(
|
named!(pub subject<String>, ws!(do_parse!(
|
||||||
list: many0!(alt_complete!( encoded_word_list | ascii_token)) >>
|
list: many0!(alt_complete!( encoded_word_list | ascii_token)) >>
|
||||||
( {
|
( {
|
||||||
|
|
Loading…
Reference in New Issue