-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshowbcc.js
50 lines (44 loc) · 1.09 KB
/
showbcc.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
var _ = require('underscore')._;
exports.hook_queue = function(next, connection) {
var transaction = connection.transaction;
var addresses = this.addresses(transaction);
var bccs = addresses.bcc();
if (bccs.length) {
transaction.add_header('X-bcc', bccs.join(', '));
}
next();
}
exports.addresses = function(transaction) {
var t = transaction;
var mailRegExp = /([^<@\s,]+@[^@>,\s]+)/;
function get_addresses(key) {
var result = [];
t.header.get(key)
.split(',')
.forEach(function(val) {
var match;
if ((match = val.match(mailRegExp)) && match.length) {
result.push(match[1]);
}
});
return result;
}
return {
rcpt_to: function() {
return t.rcpt_to.map(function(rcpt_to) {
return rcpt_to.user + '@' + rcpt_to.host;
});
},
to: function() {
return get_addresses('to');
},
cc: function() {
return get_addresses('cc');
},
bcc: function() {
var in_headers = this.to().concat(this.cc());
var diff = _(this.rcpt_to()).difference(in_headers);
return diff;
}
}
}