Skip to content

Instantly share code, notes, and snippets.

@evandhoffman
Created July 6, 2011 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evandhoffman/1068310 to your computer and use it in GitHub Desktop.
Save evandhoffman/1068310 to your computer and use it in GitHub Desktop.
aws-header-filter.pl
#!/usr/bin/perl
use strict;
use warnings;
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;
my $in_header = 1;
my $in_body = 0;
while(<>) {
# Two linebreaks between header & body
if ($in_header && ($_ =~ /^[\n\r]/)) {
$in_header = 0;
$in_body = 1;
}
if ($in_header) { # Once we leave the header, do nothing.
if ($_ =~ /^([\w\d\-]+):/) { # skips indented lines
my $header = $1;
if ($legal_headers{$header}) {
# print "Legal header: $header\n";
print;
} else {
if ($header =~ /^X-/) { # If it's already an X-header, don't touch
print;
} else {
$_ =~ s/^$header:/X-$header:/; # X-ify
print;
}
}
} else {
print;
}
}
# print;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment