1 parent
9003a50eb4
commit
2486856799
21 files changed
+538
-30
No files matched your search
@@ -1347,6 +1347,97 @@ async fn get_messages_returns_200_with_paginated_list() {
|
||||
assert_eq!(messages.len(), 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_messages_repairs_cached_missing_date_from_imap_header() {
|
||||
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");
|
||||
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, 1, 1, 1, 0).unwrap();
|
||||
crate::db::messages::upsert_message(
|
||||
&conn,
|
||||
"INBOX",
|
||||
77,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
"No Date header",
|
||||
"sender@example.com",
|
||||
"Sender",
|
||||
"[]",
|
||||
"[]",
|
||||
"",
|
||||
"",
|
||||
123,
|
||||
false,
|
||||
"",
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
crate::db::folders::mark_folder_messages_fresh(&conn, "INBOX").unwrap();
|
||||
drop(conn);
|
||||
|
||||
let repaired_date = "Tue, 3 Nov 2026 14:38:39 +0100";
|
||||
let mock = Arc::new(MockImapClient::new().with_headers(vec![ImapMessageHeader {
|
||||
uid: 77,
|
||||
subject: Some("No Date header".to_string()),
|
||||
from: vec![EmailAddress {
|
||||
name: Some("Sender".to_string()),
|
||||
address: "sender@example.com".to_string(),
|
||||
}],
|
||||
to: vec![EmailAddress {
|
||||
name: None,
|
||||
address: "alice@example.com".to_string(),
|
||||
}],
|
||||
date: Some(repaired_date.to_string()),
|
||||
flags: vec![],
|
||||
has_attachments: false,
|
||||
size: 123,
|
||||
message_id: None,
|
||||
in_reply_to: None,
|
||||
references: None,
|
||||
cc: vec![],
|
||||
reaction: None,
|
||||
}]));
|
||||
let imap_client: Arc<dyn ImapClient> = mock.clone();
|
||||
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()
|
||||
.uri("/api/folders/INBOX/messages?page=0&per_page=50")
|
||||
.header("x-requested-with", "XMLHttpRequest");
|
||||
for (name, value) in auth_headers(&browser_id, &account_id, &token) {
|
||||
req = req.header(name, value);
|
||||
}
|
||||
let response = app.oneshot(req.body(Body::empty()).unwrap()).await.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let json: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
||||
assert_eq!(json["messages"][0]["uid"], 77);
|
||||
assert_eq!(json["messages"][0]["date"], repaired_date);
|
||||
assert!(
|
||||
mock.header_requests
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|(folder, range)| folder == "INBOX" && range == "77")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_message_returns_sanitized_html() {
|
||||
let static_dir = setup_static_dir();
|
||||
@@ -2078,6 +2169,90 @@ async fn download_attachment_returns_400_for_non_numeric_id() {
|
||||
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn attach_message_source_creates_eml_draft_attachment() {
|
||||
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 raw =
|
||||
b"From: sender@example.com\r\nTo: alice@example.com\r\nSubject: forwarded\r\n\r\nhello\r\n"
|
||||
.to_vec();
|
||||
let mock = MockImapClient::new().with_raw_message(42, raw.clone());
|
||||
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/drafts/forward-test/attachments/from-message")
|
||||
.header("content-type", "application/json")
|
||||
.header("x-requested-with", "XMLHttpRequest");
|
||||
for (name, value) in auth_headers(&browser_id, &account_id, &token) {
|
||||
req = req.header(name, value);
|
||||
}
|
||||
let response = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
req.body(Body::from(r#"{"folder":"INBOX","uid":42}"#))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let json: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
||||
let attachment = &json["attachments"][0];
|
||||
assert_eq!(attachment["filename"], "message-42.eml");
|
||||
assert_eq!(attachment["content_type"], "message/rfc822");
|
||||
assert_eq!(attachment["size"], raw.len() as i64);
|
||||
let attachment_id = attachment["id"].as_str().unwrap();
|
||||
|
||||
let mut content_req = Request::builder()
|
||||
.uri(format!(
|
||||
"/api/drafts/forward-test/attachments/{attachment_id}/content"
|
||||
))
|
||||
.header("x-requested-with", "XMLHttpRequest");
|
||||
for (name, value) in auth_headers(&browser_id, &account_id, &token) {
|
||||
content_req = content_req.header(name, value);
|
||||
}
|
||||
let content_response = app
|
||||
.oneshot(content_req.body(Body::empty()).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(content_response.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
content_response
|
||||
.headers()
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"message/rfc822"
|
||||
);
|
||||
let content = content_response
|
||||
.into_body()
|
||||
.collect()
|
||||
.await
|
||||
.unwrap()
|
||||
.to_bytes();
|
||||
assert_eq!(content.as_ref(), raw.as_slice());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn send_returns_200_on_success() {
|
||||
let static_dir = setup_static_dir();
|
||||
|
||||
Reference in new issue
Block a user