From 37cf7f9b9e06ae5b2d2707574a5d32b1faaddd32 Mon Sep 17 00:00:00 2001 From: c Date: Wed, 6 Dec 2023 15:57:47 +0100 Subject: [PATCH] delete unneeded variable --- src/decoders/quoted_printable.rs | 41 +++++++++++++------------ src/parsers/message.rs | 52 +++++++++++--------------------- src/parsers/mime.rs | 8 ++--- 3 files changed, 43 insertions(+), 58 deletions(-) diff --git a/src/decoders/quoted_printable.rs b/src/decoders/quoted_printable.rs index 4493d9a..0081b78 100644 --- a/src/decoders/quoted_printable.rs +++ b/src/decoders/quoted_printable.rs @@ -312,6 +312,27 @@ impl<'x> MessageStream<'x> { None } } + +/* + * Adapted from Daniel Lemire's source: + * https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2019/04/17/hexparse.cpp + * + */ + +pub static HEX_MAP: &[i8] = &[ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, + 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +]; + #[cfg(test)] mod tests { use crate::parsers::MessageStream; @@ -468,23 +489,3 @@ mod tests { } } } - -/* - * Adapted from Daniel Lemire's source: - * https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2019/04/17/hexparse.cpp - * - */ - -pub static HEX_MAP: &[i8] = &[ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, - 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -]; diff --git a/src/parsers/message.rs b/src/parsers/message.rs index 7ca31f7..19b4ddc 100644 --- a/src/parsers/message.rs +++ b/src/parsers/message.rs @@ -306,6 +306,20 @@ impl MessageParser { (false, false) }; + if add_to_html { + message.html_body.push(message.parts.len()); + } + if add_to_text { + message.text_body.push(message.parts.len()); + } + + if !is_multipart && !add_to_text && !add_to_html + || (mime_type == MimeType::Inline || is_multipart) + && (!add_to_text || !add_to_html) + { + message.attachments.push(message.parts.len()); + } + if is_text { let text = match ( bytes, @@ -323,46 +337,16 @@ impl MessageParser { } (Cow::Borrowed(bytes), None) => String::from_utf8_lossy(bytes), }; - let is_html = mime_type == MimeType::TextHtml; - if add_to_html { - message.html_body.push(message.parts.len()); - } - if add_to_text { - message.text_body.push(message.parts.len()); - } - - if !is_multipart && !(add_to_text || add_to_html) - || (mime_type == MimeType::Inline || is_multipart) - && (!add_to_text || !add_to_html) - { - message.attachments.push(message.parts.len()); - } - - if is_html { + if mime_type == MimeType::TextHtml { PartType::Html(text) } else { PartType::Text(text) } + } else if !is_inline { + PartType::Binary(bytes) } else { - if add_to_html { - message.html_body.push(message.parts.len()); - } - if add_to_text { - message.text_body.push(message.parts.len()); - } - if !is_multipart && !(add_to_text || add_to_html) - || (mime_type == MimeType::Inline || is_multipart) - && (!add_to_text || !add_to_html) - { - message.attachments.push(message.parts.len()); - } - - if !is_inline { - PartType::Binary(bytes) - } else { - PartType::InlineBinary(bytes) - } + PartType::InlineBinary(bytes) } } else { message.attachments.push(message.parts.len()); diff --git a/src/parsers/mime.rs b/src/parsers/mime.rs index 39bb1ef..574d054 100644 --- a/src/parsers/mime.rs +++ b/src/parsers/mime.rs @@ -134,16 +134,16 @@ impl<'x> MessageStream<'x> { self.checkpoint(); match (self.next(), self.peek()) { - (Some(&a), Some(&&b)) if a == b'\r' && b == b'\n' => { + (Some(b'\r'), Some(b'\n')) => { self.next(); false } - (Some(&a), Some(&&b)) if a == b'-' && b == b'-' => { + (Some(b'-'), Some(b'-')) => { self.next(); true } - (Some(&a), _) if a == b'\n' => false, - (Some(&a), _) if a.is_ascii_whitespace() => { + (Some(b'\n'), _) => false, + (Some(a), _) if a.is_ascii_whitespace() => { self.skip_crlf(); false }