forked from smfreegard/Haraka
/
rcpt_to.in_host_list.js
42 lines (35 loc) · 1.24 KB
/
rcpt_to.in_host_list.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
// Check RCPT TO domain is in host list
var smtp = require('../constants');
exports.hook_rcpt = function(callback, connection, params) {
var rcpt = params[0];
// Check for RCPT TO without an @ first - ignore those here
if (!rcpt.match(/@/)) {
return callback(smtp.cont);
}
this.loginfo("Checking if " + rcpt + " host is in host_list");
var matches = rcpt.match(/@([^@>]*)>?/);
if (!matches) {
this.logerror("TO address does not parse: " + rcpt);
return callback(smtp.deny, "TO address does not parse");
}
var domain = matches[1];
var host_list = this.config.get('host_list', 'list');
var allow_subdomain = this.config.get('host_list.ini', 'ini').main.allow_subdomains;
var i;
for (i in host_list) {
this.logdebug("checking " + domain + " against " + host_list[i]);
var tmp_domain = domain;
while (tmp_domain.match('.')) {
if (host_list[i] === tmp_domain) {
return callback(smtp.ok);
}
if (allow_subdomain) {
tmp_domain = tmp_domain.replace(/^[^\.]*\./, '');
}
else {
break;
}
}
}
callback(smtp.cont);
}