summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hurst <tom@hur.st>2018-09-07 02:14:50 +0100
committerKartikaya Gupta (kats) <staktrace@users.noreply.github.com>2018-09-07 11:51:51 -0400
commit87eb8897eed8f9952c313a642f111fd1d255849e (patch)
tree316f10f4d8ebba7d082b3b19d5546322d092a092
parentd535c57ad328e6ed2f4d000ac88c2bcc5e2fdc35 (diff)
downloadmailparse-87eb8897eed8f9952c313a642f111fd1d255849e.tar.gz
mailparse-87eb8897eed8f9952c313a642f111fd1d255849e.tar.xz
Tidy get_body_raw()
This saves an allocation of the empty string in the no-Content-Transfer-Encoding case.
-rw-r--r--src/lib.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ad8daae..e7a74a9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -678,10 +678,13 @@ impl<'a> ParsedMail<'a> {
/// assert_eq!(p.get_body_raw().unwrap(), b"This is the body");
/// ```
pub fn get_body_raw(&self) -> Result<Vec<u8>, MailParseError> {
- let transfer_coding = self.headers.get_first_value("Content-Transfer-Encoding")?
+ let transfer_coding = self
+ .headers
+ .get_first_value("Content-Transfer-Encoding")?
.map(|s| s.to_lowercase());
- let decoded = match transfer_coding.unwrap_or_default().as_ref() {
- "base64" => {
+
+ let decoded = match transfer_coding {
+ Some(ref enc) if enc == "base64" => {
let cleaned = self
.body
.iter()
@@ -690,11 +693,8 @@ impl<'a> ParsedMail<'a> {
.collect::<Vec<u8>>();
base64::decode(&cleaned)?
}
- "quoted-printable" => {
- quoted_printable::decode(
- self.body,
- quoted_printable::ParseMode::Robust,
- )?
+ Some(ref enc) if enc == "quoted-printable" => {
+ quoted_printable::decode(self.body, quoted_printable::ParseMode::Robust)?
}
_ => Vec::<u8>::from(self.body),
};