summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandros Frantzis <alf82@freemail.gr>2019-10-05 21:11:35 +0300
committerAlexandros Frantzis <alf82@freemail.gr>2019-10-06 17:16:01 +0300
commit6db5a3fffdfe049a57a24781088d817b11d3cab1 (patch)
tree960026934fc0d4a0c049379685be55217b4b98a8
parenta054789ddb60ed1fab26e6d4e6bd36ed926273f1 (diff)
Fix folding of boundary lines
Ensure boundary lines are not folded with preceding decoded text.
-rw-r--r--src/normalize.rs13
-rw-r--r--tests/test_encoding.rs8
2 files changed, 20 insertions, 1 deletions
diff --git a/src/normalize.rs b/src/normalize.rs
index 7c8487d..3774f73 100644
--- a/src/normalize.rs
+++ b/src/normalize.rs
@@ -350,7 +350,18 @@ fn decode_text_data_to_buf(
_ => Err("unknown encoding".into()),
};
- if result.is_err() {
+ if result.is_ok() {
+ // During decoding the final CRLF/LF in the data may be dropped.
+ // Restore it to ensure that subsequent lines don't get folded
+ // with the decoded data.
+ const CRLF: &[u8] = &[b'\r', b'\n'];
+ const LF: &[u8] = &[b'\n'];
+ if data.ends_with(CRLF) && !out.ends_with(CRLF) {
+ out.extend(CRLF);
+ } else if data.ends_with(LF) && !out.ends_with(LF) {
+ out.extend(LF);
+ }
+ } else {
out.resize(initial_len, 0);
should_convert_charset = false;
}
diff --git a/tests/test_encoding.rs b/tests/test_encoding.rs
index 1579449..9b339b5 100644
--- a/tests/test_encoding.rs
+++ b/tests/test_encoding.rs
@@ -106,6 +106,14 @@ fn base64_parts_are_decoded() {
}
#[test]
+fn base64_boundaries_remain_on_their_own_line() {
+ let email = Email::from_vec(TEST_EMAIL_MULTIPART.to_string().into_bytes()).unwrap();
+
+ assert!(!email.data().search(r"[^\n]--XtT01VFrJIenjlg\+ZCXSSWq4").unwrap());
+ assert!(!email.data().search(r"[^\n]--2c\+OeCbICgJrtINI5EFlsI6G").unwrap());
+}
+
+#[test]
fn non_text_base64_is_not_decoded() {
let email = Email::from_vec(TEST_EMAIL_MULTIPART.to_string().into_bytes()).unwrap();