diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 31e801ad4..673c9a7ca 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -146,14 +146,25 @@ class Channel::EmailParser file.header.fields.each { |field| headers_store[field.name.to_s] = field.value.to_s } + + # get filename from content-disposition filename = nil - if file.header[:content_disposition].filename + if file.header[:content_disposition] && file.header[:content_disposition].filename filename = file.header[:content_disposition].filename end - if file.header[:content_type].string + + # for some broken sm mail clients (X-MimeOLE: Produced By Microsoft Exchange V6.5) + if !filename + filename = file.header[:content_location].to_s + end + + # get mime type + if file.header[:content_type] && file.header[:content_type].string headers_store['Mime-Type'] = file.header[:content_type].string end - if file.header.charset + + # get charset + if file.header && file.header.charset headers_store['Charset'] = file.header.charset end @@ -166,6 +177,7 @@ class Channel::EmailParser :filename => filename, :preferences => headers_store, } + data[:attachments].push attach } end @@ -205,7 +217,7 @@ class Channel::EmailParser attachment = { :data => mail.body.decoded, :filename => mail.filename || filename, - :preferences => headers_store + :preferences => headers_store } data[:attachments].push attachment end diff --git a/test/fixtures/mail10.box b/test/fixtures/mail10.box new file mode 100644 index 000000000..204e35a01 --- /dev/null +++ b/test/fixtures/mail10.box @@ -0,0 +1,216 @@ +From smith@example.com Tue Oct 23 14:55:00 2012 +Return-Path: +X-Original-To: info@example.com +Delivered-To: example-sales@samba.edenhofer.de +X-Greylist: delayed 1679 seconds by postgrey-1.32 at samba; Tue, 23 Oct 2012 14:54:59 BST +Received: from mailout109.bayern.de (mailout109.bayern.de [195.200.70.109]) + by samba.edenhofer.de (Postfix) with ESMTP id F2FCD500B14 + for ; Tue, 23 Oct 2012 14:54:59 +0100 (BST) +Received: from avisout130.bybn.de (avisout130.bybn.de [10.197.20.130]) + by mailout109.bayern.de (8.14.5/8.14.5) with ESMTP id q9NDR29S013763 + for ; Tue, 23 Oct 2012 15:27:02 +0200 +Received: from post23.bybn.de (post23.bybn.de [10.197.20.23]) + by avisout130.bybn.de (8.14.4/8.14.4) with ESMTP id q9NDR1NJ003273 + for ; Tue, 23 Oct 2012 15:27:02 +0200 + (envelope-from smith@example.com) +Received: from lramail1.Landratsamt.de ([10.38.19.31]) + by post23.bybn.de (8.14.5/8.14.4) with ESMTP id q9NDR1CF018327 + for ; Tue, 23 Oct 2012 15:27:01 +0200 +Content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: multipart/related; + boundary="----_=_NextPart_001_01CDB122.15B956D2"; + type="multipart/alternative" +X-MimeOLE: Produced By Microsoft Exchange V6.5 +Subject: =?iso-8859-1?Q?Gru=DF_aus_Oberalteich?= +Date: Tue, 23 Oct 2012 15:27:00 +0200 +Message-ID: <8FD7A79CBC14344E85C71183DF75D85A019B1699@lramail1.Landratsamt.de> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: =?iso-8859-1?Q?Gru=DF_aus_Oberalteich?= +Thread-Index: Ac2xIg1UWZ9khKyyT0yHHVxGjysbXQ== +From: "Smith Sepp" +To: +X-Keywords: +X-UID: 108 +Status: RO +Content-Length: 6878 +Lines: 176 + +This is a multi-part message in MIME format. + +------_=_NextPart_001_01CDB122.15B956D2 +Content-Type: multipart/alternative; + boundary="----_=_NextPart_002_01CDB122.15B956D2" + + +------_=_NextPart_002_01CDB122.15B956D2 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +Herzliche Gr=FC=DFe aus Oberalteich sendet Herrn Smith + +=20 + +Sepp Smith - Dipl.Ing. agr. (FH) + +Gesch=E4ftsf=FChrer der example Straubing-Bogen + +Klosterhof 1 | 94327 Bogen-Oberalteich + +Tel: 09422-505601 | Fax: 09422-505620 + +Internet: http://example-straubing-bogen.de = + + +Facebook: http://facebook.de/examplesrbog =20 + + - European Foundation f=FCr Quality Management + +=20 + + +------_=_NextPart_002_01CDB122.15B956D2 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +

Herzliche = +Gr=FC=DFe aus Oberalteich sendet Herrn Smith

 

Sepp Smith=A0 - Dipl.Ing. agr. (FH)

Gesch=E4ftsf=FChrer der example = +Straubing-Bogen

Klosterhof 1 | 94327 = +Bogen-Oberalteich

Tel: 09422-505601 | Fax: = +09422-505620

Internet: http://example-straubing-bogen.de<= +/span>

Facebook: http://facebook.de/examplesrbog

