Store mime_headers as BLOBs

Raw MIME messages may contain non-ASCII characters. Attempting to
store them as TEXT by using String::from_utf8_lossy results in
non-ASCII characters being replaced with Unicode U+FFFD "REPLACEMENT
CHARACTER" which is later incorrectly decoded when attempting to parse
`mime_headers` content into HTML.
This commit is contained in:
link2xt
2021-06-19 01:22:08 +03:00
parent c08df8d3da
commit a47c0486ae
6 changed files with 87 additions and 21 deletions

View File

@@ -940,12 +940,12 @@ async fn add_parts(
let mime_headers = if save_mime_headers || save_mime_modified {
if mime_parser.was_encrypted() && !mime_parser.decoded_data.is_empty() {
String::from_utf8_lossy(&mime_parser.decoded_data).to_string()
mime_parser.decoded_data.clone()
} else {
String::from_utf8_lossy(imf_raw).to_string()
imf_raw.to_vec()
}
} else {
"".into()
Vec::new()
};
let sent_timestamp = *sent_timestamp;
@@ -1048,9 +1048,9 @@ INSERT INTO msgs
part.bytes as isize,
is_hidden,
if (save_mime_headers || mime_modified) && !trash {
mime_headers.to_string()
mime_headers.clone()
} else {
"".to_string()
Vec::new()
},
mime_in_reply_to,
mime_references,
@@ -3659,8 +3659,9 @@ YEAAAAAA!.
assert_eq!(msg.get_text(), Some("hi!".to_string()));
assert!(!msg.get_showpadlock());
let mime = message::get_mime_headers(&bob, msg.id).await?;
assert!(mime.contains("Received:"));
assert!(mime.contains("From:"));
let mime_str = String::from_utf8_lossy(&mime);
assert!(mime_str.contains("Received:"));
assert!(mime_str.contains("From:"));
// another one, from bob to alice, that gets encrypted
let chat_bob = bob.create_chat(&alice).await;
@@ -3670,8 +3671,9 @@ YEAAAAAA!.
assert_eq!(msg.get_text(), Some("ho!".to_string()));
assert!(msg.get_showpadlock());
let mime = message::get_mime_headers(&alice, msg.id).await?;
assert!(mime.contains("Received:"));
assert!(mime.contains("From:"));
let mime_str = String::from_utf8_lossy(&mime);
assert!(mime_str.contains("Received:"));
assert!(mime_str.contains("From:"));
Ok(())
}