summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Korber <philippkorber@gmail.com>2018-06-01 13:56:23 +0200
committerPhilipp Korber <philippkorber@gmail.com>2018-06-01 13:57:59 +0200
commit92249080967324b63de516c658d75be16c7437f0 (patch)
tree82de70728e77e3ca550b9adc8eaa170a841f6ee9
parentf3d35383571c1cf4d50cdbefec0f7b7fbae3f7f0 (diff)
fix(request): use commit_partial_header
- for conversion of Mailbox to mailaddress the EncodingBuffer/EncodingWriter is used but we don't write a full header, so we need to use commit_partial_header or it will blow up if traceing is enabled
-rw-r--r--Cargo.toml4
-rw-r--r--src/request.rs16
2 files changed, 17 insertions, 3 deletions
diff --git a/Cargo.toml b/Cargo.toml
index b8d1315..8ac910a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,3 +17,7 @@ mail-types = { git="https://github.com/1aim/mail-types" }
mail-common = { git="https://github.com/1aim/mail-common" }
mail-headers = { git="https://github.com/1aim/mail-headers" }
new-tokio-smtp = { git="https://github.com/1aim/new-tokio-smtp" }
+
+
+[features]
+test-with-traceing = ["mail-common/traceing"] \ No newline at end of file
diff --git a/src/request.rs b/src/request.rs
index de5a0a5..71f516f 100644
--- a/src/request.rs
+++ b/src/request.rs
@@ -58,8 +58,10 @@ fn mailaddress_from_mailbox(mailbox: &Mailbox) -> Result<MailAddress, EncodingEr
let needs_smtputf8 = email.check_if_internationalized();
let mt = if needs_smtputf8 { MailType::Internationalized } else { MailType::Ascii };
let mut buffer = EncodingBuffer::new(mt);
- {
- email.encode(&mut buffer.writer())?;
+ {
+ let mut writer = buffer.writer();
+ email.encode(&mut writer)?;
+ writer.commit_partial_header();
}
let raw: Vec<u8> = buffer.into();
let address = String::from_utf8(raw).expect("[BUG] encoding Email produced non utf8 data");
@@ -183,8 +185,16 @@ mod test {
}
mod mailaddress_from_mailbox {
- use super::super::mailaddress_from_mailbox;
+ use headers::HeaderTryFrom;
use headers::components::{Mailbox, Email};
+ use super::super::mailaddress_from_mailbox;
+
+ #[test]
+ #[cfg_attr(not(feature="test-with-traceing"), ignore)]
+ fn does_not_panic_with_tracing_enabled() {
+ let mb = Mailbox::try_from("hy@b").unwrap();
+ mailaddress_from_mailbox(&mb).unwrap();
+ }
#[test]
fn correctly_converts_mailbox() {