haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.02k stars 662 forks source link

Problem with set_banner and multipart/mixed with only text/plain sections #1229

Closed melimanrique closed 8 years ago

melimanrique commented 8 years ago

I have a plugin which adds a banner for all incoming email. Like this:

exports.hook_data = function (next, connection) {
  connection.transaction.set_banner('Text banner', '<p style="color:RED;"><span>Html banner</span></p>');
  return next();
}

However, in some of the emails sent from Outlook and iPhone that are multpart/mixed with only a text/plain section the banner never appears. It seems to never be applying correctly.

You have any idea why this could be?

melimanrique commented 8 years ago

@smfreegard @Dexus Do you have any idea about this? Thank you!

Dexus commented 8 years ago

Hi @melimanrique first question do you set transaction.parse_body = true? This is needed so that the filter that is used for set_banner can access the body.

melimanrique commented 8 years ago

@Dexus Yes I do. I've done it right before calling set_banner like this:

exports.hook_data = function (next, connection) {
  connection.transaction.parse_body = true;
  connection.transaction.set_banner('Text banner', '<p style="color:RED;"><span>Html banner</span></p>');
  return next();
}

And also tried setting it only in data and then calling set_banner in data_post like this:

exports.hook_data = function (next, connection) {
  connection.transaction.parse_body = true;
  return next();
}
exports.hook_data_post = function (next, connection) {
  connection.transaction.set_banner('Text banner', '<p style="color:RED;"><span>Html banner</span></p>');
  return next();
}

But it fails only with multipart/mixed emails which have only a text/plain section. With other emails that are multipart/alternative and have both text/plain and text/html sections works perfectly

Dexus commented 8 years ago

hmm, i will look at weekend to this.

Dexus commented 8 years ago

@melimanrique hey, can you please give me some email that failed?

melimanrique commented 8 years ago

Hi @Dexus

We've discovered that the problem was related to the fact that Office365 (Exchange) sends the message body inside an attachment called winmail.dat so Haraka is unable to parse it. This is due to a format called TNEF that is proprietary from Microsoft.

So, Haraka should read the winmail.dat for being able to parse the body.

baudehlo commented 8 years ago

This is really hard to do. It's a proprietary format based on OLE documents. I wrote something in Perl a long time ago to try and read them and I think there's something better on CPAN now but I doubt there's anything in JavaScript.

On Oct 23, 2015, at 8:26 PM, Melissa Manrique notifications@github.com wrote:

Hi @Dexus

We've discovered that the problem was related to the fact that Office365 (Exchange) sends the message body inside an attachment called winmail.dat so Haraka is unable to parse it. This is due to a format called TNEF that is proprietary from Microsoft.

So, Haraka should read the winmail.dat for being able to parse the body.

— Reply to this email directly or view it on GitHub.

msimerson commented 8 years ago

but I doubt there's anything in JavaScript.

Of course not, but it's just another wrapper format. It could be unpackaged by using the cli program tnef, just like how we use bsdtar now to expand archives.

baudehlo commented 8 years ago

Indeed. I hate shelling out to something but it is a possibility.

On Oct 24, 2015, at 2:12 AM, Matt Simerson notifications@github.com wrote:

but I doubt there's anything in JavaScript.

Of course not, but it's just another wrapper format. It could be unpackaged by using the cli program tnef, just like how we use bsdtar now to expand archives.

— Reply to this email directly or view it on GitHub.

smfreegard commented 8 years ago

I have this on my list for the attachment plugin, so it can check/reject attachments inside winmail.dat files.

However to solve the bannering issue with TNEF would require us to convert the message to proper MIME format and discard the original and I really don't think we should do that. The sanest thing to do is disable rich-text format in Exchange/Outlook which makes it use proper MIME formatting instead and this gives people tge incentive to do that, whereas if we attrmpt to convert, then they won't bother...