CardDAV: Added 'card is ham' test

This commit is contained in:
mdecimus
2025-09-30 10:54:01 +02:00
parent 93a8265b98
commit d00d3dd013
3 changed files with 75 additions and 9 deletions

View File

@@ -668,9 +668,20 @@ impl<T: SessionStream> Session<T> {
// Queue message // Queue message
let source = if !self.is_authenticated() { let source = if !self.is_authenticated() {
MessageSource::Unauthenticated( let is_dmarc_authenticated =
dmarc_result.is_some_and(|result| result == DmarcResult::Pass), 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 { } else {
MessageSource::Authenticated MessageSource::Authenticated
}; };

View File

@@ -8,11 +8,13 @@ use super::JMAPTest;
use crate::{ use crate::{
directory::internal::TestInternalDirectory, directory::internal::TestInternalDirectory,
jmap::{assert_is_empty, mailbox::destroy_all_mailboxes}, jmap::{assert_is_empty, mailbox::destroy_all_mailboxes},
webdav::DummyWebDavClient,
}; };
use email::{ use email::{
cache::{MessageCacheFetch, email::MessageCacheAccess}, cache::{MessageCacheFetch, email::MessageCacheAccess},
mailbox::{INBOX_ID, JUNK_ID}, mailbox::{INBOX_ID, JUNK_ID},
}; };
use groupware::DavResourceName;
use std::{str::FromStr, time::Duration}; use std::{str::FromStr, time::Duration};
use tokio::{ use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader, Lines, ReadHalf, WriteHalf}, 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(INBOX_ID).count(), 1);
assert_eq!(john_cache.in_mailbox(JUNK_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 // EXPN and VRFY
lmtp.expn("members@example.com", 2) lmtp.expn("members@example.com", 2)
.await .await
@@ -166,7 +218,7 @@ pub async fn test(params: &mut JMAPTest) {
) )
.await; .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!( assert_eq!(
server server
.get_document_ids( .get_document_ids(
@@ -206,7 +258,7 @@ pub async fn test(params: &mut JMAPTest) {
) )
.await; .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!( assert_eq!(
server server
.get_document_ids( .get_document_ids(
@@ -244,7 +296,7 @@ pub async fn test(params: &mut JMAPTest) {
) )
.await; .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!( assert_eq!(
server server
.get_document_ids( .get_document_ids(

View File

@@ -88,8 +88,8 @@ async fn jmap_tests() {
.await; .await;
webhooks::test(&mut params).await; webhooks::test(&mut params).await;
//email_query::test(&mut params, delete).await; /*email_query::test(&mut params, delete).await;
//email_get::test(&mut params).await; email_get::test(&mut params).await;
email_set::test(&mut params).await; email_set::test(&mut params).await;
email_parse::test(&mut params).await; email_parse::test(&mut params).await;
email_search_snippet::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; email_copy::test(&mut params).await;
thread_get::test(&mut params).await; thread_get::test(&mut params).await;
thread_merge::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; delivery::test(&mut params).await;
auth_acl::test(&mut params).await; auth_acl::test(&mut params).await;
auth_limits::test(&mut params).await; auth_limits::test(&mut params).await;
@@ -979,6 +979,9 @@ WiYrLO4z8/kmkqvA7wGElBok9IqhRANCAAQxZK68FnQtHC0eyh8CA05xRIvxhVHn
''' '''
signature-algorithm = "ES256" signature-algorithm = "ES256"
[spam-filter.bayes.auto-learn]
card-is-ham = false
[session.extensions] [session.extensions]
expn = true expn = true
vrfy = true vrfy = true