#!c:\perl\bin\perl.exe
use strict;
use File::Path;
use File::Spec;
use GD;
use Mail::POP3Client;
use Mail::Internet;
use constant DESTINATION => q{d:\DigitalPhotos\Tivo\EMail};
use constant PREVIEW_LINES => 100;
use constant WIDTH => 640;
use constant HEIGHT => 480;
use constant HEADER_FONT => gdMediumBoldFont;
use constant BODY_FONT => gdLargeFont;
my @accounts = (
{
DESC => q{thoellri@foobar.com},USER => "thoellri",AUTH_MODE => "PASS",PASSWORD => "password",HOST => "pop3.foobar.com"}, { DESC => q{tobias@somewhere.com},USER => "tobias", AUTH_MODE => "PASS",PASSWORD => "password",HOST => "mail.somewhere.com"
},
);
for my $account (@accounts) {
# erase existing messages
rmtree([ File::Spec->catfile(DESTINATION, $account->{DESC}) ], 0, 0);
my $pop = new Mail::POP3Client (%$account);
unless ($pop) { warn "Couldn't connect\n"; next; }
my $count = $pop->Count;
if ($count <0) { warn "Authorization failed"; next; }
next if($count == 0); # no new messages
# create new directory for messages
mkpath([ File::Spec->catfile(DESTINATION, $account->{DESC}) ], 0, 0711);
for my $num (1..$count) {
my @preview=$pop->HeadAndBody($num,100);
my $mail=Mail::Internet->new(\@preview);
my $header=$mail->head;
my $image=render($mail);
my $out=File::Spec->catfile(DESTINATION, $account->{DESC},qq{message-}.
sprintf("%02d",$num).qq{.png});
open(OUT, qq{>$out});
binmode OUT;
print OUT $image->png;
close(OUT);
}
$pop->Close;
}
sub render {
my($m)=@_;
my $header=$m->head( );
my $im = new GD::Image(WIDTH, HEIGHT);
# allocate some colors
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my $gray = $im->colorAllocate(20,20,20);
my $red = $im->colorAllocate(255,0,0);
my $blue = $im->colorAllocate(0,0,255);
my $y=2;
$im->string(HEADER_FONT, 5,$y, "Date: ".$header->get('Date'),↵
$black);$y+=10;
$im->string(HEADER_FONT, 5,$y, "From: ".$header->get('From'),↵
$black);$y+=10;
$im->string(HEADER_FONT, 5,$y, "To: ".$header->get('To'),↵
$black);$y+=10;
$im->string(HEADER_FONT, 5,$y, "Subject: ".$header->get('Subject'),↵
$blue);$y+=10;
$im->string(HEADER_FONT, 5,$y, "-" x 80, $black);$y+=8;
foreach my $line (@{$m->body( )}) {
chomp($line);
$im->string(BODY_FONT, 5, $y, $line, $gray);
$y+=13; last if($y>=HEIGHT);
}
return $im;
}
From youbet:
Business Christmas Cards (http://www.postit4u.com.au/Business-Christmas-Cards.html)