Skip to content

Commit

Permalink
delete unneeded variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sftse committed Dec 12, 2023
1 parent 4948503 commit 37cf7f9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 58 deletions.
41 changes: 21 additions & 20 deletions src/decoders/quoted_printable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
];
52 changes: 18 additions & 34 deletions src/parsers/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions src/parsers/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 37cf7f9

Please sign in to comment.