-#!/usr/bin/perl -wT
+#!/usr/bin/perl
use warnings;
use strict;
+# Sanitize environent for taint
+BEGIN{
+ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
+}
+
+# STDOUT should be using the utf8 io layer
+binmode(STDOUT,':utf8');
+
use POSIX qw(strftime);
use MIME::Parser;
use MIME::Decoder;
}
my @log;
if ( $mbox ) {
+ binmode(STDOUT,":raw");
my $date = strftime "%a %b %d %T %Y", localtime;
if (@records > 1) {
print $q->header(-type => "text/plain",
# we want to include control messages anyway
my $record_wanted_anyway = 0;
my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
- next if exists $seen_message_ids{$msg_id};
- next if $msg_id =~/handler\..+\.ack(?:info|done)?\@/;
+ next if defined $msg_id and exists $seen_message_ids{$msg_id};
+ next if defined $msg_id and $msg_id =~/handler\..+\.ack(?:info|done)?\@/;
$record_wanted_anyway = 1 if $record->{text} =~ /^Received: \(at control\)/;
next if not $boring and not $record->{type} eq $wanted_type and not $record_wanted_anyway and @records > 1;
- $seen_message_ids{$msg_id} = 1;
+ $seen_message_ids{$msg_id} = 1 if defined $msg_id;
my @lines = split( "\n", $record->{text}, -1 );
if ( $lines[ 1 ] =~ m/^From / ) {
my $tmp = $lines[ 0 ];
else {
if (defined $att and defined $msg and @records) {
+ binmode(STDOUT,":raw");
$msg_num++;
print handle_email_message($records[0]->{text},
ref => $ref,