Skip to content

Instantly share code, notes, and snippets.

@ehamberg
Created April 15, 2011 11:14
Show Gist options
  • Save ehamberg/921537 to your computer and use it in GitHub Desktop.
Save ehamberg/921537 to your computer and use it in GitHub Desktop.
Old perl script for dumping JPEG images from an mbox
#!/usr/bin/perl
use MIME::Base64;
use Encode 'from_to';
open(MBOX, $ARGV[0]);
@mailbox = <MBOX>;
$b = join('', @mailbox);
@a = split(/\nFrom /, $b);
foreach $mail (@a) {
if ($mail =~ m/Subject: .*Foto/) {
$mail =~ m/Content-Type: TEXT\/PLAIN;.*BASE64\n\n(.*)----_.*Content-Disposition: attachment;\n.*?filename="(.*?)"\n.*?\n\n(.*)----_/s;
#print $1;
#print $2;
$c = join('', $3);
$file = "/tmp/$2";
open(FILE, ">$file");
print FILE decode_base64($c);
close(FILE);
#print pack("C*", unpack("U*", decode_base64($1)));
$text = decode_base64($1);
print "$text\n";
print length($text);
print "\n";
}
}
close(MBOX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment