@@ -96,6 +96,18 @@ SmtpServer.FILTER_ACCEPT = 0;
9696SmtpServer . FILTER_REJECT_TEMPORARILY = 1 ;
9797SmtpServer . FILTER_REJECT_PERMANENTLY = 2 ;
9898
99+ // List of DNSBL domains:
100+ // - first element is the DNSBL domain name
101+ // - second element (optional) is a callback function // TODO
102+ // - remaining elements (optional) are passed to the callback function // TODO
103+ SmtpServer . dnsbl = [
104+ [ "zen.spamhaus.org" ] , // Free for "private mail systems with low traffic";
105+ // https://www.spamhaus.org/organization/dnsblusage/
106+ [ "rbl.abuse.ro" ] , // Open; http://abuse.ro/#three
107+ //["b.barracudacentral.org"], // Open; requires registation;
108+ // http://barracudacentral.org/rbl
109+ ] ;
110+
99111SmtpServer . prototype . relayCmd = function ( cmd , args )
100112{
101113 this . smtpClient . sendCommand ( cmd , args ) ;
@@ -209,6 +221,25 @@ SmtpServer.prototype.filter = function(headers, body) {
209221 return SmtpServer . FILTER_REJECT_PERMANENTLY ;
210222 }
211223
224+ for ( var i in SmtpServer . dnsbl ) {
225+ var dnsbl = SmtpServer . dnsbl [ i ] ;
226+ var raddr = Dns . revAddr ( this . remoteAddr , dnsbl [ 0 ] ) ;
227+ var result = Dns . query ( raddr , Dns . t_a ) ;
228+ if ( typeof ( result ) == "number" ) {
229+ Sys . log ( Sys . LOG_DEBUG , "DNSBL: pass " + raddr + " (" + result + ")" ) ;
230+ continue ;
231+ }
232+ var rlist = [ ] ;
233+ for ( var j in result . answer ) {
234+ var rr = result . answer [ j ] ;
235+ if ( rr . type = Dns . t_a && rr . name . toLowerCase ( ) == raddr . toLowerCase ( ) )
236+ rlist . push ( rr . data ) ;
237+ }
238+ // TODO if `dnsbl` defines a callback function, call it and pass rlist
239+ Sys . log ( Sys . LOG_DEBUG , "DNSBL: reject " + raddr + " (" + rlist . join ( ) + ")" ) ;
240+ return SmtpServer . FILTER_REJECT_PERMANENTLY ;
241+ }
242+
212243 return SmtpServer . FILTER_ACCEPT ;
213244}
214245
0 commit comments