diff options
| author | Teddy Wing | 2021-03-14 06:17:34 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2021-03-14 06:17:34 +0100 | 
| commit | 1f9b50fe4531f2156f2fd823dc6292d18797cb1a (patch) | |
| tree | f8baae4d065d726f35ce584aa2f241542cba019e /src | |
| parent | 56555142e1a48069b035e8da6570c1d1c5a65451 (diff) | |
| download | mutt-ottolangy-1f9b50fe4531f2156f2fd823dc6292d18797cb1a.tar.bz2 | |
get_email_body(): Support emails with attachments
Parse the text email body out of `multipart/alternative` parts.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 14 | 
1 files changed, 14 insertions, 0 deletions
| diff --git a/src/main.rs b/src/main.rs index 199862c..b4d500d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -137,6 +137,20 @@ fn get_email_body(email: &[u8]) -> Result<String, WrapError> {      for part in email.subparts {          for header in part.get_headers() {              if header.get_key() == "Content-Type" +                && header.get_value().starts_with("multipart/alternative") +            { +                for alternative_part in &part.subparts { +                    for alternative_header in alternative_part.get_headers() { +                        if alternative_header.get_key() == "Content-Type" +                            && alternative_header.get_value().starts_with("text/plain") +                        { +                            return Ok(alternative_part.get_body()?); +                        } +                    } +                } +            } + +            if header.get_key() == "Content-Type"                  && header.get_value().starts_with("text/plain")              {                  return Ok(part.get_body()?); | 
