diff options
author | Thomas Hurst <tom@hur.st> | 2018-09-07 02:14:50 +0100 |
---|---|---|
committer | Kartikaya Gupta (kats) <staktrace@users.noreply.github.com> | 2018-09-07 11:51:51 -0400 |
commit | 87eb8897eed8f9952c313a642f111fd1d255849e (patch) | |
tree | 316f10f4d8ebba7d082b3b19d5546322d092a092 | |
parent | d535c57ad328e6ed2f4d000ac88c2bcc5e2fdc35 (diff) |
Tidy get_body_raw()
This saves an allocation of the empty string in the
no-Content-Transfer-Encoding case.
-rw-r--r-- | src/lib.rs | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -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), }; |