Created
September 8, 2016 16:03
-
-
Save PhrozenByte/4af0045b6507ceb24e4231988c7d9fcf to your computer and use it in GitHub Desktop.
Compare message headers against each other with SpamAssassin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <@LICENSE> | |
# Copyright 2016 Daniel Rudolf <www.daniel-rudolf.de> | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# </@LICENSE> | |
=head1 NAME | |
Mail::SpamAssassin::Plugin::HeadersEqual - compare headers against each other | |
=head1 SYNOPSIS | |
loadplugin Mail::SpamAssassin::Plugin::HeadersEqual [/path/to/HeadersEqual.pm] | |
Comparing two or more headers against each other: | |
header HEADERS_EQUAL eval:headers_equal(header1, header2, ...) | |
header HEADERS_EQUAL eval:headers_equal("eq", header1, header2, ...) | |
header HEADERS_NOT_EQUAL eval:headers_equal("ne", header1, header2, ...) | |
Headers will be passed to C<Mail::SpamAssassin::PerMsgStatus->get()>. You | |
can particularly append C<:raw>, C<:addr> and C<:name> to header names to | |
adjust what is compared. | |
=head1 DESCRIPTION | |
This SpamAssassin plugin allows one to compare headers against each other. | |
It is frequently used to compare the C<Return-Path:> and C<From:> headers: | |
header SENDER_MISMATCH eval:headers_equal("ne", "From:addr", "Return-Path:addr") | |
=head1 SEE ALSO | |
C<Mail::SpamAssassin::Plugin> | |
=cut | |
package Mail::SpamAssassin::Plugin::HeadersEqual; | |
use strict; | |
use warnings; | |
use Mail::SpamAssassin::Plugin; | |
our @ISA = qw(Mail::SpamAssassin::Plugin); | |
sub new { | |
my ($class, $mailsa) = @_; | |
$class = ref($class) || $class; | |
my $self = $class->SUPER::new($mailsa); | |
bless ($self, $class); | |
$self->register_eval_rule("headers_equal"); | |
return $self; | |
} | |
sub headers_equal { | |
my $self = shift; | |
my $status = shift; | |
my $cmp = (($_[0] eq "eq") or ($_[0] eq "ne")) ? shift : "eq"; | |
my $header = shift; | |
my $value = $status->get($header); | |
foreach (@_) { | |
if ($cmp eq "eq") { | |
return 1 if ($value eq $status->get($_)); | |
} else { | |
return 1 if ($value ne $status->get($_)); | |
} | |
} | |
return 0; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment