@@ -7,23 +7,21 @@ const DSN = require('haraka-dsn');
7
7
exports . SPF = SPF ;
8
8
9
9
exports . register = function ( ) {
10
- const plugin = this ;
11
10
12
11
// Override logging in SPF module
13
- SPF . prototype . log_debug = str => plugin . logdebug ( str ) ;
12
+ SPF . prototype . log_debug = str => this . logdebug ( str ) ;
14
13
15
- plugin . load_spf_ini ( ) ;
14
+ this . load_spf_ini ( ) ;
16
15
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' ) ;
19
18
}
20
19
21
20
exports . 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 ;
25
23
26
- plugin . cfg = plugin . config . get ( 'spf.ini' , {
24
+ this . cfg = this . config . get ( 'spf.ini' , {
27
25
booleans : [
28
26
'-defer.helo_temperror' ,
29
27
'-defer.mfrom_temperror' ,
@@ -57,30 +55,30 @@ exports.load_spf_ini = function () {
57
55
'-skip.auth' ,
58
56
]
59
57
} ,
60
- ( ) => { plugin . load_spf_ini ( ) ; }
58
+ ( ) => { this . load_spf_ini ( ) ; }
61
59
) ;
62
60
63
61
// 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 ;
67
65
}
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 ;
70
68
}
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 ;
73
71
}
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 ;
76
74
}
77
- } ) ;
75
+ }
78
76
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
81
79
}
82
80
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 ;
84
82
}
85
83
86
84
exports . helo_spf = async function ( next , connection , helo ) {
@@ -222,7 +220,6 @@ exports.hook_mail = async function (next, connection, params) {
222
220
// if we check the public IP first. Only check the public IP if the
223
221
// client IP returns a result other than 'Pass'.
224
222
const result = await spf . check_host ( connection . remote . ip , host , mfrom )
225
-
226
223
// typical inbound (!relay)
227
224
if ( ! connection . relaying ) return ch_cb ( null , result )
228
225
@@ -231,7 +228,6 @@ exports.hook_mail = async function (next, connection, params) {
231
228
232
229
// outbound (relaying), context=myself
233
230
const my_public_ip = await net_utils . get_public_ip ( )
234
-
235
231
let spf_result ;
236
232
if ( result ) spf_result = spf . result ( result ) . toLowerCase ( ) ;
237
233
@@ -256,7 +252,6 @@ exports.log_result = function (connection, scope, host, mfrom, result, ip) {
256
252
}
257
253
258
254
exports . return_results = function ( next , connection , spf , scope , result , sender ) {
259
- const plugin = this ;
260
255
const msgpre = ( scope === 'helo' ) ? `sender ${ sender } ` : `sender <${ sender } >` ;
261
256
const deny = connection . relaying ? 'deny_relay' : 'deny' ;
262
257
const defer = connection . relaying ? 'defer_relay' : 'defer' ;
@@ -265,39 +260,39 @@ exports.return_results = function (next, connection, spf, scope, result, sender)
265
260
266
261
switch ( result ) {
267
262
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` ;
270
265
return next ( DENY , text ) ;
271
266
}
272
267
return next ( ) ;
273
268
case spf . SPF_NEUTRAL :
274
269
case spf . SPF_PASS :
275
270
return next ( ) ;
276
271
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` ;
279
274
return next ( DENY , text ) ;
280
275
}
281
276
return next ( ) ;
282
277
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` ;
285
280
return next ( DENY , text ) ;
286
281
}
287
282
return next ( ) ;
288
283
case spf . SPF_TEMPERROR :
289
- if ( plugin . cfg [ defer ] [ `${ scope } _temperror` ] ) {
284
+ if ( this . cfg [ defer ] [ `${ scope } _temperror` ] ) {
290
285
return next ( DENYSOFT , `${ msgpre } SPF Temporary Error` ) ;
291
286
}
292
287
return next ( ) ;
293
288
case spf . SPF_PERMERROR :
294
- if ( plugin . cfg [ deny ] [ `${ scope } _permerror` ] ) {
289
+ if ( this . cfg [ deny ] [ `${ scope } _permerror` ] ) {
295
290
return next ( DENY , `${ msgpre } SPF Permanent Error` ) ;
296
291
}
297
292
return next ( ) ;
298
293
default :
299
294
// Unknown result
300
- connection . logerror ( plugin , `unknown result code=${ result } ` ) ;
295
+ connection . logerror ( this , `unknown result code=${ result } ` ) ;
301
296
return next ( ) ;
302
297
}
303
298
}
@@ -314,9 +309,8 @@ exports.save_to_header = (connection, spf, result, mfrom, host, id, ip) => {
314
309
}
315
310
316
311
exports . skip_hosts = function ( connection ) {
317
- const plugin = this ;
318
312
319
- const skip = plugin ?. cfg ?. skip ;
313
+ const skip = this ?. cfg ?. skip ;
320
314
if ( skip ) {
321
315
if ( skip . relaying && connection . relaying ) return 'relay' ;
322
316
if ( skip . auth && connection . notes . auth_user ) return 'auth' ;
0 commit comments