2019-11-17 11:29:12 +00:00
|
|
|
use melib;
|
|
|
|
use melib::email::Draft;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_draft() {
|
|
|
|
let mut new_draft = Draft::default();
|
2020-09-16 16:57:06 +00:00
|
|
|
let attachment = melib::email::attachment_from_file(&"./tests/test_image.gif")
|
2019-11-17 11:29:12 +00:00
|
|
|
.expect("Could not open test_image.gif.");
|
2020-08-25 09:25:26 +00:00
|
|
|
new_draft.headers_mut().remove("User-Agent");
|
|
|
|
new_draft.headers_mut().remove("Date");
|
2019-11-17 11:29:12 +00:00
|
|
|
|
|
|
|
new_draft.attachments_mut().push(attachment);
|
|
|
|
new_draft.set_body("hello world.".to_string());
|
|
|
|
let raw = new_draft.finalise().expect("could not finalise draft");
|
|
|
|
let boundary_def = raw.find("bzz_bzz__bzz__").unwrap();
|
|
|
|
let boundary_end = boundary_def + raw[boundary_def..].find("\"").unwrap();
|
|
|
|
let boundary = raw[boundary_def..boundary_end].to_string();
|
|
|
|
let boundary_str = &boundary["bzz_bzz__bzz__".len()..];
|
|
|
|
|
|
|
|
let raw = raw.replace(boundary_str, "");
|
2020-09-16 16:57:06 +00:00
|
|
|
assert_eq!(include_str!("generated_email.eml"), &raw);
|
2019-11-17 11:29:12 +00:00
|
|
|
}
|