forked from smfreegard/Haraka
/
transaction.js
75 lines (64 loc) · 2.2 KB
/
transaction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var logger = require('../logger'); // prevent compile errors in transaction.js.
var Transaction = require('../transaction');
function _set_up(done) {
this.transaction = Transaction.createTransaction();
done();
}
function _tear_down(done) {
done();
}
exports.transaction = {
setUp : _set_up,
tearDown : _tear_down,
'add_body_filter': function (test) {
var self = this;
test.expect(3);
this.transaction.add_body_filter('text/plain', function (ct, enc, buf) {
// The actual functionality of these filter functions is tested in
// mailbody.js. This just makes sure the plumbing is in place.
test.ok(ct.indexOf('text/plain') === 0, "correct body part");
test.ok(/utf-?8/i.test(enc), "correct encoding");
test.equal(buf.toString().trim(), "Text part", "correct body contents");
});
[
"Content-Type: multipart/alternative; boundary=abcd\n",
"\n",
"--abcd\n",
"Content-Type: text/plain\n",
"\n",
"Text part\n",
"--abcd\n",
"Content-Type: text/html\n",
"\n",
"<p>HTML part</p>\n",
"--abcd--\n",
].forEach(function (line) {
self.transaction.add_data(line);
});
this.transaction.end_data(function () {
test.done();
});
},
'regression: attachment_hooks before set_banner/add_body_filter': function (test) {
var self = this;
test.expect(2);
this.transaction.attachment_hooks(function () {});
this.transaction.set_banner('banner');
this.transaction.add_body_filter('', function () {
test.ok(true, "body filter called");
});
[
"Content-Type: text/plain\n",
"\n",
"Some text\n",
].forEach(function (line) {
self.transaction.add_data(line);
});
this.transaction.end_data(function () {
self.transaction.message_stream.get_data(function (body) {
test.ok(/banner$/.test(body.trim()), "banner applied");
test.done();
});
});
},
};