@@ -38,6 +38,9 @@ class SPF {
38
38
39
39
this . mech_ip4 = this . mech_ip
40
40
this . mech_ip6 = this . mech_ip
41
+
42
+ // Used for tests only
43
+ this . _found_mx_addrs = [ ] ;
41
44
}
42
45
43
46
const_translate ( value ) {
@@ -486,17 +489,15 @@ class SPF {
486
489
}
487
490
}
488
491
489
- let pending = 0
490
492
let addresses = [ ]
491
493
// RFC 4408 Section 10.1
492
494
if ( mxes . length > this . LIMIT ) return this . SPF_PERMERROR
493
495
496
+ let cidr ;
494
497
for ( const element of mxes ) {
495
- pending ++
496
498
const mx = element . exchange
497
499
// Calculate which IP method to use
498
500
let resolve_method
499
- let cidr
500
501
if ( this . ip_ver === 'ipv4' ) {
501
502
cidr = cidr4
502
503
resolve_method = 'resolve4'
@@ -519,49 +520,44 @@ class SPF {
519
520
}
520
521
}
521
522
522
- pending --
523
- if ( addrs ) {
524
- this . log_debug ( `mech_mx: mx=${ mx } addresses=${ addrs . join ( ',' ) } ` )
525
- addresses = addrs . concat ( addresses )
526
- }
527
- if ( pending === 0 ) {
528
- if ( ! addresses . length ) return this . SPF_NONE
529
- // All queries run; see if our IP matches
530
- if ( cidr ) {
531
- // CIDR match type
532
- for ( const address of addresses ) {
533
- const range = ipaddr . parse ( address )
534
- if ( this . ipaddr . match ( range , cidr ) ) {
535
- this . log_debug (
536
- `mech_mx: ${ this . ip } => ${ address } /${ cidr } : MATCH!` ,
537
- )
538
- return this . return_const ( qualifier )
539
- } else {
540
- this . log_debug (
541
- `mech_mx: ${ this . ip } => ${ address } /${ cidr } : NO MATCH` ,
542
- )
543
- }
544
- }
545
- // No matches
546
- return this . SPF_NONE
523
+ this . log_debug ( `mech_mx: mx=${ mx } addresses=${ addrs . join ( ',' ) } ` )
524
+ addresses = addrs . concat ( addresses )
525
+ }
526
+
527
+ if ( ! addresses . length ) return this . SPF_NONE
528
+ this . _found_mx_addrs = addresses ;
529
+
530
+ // All queries run; see if our IP matches
531
+ if ( cidr ) {
532
+ // CIDR match type
533
+ for ( const address of addresses ) {
534
+ const range = ipaddr . parse ( address )
535
+ if ( this . ipaddr . match ( range , cidr ) ) {
536
+ this . log_debug (
537
+ `mech_mx: ${ this . ip } => ${ address } /${ cidr } : MATCH!` ,
538
+ )
539
+ return this . return_const ( qualifier )
547
540
} else {
548
- if ( addresses . includes ( this . ip ) ) {
549
- this . log_debug (
550
- `mech_mx: ${ this . ip } => ${ addresses . join ( ',' ) } : MATCH!` ,
551
- )
552
- return this . return_const ( qualifier )
553
- } else {
554
- this . log_debug (
555
- `mech_mx: ${ this . ip } => ${ addresses . join ( ',' ) } : NO MATCH` ,
556
- )
557
- return this . SPF_NONE
558
- }
541
+ this . log_debug (
542
+ `mech_mx: ${ this . ip } => ${ address } /${ cidr } : NO MATCH` ,
543
+ )
559
544
}
560
545
}
561
- // In case we didn't run any queries...
562
- if ( pending === 0 ) return this . SPF_NONE
546
+ // No matches
547
+ return this . SPF_NONE
548
+ } else {
549
+ if ( addresses . includes ( this . ip ) ) {
550
+ this . log_debug (
551
+ `mech_mx: ${ this . ip } => ${ addresses . join ( ',' ) } : MATCH!` ,
552
+ )
553
+ return this . return_const ( qualifier )
554
+ } else {
555
+ this . log_debug (
556
+ `mech_mx: ${ this . ip } => ${ addresses . join ( ',' ) } : NO MATCH` ,
557
+ )
558
+ return this . SPF_NONE
559
+ }
563
560
}
564
- if ( pending === 0 ) this . SPF_NONE
565
561
}
566
562
567
563
async mech_ptr ( qualifier , args ) {
0 commit comments