You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.2 KiB

  1. use melib;
  2. use melib::email::Draft;
  3. use xdg_utils::query_mime_info;
  4. #[test]
  5. fn build_draft() {
  6. let mut new_draft = Draft::default();
  7. let mut attachment = melib::email::attachment_from_file(&"./tests/test_image.gif")
  8. .expect("Could not open test_image.gif.");
  9. if let Ok(mime_type) = query_mime_info("./tests/test_image.gif") {
  10. match attachment.content_type {
  11. melib::email::attachment_types::ContentType::Other { ref mut tag, .. } => {
  12. *tag = mime_type;
  13. }
  14. _ => {}
  15. }
  16. }
  17. new_draft.headers_mut().remove("User-Agent");
  18. new_draft.headers_mut().remove("Date");
  19. new_draft.attachments_mut().push(attachment);
  20. new_draft.set_body("hello world.".to_string());
  21. let raw = new_draft.finalise().expect("could not finalise draft");
  22. let boundary_def = raw.find("bzz_bzz__bzz__").unwrap();
  23. let boundary_end = boundary_def + raw[boundary_def..].find("\"").unwrap();
  24. let boundary = raw[boundary_def..boundary_end].to_string();
  25. let boundary_str = &boundary["bzz_bzz__bzz__".len()..];
  26. let raw = raw.replace(boundary_str, "");
  27. assert_eq!(include_str!("generated.mail"), &raw);
  28. }