gnats-mails mime extractor
Moin moin,
I've attached a little script that lets you extract mime parts of
gnats reports to save as files or STDOUT for you to view.
Because I'm too lazy to hit the website just to see them.
Beware, it's very simple, use at own risk. ;)
Untested with multiple attachments.
# Syntax: ... | gnats-mime [filter] | less
# no arg == save files to $PWD,
# any arg like 'filter' == print to STDOUT means act as filter
So you might pipe such a msg from mutt directly.
Enjoy.
--
© Rado S. -- You must provide YOUR effort for your goal!
Even if it seems insignificant, in fact EVERY effort counts
for a shared task, at least to show your deserving attitude.
#!/usr/bin/perl -w
######
### filter to extract gnatsweb attachments from eMails
### written 2006 by Rado Smiljanic
# Syntax: ... | gnats-mime [filter] | less
# no arg == save files to $PWD, any arg == print to STDOUT
######
### drop leading text
while (my $line=<STDIN>) {
chomp($line);
last if ($line =~ /----gnatsweb-attachment----/);
}
### loop over all parts
while (my $line=<STDIN>) {
my $file='dummy';
### get name
while (my $line=<STDIN>) {
chomp($line);
last if ($line =~ /^ *$/);
if ($line=~ /name="([^"]+)"/) { $file = $1 ; print STDERR "found name:
$file\n";}
}
my $num=2;
my $name=$file;
### serial number not to overwrite
while ( -e $name) {
$name = $file . $num++;
}
if (! @ARGV) {
print STDERR "extracting to: $name\n";
open(SAVE,">$name") || die "can't open $name";
}
my $len;
### convert base64 to text
while (my $line=<STDIN>) {
chomp($line);
last if ($line =~ /^ *$/);
### from 'perldoc -q 64'
$line =~ tr,A-Za-z0-9+/,,cd; # remove non-base64 chars
$line =~ tr,A-Za-z0-9+/, -_,; # convert to uuencoded
format
$len = pack("c", 32 + 0.75*length($line)); # compute length byte
if (! @ARGV) {
print SAVE unpack("u", $len . $line); # uudecode and print
} else {
print unpack("u", $len . $line); # uudecode and print
}
} ### convert
if (! @ARGV) {
close(SAVE);
}
} ### loop over all parts
###
# EOF
###