src/message: Add test for email with png

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
This commit is contained in:
Federico Guerinoni
2020-11-21 16:53:39 +01:00
committed by Paolo Barbolini
parent 50ac1cdbec
commit 0e3526c1bc
3 changed files with 280 additions and 2 deletions

View File

@@ -110,7 +110,7 @@
//! .singlepart(
//! SinglePart::eight_bit()
//! .header(header::ContentType("text/html; charset=utf8".parse()?))
//! .body("<p><b>Hello</b>, <i>world</i>! <img src=cid:123>")
//! .body("<p><b>Hello</b>, <i>world</i>! <img src=cid:123></p>")
//! )
//! .singlepart(
//! SinglePart::base64()
@@ -498,7 +498,7 @@ impl Default for MessageBuilder {
#[cfg(test)]
mod test {
use crate::message::{header, mailbox::Mailbox, Message};
use crate::message::{header, mailbox::Mailbox, Message, MultiPart, SinglePart};
#[test]
fn email_missing_originator() {
@@ -555,4 +555,49 @@ mod test {
)
);
}
#[test]
fn email_with_png() {
let date = "Tue, 15 Nov 1994 08:12:31 GMT".parse().unwrap();
let img = std::fs::read("./docs/lettre.png").unwrap();
let m = Message::builder()
.date(date)
.from("NoBody <nobody@domain.tld>".parse().unwrap())
.reply_to("Yuin <yuin@domain.tld>".parse().unwrap())
.to("Hei <hei@domain.tld>".parse().unwrap())
.subject("Happy new year")
.multipart(
MultiPart::related()
.singlepart(
SinglePart::eight_bit()
.header(header::ContentType(
"text/html; charset=utf8".parse().unwrap(),
))
.body("<p><b>Hello</b>, <i>world</i>! <img src=cid:123></p>"),
)
.singlepart(
SinglePart::base64()
.header(header::ContentType("image/png".parse().unwrap()))
.header(header::ContentDisposition {
disposition: header::DispositionType::Inline,
parameters: vec![],
})
.header(header::ContentId("<123>".into()))
.body(img),
),
)
.unwrap();
let output = String::from_utf8(m.formatted()).unwrap();
let file_expected = std::fs::read("./testdata/email_with_png.eml").unwrap();
let expected = String::from_utf8(file_expected).unwrap();
for (i, line) in output.lines().zip(expected.lines()).enumerate() {
if i == 6 || i == 8 || i == 13 || i == 232 {
continue;
}
assert_eq!(line.0, line.1)
}
}
}