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.

49 lines
1.6 KiB

  1. use melib;
  2. use ui::mime_apps;
  3. use melib::email::Draft;
  4. use mime_apps::query_mime_info;
  5. #[test]
  6. fn build_draft() {
  7. let mut new_draft = Draft::default();
  8. let mut attachment = melib::email::attachment_from_file(&"./tests/test_image.gif")
  9. .expect("Could not open test_image.gif.");
  10. if let Ok(mime_type) = query_mime_info("./tests/test_image.gif") {
  11. match attachment.content_type {
  12. melib::email::ContentType::Other { ref mut tag, .. } => {
  13. *tag = mime_type;
  14. }
  15. _ => {}
  16. }
  17. }
  18. if new_draft.headers().contains_key("User-Agent") {
  19. new_draft.headers_mut().remove("User-Agent");
  20. let pos = new_draft
  21. .header_order
  22. .iter()
  23. .position(|k| k == "User-Agent")
  24. .unwrap();
  25. new_draft.header_order.remove(pos);
  26. }
  27. {
  28. new_draft.headers_mut().remove("Date");
  29. let pos = new_draft
  30. .header_order
  31. .iter()
  32. .position(|k| k == "Date")
  33. .unwrap();
  34. new_draft.header_order.remove(pos);
  35. }
  36. new_draft.attachments_mut().push(attachment);
  37. new_draft.set_body("hello world.".to_string());
  38. let raw = new_draft.finalise().expect("could not finalise draft");
  39. let boundary_def = raw.find("bzz_bzz__bzz__").unwrap();
  40. let boundary_end = boundary_def + raw[boundary_def..].find("\"").unwrap();
  41. let boundary = raw[boundary_def..boundary_end].to_string();
  42. let boundary_str = &boundary["bzz_bzz__bzz__".len()..];
  43. let raw = raw.replace(boundary_str, "");
  44. assert_eq!(include_str!("generated.mail"), &raw);
  45. }