Skip to content

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Feb 16, 2022
1 parent 1486e3c commit d3d8700
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
mail-builder 0.1.3
================================
- Bug fixes.
- Headers are written sorted alplhabetically.
- Improved ID boundary generation.
- Encoding type detection for `[u8]` text parts.
- Optimised quoted-printable encoding.

mail-builder 0.1.2
================================
- All functions now take `impl Cow<str>`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mail-builder"
description = "E-mail builder library for Rust"
version = "0.1.2"
version = "0.1.3"
edition = "2018"
authors = [ "Stalwart Labs <[email protected]>"]
license = "Apache-2.0 OR MIT"
Expand Down
46 changes: 35 additions & 11 deletions src/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'x> MimePart<'x> {
let mut boundary: Option<Cow<str>> = None;

loop {
while let Some(part) = it.next() {
while let Some(mut part) = it.next() {
if let Some(boundary) = boundary.as_ref() {
output.write_all(b"\r\n--")?;
output.write_all(boundary.as_bytes())?;
Expand Down Expand Up @@ -277,21 +277,45 @@ impl<'x> MimePart<'x> {
stack.push((it, boundary));
}

boundary = Some(make_boundary().into());

for (header_name, mut header_value) in part.headers {
match &mut header_value {
HeaderType::ContentType(ref mut content_type)
if header_name == "Content-Type" =>
{
output.write_all(b"Content-Type: ")?;
boundary = if let Some(value) = part.headers.remove("Content-Type") {
match value {
HeaderType::ContentType(mut ct) => {
if let Entry::Vacant(entry) =
content_type.attributes.entry("boundary".into())
ct.attributes.entry("boundary".into())
{
entry.insert(boundary.as_ref().unwrap().as_ref().into());
entry.insert(make_boundary().into());
}
ct.write_header(&mut output, 14)?;
ct.attributes.remove("boundary")
}
HeaderType::Raw(raw) => {
if let Some(pos) = raw.raw.find("boundary=\"") {
if let Some(boundary) = raw.raw[pos..].split('"').nth(1) {
Some(boundary.to_string().into())
} else {
Some(make_boundary().into())
}
} else {
let boundary = make_boundary();
output.write_all(raw.raw.as_bytes())?;
output.write_all(b"; boundary=\"")?;
output.write_all(boundary.as_bytes())?;
output.write_all(b"\"\r\n")?;
Some(boundary.into())
}
}
_ => {}
_ => panic!("Unsupported Content-Type header value."),
}
} else {
let boundary = make_boundary();
ContentType::new("multipart/mixed")
.attribute("boundary", &boundary)
.write_header(&mut output, 14)?;
Some(boundary.into())
};

for (header_name, header_value) in part.headers {
output.write_all(header_name.as_bytes())?;
output.write_all(b": ")?;
header_value.write_header(&mut output, header_name.len() + 2)?;
Expand Down

0 comments on commit d3d8700

Please sign in to comment.