3D"Beschreibung:=A0 -=A0 = +European Foundation f=FCr Quality Management

 

+------_=_NextPart_002_01CDB122.15B956D2-- + +------_=_NextPart_001_01CDB122.15B956D2 +Content-Type: image/jpeg; + name="image001.jpg" +Content-Transfer-Encoding: base64 +Content-ID: +Content-Description: image001.jpg +Content-Location: image001.jpg + +/9j/4AAQSkZJRgABAQEAYABgAAD//gAcU29mdHdhcmU6IE1pY3Jvc29mdCBPZmZpY2X/2wBDAAoH +BwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8 +SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7 +Ozs7Ozs7Ozs7Ozs7Ozs7Ozv/wAARCAATADwDASIAAhEBAxEB/8QAGwAAAgIDAQAAAAAAAAAAAAAA +AAYEBQIDBwj/xAAuEAABAwMDAwMDAwUAAAAAAAABAgMEAAURBhJBByExEyJhFFFxFRZDgZGhsdH/ +xAAZAQACAwEAAAAAAAAAAAAAAAACBQADBAH/xAAiEQACAgEDBAMAAAAAAAAAAAABAgARAwQSITFB +UXETocH/3QAEACj/2gAMAwEAAhEDEQA/ANWnrxrfVV4ukWLqluEmG4ceu2nBBUQAO3GKstUz9Y6S +0e7Lk6lbmSXJraG3WED2I2qyk9uTikvTcTSsy/XkapnriNpeUWChZTuO9WfAPxVvq9nSkPp89G0t +cFS2/wBRbcf3rKiklCgPIH2pmyL8gFcev2B2jNabX1BuUGHcP3nGS3IQh30y0MgHBx484ptdem3a +U4xCllpln2rW2Ofzz/SlnSHTWyogWi+JkTfqiy2/tL3s3FOfGPHer63y1WRhyI+EodUVKaLh2pUo +cE8Z7d6Ta5g2RUJpTdnpNeAUpYCyOk3SU3e0Mev9V9W013O7yRyD/wBpE6ha9vdk1Jbl2mXtiORU +PKjlAKVnccg88Ux3DqHZJFufhPPG3ziNjkeYNhR9znwofYiki+llzqHpL01peaW2yclJwoFxXB4o +9HjbHqCpFpXfzJkIbFuPDX9RtunVq0taQbudvKXLjJBQiIruWnOSr4H+e1IEHqNq95lSl3hZO8/x +o7ePiuixeldmtmpZd7ThbAQVx4ik+1peDk/IHA4riluWPScOfLpP+qb6dcLXtF+5kJM9IK0Vphxa +lrsUFSlElRLIySfNZDR+m0x1xk2SEGXFBa0BoYUR4J/uaKKWbm8wpaMMNRWEMMNpbabTtQhIwEge +AKi3GJHmMbJDSXAO4zwaKKqygFDcsxkhgRIKdM2OWhpUq2R31MHc2p1G4pP5PHxUyRYrVMmNTpFv +juyY4HpOqQCpGO4xRRXcJOwSZOWNyeQFJKVDIPYg81UI0dppsEIscIAnJwyKKKsBI6QJ/9k= + +------_=_NextPart_001_01CDB122.15B956D2-- + diff --git a/test/unit/email_parser_test.rb b/test/unit/email_parser_test.rb index 38ef55aa4..06184535a 100644 --- a/test/unit/email_parser_test.rb +++ b/test/unit/email_parser_test.rb @@ -195,13 +195,33 @@ Hof", :body => "Enjoy!\n\n-Martin\n\n--\nOld programmers never die. They just branch to a new address." }, }, + { + :data => IO.read('test/fixtures/mail10.box'), + :body_md5 => '8d6ea42f7f36a790e67f50e3a5f27063', + :attachments => [ + { + :md5 => '08b0c83fd155db23f22bed845715225d', + :filename => 'message.html', + }, + { + :md5 => 'a618d671348735744d4c9a4005b56799', + :filename => 'image001.jpg', + }, + ], + :params => { + :from => 'Smith Sepp ', + :from_email => 'smith@example.com', + :from_display_name => 'Smith Sepp', + :subject => 'Gruß aus Oberalteich', +# :body => "Herzliche Grüße aus Oberalteich sendet Herrn Smith\n\n \n\nSepp Smith - Dipl.Ing. agr. (FH)\n\nGeschäftsführer der example Straubing-Bogen\n\nKlosterhof 1 | 94327 Bogen-Oberalteich\n\nTel: 09422-505601 | Fax: 09422-505620\n\nInternet: http://example-straubing-bogen.de \n\nFacebook: http://facebook.de/examplesrbog \n\n - European Foundation für Quality Management\n\n" + }, + }, ] files.each { |file| - parser = Channel::EmailParser.new data = parser.parse( file[:data] ) - + # check body md5 = Digest::MD5.hexdigest( data[:body] ) assert_equal( file[:body_md5], md5 )