Remove MimeMessage::from_bytes()

It was not used anywhere except the tests.
This commit is contained in:
link2xt
2023-02-13 17:53:54 +00:00
parent 2e4f63a290
commit 71d9716117
7 changed files with 91 additions and 87 deletions

View File

@@ -29,6 +29,7 @@
Rust and JSON-RPC API have `flags` integer argument Rust and JSON-RPC API have `flags` integer argument
replaced with two boolean flags `info_only` and `add_daymarker`. replaced with two boolean flags `info_only` and `add_daymarker`.
- jsonrpc: add API to check if the message is sent by a bot #3877 - jsonrpc: add API to check if the message is sent by a bot #3877
- Remove `MimeMessage::from_bytes()` public interface. #4033
## 1.107.1 ## 1.107.1

View File

@@ -2009,7 +2009,7 @@ mod tests {
"1.0" "1.0"
); );
let _mime_msg = MimeMessage::from_bytes(context, rendered_msg.message.as_bytes()) let _mime_msg = MimeMessage::from_bytes(context, rendered_msg.message.as_bytes(), None)
.await .await
.unwrap(); .unwrap();
} }

View File

@@ -48,7 +48,7 @@ use crate::{location, tools};
/// It is created by parsing the raw data of an actual MIME message /// It is created by parsing the raw data of an actual MIME message
/// using the [MimeMessage::from_bytes] constructor. /// using the [MimeMessage::from_bytes] constructor.
#[derive(Debug)] #[derive(Debug)]
pub struct MimeMessage { pub(crate) struct MimeMessage {
/// Parsed MIME parts. /// Parsed MIME parts.
pub parts: Vec<Part>, pub parts: Vec<Part>,
@@ -186,15 +186,11 @@ impl Default for SystemMessage {
const MIME_AC_SETUP_FILE: &str = "application/autocrypt-setup"; const MIME_AC_SETUP_FILE: &str = "application/autocrypt-setup";
impl MimeMessage { impl MimeMessage {
pub async fn from_bytes(context: &Context, body: &[u8]) -> Result<Self> {
MimeMessage::from_bytes_with_partial(context, body, None).await
}
/// Parse a mime message. /// Parse a mime message.
/// ///
/// If `partial` is set, it contains the full message size in bytes /// If `partial` is set, it contains the full message size in bytes
/// and `body` contains the header only. /// and `body` contains the header only.
pub(crate) async fn from_bytes_with_partial( pub(crate) async fn from_bytes(
context: &Context, context: &Context,
body: &[u8], body: &[u8],
partial: Option<u32>, partial: Option<u32>,
@@ -2012,35 +2008,35 @@ mod tests {
async fn test_mimeparser_fromheader() { async fn test_mimeparser_fromheader() {
let ctx = TestContext::new_alice().await; let ctx = TestContext::new_alice().await;
let mimemsg = MimeMessage::from_bytes(&ctx, b"From: g@c.de\n\nhi") let mimemsg = MimeMessage::from_bytes(&ctx, b"From: g@c.de\n\nhi", None)
.await .await
.unwrap(); .unwrap();
let contact = mimemsg.from; let contact = mimemsg.from;
assert_eq!(contact.addr, "g@c.de"); assert_eq!(contact.addr, "g@c.de");
assert_eq!(contact.display_name, None); assert_eq!(contact.display_name, None);
let mimemsg = MimeMessage::from_bytes(&ctx, b"From: g@c.de \n\nhi") let mimemsg = MimeMessage::from_bytes(&ctx, b"From: g@c.de \n\nhi", None)
.await .await
.unwrap(); .unwrap();
let contact = mimemsg.from; let contact = mimemsg.from;
assert_eq!(contact.addr, "g@c.de"); assert_eq!(contact.addr, "g@c.de");
assert_eq!(contact.display_name, None); assert_eq!(contact.display_name, None);
let mimemsg = MimeMessage::from_bytes(&ctx, b"From: <g@c.de>\n\nhi") let mimemsg = MimeMessage::from_bytes(&ctx, b"From: <g@c.de>\n\nhi", None)
.await .await
.unwrap(); .unwrap();
let contact = mimemsg.from; let contact = mimemsg.from;
assert_eq!(contact.addr, "g@c.de"); assert_eq!(contact.addr, "g@c.de");
assert_eq!(contact.display_name, None); assert_eq!(contact.display_name, None);
let mimemsg = MimeMessage::from_bytes(&ctx, b"From: Goetz C <g@c.de>\n\nhi") let mimemsg = MimeMessage::from_bytes(&ctx, b"From: Goetz C <g@c.de>\n\nhi", None)
.await .await
.unwrap(); .unwrap();
let contact = mimemsg.from; let contact = mimemsg.from;
assert_eq!(contact.addr, "g@c.de"); assert_eq!(contact.addr, "g@c.de");
assert_eq!(contact.display_name, Some("Goetz C".to_string())); assert_eq!(contact.display_name, Some("Goetz C".to_string()));
let mimemsg = MimeMessage::from_bytes(&ctx, b"From: \"Goetz C\" <g@c.de>\n\nhi") let mimemsg = MimeMessage::from_bytes(&ctx, b"From: \"Goetz C\" <g@c.de>\n\nhi", None)
.await .await
.unwrap(); .unwrap();
let contact = mimemsg.from; let contact = mimemsg.from;
@@ -2048,7 +2044,7 @@ mod tests {
assert_eq!(contact.display_name, Some("Goetz C".to_string())); assert_eq!(contact.display_name, Some("Goetz C".to_string()));
let mimemsg = let mimemsg =
MimeMessage::from_bytes(&ctx, b"From: =?utf-8?q?G=C3=B6tz?= C <g@c.de>\n\nhi") MimeMessage::from_bytes(&ctx, b"From: =?utf-8?q?G=C3=B6tz?= C <g@c.de>\n\nhi", None)
.await .await
.unwrap(); .unwrap();
let contact = mimemsg.from; let contact = mimemsg.from;
@@ -2057,10 +2053,13 @@ mod tests {
// although RFC 2047 says, encoded-words shall not appear inside quoted-string, // although RFC 2047 says, encoded-words shall not appear inside quoted-string,
// this combination is used in the wild eg. by MailMate // this combination is used in the wild eg. by MailMate
let mimemsg = let mimemsg = MimeMessage::from_bytes(
MimeMessage::from_bytes(&ctx, b"From: \"=?utf-8?q?G=C3=B6tz?= C\" <g@c.de>\n\nhi") &ctx,
.await b"From: \"=?utf-8?q?G=C3=B6tz?= C\" <g@c.de>\n\nhi",
.unwrap(); None,
)
.await
.unwrap();
let contact = mimemsg.from; let contact = mimemsg.from;
assert_eq!(contact.addr, "g@c.de"); assert_eq!(contact.addr, "g@c.de");
assert_eq!(contact.display_name, Some("Götz C".to_string())); assert_eq!(contact.display_name, Some("Götz C".to_string()));
@@ -2070,7 +2069,7 @@ mod tests {
async fn test_mimeparser_crash() { async fn test_mimeparser_crash() {
let context = TestContext::new_alice().await; let context = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/issue_523.txt"); let raw = include_bytes!("../test-data/message/issue_523.txt");
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
@@ -2082,7 +2081,7 @@ mod tests {
async fn test_get_rfc724_mid_exists() { async fn test_get_rfc724_mid_exists() {
let context = TestContext::new_alice().await; let context = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/mail_with_message_id.txt"); let raw = include_bytes!("../test-data/message/mail_with_message_id.txt");
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
@@ -2096,7 +2095,7 @@ mod tests {
async fn test_get_rfc724_mid_not_exists() { async fn test_get_rfc724_mid_not_exists() {
let context = TestContext::new_alice().await; let context = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/issue_523.txt"); let raw = include_bytes!("../test-data/message/issue_523.txt");
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!(mimeparser.get_rfc724_mid(), None); assert_eq!(mimeparser.get_rfc724_mid(), None);
@@ -2293,7 +2292,7 @@ mod tests {
test1\n\ test1\n\
"; ";
let mimeparser = MimeMessage::from_bytes_with_partial(&context.ctx, &raw[..], None).await; let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None).await;
assert!(mimeparser.is_err()); assert!(mimeparser.is_err());
} }
@@ -2308,7 +2307,7 @@ mod tests {
\n\ \n\
Some reply\n\ Some reply\n\
"; ";
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -2354,7 +2353,7 @@ mod tests {
--==break==--\n\ --==break==--\n\
\n"; \n";
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
@@ -2388,26 +2387,26 @@ mod tests {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/mail_attach_txt.eml"); let raw = include_bytes!("../test-data/message/mail_attach_txt.eml");
let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..], None).await.unwrap();
assert_eq!(mimeparser.user_avatar, None); assert_eq!(mimeparser.user_avatar, None);
assert_eq!(mimeparser.group_avatar, None); assert_eq!(mimeparser.group_avatar, None);
let raw = include_bytes!("../test-data/message/mail_with_user_avatar.eml"); let raw = include_bytes!("../test-data/message/mail_with_user_avatar.eml");
let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..], None).await.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::Text); assert_eq!(mimeparser.parts[0].typ, Viewtype::Text);
assert!(mimeparser.user_avatar.unwrap().is_change()); assert!(mimeparser.user_avatar.unwrap().is_change());
assert_eq!(mimeparser.group_avatar, None); assert_eq!(mimeparser.group_avatar, None);
let raw = include_bytes!("../test-data/message/mail_with_user_avatar_deleted.eml"); let raw = include_bytes!("../test-data/message/mail_with_user_avatar_deleted.eml");
let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..], None).await.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::Text); assert_eq!(mimeparser.parts[0].typ, Viewtype::Text);
assert_eq!(mimeparser.user_avatar, Some(AvatarAction::Delete)); assert_eq!(mimeparser.user_avatar, Some(AvatarAction::Delete));
assert_eq!(mimeparser.group_avatar, None); assert_eq!(mimeparser.group_avatar, None);
let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml"); let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml");
let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..], None).await.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::Text); assert_eq!(mimeparser.parts[0].typ, Viewtype::Text);
assert!(mimeparser.user_avatar.unwrap().is_change()); assert!(mimeparser.user_avatar.unwrap().is_change());
@@ -2417,7 +2416,9 @@ mod tests {
let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml"); let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml");
let raw = String::from_utf8_lossy(raw).to_string(); let raw = String::from_utf8_lossy(raw).to_string();
let raw = raw.replace("Chat-User-Avatar:", "Xhat-Xser-Xvatar:"); let raw = raw.replace("Chat-User-Avatar:", "Xhat-Xser-Xvatar:");
let mimeparser = MimeMessage::from_bytes(&t, raw.as_bytes()).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, raw.as_bytes(), None)
.await
.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::Image); assert_eq!(mimeparser.parts[0].typ, Viewtype::Image);
assert_eq!(mimeparser.user_avatar, None); assert_eq!(mimeparser.user_avatar, None);
@@ -2429,7 +2430,7 @@ mod tests {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/videochat_invitation.eml"); let raw = include_bytes!("../test-data/message/videochat_invitation.eml");
let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..], None).await.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::VideochatInvitation); assert_eq!(mimeparser.parts[0].typ, Viewtype::VideochatInvitation);
assert_eq!( assert_eq!(
@@ -2476,7 +2477,7 @@ Content-Disposition: attachment; filename=\"message.kml\"\n\
--==break==--\n\ --==break==--\n\
;"; ;";
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -2525,7 +2526,7 @@ Disposition: manual-action/MDN-sent-automatically; displayed\n\
--kJBbU58X1xeWNHgBtTbMk80M5qnV4N--\n\ --kJBbU58X1xeWNHgBtTbMk80M5qnV4N--\n\
"; ";
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -2605,7 +2606,7 @@ Disposition: manual-action/MDN-sent-automatically; displayed\n\
--outer--\n\ --outer--\n\
"; ";
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -2652,7 +2653,7 @@ Additional-Message-IDs: <foo@example.com> <foo@example.net>\n\
--kJBbU58X1xeWNHgBtTbMk80M5qnV4N--\n\ --kJBbU58X1xeWNHgBtTbMk80M5qnV4N--\n\
"; ";
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -2699,7 +2700,7 @@ MDYyMDYxNTE1RTlDOEE4Cj4+CnN0YXJ0eHJlZgo4Mjc4CiUlRU9GCg==
------=_Part_25_46172632.1581201680436-- ------=_Part_25_46172632.1581201680436--
"#; "#;
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -2743,7 +2744,7 @@ MDYyMDYxNTE1RTlDOEE4Cj4+CnN0YXJ0eHJlZgo4Mjc4CiUlRU9GCg==
------=_Part_25_46172632.1581201680436-- ------=_Part_25_46172632.1581201680436--
"#; "#;
let message = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap(); let message = MimeMessage::from_bytes(&t, &raw[..], None).await.unwrap();
assert_eq!(message.parts.len(), 1); assert_eq!(message.parts.len(), 1);
assert_eq!(message.parts[0].typ, Viewtype::File); assert_eq!(message.parts[0].typ, Viewtype::File);
@@ -2797,7 +2798,7 @@ CWt6wx7fiLp0qS9RrX75g6Gqw7nfCs6EcBERcIPt7DTe8VStJwf3LWqVwxl4gQl46yhfoqwEO+I=
----11019878869865180-- ----11019878869865180--
"#; "#;
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!(message.get_subject(), Some("example".to_string())); assert_eq!(message.get_subject(), Some("example".to_string()));
@@ -2869,7 +2870,7 @@ CWt6wx7fiLp0qS9RrX75g6Gqw7nfCs6EcBERcIPt7DTe8VStJwf3LWqVwxl4gQl46yhfoqwEO+I=
--------------779C1631600DF3DB8C02E53A--"#; --------------779C1631600DF3DB8C02E53A--"#;
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!(message.get_subject(), Some("Test subject".to_string())); assert_eq!(message.get_subject(), Some("Test subject".to_string()));
@@ -2940,7 +2941,7 @@ CWt6wx7fiLp0qS9RrX75g6Gqw7nfCs6EcBERcIPt7DTe8VStJwf3LWqVwxl4gQl46yhfoqwEO+I=
------=_NextPart_000_0003_01D622B3.CA753E60-- ------=_NextPart_000_0003_01D622B3.CA753E60--
"##; "##;
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -3038,7 +3039,7 @@ From: alice <alice@example.org>
Reply Reply
"##; "##;
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -3070,7 +3071,7 @@ From: alice <alice@example.org>
> Just a quote. > Just a quote.
"##; "##;
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -3104,7 +3105,7 @@ On 2020-10-25, Bob wrote:
> A quote. > A quote.
"##; "##;
let message = MimeMessage::from_bytes(&context.ctx, &raw[..]) let message = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!(message.get_subject(), Some("Re: top posting".to_string())); assert_eq!(message.get_subject(), Some("Re: top posting".to_string()));
@@ -3122,7 +3123,7 @@ On 2020-10-25, Bob wrote:
async fn test_attachment_quote() { async fn test_attachment_quote() {
let context = TestContext::new_alice().await; let context = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/quote_attach.eml"); let raw = include_bytes!("../test-data/message/quote_attach.eml");
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
@@ -3140,7 +3141,7 @@ On 2020-10-25, Bob wrote:
async fn test_quote_div() { async fn test_quote_div() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/gmx-quote.eml"); let raw = include_bytes!("../test-data/message/gmx-quote.eml");
let mimeparser = MimeMessage::from_bytes(&t, raw).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, raw, None).await.unwrap();
assert_eq!(mimeparser.parts[0].msg, "YIPPEEEEEE\n\nMulti-line"); assert_eq!(mimeparser.parts[0].msg, "YIPPEEEEEE\n\nMulti-line");
assert_eq!(mimeparser.parts[0].param.get(Param::Quote).unwrap(), "Now?"); assert_eq!(mimeparser.parts[0].param.get(Param::Quote).unwrap(), "Now?");
} }
@@ -3150,7 +3151,7 @@ On 2020-10-25, Bob wrote:
// all-inkl.com puts quotes into `<blockquote> </blockquote>`. // all-inkl.com puts quotes into `<blockquote> </blockquote>`.
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/allinkl-quote.eml"); let raw = include_bytes!("../test-data/message/allinkl-quote.eml");
let mimeparser = MimeMessage::from_bytes(&t, raw).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, raw, None).await.unwrap();
assert!(mimeparser.parts[0].msg.starts_with("It's 1.0.")); assert!(mimeparser.parts[0].msg.starts_with("It's 1.0."));
assert_eq!( assert_eq!(
mimeparser.parts[0].param.get(Param::Quote).unwrap(), mimeparser.parts[0].param.get(Param::Quote).unwrap(),
@@ -3194,7 +3195,7 @@ On 2020-10-25, Bob wrote:
async fn test_mime_modified_plain() { async fn test_mime_modified_plain() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/text_plain_unspecified.eml"); let raw = include_bytes!("../test-data/message/text_plain_unspecified.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, raw).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t.ctx, raw, None).await.unwrap();
assert!(!mimeparser.is_mime_modified); assert!(!mimeparser.is_mime_modified);
assert_eq!( assert_eq!(
mimeparser.parts[0].msg, mimeparser.parts[0].msg,
@@ -3206,7 +3207,7 @@ On 2020-10-25, Bob wrote:
async fn test_mime_modified_alt_plain_html() { async fn test_mime_modified_alt_plain_html() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/text_alt_plain_html.eml"); let raw = include_bytes!("../test-data/message/text_alt_plain_html.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, raw).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t.ctx, raw, None).await.unwrap();
assert!(mimeparser.is_mime_modified); assert!(mimeparser.is_mime_modified);
assert_eq!( assert_eq!(
mimeparser.parts[0].msg, mimeparser.parts[0].msg,
@@ -3218,7 +3219,7 @@ On 2020-10-25, Bob wrote:
async fn test_mime_modified_alt_plain() { async fn test_mime_modified_alt_plain() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/text_alt_plain.eml"); let raw = include_bytes!("../test-data/message/text_alt_plain.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, raw).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t.ctx, raw, None).await.unwrap();
assert!(!mimeparser.is_mime_modified); assert!(!mimeparser.is_mime_modified);
assert_eq!( assert_eq!(
mimeparser.parts[0].msg, mimeparser.parts[0].msg,
@@ -3233,7 +3234,7 @@ On 2020-10-25, Bob wrote:
async fn test_mime_modified_alt_html() { async fn test_mime_modified_alt_html() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/text_alt_html.eml"); let raw = include_bytes!("../test-data/message/text_alt_html.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, raw).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t.ctx, raw, None).await.unwrap();
assert!(mimeparser.is_mime_modified); assert!(mimeparser.is_mime_modified);
assert_eq!( assert_eq!(
mimeparser.parts[0].msg, mimeparser.parts[0].msg,
@@ -3245,7 +3246,7 @@ On 2020-10-25, Bob wrote:
async fn test_mime_modified_html() { async fn test_mime_modified_html() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/text_html.eml"); let raw = include_bytes!("../test-data/message/text_html.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, raw).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t.ctx, raw, None).await.unwrap();
assert!(mimeparser.is_mime_modified); assert!(mimeparser.is_mime_modified);
assert_eq!( assert_eq!(
mimeparser.parts[0].msg, mimeparser.parts[0].msg,
@@ -3261,7 +3262,7 @@ On 2020-10-25, Bob wrote:
static REPEAT_CNT: usize = 2000; // results in a text of 84k, should be more than DC_DESIRED_TEXT_LEN static REPEAT_CNT: usize = 2000; // results in a text of 84k, should be more than DC_DESIRED_TEXT_LEN
let long_txt = format!("From: alice@c.de\n\n{}", REPEAT_TXT.repeat(REPEAT_CNT)); let long_txt = format!("From: alice@c.de\n\n{}", REPEAT_TXT.repeat(REPEAT_CNT));
let mimemsg = MimeMessage::from_bytes(&t, long_txt.as_ref()) let mimemsg = MimeMessage::from_bytes(&t, long_txt.as_ref(), None)
.await .await
.unwrap(); .unwrap();
assert_eq!(long_txt.matches("just repeated").count(), REPEAT_CNT); assert_eq!(long_txt.matches("just repeated").count(), REPEAT_CNT);
@@ -3288,7 +3289,7 @@ On 2020-10-25, Bob wrote:
MIME-Version: 1.0\n\ MIME-Version: 1.0\n\
\n\ \n\
Does it work with outlook now?\n\ Does it work with outlook now?\n\
") ", None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@@ -3453,7 +3454,7 @@ Message.
// 1. Test mimeparser directly // 1. Test mimeparser directly
let mdn = let mdn =
include_bytes!("../test-data/message/ms_exchange_report_disposition_notification.eml"); include_bytes!("../test-data/message/ms_exchange_report_disposition_notification.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, mdn).await?; let mimeparser = MimeMessage::from_bytes(&t.ctx, mdn, None).await?;
assert_eq!(mimeparser.mdn_reports.len(), 1); assert_eq!(mimeparser.mdn_reports.len(), 1);
assert_eq!( assert_eq!(
mimeparser.mdn_reports[0].original_message_id.as_deref(), mimeparser.mdn_reports[0].original_message_id.as_deref(),
@@ -3479,6 +3480,7 @@ Message.
let mime_message = MimeMessage::from_bytes( let mime_message = MimeMessage::from_bytes(
&alice, &alice,
include_bytes!("../test-data/message/attached-eml.eml"), include_bytes!("../test-data/message/attached-eml.eml"),
None,
) )
.await?; .await?;
@@ -3521,6 +3523,7 @@ Content-Disposition: reaction\n\
\n\ \n\
\u{1F44D}" \u{1F44D}"
.as_bytes(), .as_bytes(),
None,
) )
.await?; .await?;

View File

@@ -103,35 +103,35 @@ pub(crate) async fn receive_imf_inner(
); );
} }
let mut mime_parser = let mut mime_parser = match MimeMessage::from_bytes(context, imf_raw, is_partial_download).await
match MimeMessage::from_bytes_with_partial(context, imf_raw, is_partial_download).await { {
Err(err) => { Err(err) => {
warn!(context, "receive_imf: can't parse MIME: {:#}", err); warn!(context, "receive_imf: can't parse MIME: {:#}", err);
let msg_ids; let msg_ids;
if !rfc724_mid.starts_with(GENERATED_PREFIX) { if !rfc724_mid.starts_with(GENERATED_PREFIX) {
let row_id = context let row_id = context
.sql .sql
.execute( .execute(
"INSERT INTO msgs(rfc724_mid, chat_id) VALUES (?,?)", "INSERT INTO msgs(rfc724_mid, chat_id) VALUES (?,?)",
paramsv![rfc724_mid, DC_CHAT_ID_TRASH], paramsv![rfc724_mid, DC_CHAT_ID_TRASH],
) )
.await?; .await?;
msg_ids = vec![MsgId::new(u32::try_from(row_id)?)]; msg_ids = vec![MsgId::new(u32::try_from(row_id)?)];
} else { } else {
return Ok(None); return Ok(None);
// We don't have an rfc724_mid, there's no point in adding a trash entry // We don't have an rfc724_mid, there's no point in adding a trash entry
}
return Ok(Some(ReceivedMsg {
chat_id: DC_CHAT_ID_TRASH,
state: MessageState::Undefined,
sort_timestamp: 0,
msg_ids,
needs_delete_job: false,
}));
} }
Ok(mime_parser) => mime_parser,
}; return Ok(Some(ReceivedMsg {
chat_id: DC_CHAT_ID_TRASH,
state: MessageState::Undefined,
sort_timestamp: 0,
msg_ids,
needs_delete_job: false,
}));
}
Ok(mime_parser) => mime_parser,
};
// we can not add even an empty record if we have no info whatsoever // we can not add even an empty record if we have no info whatsoever
if !mime_parser.has_headers() { if !mime_parser.has_headers() {

View File

@@ -20,7 +20,7 @@ async fn test_grpid_simple() {
References: <Gr.HcxyMARjyJy.9-uvzWPTLtV@nauta.cu>\n\ References: <Gr.HcxyMARjyJy.9-uvzWPTLtV@nauta.cu>\n\
\n\ \n\
hello\x00"; hello\x00";
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
assert_eq!(extract_grpid(&mimeparser, HeaderDef::InReplyTo), None); assert_eq!(extract_grpid(&mimeparser, HeaderDef::InReplyTo), None);
@@ -38,7 +38,7 @@ async fn test_bad_from() {
References: <Gr.HcxyMARjyJy.9-uvzWPTLtV@nauta.cu>\n\ References: <Gr.HcxyMARjyJy.9-uvzWPTLtV@nauta.cu>\n\
\n\ \n\
hello\x00"; hello\x00";
let mimeparser = MimeMessage::from_bytes_with_partial(&context.ctx, &raw[..], None).await; let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None).await;
assert!(mimeparser.is_err()); assert!(mimeparser.is_err());
} }
@@ -52,7 +52,7 @@ async fn test_grpid_from_multiple() {
References: <qweqweqwe>, <Gr.HcxyMARjyJy.9-uvzWPTLtV@nau.ca>\n\ References: <qweqweqwe>, <Gr.HcxyMARjyJy.9-uvzWPTLtV@nau.ca>\n\
\n\ \n\
hello\x00"; hello\x00";
let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..]) let mimeparser = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await .await
.unwrap(); .unwrap();
let grpid = Some("HcxyMARjyJy"); let grpid = Some("HcxyMARjyJy");
@@ -2614,7 +2614,7 @@ References: <second@example.net> <nonexistent@example.net> <first@example.net>
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
Message with references."#; Message with references."#;
let mime_parser = MimeMessage::from_bytes(&t, &mime[..]).await?; let mime_parser = MimeMessage::from_bytes(&t, &mime[..], None).await?;
let parent = get_parent_message(&t, &mime_parser).await?.unwrap(); let parent = get_parent_message(&t, &mime_parser).await?.unwrap();
assert_eq!(parent.id, first.id); assert_eq!(parent.id, first.id);

View File

@@ -236,7 +236,7 @@ impl BobState {
/// stage is returned. Once [`BobHandshakeStage::Completed`] or /// stage is returned. Once [`BobHandshakeStage::Completed`] or
/// [`BobHandshakeStage::Terminated`] are reached this [`BobState`] should be destroyed, /// [`BobHandshakeStage::Terminated`] are reached this [`BobState`] should be destroyed,
/// further calling it will just result in the messages being unused by this handshake. /// further calling it will just result in the messages being unused by this handshake.
pub async fn handle_message( pub(crate) async fn handle_message(
&mut self, &mut self,
context: &Context, context: &Context,
mime_message: &MimeMessage, mime_message: &MimeMessage,

View File

@@ -441,8 +441,8 @@ impl TestContext {
/// peerstates will be updated. Later receiving the message using [recv_msg] is /// peerstates will be updated. Later receiving the message using [recv_msg] is
/// unlikely to be affected as the peerstate would be processed again in exactly the /// unlikely to be affected as the peerstate would be processed again in exactly the
/// same way. /// same way.
pub async fn parse_msg(&self, msg: &SentMessage<'_>) -> MimeMessage { pub(crate) async fn parse_msg(&self, msg: &SentMessage<'_>) -> MimeMessage {
MimeMessage::from_bytes(&self.ctx, msg.payload().as_bytes()) MimeMessage::from_bytes(&self.ctx, msg.payload().as_bytes(), None)
.await .await
.unwrap() .unwrap()
} }