Skip to content

Commit

Permalink
v0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Sep 22, 2023
1 parent 816d944 commit 56d2c3b
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
mail-parser 0.9.1
================================
- Fixed panic when Content-Disposition is empty (#63)
- Removed `content_type()` and `address()` functions that could `panic!`. Use `as_content_type()` and `as_address()` instead.
- Updated Rust edition to 2021.

mail-parser 0.9.0
================================
This version introduces multiple breaking changes. Please read the following notes carefully.
Expand Down
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-parser"
description = "Fast and robust e-mail parsing library for Rust"
version = "0.9.0"
version = "0.9.1"
edition = "2021"
authors = [ "Stalwart Labs <[email protected]>"]
license = "Apache-2.0 OR MIT"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7

// Integrates with Serde
println!("{}", serde_json::to_string_pretty(&message).unwrap());
println!("{}", serde_yaml::to_string(&message).unwrap());
```

More examples available under the [examples](examples) directory. Please note that this library does not support building e-mail messages as this functionality is provided separately by the [`mail-builder`](https://crates.io/crates/mail-builder) crate.
Expand Down
147 changes: 147 additions & 0 deletions resources/eml/malformed/017.crlf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"html_body": [
1
],
"text_body": [
1
],
"attachments": [
1
],
"parts": [
{
"headers": [
{
"name": "subject",
"value": {
"Text": "Hello world"
},
"offset_field": 0,
"offset_start": 8,
"offset_end": 22
},
{
"name": "from",
"value": {
"Address": {
"List": [
{
"name": "Test User",
"address": "[email protected]"
}
]
}
},
"offset_field": 22,
"offset_start": 27,
"offset_end": 58
},
{
"name": "to",
"value": {
"Address": {
"List": [
{
"name": "Another User",
"address": "[email protected]"
}
]
}
},
"offset_field": 58,
"offset_start": 61,
"offset_end": 96
},
{
"name": "content_type",
"value": {
"ContentType": {
"c_type": "multipart",
"c_subtype": "mixed",
"attributes": [
[
"boundary",
"boundary"
]
]
}
},
"offset_field": 96,
"offset_start": 109,
"offset_end": 149
}
],
"is_encoding_problem": false,
"body": {
"Multipart": [
1
]
},
"offset_header": 0,
"offset_body": 151,
"offset_end": 348
},
{
"headers": [
{
"name": "content_type",
"value": {
"ContentType": {
"c_type": "image",
"c_subtype": "png",
"attributes": null
}
},
"offset_field": 163,
"offset_start": 176,
"offset_end": 188
},
{
"name": "content_transfer_encoding",
"value": {
"Text": "base64"
},
"offset_field": 188,
"offset_start": 214,
"offset_end": 223
},
{
"name": "content_disposition",
"value": "Empty",
"offset_field": 223,
"offset_start": 243,
"offset_end": 280
},
{
"name": "content_id",
"value": {
"Text": "image001.png@[...]"
},
"offset_field": 280,
"offset_start": 291,
"offset_end": 314
}
],
"is_encoding_problem": false,
"body": {
"InlineBinary": [
104,
101,
108,
108,
111,
32,
119,
111,
114,
108,
100,
10
]
},
"offset_header": 163,
"offset_body": 316,
"offset_end": 332
}
]
}
15 changes: 15 additions & 0 deletions resources/eml/malformed/017.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Subject: Hello world
From: Test User <[email protected]>
To: Another User <[email protected]>
Content-Type: multipart/mixed
boundary="boundary"

--boundary
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: ;
filename="image001.png"
Content-ID: <image001.png@[...]>
aGVsbG8gd29ybGQK
--boundary--
147 changes: 147 additions & 0 deletions resources/eml/malformed/017.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"html_body": [
1
],
"text_body": [
1
],
"attachments": [
1
],
"parts": [
{
"headers": [
{
"name": "subject",
"value": {
"Text": "Hello world"
},
"offset_field": 0,
"offset_start": 8,
"offset_end": 21
},
{
"name": "from",
"value": {
"Address": {
"List": [
{
"name": "Test User",
"address": "[email protected]"
}
]
}
},
"offset_field": 21,
"offset_start": 26,
"offset_end": 56
},
{
"name": "to",
"value": {
"Address": {
"List": [
{
"name": "Another User",
"address": "[email protected]"
}
]
}
},
"offset_field": 56,
"offset_start": 59,
"offset_end": 93
},
{
"name": "content_type",
"value": {
"ContentType": {
"c_type": "multipart",
"c_subtype": "mixed",
"attributes": [
[
"boundary",
"boundary"
]
]
}
},
"offset_field": 93,
"offset_start": 106,
"offset_end": 144
}
],
"is_encoding_problem": false,
"body": {
"Multipart": [
1
]
},
"offset_header": 0,
"offset_body": 145,
"offset_end": 333
},
{
"headers": [
{
"name": "content_type",
"value": {
"ContentType": {
"c_type": "image",
"c_subtype": "png",
"attributes": null
}
},
"offset_field": 156,
"offset_start": 169,
"offset_end": 180
},
{
"name": "content_transfer_encoding",
"value": {
"Text": "base64"
},
"offset_field": 180,
"offset_start": 206,
"offset_end": 214
},
{
"name": "content_disposition",
"value": "Empty",
"offset_field": 214,
"offset_start": 234,
"offset_end": 269
},
{
"name": "content_id",
"value": {
"Text": "image001.png@[...]"
},
"offset_field": 269,
"offset_start": 280,
"offset_end": 302
}
],
"is_encoding_problem": false,
"body": {
"InlineBinary": [
104,
101,
108,
108,
111,
32,
119,
111,
114,
108,
100,
10
]
},
"offset_header": 156,
"offset_body": 303,
"offset_end": 319
}
]
}
17 changes: 0 additions & 17 deletions src/core/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ impl<'x> HeaderValue<'x> {
}
}

pub fn address(&self) -> &Address<'x> {
match *self {
HeaderValue::Address(ref a) => a,
_ => panic!("HeaderValue::address called on non-Address: {:?}", self),
}
}

pub fn as_address(&self) -> Option<&Address<'x>> {
match *self {
HeaderValue::Address(ref a) => Some(a),
Expand All @@ -185,16 +178,6 @@ impl<'x> HeaderValue<'x> {
}
}

pub fn content_type(&self) -> &ContentType<'x> {
match *self {
HeaderValue::ContentType(ref ct) => ct,
_ => panic!(
"HeaderValue::content_type called on non-ContentType: {:?}",
self
),
}
}

pub fn as_content_type(&self) -> Option<&ContentType> {
match *self {
HeaderValue::ContentType(ref c) => Some(c),
Expand Down
5 changes: 4 additions & 1 deletion src/parsers/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ impl MessageParser {
let is_inline = is_inline
&& part_headers
.header_value(&HeaderName::ContentDisposition)
.map_or_else(|| true, |d| !d.content_type().is_attachment())
.map_or_else(
|| true,
|d| !d.as_content_type().map_or(false, |ct| ct.is_attachment()),
)
&& (state.parts == 1
|| (state.mime_type != MimeType::MultipartRelated
&& (mime_type == MimeType::Inline
Expand Down

0 comments on commit 56d2c3b

Please sign in to comment.