Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jetonk opened this issue Nov 7, 2017 · 5 comments
Open

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

jetonk opened this issue Nov 7, 2017 · 5 comments

Comments

@jetonk
Copy link

jetonk commented Nov 7, 2017

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?

@jetonk jetonk changed the title I have issue with transaction.add_body_filter(ct_match, filter) I have an issue with transaction.add_body_filter(ct_match, filter) Nov 7, 2017
@baudehlo
Copy link
Collaborator

baudehlo commented Nov 7, 2017 via email

@jetonk
Copy link
Author

jetonk commented Nov 7, 2017

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
Copy link

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
Copy link

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 dc43bdc.

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.

Haraka/transaction.js

Lines 104 to 105 in 01c3a80

new_line = new_line.replace(/^\./gm, '..').replace(/\r?\n/gm, '\r\n');
line = new Buffer(new_line, this.encoding);

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

@skkiran-pro
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants