Skip to content

Instantly share code, notes, and snippets.

@evandhoffman
Created August 2, 2011 18:05
Show Gist options
  • Save evandhoffman/1120804 to your computer and use it in GitHub Desktop.
Save evandhoffman/1120804 to your computer and use it in GitHub Desktop.
Amazon's ses-send-email.pl vs mine.
# Read message body from STDIN, replacing illegal headers with X-headers.
my @legal_headers = qw( Accept-Language Bcc Cc Comments Content-Type Content-Transfer-Encoding Content-ID Content-Description Content-Disposition Content-Language Date DKIM-Signature DomainKey-Signature From In-Reply-To Keywords List-Archive List-Help List-Id List-Owner List-Post List-Subscribe List-Unsubscribe Message-Id MIME-Version Received References Reply-To Return-Path Sender Subject Thread-Index Thread-Topic To User-Agent );
my %legal_headers;
@legal_headers{@legal_headers} = (1) x @legal_headers;
sub read_message {
my $in_header = 1;
my $in_body = 0;
while (<STDIN>) {
my $line = $_;
if ($in_header && ($line =~ /^[\n\r]/)) {
$in_header = 0;
$in_body = 1;
}
if ($in_header) { # Once we leave the header, do nothing.
if ($line =~ /^([\w\d\-]+):/) { # skips indented lines
my $header = $1;
unless (($legal_headers{$header}) || ($header =~/^X-/)) {
$line =~ s/^$header:/X-$header:/; # X-ify
}
}
}
$opts{'m'} .= join '', $line;
}
$opts{'m'} =~ s/^\x{FEFF}//;
}
# Read message body from STDIN.
sub read_message {
$opts{'m'} = join '', readline *STDIN;
$opts{'m'} =~ s/^\x{FEFF}//;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment