~asimpson/mailpreview-cli

7ad075c9e6d49304d76130bed2fca258e70a4e9e — Adam Simpson 2 years ago 33a6db2
feat: account for related type (RFC 2387[1])

[1]: https://tools.ietf.org/html/rfc2387
1 files changed, 20 insertions(+), 3 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +20 -3
@@ 4,18 4,35 @@ use std::fs::File;
use std::io::prelude::*;
use std::io::Read;

fn return_body_from_alternative(mail: &ParsedMail, format: &String) -> Result<String, MailParseError> {
    let mut body = String::new();

    for m in mail.subparts.iter() {
      if &m.ctype.mimetype == format {
        body = m.get_body()?;
      }
    }

    Ok(body)
}

fn return_body(mail: ParsedMail, format: String) -> Result<String, MailParseError> {
    let mut body = String::new();

    if mail.subparts.len() > 0 {
        for m in mail.subparts.iter() {
            if m.ctype.mimetype == "multipart/alternative" {
            if m.ctype.mimetype == "multipart/related" {
              // TODO make alternative extractor func
              // TODO account for mixed
              for i in m.subparts.iter() {
                if i.ctype.mimetype == format {
                  body = i.get_body()?;
                if i.ctype.mimetype == "multipart/alternative" {
                  body = return_body_from_alternative(i, &format)?;
                }
              }
            }
            if m.ctype.mimetype == "multipart/alternative" {
                body = return_body_from_alternative(m, &format)?;
            }
            if m.ctype.mimetype == format {
                body = m.get_body()?;
            }