~asimpson/mailpreview-cli

cd3871fda618611ecef0f5cf453211c656431ba9 — Adam Simpson 1 year, 5 months ago 0618484
fix: use children of multipart/related that are in right format

This came up with an email that was an invite. The top level was
multipart/mixed and multipart/related. Diving into related revealed a
text/html block not the codified multipart/alternative block I've been
expecting. multipart/mixed is codified in RFC-1521[1]

[1]https://tools.ietf.org/html/rfc1521#section-7.2.2
3 files changed, 37 insertions(+), 2 deletions(-)

M Cargo.lock
M Cargo.toml
M src/main.rs
M Cargo.lock => Cargo.lock +1 -1
@@ 59,7 59,7 @@ dependencies = [

[[package]]
name = "mailpreview-cli"
version = "0.2.0"
version = "0.2.1"
dependencies = [
 "mailparse",
]

M Cargo.toml => Cargo.toml +1 -1
@@ 1,6 1,6 @@
[package]
name = "mailpreview-cli"
version = "0.2.0"
version = "0.2.1"
authors = ["Adam Simpson <adam@adamsimpson.net"]
edition = "2018"


M src/main.rs => src/main.rs +35 -0
@@ 27,6 27,10 @@ fn return_body(mail: ParsedMail, format: String) -> Result<String, MailParseErro
                    if i.ctype.mimetype == "multipart/alternative" {
                        body = return_body_from_alternative(i, &format)?;
                    }

                    if i.ctype.mimetype == format {
                        body = i.get_body()?;
                    }
                }
            }
            if m.ctype.mimetype == "multipart/alternative" {


@@ 48,6 52,37 @@ fn return_body(mail: ParsedMail, format: String) -> Result<String, MailParseErro
    Ok(body)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn multipart_mixed() {
        let body = "Content-Type: multipart/mixed;
	boundary=\"mixed\"

--mixed
Content-Type: multipart/related;
	boundary=\"related\"

--related
Content-Type: text/html

hello!
--related--

--mixed
Content-Type: text/plain

bye!
--mixed--
";
        let mail = parse_mail(body.as_bytes()).unwrap();
        let body = return_body(mail, "text/html".to_string()).unwrap();
        assert_eq!(body.trim(), "hello!");
    }
}

fn return_path_from_cli() -> Result<String, String> {
    let file = std::env::args().nth(1);