1 parent
beae94e932
commit
de4d70970c
51 files changed
+4034
-421
No files matched your search
@@ -2977,3 +2977,99 @@ async fn sends_with_attachments_release_their_build_slot() {
|
||||
}
|
||||
assert_eq!(mock_imap.appended.lock().unwrap().len(), 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn filter_match_narrows_imap_candidates_from_the_cache() {
|
||||
let static_dir = setup_static_dir();
|
||||
let data_dir = TempDir::new().unwrap();
|
||||
let config = test_config_with_imap(
|
||||
static_dir.path().to_str().unwrap(),
|
||||
data_dir.path().to_str().unwrap(),
|
||||
);
|
||||
let store = test_store();
|
||||
let (browser_id, account_id, token) = setup_test_account(&store, "alice@example.com");
|
||||
|
||||
let user_hash = crate::auth::user_data::hash_email("alice@example.com");
|
||||
provision_user_db(data_dir.path().to_str().unwrap(), &user_hash);
|
||||
let conn =
|
||||
crate::db::pool::open_user_db(data_dir.path().to_str().unwrap(), &user_hash).unwrap();
|
||||
crate::db::folders::upsert_folder(&conn, "INBOX", None, None, "", true, 0, 0, 0, 0).unwrap();
|
||||
for (uid, from) in [(1u32, "news@shop.example"), (2u32, "friend@example.com")] {
|
||||
crate::db::messages::upsert_message(
|
||||
&conn,
|
||||
"INBOX",
|
||||
uid,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
"Hello",
|
||||
from,
|
||||
"",
|
||||
"[]",
|
||||
"[]",
|
||||
"2024-01-01",
|
||||
"",
|
||||
100,
|
||||
false,
|
||||
"",
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
drop(conn);
|
||||
|
||||
let header = |uid: u32, address: &str| ImapMessageHeader {
|
||||
uid,
|
||||
subject: Some("Hello".to_string()),
|
||||
from: vec![EmailAddress {
|
||||
name: None,
|
||||
address: address.to_string(),
|
||||
}],
|
||||
to: vec![],
|
||||
date: None,
|
||||
flags: vec![],
|
||||
has_attachments: false,
|
||||
size: 100,
|
||||
message_id: None,
|
||||
in_reply_to: None,
|
||||
references: None,
|
||||
cc: vec![],
|
||||
reaction: None,
|
||||
};
|
||||
// The mock answers every search with all UIDs, i.e. a pure superset, so
|
||||
// the exact answer has to come from the cache.
|
||||
let mock = MockImapClient::new().with_headers(vec![
|
||||
header(1, "news@shop.example"),
|
||||
header(2, "friend@example.com"),
|
||||
]);
|
||||
let imap_client: Arc<dyn ImapClient> = Arc::new(mock);
|
||||
let app = create_router(
|
||||
config,
|
||||
store,
|
||||
imap_client,
|
||||
test_smtp_client(),
|
||||
test_search_engine(data_dir.path().to_str().unwrap()),
|
||||
test_event_bus(),
|
||||
test_idle_manager(),
|
||||
);
|
||||
|
||||
let mut req = Request::builder()
|
||||
.method("POST")
|
||||
.uri("/api/filters/match")
|
||||
.header("x-requested-with", "XMLHttpRequest")
|
||||
.header("content-type", "application/json");
|
||||
for (name, value) in auth_headers(&browser_id, &account_id, &token) {
|
||||
req = req.header(name, value);
|
||||
}
|
||||
let body = r#"{"folder":"INBOX","rule":{"test":{"kind":"from-domain","match":"is","value":"shop.example"}}}"#;
|
||||
let response = app
|
||||
.oneshot(req.body(Body::from(body)).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let bytes = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let json: serde_json::Value = serde_json::from_slice(&bytes).unwrap();
|
||||
assert_eq!(json["uids"], serde_json::json!([1]));
|
||||
assert_eq!(json["matched"], 1);
|
||||
assert_eq!(json["uncertain"], 0);
|
||||
}
|
||||
Reference in new issue
Block a user