Closed longlostnick closed 8 years ago
I'm thinking this is because often there is no content-type header at all. Will investigate.
Can you supply an example email on which things don't trigger right?
Sorry for the late reply. Here's an example:
Authentication-Results: ip-172-31-20-221; auth=pass (plain)
Received: from [10.1.2.119] ([99.43.92.137])
by ip-172-31-20-221 (Haraka/2.7.3) with ESMTPSA id C4D7B63A-0219-4C72-993D-192535D36D1A.1
envelope-from <username@me.com> (authenticated bits=0)
(version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA verify=NO);
Wed, 13 Apr 2016 02:58:10 +0000
From: Nick Larson <username@me.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Subject: this is a test.
Message-Id: <F8E749C0-9D1C-46AA-B5FB-386982047C5C@me.com>
Date: Tue, 12 Apr 2016 19:58:08 -0700
To: Nick <username@gmail.com>
Mime-Version: 1.0 (Mac OS X Mail 9.2 \(3112\))
X-Mailer: Apple Mail (2.3112)
nick
Oddly this one does have a Content-Type. Here's my plugin:
exports.hook_data = function (next, connection) {
connection.transaction.parse_body = 1;
connection.transaction.add_body_filter(/^text/, function (content_type, encoding, body_buffer) {
var body = body_buffer.toString();
var transformed = body.replace(/nick/ig, 'nicky l');
return new Buffer(transformed);
});
next();
}
It works fine if I provide an empty string, but then I'm guessing it's called on every Content-Type. I'm on node v5.9.0
Hey normally it should work, for me it does with:
connection.transaction.add_body_filter(/^text\/plain/i, func....
Haraka version
2.8.0-alpha.7
Expected behavior
By the documentation here I should be able to pass in a regex or string to match on the content type.
Observed behavior
If I pass in 'text/plain' or use a regex of something like
/text\/plain/
or/^text\/plain/
, myadd_body_filter
callback is never called.Setting it to an empty string works fine. If I log
content_type
in then callback it outputs 'text/plain'.I also noticed that if I log
connection.transaction.headers
it returns a bunch of auth related headers, and no other headers (am using an auth plugin). Is that because at the point ofhook_data
it hasn't received the headers of the content of the message yet?Steps to reproduce