From 87eb8897eed8f9952c313a642f111fd1d255849e Mon Sep 17 00:00:00 2001 From: Thomas Hurst Date: Fri, 7 Sep 2018 02:14:50 +0100 Subject: Tidy get_body_raw() This saves an allocation of the empty string in the no-Content-Transfer-Encoding case. --- src/lib.rs | 16 ++++++++-------- 1 file 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, 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::>(); 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::::from(self.body), }; -- cgit v1.2.3