apply clippy --fix

This commit is contained in:
Quentin 2023-07-24 09:24:38 +02:00
parent 5f449714f5
commit 6c74860f82
Signed by: quentin
GPG key ID: E9602264D639FF68
12 changed files with 45 additions and 48 deletions

View file

@ -1,4 +1,4 @@
use nom;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum EMLError<'a> { pub enum EMLError<'a> {

View file

@ -23,11 +23,10 @@ impl<'a, T> CompFieldList<'a, T> {
pub fn known(self) -> Vec<T> { pub fn known(self) -> Vec<T> {
self.0 self.0
.into_iter() .into_iter()
.map(|v| match v { .filter_map(|v| match v {
CompField::Known(f) => Some(f), CompField::Known(f) => Some(f),
_ => None, _ => None,
}) })
.flatten()
.collect() .collect()
} }
} }
@ -81,7 +80,7 @@ pub fn opt_field(input: &[u8]) -> IResult<&[u8], (&[u8], Unstructured)> {
terminated( terminated(
pair( pair(
terminated( terminated(
take_while1(|c| c >= 0x21 && c <= 0x7E && c != 0x3A), take_while1(|c| (0x21..=0x7E).contains(&c) && c != 0x3A),
tuple((space0, tag(b":"), space0)), tuple((space0, tag(b":"), space0)),
), ),
unstructured, unstructured,

View file

@ -11,5 +11,5 @@ fn main() {
let eml = eml_codec::email(&rawmail).unwrap(); let eml = eml_codec::email(&rawmail).unwrap();
println!("{:#?}", eml); println!("{:#?}", eml);
assert!(eml.1.date.is_some()); assert!(eml.1.date.is_some());
assert!(eml.1.from.len() > 0); assert!(!eml.1.from.is_empty());
} }

View file

@ -96,13 +96,11 @@ impl<'a> CompFieldList<'a, MixedField<'a>> {
k.into_iter().partition(|v| v.mime().is_some()); k.into_iter().partition(|v| v.mime().is_some());
let mime = v1 let mime = v1
.into_iter() .into_iter()
.map(|v| v.to_mime()) .filter_map(|v| v.to_mime())
.flatten()
.collect::<mime::mime::AnyMIME>(); .collect::<mime::mime::AnyMIME>();
let imf = v2 let imf = v2
.into_iter() .into_iter()
.map(|v| v.to_imf()) .filter_map(|v| v.to_imf())
.flatten()
.collect::<imf::message::Message>(); .collect::<imf::message::Message>();
(mime, imf) (mime, imf)
} }

View file

@ -144,7 +144,7 @@ fn strict_year(input: &[u8]) -> IResult<&[u8], i32> {
delimited( delimited(
fws, fws,
map( map(
terminated(take_while_m_n(4, 9, |c| c >= 0x30 && c <= 0x39), digit0), terminated(take_while_m_n(4, 9, |c| (0x30..=0x39).contains(&c)), digit0),
|d: &[u8]| { |d: &[u8]| {
encoding_rs::UTF_8 encoding_rs::UTF_8
.decode_without_bom_handling(d) .decode_without_bom_handling(d)
@ -162,15 +162,15 @@ fn obs_year(input: &[u8]) -> IResult<&[u8], i32> {
map( map(
delimited( delimited(
opt(cfws), opt(cfws),
terminated(take_while_m_n(2, 7, |c| c >= 0x30 && c <= 0x39), digit0), terminated(take_while_m_n(2, 7, |c| (0x30..=0x39).contains(&c)), digit0),
opt(cfws), opt(cfws),
), ),
|cap: &[u8]| { |cap: &[u8]| {
let year_txt = encoding_rs::UTF_8.decode_without_bom_handling(cap).0; let year_txt = encoding_rs::UTF_8.decode_without_bom_handling(cap).0;
let d = year_txt.parse::<i32>().unwrap_or(0); let d = year_txt.parse::<i32>().unwrap_or(0);
if d >= 0 && d <= 49 { if (0..=49).contains(&d) {
2000 + d 2000 + d
} else if d >= 50 && d <= 999 { } else if (50..=999).contains(&d) {
1900 + d 1900 + d
} else { } else {
d d
@ -227,8 +227,8 @@ fn strict_zone(input: &[u8]) -> IResult<&[u8], Option<FixedOffset>> {
tuple(( tuple((
opt(fws), opt(fws),
is_a("+-"), is_a("+-"),
take_while_m_n(2, 2, |c| c >= 0x30 && c <= 0x39), take_while_m_n(2, 2, |c| (0x30..=0x39).contains(&c)),
take_while_m_n(2, 2, |c| c >= 0x30 && c <= 0x39), take_while_m_n(2, 2, |c| (0x30..=0x39).contains(&c)),
)), )),
|(_, op, dig_zone_hour, dig_zone_min)| { |(_, op, dig_zone_hour, dig_zone_min)| {
let zone_hour: i32 = let zone_hour: i32 =
@ -293,7 +293,7 @@ fn obs_zone(input: &[u8]) -> IResult<&[u8], Option<FixedOffset>> {
value(FixedOffset::west_opt(0 * HOUR), tag_no_case(b"Z")), value(FixedOffset::west_opt(0 * HOUR), tag_no_case(b"Z")),
// Military Timezones East // Military Timezones East
alt(( alt((
value(FixedOffset::east_opt(1 * HOUR), tag_no_case(b"A")), value(FixedOffset::east_opt(HOUR), tag_no_case(b"A")),
value(FixedOffset::east_opt(2 * HOUR), tag_no_case(b"B")), value(FixedOffset::east_opt(2 * HOUR), tag_no_case(b"B")),
value(FixedOffset::east_opt(3 * HOUR), tag_no_case(b"C")), value(FixedOffset::east_opt(3 * HOUR), tag_no_case(b"C")),
value(FixedOffset::east_opt(4 * HOUR), tag_no_case(b"D")), value(FixedOffset::east_opt(4 * HOUR), tag_no_case(b"D")),
@ -308,7 +308,7 @@ fn obs_zone(input: &[u8]) -> IResult<&[u8], Option<FixedOffset>> {
)), )),
// Military Timezones West // Military Timezones West
alt(( alt((
value(FixedOffset::west_opt(1 * HOUR), tag_no_case(b"N")), value(FixedOffset::west_opt(HOUR), tag_no_case(b"N")),
value(FixedOffset::west_opt(2 * HOUR), tag_no_case(b"O")), value(FixedOffset::west_opt(2 * HOUR), tag_no_case(b"O")),
value(FixedOffset::west_opt(3 * HOUR), tag_no_case(b"P")), value(FixedOffset::west_opt(3 * HOUR), tag_no_case(b"P")),
value(FixedOffset::west_opt(4 * HOUR), tag_no_case(b"Q")), value(FixedOffset::west_opt(4 * HOUR), tag_no_case(b"Q")),

View file

@ -166,9 +166,9 @@ fn obs_local_part(input: &[u8]) -> IResult<&[u8], LocalPart> {
map( map(
many0(alt(( many0(alt((
map(tag(&[ascii::PERIOD]), |_| LocalPartToken::Dot), map(tag(&[ascii::PERIOD]), |_| LocalPartToken::Dot),
map(word, |v| LocalPartToken::Word(v)), map(word, LocalPartToken::Word),
))), ))),
|v| LocalPart(v), LocalPart,
)(input) )(input)
} }
@ -223,7 +223,7 @@ impl<'a> fmt::Debug for Domain<'a> {
/// ``` /// ```
pub fn obs_domain(input: &[u8]) -> IResult<&[u8], Domain> { pub fn obs_domain(input: &[u8]) -> IResult<&[u8], Domain> {
alt(( alt((
map(separated_list1(tag("."), atom), |v| Domain::Atoms(v)), map(separated_list1(tag("."), atom), Domain::Atoms),
domain_litteral, domain_litteral,
))(input) ))(input)
} }
@ -244,12 +244,12 @@ fn domain_litteral(input: &[u8]) -> IResult<&[u8], Domain> {
fn inner_domain_litteral(input: &[u8]) -> IResult<&[u8], Domain> { fn inner_domain_litteral(input: &[u8]) -> IResult<&[u8], Domain> {
map( map(
terminated(many0(preceded(opt(fws), take_while1(is_dtext))), opt(fws)), terminated(many0(preceded(opt(fws), take_while1(is_dtext))), opt(fws)),
|v| Domain::Litteral(v), Domain::Litteral,
)(input) )(input)
} }
fn is_strict_dtext(c: u8) -> bool { fn is_strict_dtext(c: u8) -> bool {
(c >= 0x21 && c <= 0x5A) || (c >= 0x5E && c <= 0x7E) (0x21..=0x5A).contains(&c) || (0x5E..=0x7E).contains(&c)
} }
/// Is domain text /// Is domain text

View file

@ -46,7 +46,7 @@ pub fn received_log(input: &[u8]) -> IResult<&[u8], ReceivedLog> {
} }
pub fn return_path(input: &[u8]) -> IResult<&[u8], Option<mailbox::AddrSpec>> { pub fn return_path(input: &[u8]) -> IResult<&[u8], Option<mailbox::AddrSpec>> {
alt((map(mailbox::angle_addr, |a| Some(a)), empty_path))(input) alt((map(mailbox::angle_addr, Some), empty_path))(input)
} }
fn empty_path(input: &[u8]) -> IResult<&[u8], Option<mailbox::AddrSpec>> { fn empty_path(input: &[u8]) -> IResult<&[u8], Option<mailbox::AddrSpec>> {
@ -63,12 +63,12 @@ fn empty_path(input: &[u8]) -> IResult<&[u8], Option<mailbox::AddrSpec>> {
fn received_tokens(input: &[u8]) -> IResult<&[u8], ReceivedLogToken> { fn received_tokens(input: &[u8]) -> IResult<&[u8], ReceivedLogToken> {
alt(( alt((
terminated( terminated(
map(misc_token::word, |x| ReceivedLogToken::Word(x)), map(misc_token::word, ReceivedLogToken::Word),
not(is_a([ascii::PERIOD, ascii::AT])), not(is_a([ascii::PERIOD, ascii::AT])),
), ),
map(mailbox::angle_addr, |x| ReceivedLogToken::Addr(x)), map(mailbox::angle_addr, ReceivedLogToken::Addr),
map(mailbox::addr_spec, |x| ReceivedLogToken::Addr(x)), map(mailbox::addr_spec, ReceivedLogToken::Addr),
map(mailbox::obs_domain, |x| ReceivedLogToken::Domain(x)), map(mailbox::obs_domain, ReceivedLogToken::Domain),
))(input) ))(input)
} }

View file

@ -127,7 +127,7 @@ pub fn ptext(input: &[u8]) -> IResult<&[u8], Vec<QuotedChunk>> {
} }
fn safe_char2(input: &[u8]) -> IResult<&[u8], QuotedChunk> { fn safe_char2(input: &[u8]) -> IResult<&[u8], QuotedChunk> {
map(take_while1(is_safe_char2), |v| QuotedChunk::Safe(v))(input) map(take_while1(is_safe_char2), QuotedChunk::Safe)(input)
} }
/// RFC2047 section 4.2 /// RFC2047 section 4.2

View file

@ -83,9 +83,9 @@ impl<'a> fmt::Debug for Word<'a> {
/// ``` /// ```
pub fn word(input: &[u8]) -> IResult<&[u8], Word> { pub fn word(input: &[u8]) -> IResult<&[u8], Word> {
alt(( alt((
map(quoted_string, |v| Word::Quoted(v)), map(quoted_string, Word::Quoted),
map(encoded_word, |v| Word::Encoded(v)), map(encoded_word, Word::Encoded),
map(atom, |v| Word::Atom(v)), map(atom, Word::Atom),
))(input) ))(input)
} }
@ -113,7 +113,7 @@ impl<'a> fmt::Debug for Phrase<'a> {
/// phrase = 1*word / obs-phrase /// phrase = 1*word / obs-phrase
/// ``` /// ```
pub fn phrase(input: &[u8]) -> IResult<&[u8], Phrase> { pub fn phrase(input: &[u8]) -> IResult<&[u8], Phrase> {
let (input, phrase) = map(many1(word), |v| Phrase(v))(input)?; let (input, phrase) = map(many1(word), Phrase)(input)?;
Ok((input, phrase)) Ok((input, phrase))
} }
@ -188,8 +188,8 @@ pub fn unstructured(input: &[u8]) -> IResult<&[u8], Unstructured> {
let (input, r) = many0(preceded( let (input, r) = many0(preceded(
opt(fws), opt(fws),
alt(( alt((
map(encoded_word, |v| UnstrToken::Encoded(v)), map(encoded_word, UnstrToken::Encoded),
map(take_while1(is_unstructured), |v| UnstrToken::Plain(v)), map(take_while1(is_unstructured), UnstrToken::Plain),
)), )),
))(input)?; ))(input)?;

View file

@ -52,8 +52,8 @@ pub fn quoted_pair(input: &[u8]) -> IResult<&[u8], &[u8]> {
/// ``` /// ```
fn is_restr_qtext(c: u8) -> bool { fn is_restr_qtext(c: u8) -> bool {
c == ascii::EXCLAMATION c == ascii::EXCLAMATION
|| (c >= ascii::NUM && c <= ascii::LEFT_BRACKET) || (ascii::NUM..=ascii::LEFT_BRACKET).contains(&c)
|| (c >= ascii::RIGHT_BRACKET && c <= ascii::TILDE) || (ascii::RIGHT_BRACKET..=ascii::TILDE).contains(&c)
} }
fn is_qtext(c: u8) -> bool { fn is_qtext(c: u8) -> bool {
@ -85,7 +85,7 @@ pub fn quoted_string(input: &[u8]) -> IResult<&[u8], QuotedString> {
let mut qstring = content let mut qstring = content
.iter() .iter()
.fold(QuotedString::default(), |mut acc, (maybe_wsp, c)| { .fold(QuotedString::default(), |mut acc, (maybe_wsp, c)| {
if let Some(_) = maybe_wsp { if maybe_wsp.is_some() {
acc.push(&[ascii::SP]); acc.push(&[ascii::SP]);
} }
acc.push(c); acc.push(c);
@ -93,7 +93,7 @@ pub fn quoted_string(input: &[u8]) -> IResult<&[u8], QuotedString> {
}); });
let (input, maybe_wsp) = opt(fws)(input)?; let (input, maybe_wsp) = opt(fws)(input)?;
if let Some(_) = maybe_wsp { if maybe_wsp.is_some() {
qstring.push(&[ascii::SP]); qstring.push(&[ascii::SP]);
} }

View file

@ -117,9 +117,9 @@ pub fn is_ctext(c: u8) -> bool {
/// obs-ctext /// obs-ctext
///``` ///```
pub fn is_restr_ctext(c: u8) -> bool { pub fn is_restr_ctext(c: u8) -> bool {
(c >= ascii::EXCLAMATION && c <= ascii::SQUOTE) (ascii::EXCLAMATION..=ascii::SQUOTE).contains(&c)
|| (c >= ascii::ASTERISK && c <= ascii::LEFT_BRACKET) || (ascii::ASTERISK..=ascii::LEFT_BRACKET).contains(&c)
|| (c >= ascii::RIGHT_BRACKET && c <= ascii::TILDE) || (ascii::RIGHT_BRACKET..=ascii::TILDE).contains(&c)
} }
/// US ASCII control characters without effect /// US ASCII control characters without effect
@ -132,10 +132,10 @@ pub fn is_restr_ctext(c: u8) -> bool {
/// %d127 ; white space characters /// %d127 ; white space characters
/// ``` /// ```
pub fn is_obs_no_ws_ctl(c: u8) -> bool { pub fn is_obs_no_ws_ctl(c: u8) -> bool {
(c >= ascii::SOH && c <= ascii::BS) (ascii::SOH..=ascii::BS).contains(&c)
|| c == ascii::VT || c == ascii::VT
|| c == ascii::FF || c == ascii::FF
|| (c >= ascii::SO && c <= ascii::US) || (ascii::SO..=ascii::US).contains(&c)
|| c == ascii::DEL || c == ascii::DEL
} }

View file

@ -10,7 +10,7 @@ use nom::{
}; };
pub fn is_vchar(c: u8) -> bool { pub fn is_vchar(c: u8) -> bool {
c >= ascii::EXCLAMATION && c <= ascii::TILDE (ascii::EXCLAMATION..=ascii::TILDE).contains(&c)
} }
/// MIME Token allowed characters /// MIME Token allowed characters
@ -101,10 +101,10 @@ mod tests {
#[test] #[test]
fn test_atext() { fn test_atext() {
assert!(is_atext('=' as u8)); assert!(is_atext(b'='));
assert!(is_atext('5' as u8)); assert!(is_atext(b'5'));
assert!(is_atext('Q' as u8)); assert!(is_atext(b'Q'));
assert!(!is_atext(' ' as u8)); assert!(!is_atext(b' '));
//assert!(is_atext('É')); // support utf8 //assert!(is_atext('É')); // support utf8
} }