fix: add X-WS-* header detection and attachment test

- Detect X-WS-* headers (e.g., X-WS-Attachment-UUID) as MIME headers
  to ensure attachment headers like Content-Type and Content-Disposition
  get normalized properly
- Add test case for attachment header normalization
- Bump version to 0.5.0

The normalization fixes malformed continuation lines in attachment
headers generated by Infomaniak webmail, where lines like
"name=file.pdf" are missing the required leading whitespace.
This commit is contained in:
2025-12-10 15:22:35 +01:00
parent d1dd56341f
commit e0b0c5e964
3 changed files with 25 additions and 3 deletions

2
Cargo.lock generated
View File

@@ -597,7 +597,7 @@ dependencies = [
[[package]]
name = "rs_pop_imap_importer"
version = "0.3.0"
version = "0.5.0"
dependencies = [
"clap",
"dotenvy",

View File

@@ -1,6 +1,6 @@
[package]
name = "rs_pop_imap_importer"
version = "0.3.0"
version = "0.5.0"
edition = "2024"
[lib]

View File

@@ -136,7 +136,7 @@ pub fn normalize_headers(email: &str) -> Result<String, Box<dyn Error>> {
header_count += 1;
last_was_header = true;
// Check for typical MIME headers
if line.starts_with("Content-") || line.starts_with("MIME-Version") {
if line.starts_with("Content-") || line.starts_with("MIME-Version") || line.starts_with("X-WS-") {
has_mime_headers = true;
}
} else if is_continuation || last_was_header {
@@ -234,4 +234,26 @@ mod tests {
let result = normalize_headers(email).unwrap();
assert_eq!(email, result, "Email should not be modified if already compliant");
}
#[test]
fn test_normalize_attachment_headers() {
let email = concat!(
"From: test@example.com\r\n",
"Subject: Test\r\n",
"\r\n",
"--boundary\r\n",
"X-WS-Attachment-UUID: 123\r\n",
"Content-Type: application/pdf;\r\n",
"name=test.pdf\r\n",
"Content-Disposition: attachment;\r\n",
"filename=test.pdf\r\n",
"\r\n",
"data"
);
let result = normalize_headers(email).unwrap();
assert!(result.contains("Content-Type: application/pdf;\r\n name=test.pdf"),
"Should add space to Content-Type continuation");
assert!(result.contains("Content-Disposition: attachment;\r\n filename=test.pdf"),
"Should add space to Content-Disposition continuation");
}
}