Skip to content

Commit d65eb30

Browse files
committed
fix: Don't send self-avatar in unencrypted messages (#7136)
We don't display avatars for address-contacts, so sending avatars w/o encryption is not useful and causes e.g. Outlook to reject a message with a big header, see https://support.delta.chat/t/invalid-mime-content-single-text-value-size-32822-exceeded-allowed-maximum-32768-for-the-chat-user-avatar-header/4067.
1 parent 38a547d commit d65eb30

File tree

2 files changed

+6
-74
lines changed

2 files changed

+6
-74
lines changed

src/mimefactory.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,11 @@ impl MimeFactory {
464464
.unwrap_or_default(),
465465
false => "".to_string(),
466466
};
467-
let attach_selfavatar = Self::should_attach_selfavatar(context, &msg).await;
467+
// We don't display avatars for address-contacts, so sending avatars w/o encryption is not
468+
// useful and causes e.g. Outlook to reject a message with a big header, see
469+
// https://support.delta.chat/t/invalid-mime-content-single-text-value-size-32822-exceeded-allowed-maximum-32768-for-the-chat-user-avatar-header/4067.
470+
let attach_selfavatar =
471+
Self::should_attach_selfavatar(context, &msg).await && encryption_keys.is_some();
468472

469473
ensure_and_debug_assert!(
470474
member_timestamps.is_empty()

src/mimefactory/mimefactory_tests.rs

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -592,26 +592,6 @@ async fn test_selfavatar_unencrypted() -> anyhow::Result<()> {
592592
assert_eq!(outer.match_indices("Autocrypt:").count(), 1);
593593
assert_eq!(outer.match_indices("Chat-User-Avatar:").count(), 0);
594594

595-
assert_eq!(inner.match_indices("text/plain").count(), 1);
596-
assert_eq!(inner.match_indices("Message-ID:").count(), 1);
597-
assert_eq!(inner.match_indices("Chat-User-Avatar:").count(), 1);
598-
assert_eq!(inner.match_indices("Subject:").count(), 0);
599-
600-
assert_eq!(body.match_indices("this is the text!").count(), 1);
601-
602-
// if another message is sent, that one must not contain the avatar
603-
let sent_msg = t.send_msg(chat.id, &mut msg).await;
604-
let mut payload = sent_msg.payload().splitn(3, "\r\n\r\n");
605-
let outer = payload.next().unwrap();
606-
let inner = payload.next().unwrap();
607-
let body = payload.next().unwrap();
608-
609-
assert_eq!(outer.match_indices("multipart/mixed").count(), 1);
610-
assert_eq!(outer.match_indices("Message-ID:").count(), 1);
611-
assert_eq!(outer.match_indices("Subject:").count(), 1);
612-
assert_eq!(outer.match_indices("Autocrypt:").count(), 1);
613-
assert_eq!(outer.match_indices("Chat-User-Avatar:").count(), 0);
614-
615595
assert_eq!(inner.match_indices("text/plain").count(), 1);
616596
assert_eq!(inner.match_indices("Message-ID:").count(), 1);
617597
assert_eq!(inner.match_indices("Chat-User-Avatar:").count(), 0);
@@ -670,7 +650,7 @@ async fn test_selfavatar_unencrypted_signed() {
670650
assert_eq!(part.match_indices("text/plain").count(), 1);
671651
assert_eq!(part.match_indices("From:").count(), 0);
672652
assert_eq!(part.match_indices("Message-ID:").count(), 1);
673-
assert_eq!(part.match_indices("Chat-User-Avatar:").count(), 1);
653+
assert_eq!(part.match_indices("Chat-User-Avatar:").count(), 0);
674654
assert_eq!(part.match_indices("Subject:").count(), 0);
675655

676656
let body = payload.next().unwrap();
@@ -684,58 +664,6 @@ async fn test_selfavatar_unencrypted_signed() {
684664
.unwrap();
685665
let alice_contact = Contact::get_by_id(&bob.ctx, alice_id).await.unwrap();
686666
assert_eq!(alice_contact.is_key_contact(), false);
687-
assert!(
688-
alice_contact
689-
.get_profile_image(&bob.ctx)
690-
.await
691-
.unwrap()
692-
.is_some()
693-
);
694-
695-
// if another message is sent, that one must not contain the avatar
696-
let mut msg = Message::new_text("this is the text!".to_string());
697-
let sent_msg = t.send_msg(chat.id, &mut msg).await;
698-
let mut payload = sent_msg.payload().splitn(4, "\r\n\r\n");
699-
700-
let part = payload.next().unwrap();
701-
assert_eq!(part.match_indices("multipart/signed").count(), 1);
702-
assert_eq!(part.match_indices("From:").count(), 1);
703-
assert_eq!(part.match_indices("Message-ID:").count(), 1);
704-
assert_eq!(part.match_indices("Subject:").count(), 1);
705-
assert_eq!(part.match_indices("Autocrypt:").count(), 1);
706-
assert_eq!(part.match_indices("Chat-User-Avatar:").count(), 0);
707-
708-
let part = payload.next().unwrap();
709-
assert_eq!(
710-
part.match_indices("multipart/mixed; protected-headers=\"v1\"")
711-
.count(),
712-
1
713-
);
714-
assert_eq!(part.match_indices("From:").count(), 1);
715-
assert_eq!(part.match_indices("Message-ID:").count(), 0);
716-
assert_eq!(part.match_indices("Subject:").count(), 1);
717-
assert_eq!(part.match_indices("Autocrypt:").count(), 1);
718-
assert_eq!(part.match_indices("Chat-User-Avatar:").count(), 0);
719-
720-
let part = payload.next().unwrap();
721-
assert_eq!(part.match_indices("text/plain").count(), 1);
722-
assert_eq!(body.match_indices("From:").count(), 0);
723-
assert_eq!(part.match_indices("Message-ID:").count(), 1);
724-
assert_eq!(part.match_indices("Chat-User-Avatar:").count(), 0);
725-
assert_eq!(part.match_indices("Subject:").count(), 0);
726-
727-
let body = payload.next().unwrap();
728-
assert_eq!(body.match_indices("this is the text!").count(), 1);
729-
730-
bob.recv_msg(&sent_msg).await;
731-
let alice_contact = Contact::get_by_id(&bob.ctx, alice_id).await.unwrap();
732-
assert!(
733-
alice_contact
734-
.get_profile_image(&bob.ctx)
735-
.await
736-
.unwrap()
737-
.is_some()
738-
);
739667
}
740668

741669
/// Test that removed member address does not go into the `To:` field.

0 commit comments

Comments
 (0)