Skip to content

Commit a4c3d16

Browse files
committed
feat: create all contacts from the To field with IncomingUnknownTo origin
Contacts are created with IncomingUnknownTo origin instead of IncomingTo now even if the message is from a known contact. Removed IncomingTo, IncomingCc, OutgoingBcc, OutgoingCc, IncomingUnknownCc origins.
1 parent 246b5a1 commit a4c3d16

File tree

4 files changed

+30
-49
lines changed

4 files changed

+30
-49
lines changed

src/contact.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,12 @@ pub enum Origin {
501501
MailinglistAddress = 0x2,
502502

503503
/// Hidden on purpose, e.g. addresses with the word "noreply" in it
504+
/// or past members of the groups.
504505
Hidden = 0x8,
505506

506507
/// From: of incoming messages of unknown sender
507508
IncomingUnknownFrom = 0x10,
508509

509-
/// Cc: of incoming messages of unknown sender
510-
IncomingUnknownCc = 0x20,
511-
512510
/// To: of incoming messages of unknown sender
513511
IncomingUnknownTo = 0x40,
514512

@@ -522,21 +520,9 @@ pub enum Origin {
522520
/// Contacts with at least this origin value are shown in the contact list.
523521
IncomingReplyTo = 0x100,
524522

525-
/// Cc: of incoming message of known sender
526-
IncomingCc = 0x200,
527-
528-
/// additional To:'s of incoming message of known sender
529-
IncomingTo = 0x400,
530-
531523
/// a chat was manually created for this user, but no message yet sent
532524
CreateChat = 0x800,
533525

534-
/// message sent by us
535-
OutgoingBcc = 0x1000,
536-
537-
/// message sent by us
538-
OutgoingCc = 0x2000,
539-
540526
/// message sent by us
541527
OutgoingTo = 0x4000,
542528

src/imap.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -1885,20 +1885,19 @@ async fn should_move_out_of_spam(
18851885
None => return Ok(false),
18861886
};
18871887
// No chat found.
1888-
let (from_id, blocked_contact, _origin) =
1889-
match from_field_to_contact_id(context, &from, true)
1890-
.await
1891-
.context("from_field_to_contact_id")?
1892-
{
1893-
Some(res) => res,
1894-
None => {
1895-
warn!(
1896-
context,
1897-
"Contact with From address {:?} cannot exist, not moving out of spam", from
1898-
);
1899-
return Ok(false);
1900-
}
1901-
};
1888+
let (from_id, blocked_contact) = match from_field_to_contact_id(context, &from, true)
1889+
.await
1890+
.context("from_field_to_contact_id")?
1891+
{
1892+
Some(res) => res,
1893+
None => {
1894+
warn!(
1895+
context,
1896+
"Contact with From address {:?} cannot exist, not moving out of spam", from
1897+
);
1898+
return Ok(false);
1899+
}
1900+
};
19021901
if blocked_contact {
19031902
// Contact is blocked, leave the message in spam.
19041903
return Ok(false);
@@ -2243,11 +2242,10 @@ pub(crate) async fn prefetch_should_download(
22432242
Some(f) => f,
22442243
None => return Ok(false),
22452244
};
2246-
let (_from_id, blocked_contact, _origin) =
2247-
match from_field_to_contact_id(context, &from, true).await? {
2248-
Some(res) => res,
2249-
None => return Ok(false),
2250-
};
2245+
let (_from_id, blocked_contact) = match from_field_to_contact_id(context, &from, true).await? {
2246+
Some(res) => res,
2247+
None => return Ok(false),
2248+
};
22512249
// prevent_rename=true as this might be a mailing list message and in this case it would be bad if we rename the contact.
22522250
// (prevent_rename is the last argument of from_field_to_contact_id())
22532251

src/receive_imf.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ pub(crate) async fn receive_imf_inner(
322322
// For example, GitHub sends messages from `[email protected]`,
323323
// but uses display name of the user whose action generated the notification
324324
// as the display name.
325-
let (from_id, _from_id_blocked, incoming_origin) =
325+
let (from_id, _from_id_blocked) =
326326
match from_field_to_contact_id(context, &mime_parser.from, prevent_rename).await? {
327327
Some(contact_id_res) => contact_id_res,
328328
None => {
@@ -337,12 +337,10 @@ pub(crate) async fn receive_imf_inner(
337337
let to_ids = add_or_lookup_contacts_by_address_list(
338338
context,
339339
&mime_parser.recipients,
340-
if !mime_parser.incoming {
341-
Origin::OutgoingTo
342-
} else if incoming_origin.is_known() {
343-
Origin::IncomingTo
344-
} else {
340+
if mime_parser.incoming {
345341
Origin::IncomingUnknownTo
342+
} else {
343+
Origin::OutgoingTo
346344
},
347345
)
348346
.await?;
@@ -646,7 +644,7 @@ pub(crate) async fn receive_imf_inner(
646644

647645
/// Converts "From" field to contact id.
648646
///
649-
/// Also returns whether it is blocked or not and its origin.
647+
/// Also returns whether it is blocked or not.
650648
///
651649
/// * `prevent_rename`: if true, the display_name of this contact will not be changed. Useful for
652650
/// mailing lists: In some mailing lists, many users write from the same address but with different
@@ -658,7 +656,7 @@ pub async fn from_field_to_contact_id(
658656
context: &Context,
659657
from: &SingleInfo,
660658
prevent_rename: bool,
661-
) -> Result<Option<(ContactId, bool, Origin)>> {
659+
) -> Result<Option<(ContactId, bool)>> {
662660
let display_name = if prevent_rename {
663661
Some("")
664662
} else {
@@ -684,12 +682,11 @@ pub async fn from_field_to_contact_id(
684682
.await?;
685683

686684
if from_id == ContactId::SELF {
687-
Ok(Some((ContactId::SELF, false, Origin::OutgoingBcc)))
685+
Ok(Some((ContactId::SELF, false)))
688686
} else {
689687
let contact = Contact::get_by_id(context, from_id).await?;
690688
let from_id_blocked = contact.blocked;
691-
let incoming_origin = contact.origin;
692-
Ok(Some((from_id, from_id_blocked, incoming_origin)))
689+
Ok(Some((from_id, from_id_blocked)))
693690
}
694691
}
695692

src/receive_imf/receive_imf_tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async fn test_adhoc_group_outgoing_show_accepted_contact_unaccepted() -> Result<
137137
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
138138
async fn test_adhoc_group_show_accepted_contact_known() {
139139
let t = TestContext::new_alice().await;
140-
t.set_config(Config::ShowEmails, Some("1")).await.unwrap();
140+
t.set_config(Config::ShowEmails, Some("2")).await.unwrap();
141141
Contact::create(&t, "Bob", "[email protected]").await.unwrap();
142142
receive_imf(&t, GRP_MAIL, false).await.unwrap();
143143

@@ -150,7 +150,7 @@ async fn test_adhoc_group_show_accepted_contact_known() {
150150
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
151151
async fn test_adhoc_group_show_accepted_contact_accepted() {
152152
let t = TestContext::new_alice().await;
153-
t.set_config(Config::ShowEmails, Some("1")).await.unwrap();
153+
t.set_config(Config::ShowEmails, Some("2")).await.unwrap();
154154

155155
// accept Bob by accepting a delta-message from Bob
156156
receive_imf(&t, MSGRMSG, false).await.unwrap();
@@ -2319,7 +2319,7 @@ async fn test_ignore_footer_status_from_mailinglist() -> Result<()> {
23192319
&t,
23202320
"",
23212321
&ContactAddress::new("[email protected]").unwrap(),
2322-
Origin::IncomingUnknownCc,
2322+
Origin::IncomingUnknownTo,
23232323
)
23242324
.await?
23252325
.0;
@@ -3985,7 +3985,7 @@ async fn test_mua_user_adds_recipient_to_single_chat() -> Result<()> {
39853985
chat::get_chat_contacts(&alice, group_chat.id).await?.len(),
39863986
4
39873987
);
3988-
let fiona = Contact::lookup_id_by_addr(&alice, "[email protected]", Origin::IncomingTo)
3988+
let fiona = Contact::lookup_id_by_addr(&alice, "[email protected]", Origin::IncomingUnknownTo)
39893989
.await?
39903990
.unwrap();
39913991
assert!(chat::is_contact_in_chat(&alice, group_chat.id, fiona).await?);

0 commit comments

Comments
 (0)