Skip to content

Commit 845c50c

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 137ede8 commit 845c50c

File tree

2 files changed

+5
-74
lines changed

2 files changed

+5
-74
lines changed

src/mimefactory.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ impl MimeFactory {
464464
.unwrap_or_default(),
465465
false => "".to_string(),
466466
};
467-
let attach_selfavatar = should_attach_profile;
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 = should_attach_profile && encryption_keys.is_some();
468471

469472
ensure_and_debug_assert!(
470473
member_timestamps.is_empty()

src/mimefactory/mimefactory_tests.rs

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

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

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

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

0 commit comments

Comments
 (0)