haraka / Haraka

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

I have an issue with transaction.add_body_filter(ct_match, filter) #2290

Open jetonk opened 6 years ago

jetonk commented 6 years ago
Haraka Haraka.js — Version: 2.8.16
Node v8.6.0
OS Linux h2739470 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
openssl OpenSSL 1.0.2g 1 Mar 2016

I'm trying to edit the body content with transaction.add_body_filter(/text\/(plain|html)/, function (ct, enc, buff), it won't work, the received email is empty, and just the subject is ok. Even when I just return the buff again it doesn't work at all.

But when I send the email as plain text, it works. Any idea?

baudehlo commented 6 years ago

We will need more info. Show us some code and the source of the email in question.

On Tue, Nov 7, 2017 at 9:26 AM, jetonk notifications@github.com wrote:

Haraka Haraka.js — Version: 2.8.16 Node v8.6.0 OS Linux h2739470 4.4.0-98-generic #121 https://github.com/haraka/Haraka/issues/121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux openssl OpenSSL 1.0.2g 1 Mar 2016

I'm trying to edit the body content with transaction.add_body_filter(ct, enc, buff), it won't work, the received email is empty, and just the subject is ok. Even when I just return the buff again it doesn't work at all.

But when I send the email as plain text, it works. Any idea?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/haraka/Haraka/issues/2290, or mute the thread https://github.com/notifications/unsubscribe-auth/AAobY34k509UwWyLEuyLF5SRdmQxrl-Kks5s0GiGgaJpZM4QU3c4 .

jetonk commented 6 years ago

I'm sending email from my office365 account.

exports.hook_data = function (next, connection){
    var plugin = this ;
    connection.relaying = true;
    connection.transaction.parse_body = true;
    connection.transaction.add_body_filter(/text\/(plain|html)/, function (ct, enc, buff)
    {
        var buf = buff.toString('utf-8');
        var pos = buf.indexOf('\<\/body\>');
        buf = [buf.slice(0, pos), '\n Added this paragraph to the existing body.', buf.slice(pos)].join('');
        return new Buffer(buf);

    });
    next();
}
mike3784 commented 5 years ago

i can confirm got the same problem, when i put anything into connection.transaction.add_body_filter() got empty body even if the filter is not firing the issue become active with recent versions Haraka

stevejost commented 5 years ago

I can confirm the same problem - I have an internal plugin that adds a body filter. I have found that PR #2187 that fixed bug #2176 is where the behavior change occurred. The specific commit is https://github.com/haraka/Haraka/commit/dc43bdc36ab54a1137827f942423e8240c70f83c.

I have confirmed that re-adding the following lines seems to fix the issue but am not 100% sure if this is the correct fix.

https://github.com/haraka/Haraka/blob/01c3a803833255e7ec7ef55e7f3c18390069db75/transaction.js#L104-L105

I will try to get an SMTP conversation capture later tonight for an easier reproduction.

skkiran-pro commented 5 years ago

Same here. It happens only for mails with multipart bodies. Works fine for plain text or plain html emails. Is there any plan to fix this?