Flolagale / mailin

Artisanal inbound emails for every web app
mailin.io
MIT License
1.95k stars 152 forks source link

Attachments are not being parsed #70

Closed jkrenge closed 8 years ago

jkrenge commented 8 years ago

Hi there! First off: I am amazed by mailin, awesome piece of software. Saved me days in development. I have a slight issue with the attachments though:


I am not using the webhook, but rather the embedded mailin server. For that, I plugged myself into mailin.on('message', function(connection, data, content) {});. And this works fine, but somehow data.attachments is always non-existing. For debugging I printed both data and content:

Excerpt from content:

--Apple-Mail=_1CE57DD1-5830-4E39-BB06-17F285909745
Content-Disposition: attachment; filename=X
Content-Type: application/octet-stream;name="X"
Content-Transfer-Encoding: 7bit

TEST

But in data (shortened):

  { html: 'html',
    headers:
     { received: [ Object object ],
       from: 'Julian Krenge <julian@parcellab.com>',
       to: 'Tracking Agent <track@parcellab.com>',
       subject: 'test',
       'thread-topic': 'test',
       'thread-index': 'AQHRJ1UYzntn5mE26ECrsi6sDecCjw==',
       date: 'Wed, 25 Nov 2015 07:44:20 +0000',
       'message-id': '<06C9DE21-CC9A-4732-AFD6-D48ACC49A74E@parcellab.com>',
       'accept-language': 'de-DE, en-US',
       'content-language': 'en-US',
       'x-ms-has-attach': 'yes',
       'x-ms-tnef-correlator': '',
       'authentication-results': 'spf=none (sender IP is ) smtp.mailfrom=julian@parcellab.com;',
       'x-ms-exchange-messagesentrepresentingtype': '1',
       'x-originating-ip': '[77.47.69.145]',
       'x-microsoft-exchange-diagnostics': 'string,
       'x-microsoft-antispam': 'UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AMXPR07MB184;',
       'x-ld-processed': 'c9ad2ae3-2857-429e-bddf-50e548a323c0,ExtAddr',
       'x-microsoft-antispam-prvs': '<AMXPR07MB184102A08E5ECE495676F2CC6050@AMXPR07MB184.eurprd07.prod.outlook.com>',
       'x-exchange-antispam-report-test': 'UriScan:;',
       'x-exchange-antispam-report-cfa-test': 'BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(520078)(10201501046)(3002001);SRVR:AMXPR07MB184;BCL:0;PCL:0;RULEID:;SRVR:AMXPR07MB184;',
       'x-forefront-prvs': '0771670921',
       'x-forefront-antispam-report': 'string',
       'received-spf': 'None (protection.outlook.com: parcellab.com does not designate permitted sender hosts)',
       spamdiagnosticoutput: '1:23',
       spamdiagnosticmetadata: 'NSPM',
       'content-type': 'multipart/signed; boundary="Apple-Mail=_F0CC39CA-E1ED-482A-B618-7EFEA7071FED"; protocol="application/pkcs7-signature"; micalg=sha1',
       'mime-version': '1.0',
       'x-originatororg': 'parcellab.com',
       'x-ms-exchange-crosstenant-originalarrivaltime': '25 Nov 2015 07:44:20.6059 (UTC)',
       'x-ms-exchange-crosstenant-fromentityheader': 'Hosted',
       'x-ms-exchange-crosstenant-id': 'c9ad2ae3-2857-429e-bddf-50e548a323c0',
       'x-ms-exchange-transport-crosstenantheadersstamped': 'AMXPR07MB184' },
    subject: 'test',
    messageId: '06C9DE21-CC9A-4732-AFD6-D48ACC49A74E@parcellab.com',
    priority: 'normal',
    from: [ Array ],
    to: [ Array ],
    date: Wed Nov 25 2015 07:44:20 GMT+0000 (UTC),
    receivedDate: Wed Nov 25 2015 07:44:21 GMT+0000 (UTC),
    dkim: 'failed',
    spf: 'failed',
    spamScore: 0,
    language: 'romanian',
    cc: [],
    connection: [ Object object ],
    envelopeFrom: { address: 'julian@parcellab.com', args: false },
    envelopeTo: [ { address: 'track@track.parcellab.com', args: false } ] }

Then I tried to check the webhook: But enabling this even throws an exception and mailin crashes.

Any ideas? :-)

ghost commented 8 years ago

Any updates on this?

jkrenge commented 8 years ago

I think I'm just stupid. :-)

ghost commented 8 years ago

What happened? I'm having a similar issue: the attachment array is populated correctly, but I have no way to access the actual content of the attachment. I tracked it down to https://github.com/andris9/mailparser#attachment-streaming -- take a look at https://github.com/Flolagale/mailin/blob/master/lib/mailin.js to see how mailin is using MailParser -- and it's pretty clear how to get the actual attachment content from a MailParser instance, but I just don't know how to access that instance from within mailin. Any ideas? Could you maybe post an example of how you streamed your attachments? :100:

jkrenge commented 8 years ago

For me, the whole attribute attachments was gone, so I think it was rather removed by different code before processing. But, I hacked it a little bit:

I basically store the whole raw email, as I want to archive the file anyways:

mailin.on('message', function(connection, data, content) {
  fs.writeFile(output, content, function(err) {
    if (err) console.log(err);
  });
});

Then I monitor the folder where the emails are stored and extract contents manually:

AttachmentMaster / index.js.

We will fix this, but for the meantime this also kind of works. :-)

ghost commented 8 years ago

Thanks! :+1: