diff --git a/src/headerdef.rs b/src/headerdef.rs index d87929435..a3b079fe0 100644 --- a/src/headerdef.rs +++ b/src/headerdef.rs @@ -35,6 +35,7 @@ pub enum HeaderDef { ChatContent, ChatDuration, ChatDispositionNotificationTo, + ChatVideochatUrl, Autocrypt, AutocryptSetupMessage, SecureJoin, diff --git a/src/mimeparser.rs b/src/mimeparser.rs index f467538ac..5f3338804 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -242,6 +242,18 @@ impl MimeMessage { } } + fn parse_videochat_headers(&mut self) { + if let Some(value) = self.get(HeaderDef::ChatContent).cloned() { + if value == "videochat-invitation" { + let url = self.get(HeaderDef::ChatVideochatUrl).cloned(); + if let Some(part) = self.parts.first_mut() { + part.typ = Viewtype::VideochatInvitation; + part.param.set(Param::VideochatUrl, url.unwrap_or_default()); + } + } + } + } + /// Squashes mutlipart chat messages with attachment into single-part messages. /// /// Delta Chat sends attachments, such as images, in two-part messages, with the first message @@ -314,6 +326,7 @@ impl MimeMessage { fn parse_headers(&mut self, context: &Context) -> Result<()> { self.parse_system_message_headers(context)?; self.parse_avatar_headers(); + self.parse_videochat_headers(); self.squash_attachment_parts(); if let Some(ref subject) = self.get_subject() { @@ -1449,6 +1462,28 @@ mod tests { assert!(mimeparser.group_avatar.unwrap().is_change()); } + #[async_std::test] + async fn test_mimeparser_with_videochat() { + let t = TestContext::new().await; + + let raw = include_bytes!("../test-data/message/videochat_invitation.eml"); + let mimeparser = MimeMessage::from_bytes(&t.ctx, &raw[..]).await.unwrap(); + assert_eq!(mimeparser.parts.len(), 1); + assert_eq!(mimeparser.parts[0].typ, Viewtype::VideochatInvitation); + assert_eq!( + mimeparser.parts[0] + .param + .get(Param::VideochatUrl) + .unwrap_or_default(), + "https://example.org/p2p/?roomname=6HiduoAn4xN" + ); + assert!(mimeparser.parts[0] + .msg + .contains("https://example.org/p2p/?roomname=6HiduoAn4xN")); + assert_eq!(mimeparser.user_avatar, None); + assert_eq!(mimeparser.group_avatar, None); + } + #[async_std::test] async fn test_mimeparser_message_kml() { let context = TestContext::new().await; diff --git a/test-data/message/videochat_invitation.eml b/test-data/message/videochat_invitation.eml new file mode 100644 index 000000000..96f1df16b --- /dev/null +++ b/test-data/message/videochat_invitation.eml @@ -0,0 +1,15 @@ +Content-Type: text/plain; charset=utf-8 +Subject: Message from user +Message-ID: +Date: Mon, 20 Jul 2020 14:28:30 +0000 +X-Mailer: Delta Chat Core 1.40.0/CLI +Chat-Version: 1.0 +Chat-Content: videochat-invitation +Chat-Videochat-Url: https://example.org/p2p/?roomname=6HiduoAn4xN +To: +From: "=?utf-8?q??=" + +You are invited to an videochat, click https://example.org/p2p/?roomname=6HiduoAn4xN to join. + +-- +Sent with my Delta Chat Messenger: https://delta.chat