[Mimedefang] [External] Re: Help with header checking

Kevin A. McGrail kmcgrail at pccc.com
Tue Dec 1 18:12:21 EST 2020


On 12/1/2020 1:10 PM, Joseph Brennan wrote:
> We used this to create an array of header information:
>
> if (open(IN, '<', './HEADERS')) {
>          while(<IN>) {
>              chomp;
>              if (/^(\S+):\s*(.*)/) {
>                  my $label = $1;
>                  my $data  = $2;
>                  $label = lc($label);
>                  $Header{$label} = $data;
>                  if ($label eq 'received') {
>                      push(@Received,$data);
>                  }
>          }
>          close(IN);
>      }
>
>
> So following this, if for example we want to test the From: header, we
> check $Header{'from'}
> Received: was handled specially. It could end up an empty list. I
> don't think we checked for that!
>
> Hmm... If HEADERS was not there (??) it fails silently and
> $Header{'anything'} is empty. The rest of filter still works,
> but maybe we should have logged that case.

Does using MIME::Tools and $entity->head->get('Received'), for example, 
work?  Not sure how it parses through the various received headers.

For example, I convert Date's to unix epoch time format with something 
like this and the Date::Parse module:

$date_unixtime = Date::Parse::str2time($entity->head->get('Date'));

Regards,

KAM




More information about the MIMEDefang mailing list