Skip to content

Commit

Permalink
This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
Reimplement as a ternary using the can method

This avoids the hard coded version string and will use txtdata whenever
it is available
  • Loading branch information
marcbradshaw committed Nov 13, 2023
1 parent b3a6ebd commit 43c5898
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
30 changes: 12 additions & 18 deletions lib/Mail/SPF/Mod/Exp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,19 @@ sub process {
or $server->throw_result('permerror', $request,
"Redundant authority explanation strings found at domain '$exp_domain'"); # RFC 4408, 6.2/4

my $explanation;
# char_str_list method is 'historical', use as a fallback for Net::DNS prior to 0.69
# where txtdata is not available.
# join with no intervening spaces, RFC 6376
if ( Net::DNS->VERSION >= 0.69 ) {
# must call txtdata() in a list context
$explanation = Mail::SPF::MacroString->new(
text => join('', $txt_rrs[0]->txtdata),
server => $server,
request => $request,
is_explanation => TRUE
);
} else {
# char_str_list method is 'historical'
$explanation = Mail::SPF::MacroString->new(
text => join('', $txt_rrs[0]->char_str_list),
server => $server,
request => $request,
is_explanation => TRUE
);
}
# must call txtdata() in a list context
my $text = $txt_rrs[0]->can('txtdata')
? join('', $txt_rrs[0]->txtdata)
: join('', $txt_rrs[0]->char_str_list);
my $explanation = Mail::SPF::MacroString->new(
text => $text,
server => $server,
request => $request,
is_explanation => TRUE
);

$request->state('authority_explanation', $explanation);
}
Expand Down
14 changes: 6 additions & 8 deletions lib/Mail/SPF/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,13 @@ sub get_acceptable_records_from_packet {
foreach my $rr ($packet->answer) {
next if $rr->type ne $rr_type; # Ignore RRs of unexpected type.

my $text;
# char_str_list method is 'historical', use as a fallback for Net::DNS prior to 0.69
# where txtdata is not available.
# join with no intervening spaces, RFC 6376
if ( Net::DNS->VERSION >= 0.69 ) {
# must call txtdata() in a list context
$text = join '', $rr->txtdata;
} else {
# char_str_list method is 'historical'
$text = join('', $rr->char_str_list);
}
# must call txtdata() in a list context
my $text = $rr->can('txtdata')
? join('', $rr->txtdata)
: join('', $rr->char_str_list);
my $record;

# Try to parse RR as each of the requested record versions,
Expand Down

0 comments on commit 43c5898

Please sign in to comment.