[Mimedefang] Testing for the existence of a header
Joseph Brennan
brennan at columbia.edu
Tue Sep 30 21:36:37 EDT 2008
> Can anyone please tell me how to test for the existence of a header in an
> email?
We've generalized this, because we check several headers. In
filter, you could do this:
# In the HEADERS file, any multiline headers have been rewritten to
# be one line. Received: is a typical example. So here we do not
# need to worry about continuation lines.
#
# Where there are multiple headers with the same name, what we do
# here will overwrite and end up with the data for the last one.
# If we want to collect them all we make a list like @Received.
if (open(IN,"<./HEADERS")) {
while(<IN>) {
chomp;
if (/^(\S+): (.*)/) {
my $label = $1;
my $data = $2;
$label = lc($label);
$Header{$label} = $data;
if ($label eq 'received') {
push(@Received,$data);
}
}
}
}
close(IN);
Taking your example, then the contents of a header "X-ABC:" would be
stored in $Header{'x-abc'}. You could test both existence:
if ($Header{'x-abc'})
and contents:
if ($Header{'x-abc'} =~ /some string/)
Joseph Brennan
Lead Email Systems Engineer
Columbia University Information Technology
More information about the MIMEDefang
mailing list