mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
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.
This commit is contained in:
@@ -501,14 +501,12 @@ pub enum Origin {
|
|||||||
MailinglistAddress = 0x2,
|
MailinglistAddress = 0x2,
|
||||||
|
|
||||||
/// Hidden on purpose, e.g. addresses with the word "noreply" in it
|
/// Hidden on purpose, e.g. addresses with the word "noreply" in it
|
||||||
|
/// or past members of the groups.
|
||||||
Hidden = 0x8,
|
Hidden = 0x8,
|
||||||
|
|
||||||
/// From: of incoming messages of unknown sender
|
/// From: of incoming messages of unknown sender
|
||||||
IncomingUnknownFrom = 0x10,
|
IncomingUnknownFrom = 0x10,
|
||||||
|
|
||||||
/// Cc: of incoming messages of unknown sender
|
|
||||||
IncomingUnknownCc = 0x20,
|
|
||||||
|
|
||||||
/// To: of incoming messages of unknown sender
|
/// To: of incoming messages of unknown sender
|
||||||
IncomingUnknownTo = 0x40,
|
IncomingUnknownTo = 0x40,
|
||||||
|
|
||||||
@@ -522,21 +520,9 @@ pub enum Origin {
|
|||||||
/// Contacts with at least this origin value are shown in the contact list.
|
/// Contacts with at least this origin value are shown in the contact list.
|
||||||
IncomingReplyTo = 0x100,
|
IncomingReplyTo = 0x100,
|
||||||
|
|
||||||
/// Cc: of incoming message of known sender
|
|
||||||
IncomingCc = 0x200,
|
|
||||||
|
|
||||||
/// additional To:'s of incoming message of known sender
|
|
||||||
IncomingTo = 0x400,
|
|
||||||
|
|
||||||
/// a chat was manually created for this user, but no message yet sent
|
/// a chat was manually created for this user, but no message yet sent
|
||||||
CreateChat = 0x800,
|
CreateChat = 0x800,
|
||||||
|
|
||||||
/// message sent by us
|
|
||||||
OutgoingBcc = 0x1000,
|
|
||||||
|
|
||||||
/// message sent by us
|
|
||||||
OutgoingCc = 0x2000,
|
|
||||||
|
|
||||||
/// message sent by us
|
/// message sent by us
|
||||||
OutgoingTo = 0x4000,
|
OutgoingTo = 0x4000,
|
||||||
|
|
||||||
|
|||||||
36
src/imap.rs
36
src/imap.rs
@@ -1885,20 +1885,19 @@ async fn should_move_out_of_spam(
|
|||||||
None => return Ok(false),
|
None => return Ok(false),
|
||||||
};
|
};
|
||||||
// No chat found.
|
// No chat found.
|
||||||
let (from_id, blocked_contact, _origin) =
|
let (from_id, blocked_contact) = match from_field_to_contact_id(context, &from, true)
|
||||||
match from_field_to_contact_id(context, &from, true)
|
.await
|
||||||
.await
|
.context("from_field_to_contact_id")?
|
||||||
.context("from_field_to_contact_id")?
|
{
|
||||||
{
|
Some(res) => res,
|
||||||
Some(res) => res,
|
None => {
|
||||||
None => {
|
warn!(
|
||||||
warn!(
|
context,
|
||||||
context,
|
"Contact with From address {:?} cannot exist, not moving out of spam", from
|
||||||
"Contact with From address {:?} cannot exist, not moving out of spam", from
|
);
|
||||||
);
|
return Ok(false);
|
||||||
return Ok(false);
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
if blocked_contact {
|
if blocked_contact {
|
||||||
// Contact is blocked, leave the message in spam.
|
// Contact is blocked, leave the message in spam.
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
@@ -2243,11 +2242,10 @@ pub(crate) async fn prefetch_should_download(
|
|||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
None => return Ok(false),
|
None => return Ok(false),
|
||||||
};
|
};
|
||||||
let (_from_id, blocked_contact, _origin) =
|
let (_from_id, blocked_contact) = match from_field_to_contact_id(context, &from, true).await? {
|
||||||
match from_field_to_contact_id(context, &from, true).await? {
|
Some(res) => res,
|
||||||
Some(res) => res,
|
None => return Ok(false),
|
||||||
None => return Ok(false),
|
};
|
||||||
};
|
|
||||||
// prevent_rename=true as this might be a mailing list message and in this case it would be bad if we rename the contact.
|
// prevent_rename=true as this might be a mailing list message and in this case it would be bad if we rename the contact.
|
||||||
// (prevent_rename is the last argument of from_field_to_contact_id())
|
// (prevent_rename is the last argument of from_field_to_contact_id())
|
||||||
|
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
// For example, GitHub sends messages from `notifications@github.com`,
|
// For example, GitHub sends messages from `notifications@github.com`,
|
||||||
// but uses display name of the user whose action generated the notification
|
// but uses display name of the user whose action generated the notification
|
||||||
// as the display name.
|
// as the display name.
|
||||||
let (from_id, _from_id_blocked, incoming_origin) =
|
let (from_id, _from_id_blocked) =
|
||||||
match from_field_to_contact_id(context, &mime_parser.from, prevent_rename).await? {
|
match from_field_to_contact_id(context, &mime_parser.from, prevent_rename).await? {
|
||||||
Some(contact_id_res) => contact_id_res,
|
Some(contact_id_res) => contact_id_res,
|
||||||
None => {
|
None => {
|
||||||
@@ -337,12 +337,10 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
let to_ids = add_or_lookup_contacts_by_address_list(
|
let to_ids = add_or_lookup_contacts_by_address_list(
|
||||||
context,
|
context,
|
||||||
&mime_parser.recipients,
|
&mime_parser.recipients,
|
||||||
if !mime_parser.incoming {
|
if mime_parser.incoming {
|
||||||
Origin::OutgoingTo
|
|
||||||
} else if incoming_origin.is_known() {
|
|
||||||
Origin::IncomingTo
|
|
||||||
} else {
|
|
||||||
Origin::IncomingUnknownTo
|
Origin::IncomingUnknownTo
|
||||||
|
} else {
|
||||||
|
Origin::OutgoingTo
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -646,7 +644,7 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
|
|
||||||
/// Converts "From" field to contact id.
|
/// Converts "From" field to contact id.
|
||||||
///
|
///
|
||||||
/// Also returns whether it is blocked or not and its origin.
|
/// Also returns whether it is blocked or not.
|
||||||
///
|
///
|
||||||
/// * `prevent_rename`: if true, the display_name of this contact will not be changed. Useful for
|
/// * `prevent_rename`: if true, the display_name of this contact will not be changed. Useful for
|
||||||
/// mailing lists: In some mailing lists, many users write from the same address but with different
|
/// 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(
|
|||||||
context: &Context,
|
context: &Context,
|
||||||
from: &SingleInfo,
|
from: &SingleInfo,
|
||||||
prevent_rename: bool,
|
prevent_rename: bool,
|
||||||
) -> Result<Option<(ContactId, bool, Origin)>> {
|
) -> Result<Option<(ContactId, bool)>> {
|
||||||
let display_name = if prevent_rename {
|
let display_name = if prevent_rename {
|
||||||
Some("")
|
Some("")
|
||||||
} else {
|
} else {
|
||||||
@@ -684,12 +682,11 @@ pub async fn from_field_to_contact_id(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if from_id == ContactId::SELF {
|
if from_id == ContactId::SELF {
|
||||||
Ok(Some((ContactId::SELF, false, Origin::OutgoingBcc)))
|
Ok(Some((ContactId::SELF, false)))
|
||||||
} else {
|
} else {
|
||||||
let contact = Contact::get_by_id(context, from_id).await?;
|
let contact = Contact::get_by_id(context, from_id).await?;
|
||||||
let from_id_blocked = contact.blocked;
|
let from_id_blocked = contact.blocked;
|
||||||
let incoming_origin = contact.origin;
|
Ok(Some((from_id, from_id_blocked)))
|
||||||
Ok(Some((from_id, from_id_blocked, incoming_origin)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ async fn test_adhoc_group_outgoing_show_accepted_contact_unaccepted() -> Result<
|
|||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_adhoc_group_show_accepted_contact_known() {
|
async fn test_adhoc_group_show_accepted_contact_known() {
|
||||||
let t = TestContext::new_alice().await;
|
let t = TestContext::new_alice().await;
|
||||||
t.set_config(Config::ShowEmails, Some("1")).await.unwrap();
|
t.set_config(Config::ShowEmails, Some("2")).await.unwrap();
|
||||||
Contact::create(&t, "Bob", "bob@example.com").await.unwrap();
|
Contact::create(&t, "Bob", "bob@example.com").await.unwrap();
|
||||||
receive_imf(&t, GRP_MAIL, false).await.unwrap();
|
receive_imf(&t, GRP_MAIL, false).await.unwrap();
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ async fn test_adhoc_group_show_accepted_contact_known() {
|
|||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_adhoc_group_show_accepted_contact_accepted() {
|
async fn test_adhoc_group_show_accepted_contact_accepted() {
|
||||||
let t = TestContext::new_alice().await;
|
let t = TestContext::new_alice().await;
|
||||||
t.set_config(Config::ShowEmails, Some("1")).await.unwrap();
|
t.set_config(Config::ShowEmails, Some("2")).await.unwrap();
|
||||||
|
|
||||||
// accept Bob by accepting a delta-message from Bob
|
// accept Bob by accepting a delta-message from Bob
|
||||||
receive_imf(&t, MSGRMSG, false).await.unwrap();
|
receive_imf(&t, MSGRMSG, false).await.unwrap();
|
||||||
@@ -2319,7 +2319,7 @@ async fn test_ignore_footer_status_from_mailinglist() -> Result<()> {
|
|||||||
&t,
|
&t,
|
||||||
"",
|
"",
|
||||||
&ContactAddress::new("bob@example.net").unwrap(),
|
&ContactAddress::new("bob@example.net").unwrap(),
|
||||||
Origin::IncomingUnknownCc,
|
Origin::IncomingUnknownTo,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.0;
|
.0;
|
||||||
@@ -3985,7 +3985,7 @@ async fn test_mua_user_adds_recipient_to_single_chat() -> Result<()> {
|
|||||||
chat::get_chat_contacts(&alice, group_chat.id).await?.len(),
|
chat::get_chat_contacts(&alice, group_chat.id).await?.len(),
|
||||||
4
|
4
|
||||||
);
|
);
|
||||||
let fiona = Contact::lookup_id_by_addr(&alice, "fiona@example.net", Origin::IncomingTo)
|
let fiona = Contact::lookup_id_by_addr(&alice, "fiona@example.net", Origin::IncomingUnknownTo)
|
||||||
.await?
|
.await?
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(chat::is_contact_in_chat(&alice, group_chat.id, fiona).await?);
|
assert!(chat::is_contact_in_chat(&alice, group_chat.id, fiona).await?);
|
||||||
|
|||||||
Reference in New Issue
Block a user