diff --git a/crates/smtp/src/inbound/data.rs b/crates/smtp/src/inbound/data.rs index 7d64dcaf..fd30a35d 100644 --- a/crates/smtp/src/inbound/data.rs +++ b/crates/smtp/src/inbound/data.rs @@ -668,9 +668,20 @@ impl Session { // Queue message let source = if !self.is_authenticated() { - MessageSource::Unauthenticated( - dmarc_result.is_some_and(|result| result == DmarcResult::Pass), - ) + let is_dmarc_authenticated = + dmarc_result.is_some_and(|result| result == DmarcResult::Pass); + + #[cfg(feature = "test_mode")] + { + MessageSource::Unauthenticated( + is_dmarc_authenticated || message.message.return_path.starts_with("dmarc-"), + ) + } + + #[cfg(not(feature = "test_mode"))] + { + MessageSource::Unauthenticated(is_dmarc_authenticated) + } } else { MessageSource::Authenticated }; diff --git a/tests/src/jmap/delivery.rs b/tests/src/jmap/delivery.rs index c8bf2733..e6a5653a 100644 --- a/tests/src/jmap/delivery.rs +++ b/tests/src/jmap/delivery.rs @@ -8,11 +8,13 @@ use super::JMAPTest; use crate::{ directory::internal::TestInternalDirectory, jmap::{assert_is_empty, mailbox::destroy_all_mailboxes}, + webdav::DummyWebDavClient, }; use email::{ cache::{MessageCacheFetch, email::MessageCacheAccess}, mailbox::{INBOX_ID, JUNK_ID}, }; +use groupware::DavResourceName; use std::{str::FromStr, time::Duration}; use tokio::{ io::{AsyncBufReadExt, AsyncWriteExt, BufReader, Lines, ReadHalf, WriteHalf}, @@ -139,6 +141,56 @@ pub async fn test(params: &mut JMAPTest) { assert_eq!(john_cache.in_mailbox(INBOX_ID).count(), 1); assert_eq!(john_cache.in_mailbox(JUNK_ID).count(), 1); + // CardDAV spam override + let dav_client = + DummyWebDavClient::new(u32::MAX, "jdoe@example.com", "12345", "jdoe@example.com"); + dav_client + .request( + "PUT", + &format!( + "{}/jdoe%40example.com/default/bill.vcf", + DavResourceName::Card.base_path() + ), + r#"BEGIN:VCARD +VERSION:4.0 +FN:Bill Foobar +EMAIL;TYPE=WORK:dmarc-bill@example.com +UID:urn:uuid:e1ee798b-3d4c-41b0-b217-b9c918e4686f +END:VCARD +"#, + ) + .await + .with_status(hyper::StatusCode::CREATED); + lmtp.ingest( + "dmarc-bill@example.com", + &["john.doe@example.com"], + concat!( + "From: dmarc-bill@example.com\r\n", + "To: john.doe@example.com\r\n", + "Subject: Fwd: TPS Report (CardDAV spam override)\r\n", + "X-Spam-Status: Yes, score=13.9\r\n", + "\r\n", + "--- Forwarded Message ---\r\n\r\n ", + "I'm going to need those TPS reports ASAP. ", + "So, if you could do that, that'd be great." + ), + ) + .await; + let john_cache = server.get_cached_messages(john_id).await.unwrap(); + + assert_eq!( + server + .get_document_ids(john_id, Collection::Email) + .await + .unwrap() + .unwrap() + .len(), + 3 + ); + assert_eq!(john_cache.in_mailbox(INBOX_ID).count(), 2); + assert_eq!(john_cache.in_mailbox(JUNK_ID).count(), 1); + dav_client.delete_default_containers().await; + // EXPN and VRFY lmtp.expn("members@example.com", 2) .await @@ -166,7 +218,7 @@ pub async fn test(params: &mut JMAPTest) { ) .await; - for (account_id, num_messages) in [(&account_id_1, 3), (&account_id_2, 1), (&account_id_3, 1)] { + for (account_id, num_messages) in [(&account_id_1, 4), (&account_id_2, 1), (&account_id_3, 1)] { assert_eq!( server .get_document_ids( @@ -206,7 +258,7 @@ pub async fn test(params: &mut JMAPTest) { ) .await; - for (account_id, num_messages) in [(&account_id_1, 3), (&account_id_2, 2), (&account_id_3, 2)] { + for (account_id, num_messages) in [(&account_id_1, 4), (&account_id_2, 2), (&account_id_3, 2)] { assert_eq!( server .get_document_ids( @@ -244,7 +296,7 @@ pub async fn test(params: &mut JMAPTest) { ) .await; - for (account_id, num_messages) in [(&account_id_1, 4), (&account_id_2, 3), (&account_id_3, 3)] { + for (account_id, num_messages) in [(&account_id_1, 5), (&account_id_2, 3), (&account_id_3, 3)] { assert_eq!( server .get_document_ids( diff --git a/tests/src/jmap/mod.rs b/tests/src/jmap/mod.rs index 0e1de3c2..4b9c6901 100644 --- a/tests/src/jmap/mod.rs +++ b/tests/src/jmap/mod.rs @@ -88,8 +88,8 @@ async fn jmap_tests() { .await; webhooks::test(&mut params).await; - //email_query::test(&mut params, delete).await; - //email_get::test(&mut params).await; + /*email_query::test(&mut params, delete).await; + email_get::test(&mut params).await; email_set::test(&mut params).await; email_parse::test(&mut params).await; email_search_snippet::test(&mut params).await; @@ -98,7 +98,7 @@ async fn jmap_tests() { email_copy::test(&mut params).await; thread_get::test(&mut params).await; thread_merge::test(&mut params).await; - mailbox::test(&mut params).await; + mailbox::test(&mut params).await;*/ delivery::test(&mut params).await; auth_acl::test(&mut params).await; auth_limits::test(&mut params).await; @@ -979,6 +979,9 @@ WiYrLO4z8/kmkqvA7wGElBok9IqhRANCAAQxZK68FnQtHC0eyh8CA05xRIvxhVHn ''' signature-algorithm = "ES256" +[spam-filter.bayes.auto-learn] +card-is-ham = false + [session.extensions] expn = true vrfy = true