diff options
| author | Teddy Wing | 2021-03-14 17:48:10 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2021-03-14 17:48:10 +0100 | 
| commit | 4f8f5671f15fc08724875eecc7036dc41def0043 (patch) | |
| tree | 229e02b902bdcc46e36b168b2a6e48f519b77257 | |
| parent | 62c083b5e3a164d596b49132c8c53248aa2daf42 (diff) | |
| download | mutt-ottolangy-4f8f5671f15fc08724875eecc7036dc41def0043.tar.bz2 | |
get_email_body(): Remove unnecessary loops over headers
Now that I know the `Content-Type` header is already parsed in the
original email parse call, use that instead of looping over the headers
trying to find the content type.
| -rw-r--r-- | src/main.rs | 27 | 
1 files changed, 9 insertions, 18 deletions
| diff --git a/src/main.rs b/src/main.rs index 656403a..15c9c78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,27 +155,18 @@ fn get_email_body(email: &[u8]) -> Result<String, WrapError> {          println!("part ctype: {:?}", part.ctype); -        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 { -                    println!("apart ctype: {:?}", alternative_part.ctype); -                    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 part.ctype.mimetype == "multipart/alternative" { +            for alternative_part in &part.subparts { +                println!("apart ctype: {:?}", alternative_part.ctype); + +                if alternative_part.ctype.mimetype == "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()?); -            } +        if part.ctype.mimetype == "text/plain" { +            return Ok(part.get_body()?);          }      } | 
