Return Option from Contact::add_or_lookup()

This allows to distinguish exceptions,
such as database errors, from invalid user input.
For example, if the From: field of the message
does not look like an email address, the mail
should be ignored. But if there is a database
failure while writing a new contact for the address,
this error should be bubbled up.
This commit is contained in:
link2xt
2023-01-09 22:28:06 +00:00
parent 5ae6c25394
commit e215b4d919
13 changed files with 176 additions and 56 deletions

View File

@@ -429,6 +429,7 @@ async fn test_escaped_recipients() {
Contact::add_or_lookup(&t, "Carl", "carl@host.tld", Origin::IncomingUnknownFrom)
.await
.unwrap()
.unwrap()
.0;
receive_imf(
@@ -471,6 +472,7 @@ async fn test_cc_to_contact() {
Contact::add_or_lookup(&t, "garabage", "carl@host.tld", Origin::IncomingUnknownFrom)
.await
.unwrap()
.unwrap()
.0;
receive_imf(
@@ -2058,6 +2060,7 @@ async fn test_duplicate_message() -> Result<()> {
Origin::IncomingUnknownFrom,
)
.await?
.unwrap()
.0;
let first_message = b"Received: from [127.0.0.1]
@@ -2111,6 +2114,7 @@ async fn test_ignore_footer_status_from_mailinglist() -> Result<()> {
t.set_config(Config::ShowEmails, Some("2")).await?;
let bob_id = Contact::add_or_lookup(&t, "", "bob@example.net", Origin::IncomingUnknownCc)
.await?
.unwrap()
.0;
let bob = Contact::load_from_db(&t, bob_id).await?;
assert_eq!(bob.get_status(), "");
@@ -2529,7 +2533,8 @@ Second thread."#;
"fiona@example.net",
Origin::IncomingUnknownTo,
)
.await?;
.await?
.unwrap();
chat::add_contact_to_chat(&alice, alice_first_msg.chat_id, alice_fiona_contact_id).await?;
let alice_first_invite = alice.pop_sent_msg().await;