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:
Generated
+1
-1
@@ -597,7 +597,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rs_pop_imap_importer"
|
name = "rs_pop_imap_importer"
|
||||||
version = "0.3.0"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rs_pop_imap_importer"
|
name = "rs_pop_imap_importer"
|
||||||
version = "0.3.0"
|
version = "0.5.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|||||||
+23
-1
@@ -136,7 +136,7 @@ pub fn normalize_headers(email: &str) -> Result<String, Box<dyn Error>> {
|
|||||||
header_count += 1;
|
header_count += 1;
|
||||||
last_was_header = true;
|
last_was_header = true;
|
||||||
// Check for typical MIME headers
|
// 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;
|
has_mime_headers = true;
|
||||||
}
|
}
|
||||||
} else if is_continuation || last_was_header {
|
} else if is_continuation || last_was_header {
|
||||||
@@ -234,4 +234,26 @@ mod tests {
|
|||||||
let result = normalize_headers(email).unwrap();
|
let result = normalize_headers(email).unwrap();
|
||||||
assert_eq!(email, result, "Email should not be modified if already compliant");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user