Extra boundaries are output when using BinaryStream/EncodedBinaryStream
philbooth opened this issue · 0 comments
philbooth commented
I see slightly different behaviour when using this crate with a BinaryStream
than I do when using MultiPart<String>
. I'm not sure if it is intentional, or maybe I'm doing something wrong.
To show what I mean, I tried to hack together a test case. If you apply this diff to current master:
diff --git a/Cargo.toml b/Cargo.toml
index afc418a..d0c219a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,3 +27,4 @@ futures = "^0.1"
[dev-dependencies]
tokio = "^0.1"
+tokio-core = "^0.1"
diff --git a/src/lib.rs b/src/lib.rs
index 655fcf1..6a88f67 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -462,6 +462,8 @@ extern crate textnonce;
#[cfg(test)]
extern crate tokio;
+#[cfg(test)]
+extern crate tokio_core;
mod encoder;
pub mod header;
diff --git a/src/mimebody.rs b/src/mimebody.rs
index c03123d..94a7bd4 100644
--- a/src/mimebody.rs
+++ b/src/mimebody.rs
@@ -501,7 +501,10 @@ where
#[cfg(test)]
mod test {
- use super::{MultiPart, MultiPartKind, Part, SinglePart};
+ use futures::Stream;
+ use tokio_core::reactor::Core;
+
+ use super::{EncodedBinaryStream, MultiPart, MultiPartKind, Part, SinglePart};
use header;
#[test]
@@ -633,6 +636,22 @@ mod test {
"\r\n",
"<p>Текст <em>письма</em> в <a href=\"https://ru.wikipedia.org/wiki/Юникод\">уникоде</a><p>\r\n",
"--F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK--\r\n"));
+
+ let binary_part: MultiPart = MultiPart::new(MultiPartKind::Alternative)
+ .with_boundary("F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK")
+ .with_part(Part::Single(SinglePart::new()
+ .with_header(header::ContentType("text/plain; charset=utf8".parse().unwrap()))
+ .with_header(header::ContentTransferEncoding::Binary)
+ .with_body(String::from("Текст письма в уникоде"))))
+ .with_singlepart(SinglePart::new()
+ .with_header(header::ContentType("text/html; charset=utf8".parse().unwrap()))
+ .with_header(header::ContentTransferEncoding::Binary)
+ .with_body(String::from("<p>Текст <em>письма</em> в <a href=\"https://ru.wikipedia.org/wiki/Юникод\">уникоде</a><p>")));
+ let mut core = Core::new().unwrap();
+ let future = Into::<Box<EncodedBinaryStream<_>>>::into(binary_part).concat2();
+ let binary_part = String::from_utf8(core.run(future).unwrap().to_vec()).unwrap();
+
+ assert_eq!(part.to_string(), binary_part);
}
#[test]
I would expect the assertion assert_eq!(part.to_string(), binary_part);
to succeed but it doesn't. Instead the second string contains extra boundary separators between the parts:
failures:
---- mimebody::test::multi_part_alternative stdout ----
thread 'mimebody::test::multi_part_alternative' panicked at 'assertion failed: `(left == right)`
left: `"Content-Type: multipart/alternative; boundary=\"F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK\"\r\n\r\n--F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK\r\nContent-Type: text/plain; charset=utf8\r\nContent-Transfer-Encoding: binary\r\n\r\nТекст письма в уникоде\r\n--F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK\r\nContent-Type: text/html; charset=utf8\r\nContent-Transfer-Encoding: binary\r\n\r\n<p>Текст <em>письма</em> в <a href=\"https://ru.wikipedia.org/wiki/Юникод\">уникоде</a><p>\r\n--F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK--\r\n"`,
right: `"Content-Type: multipart/alternative; boundary=\"F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK\"\r\n\r\n--F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK\r\n--F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK\r\nContent-Type: text/plain; charset=utf8\r\nContent-Transfer-Encoding: binary\r\n\r\nТекст письма в уникоде\r\n--F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK\r\nContent-Type: text/html; charset=utf8\r\nContent-Transfer-Encoding: binary\r\n\r\n<p>Текст <em>письма</em> в <a href=\"https://ru.wikipedia.org/wiki/Юникод\">уникоде</a><p>\r\n--F2mTKN843loAAAAA8porEdAjCKhArPxGeahYoZYSftse1GT/84tup+O0bs8eueVuAlMK--\r\n"`', src/mimebody.rs:654:9
failures:
mimebody::test::multi_part_alternative
test result: FAILED. 44 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
Is this expected behaviour?