Check if in text/plain is content - if not, use text/html.

This commit is contained in:
Martin Edenhofer 2015-11-26 09:29:58 +01:00
parent 8a770cff94
commit b3aa055c0e
3 changed files with 49 additions and 4 deletions

View file

@ -134,9 +134,10 @@ class Channel::EmailParser
if !data[:body].valid_encoding?
data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
end
end
# html attachment/body may exists and will be converted to text
else
if !mail.text_part || !data[:body] || data[:body] == ''
filename = '-no name-'
if mail.html_part && mail.html_part.body
filename = 'message.html'

29
test/fixtures/mail34.box vendored Normal file
View file

@ -0,0 +1,29 @@
From: "Bay" <memberbay+12345@members.somewhat>
Subject: strange email with empty text/plain
To: bay@example.com
Date: 11 Nov 2015 12:07:51 +0000
Priority: normal
X-Priority: 3 (Normal)
Importance: normal
X-David-SYM: 0
X-David-Flags: 0
Message-ID: <7ca10659-214c-4bd0-8438-b935a01c7601@stange>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----_=_NextPart_000_06409CFC.56433DA7"
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_06409CFC.56433DA7
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
------_=_NextPart_000_06409CFC.56433DA7
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<b>some html text</b>
------_=_NextPart_000_06409CFC.56433DA7

View file

@ -308,7 +308,7 @@ Hof
# spam email
{
data: IO.read('test/fixtures/mail15.box'),
body_md5: 'd41d8cd98f00b204e9800998ecf8427e',
body_md5: '5872ddcdfdf6bfe40f36cd0408fca667',
attachments: [
# :preferences=>{"Message-ID"=>"<temp@test>", "Content-Type"=>"application/octet-stream; name=\"\xBC\xA8\xD0\xA7\xB9\xDC\xC0\xED,\xBE\xBF\xBE\xB9\xCB\xAD\xB4\xED\xC1\xCB.xls\"", "Mime-Type"=>"application/octet-stream", "Charset"=>"UTF-8"}}
# mutt c1abb5fb77a9d2ab2017749a7987c074
@ -466,14 +466,14 @@ Freemont and pulling out several minutes.
},
{
data: IO.read('test/fixtures/mail24.box'),
body_md5: 'd41d8cd98f00b204e9800998ecf8427e',
body_md5: '5872ddcdfdf6bfe40f36cd0408fca667',
params: {
from: 'oracle@IG0-1-DB01.example.com',
from_email: 'oracle@IG0-1-DB01.example.com',
from_display_name: '',
subject: 'Regelsets im Test-Status gefunden: 1',
to: 'support@example.com',
body: '',
body: 'no visible content',
},
attachments: [
{
@ -672,9 +672,24 @@ Weil wir die Echtheit oder Vollständigkeit der in dieserNachricht enthaltenen I
to: 'info@znuny.inc',
},
},
{
data: IO.read('test/fixtures/mail34.box'),
body_md5: 'b6e46176404ec81b3ab412fe71dff0f0',
params: {
from: 'Bay <memberbay+12345@members.somewhat>',
from_email: 'memberbay+12345@members.somewhat',
from_display_name: 'Bay',
subject: 'strange email with empty text/plain',
to: 'bay@example.com',
body: 'some html text',
},
},
]
count = 0
files.each { |file|
count += 1
#p "Count: #{count}"
parser = Channel::EmailParser.new
data = parser.parse( file[:data] )