mirror of
https://github.com/stalwartlabs/mail-parser.git
synced 2026-11-28 08:01:24 +00:00
Add .eml example with odd behavior (#88)
* Add .eml example with odd behavior * Parse malformed, non-multipart, single text/plain messages best-effort as if text is not malformed
This commit is contained in:
@@ -146,11 +146,13 @@
|
||||
"is_encoding_problem": false,
|
||||
"body": {
|
||||
"Message": {
|
||||
"html_body": [],
|
||||
"text_body": [],
|
||||
"attachments": [
|
||||
"html_body": [
|
||||
0
|
||||
],
|
||||
"text_body": [
|
||||
0
|
||||
],
|
||||
"attachments": [],
|
||||
"parts": [
|
||||
{
|
||||
"headers": [
|
||||
|
||||
@@ -146,11 +146,13 @@
|
||||
"is_encoding_problem": false,
|
||||
"body": {
|
||||
"Message": {
|
||||
"html_body": [],
|
||||
"text_body": [],
|
||||
"attachments": [
|
||||
"html_body": [
|
||||
0
|
||||
],
|
||||
"text_body": [
|
||||
0
|
||||
],
|
||||
"attachments": [],
|
||||
"parts": [
|
||||
{
|
||||
"headers": [
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"html_body": [
|
||||
0
|
||||
],
|
||||
"text_body": [
|
||||
0
|
||||
],
|
||||
"attachments": [],
|
||||
"parts": [
|
||||
{
|
||||
"headers": [
|
||||
{
|
||||
"name": "content_type",
|
||||
"value": {
|
||||
"ContentType": {
|
||||
"c_type": "text",
|
||||
"c_subtype": "plain",
|
||||
"attributes": [
|
||||
[
|
||||
"charset",
|
||||
"Windows-1252"
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"offset_field": 0,
|
||||
"offset_start": 13,
|
||||
"offset_end": 52
|
||||
},
|
||||
{
|
||||
"name": "content_transfer_encoding",
|
||||
"value": {
|
||||
"Text": "quoted-printable"
|
||||
},
|
||||
"offset_field": 52,
|
||||
"offset_start": 78,
|
||||
"offset_end": 97
|
||||
},
|
||||
{
|
||||
"name": "mime_version",
|
||||
"value": {
|
||||
"Text": "1.0"
|
||||
},
|
||||
"offset_field": 97,
|
||||
"offset_start": 110,
|
||||
"offset_end": 116
|
||||
}
|
||||
],
|
||||
"is_encoding_problem": true,
|
||||
"body": {
|
||||
"Text": "Best\r\nEnviado desde mi BlackBerry=AE de Vodafone=\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\r\n<plist version=\"1.0\">\r\n<dict>\r\n</dict>\r\n</plist>"
|
||||
},
|
||||
"offset_header": 0,
|
||||
"offset_body": 118,
|
||||
"offset_end": 361
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
Content-Type: text/plain;
|
||||
charset="Windows-1252"
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
MIME-Version: 1.0
|
||||
|
||||
Best
|
||||
Enviado desde mi BlackBerry=AE de Vodafone=
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"html_body": [
|
||||
0
|
||||
],
|
||||
"text_body": [
|
||||
0
|
||||
],
|
||||
"attachments": [],
|
||||
"parts": [
|
||||
{
|
||||
"headers": [
|
||||
{
|
||||
"name": "content_type",
|
||||
"value": {
|
||||
"ContentType": {
|
||||
"c_type": "text",
|
||||
"c_subtype": "plain",
|
||||
"attributes": [
|
||||
[
|
||||
"charset",
|
||||
"Windows-1252"
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"offset_field": 0,
|
||||
"offset_start": 13,
|
||||
"offset_end": 52
|
||||
},
|
||||
{
|
||||
"name": "content_transfer_encoding",
|
||||
"value": {
|
||||
"Text": "quoted-printable"
|
||||
},
|
||||
"offset_field": 52,
|
||||
"offset_start": 78,
|
||||
"offset_end": 97
|
||||
},
|
||||
{
|
||||
"name": "mime_version",
|
||||
"value": {
|
||||
"Text": "1.0"
|
||||
},
|
||||
"offset_field": 97,
|
||||
"offset_start": 110,
|
||||
"offset_end": 116
|
||||
}
|
||||
],
|
||||
"is_encoding_problem": true,
|
||||
"body": {
|
||||
"Text": "Best\nEnviado desde mi BlackBerry=AE de Vodafone=\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n</dict>\n</plist>"
|
||||
},
|
||||
"offset_header": 0,
|
||||
"offset_body": 118,
|
||||
"offset_end": 354
|
||||
}
|
||||
]
|
||||
}
|
||||
+11
-1
@@ -250,7 +250,9 @@ impl MessageParser {
|
||||
let mut is_encoding_problem = offset_end == usize::MAX;
|
||||
if is_encoding_problem {
|
||||
encoding = Encoding::None;
|
||||
mime_type = MimeType::TextOther;
|
||||
if mime_type != MimeType::TextPlain {
|
||||
mime_type = MimeType::TextOther;
|
||||
}
|
||||
is_inline = false;
|
||||
is_text = true;
|
||||
|
||||
@@ -278,6 +280,14 @@ impl MessageParser {
|
||||
&& (mime_type == MimeType::Inline
|
||||
|| content_type.map_or(true, |c| !c.has_attribute("name"))));
|
||||
|
||||
// if message consists of single text/plain part, classify as text regardless
|
||||
// of encoding issues: see malformed/018.eml
|
||||
let is_inline = is_inline
|
||||
|| state.parts == 1
|
||||
&& state.mime_type == MimeType::Message
|
||||
&& mime_type == MimeType::TextPlain
|
||||
&& is_encoding_problem;
|
||||
|
||||
let (add_to_html, add_to_text) =
|
||||
if let MimeType::MultipartAlternative = state.mime_type {
|
||||
match mime_type {
|
||||
|
||||
Reference in New Issue
Block a user