mirror of
https://github.com/stalwartlabs/mail-parser.git
synced 2026-11-28 08:01:24 +00:00
v0.9.1
This commit is contained in:
@@ -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.
|
||||
|
||||
+1
-1
@@ -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 <hello@stalw.art>"]
|
||||
license = "Apache-2.0 OR MIT"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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": "test@example.org"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"offset_field": 22,
|
||||
"offset_start": 27,
|
||||
"offset_end": 58
|
||||
},
|
||||
{
|
||||
"name": "to",
|
||||
"value": {
|
||||
"Address": {
|
||||
"List": [
|
||||
{
|
||||
"name": "Another User",
|
||||
"address": "test2@example.org"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
Subject: Hello world
|
||||
From: Test User <test@example.org>
|
||||
To: Another User <test2@example.org>
|
||||
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--
|
||||
@@ -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": "test@example.org"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"offset_field": 21,
|
||||
"offset_start": 26,
|
||||
"offset_end": 56
|
||||
},
|
||||
{
|
||||
"name": "to",
|
||||
"value": {
|
||||
"Address": {
|
||||
"List": [
|
||||
{
|
||||
"name": "Another User",
|
||||
"address": "test2@example.org"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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),
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user