@@ -7,23 +7,21 @@ const DSN = require('haraka-dsn');
77exports . SPF = SPF ;
88
99exports . register = function ( ) {
10- const plugin = this ;
1110
1211 // Override logging in SPF module
13- SPF . prototype . log_debug = str => plugin . logdebug ( str ) ;
12+ SPF . prototype . log_debug = str => this . logdebug ( str ) ;
1413
15- plugin . load_spf_ini ( ) ;
14+ this . load_spf_ini ( ) ;
1615
17- plugin . register_hook ( 'helo' , 'helo_spf' ) ;
18- plugin . register_hook ( 'ehlo' , 'helo_spf' ) ;
16+ this . register_hook ( 'helo' , 'helo_spf' ) ;
17+ this . register_hook ( 'ehlo' , 'helo_spf' ) ;
1918}
2019
2120exports . load_spf_ini = function ( ) {
22- const plugin = this ;
23- plugin . nu = net_utils ; // so tests can set public_ip
24- plugin . SPF = SPF ;
21+ this . nu = net_utils ; // so tests can set public_ip
22+ this . SPF = SPF ;
2523
26- plugin . cfg = plugin . config . get ( 'spf.ini' , {
24+ this . cfg = this . config . get ( 'spf.ini' , {
2725 booleans : [
2826 '-defer.helo_temperror' ,
2927 '-defer.mfrom_temperror' ,
@@ -57,30 +55,30 @@ exports.load_spf_ini = function () {
5755 '-skip.auth' ,
5856 ]
5957 } ,
60- ( ) => { plugin . load_spf_ini ( ) ; }
58+ ( ) => { this . load_spf_ini ( ) ; }
6159 ) ;
6260
6361 // when set, preserve legacy config settings
64- [ 'helo' , 'mail' ] . forEach ( phase => {
65- if ( plugin . cfg . main [ `${ phase } _softfail_reject` ] ) {
66- plugin . cfg . deny [ `${ phase } _softfail` ] = true ;
62+ for ( const phase of [ 'helo' , 'mail' ] ) {
63+ if ( this . cfg . main [ `${ phase } _softfail_reject` ] ) {
64+ this . cfg . deny [ `${ phase } _softfail` ] = true ;
6765 }
68- if ( plugin . cfg . main [ `${ phase } _fail_reject` ] ) {
69- plugin . cfg . deny [ `${ phase } _fail` ] = true ;
66+ if ( this . cfg . main [ `${ phase } _fail_reject` ] ) {
67+ this . cfg . deny [ `${ phase } _fail` ] = true ;
7068 }
71- if ( plugin . cfg . main [ `${ phase } _temperror_defer` ] ) {
72- plugin . cfg . defer [ `${ phase } _temperror` ] = true ;
69+ if ( this . cfg . main [ `${ phase } _temperror_defer` ] ) {
70+ this . cfg . defer [ `${ phase } _temperror` ] = true ;
7371 }
74- if ( plugin . cfg . main [ `${ phase } _permerror_reject` ] ) {
75- plugin . cfg . deny [ `${ phase } _permerror` ] = true ;
72+ if ( this . cfg . main [ `${ phase } _permerror_reject` ] ) {
73+ this . cfg . deny [ `${ phase } _permerror` ] = true ;
7674 }
77- } ) ;
75+ }
7876
79- if ( ! plugin . cfg . relay ) {
80- plugin . cfg . relay = { context : 'sender' } ; // default/legacy
77+ if ( ! this . cfg . relay ) {
78+ this . cfg . relay = { context : 'sender' } ; // default/legacy
8179 }
8280
83- plugin . cfg . lookup_timeout = plugin . cfg . main . lookup_timeout || plugin . timeout - 1 ;
81+ this . cfg . lookup_timeout = this . cfg . main . lookup_timeout || this . timeout - 1 ;
8482}
8583
8684exports . helo_spf = async function ( next , connection , helo ) {
@@ -222,7 +220,6 @@ exports.hook_mail = async function (next, connection, params) {
222220 // if we check the public IP first. Only check the public IP if the
223221 // client IP returns a result other than 'Pass'.
224222 const result = await spf . check_host ( connection . remote . ip , host , mfrom )
225-
226223 // typical inbound (!relay)
227224 if ( ! connection . relaying ) return ch_cb ( null , result )
228225
@@ -231,7 +228,6 @@ exports.hook_mail = async function (next, connection, params) {
231228
232229 // outbound (relaying), context=myself
233230 const my_public_ip = await net_utils . get_public_ip ( )
234-
235231 let spf_result ;
236232 if ( result ) spf_result = spf . result ( result ) . toLowerCase ( ) ;
237233
@@ -256,7 +252,6 @@ exports.log_result = function (connection, scope, host, mfrom, result, ip) {
256252}
257253
258254exports . return_results = function ( next , connection , spf , scope , result , sender ) {
259- const plugin = this ;
260255 const msgpre = ( scope === 'helo' ) ? `sender ${ sender } ` : `sender <${ sender } >` ;
261256 const deny = connection . relaying ? 'deny_relay' : 'deny' ;
262257 const defer = connection . relaying ? 'defer_relay' : 'defer' ;
@@ -265,39 +260,39 @@ exports.return_results = function (next, connection, spf, scope, result, sender)
265260
266261 switch ( result ) {
267262 case spf . SPF_NONE :
268- if ( plugin . cfg [ deny ] [ `${ scope } _none` ] ) {
269- text = plugin . cfg [ deny ] . openspf_text ? text : `${ msgpre } SPF record not found` ;
263+ if ( this . cfg [ deny ] [ `${ scope } _none` ] ) {
264+ text = this . cfg [ deny ] . openspf_text ? text : `${ msgpre } SPF record not found` ;
270265 return next ( DENY , text ) ;
271266 }
272267 return next ( ) ;
273268 case spf . SPF_NEUTRAL :
274269 case spf . SPF_PASS :
275270 return next ( ) ;
276271 case spf . SPF_SOFTFAIL :
277- if ( plugin . cfg [ deny ] [ `${ scope } _softfail` ] ) {
278- text = plugin . cfg [ deny ] . openspf_text ? text : `${ msgpre } SPF SoftFail` ;
272+ if ( this . cfg [ deny ] [ `${ scope } _softfail` ] ) {
273+ text = this . cfg [ deny ] . openspf_text ? text : `${ msgpre } SPF SoftFail` ;
279274 return next ( DENY , text ) ;
280275 }
281276 return next ( ) ;
282277 case spf . SPF_FAIL :
283- if ( plugin . cfg [ deny ] [ `${ scope } _fail` ] ) {
284- text = plugin . cfg [ deny ] . openspf_text ? text : `${ msgpre } SPF Fail` ;
278+ if ( this . cfg [ deny ] [ `${ scope } _fail` ] ) {
279+ text = this . cfg [ deny ] . openspf_text ? text : `${ msgpre } SPF Fail` ;
285280 return next ( DENY , text ) ;
286281 }
287282 return next ( ) ;
288283 case spf . SPF_TEMPERROR :
289- if ( plugin . cfg [ defer ] [ `${ scope } _temperror` ] ) {
284+ if ( this . cfg [ defer ] [ `${ scope } _temperror` ] ) {
290285 return next ( DENYSOFT , `${ msgpre } SPF Temporary Error` ) ;
291286 }
292287 return next ( ) ;
293288 case spf . SPF_PERMERROR :
294- if ( plugin . cfg [ deny ] [ `${ scope } _permerror` ] ) {
289+ if ( this . cfg [ deny ] [ `${ scope } _permerror` ] ) {
295290 return next ( DENY , `${ msgpre } SPF Permanent Error` ) ;
296291 }
297292 return next ( ) ;
298293 default :
299294 // Unknown result
300- connection . logerror ( plugin , `unknown result code=${ result } ` ) ;
295+ connection . logerror ( this , `unknown result code=${ result } ` ) ;
301296 return next ( ) ;
302297 }
303298}
@@ -314,9 +309,8 @@ exports.save_to_header = (connection, spf, result, mfrom, host, id, ip) => {
314309}
315310
316311exports . skip_hosts = function ( connection ) {
317- const plugin = this ;
318312
319- const skip = plugin ?. cfg ?. skip ;
313+ const skip = this ?. cfg ?. skip ;
320314 if ( skip ) {
321315 if ( skip . relaying && connection . relaying ) return 'relay' ;
322316 if ( skip . auth && connection . notes . auth_user ) return 'auth' ;
0 commit comments