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)]
pub enum EMLError<'a> {

View file

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

View file

@ -11,5 +11,5 @@ fn main() {
let eml = eml_codec::email(&rawmail).unwrap();
println!("{:#?}", eml);
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());
let mime = v1
.into_iter()
.map(|v| v.to_mime())
.flatten()
.filter_map(|v| v.to_mime())
.collect::<mime::mime::AnyMIME>();
let imf = v2
.into_iter()
.map(|v| v.to_imf())
.flatten()
.filter_map(|v| v.to_imf())
.collect::<imf::message::Message>();
(mime, imf)
}

View file

@ -144,7 +144,7 @@ fn strict_year(input: &[u8]) -> IResult<&[u8], i32> {
delimited(
fws,
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]| {
encoding_rs::UTF_8
.decode_without_bom_handling(d)
@ -162,15 +162,15 @@ fn obs_year(input: &[u8]) -> IResult<&[u8], i32> {
map(
delimited(
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),
),
|cap: &[u8]| {
let year_txt = encoding_rs::UTF_8.decode_without_bom_handling(cap).0;
let d = year_txt.parse::<i32>().unwrap_or(0);
if d >= 0 && d <= 49 {
if (0..=49).contains(&d) {
2000 + d
} else if d >= 50 && d <= 999 {
} else if (50..=999).contains(&d) {
1900 + d
} else {
d
@ -227,8 +227,8 @@ fn strict_zone(input: &[u8]) -> IResult<&[u8], Option<FixedOffset>> {
tuple((
opt(fws),
is_a("+-"),
take_while_m_n(2, 2, |c| c >= 0x30 && c <= 0x39),
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| (0x30..=0x39).contains(&c)),
)),
|(_, op, dig_zone_hour, dig_zone_min)| {
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")),
// Military Timezones East
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(3 * HOUR), tag_no_case(b"C")),
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
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(3 * HOUR), tag_no_case(b"P")),
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(
many0(alt((
map(tag(&[ascii::PERIOD]), |_| LocalPartToken::Dot),
map(word, |v| LocalPartToken::Word(v)),
map(word, LocalPartToken::Word),
))),
|v| LocalPart(v),
LocalPart,
)(input)
}
@ -223,7 +223,7 @@ impl<'a> fmt::Debug for Domain<'a> {
/// ```
pub fn obs_domain(input: &[u8]) -> IResult<&[u8], Domain> {
alt((
map(separated_list1(tag("."), atom), |v| Domain::Atoms(v)),
map(separated_list1(tag("."), atom), Domain::Atoms),
domain_litteral,
))(input)
}
@ -244,12 +244,12 @@ fn domain_litteral(input: &[u8]) -> IResult<&[u8], Domain> {
fn inner_domain_litteral(input: &[u8]) -> IResult<&[u8], Domain> {
map(
terminated(many0(preceded(opt(fws), take_while1(is_dtext))), opt(fws)),
|v| Domain::Litteral(v),
Domain::Litteral,
)(input)
}
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

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

View file

@ -127,7 +127,7 @@ pub fn ptext(input: &[u8]) -> IResult<&[u8], Vec<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

View file

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

View file

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

View file

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

View file

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