#!/usr/bin/perl use strict; use IO::Socket::SSL; use Mail::IMAPClient; use Term::ReadKey; use Term::ANSIColor; my $username = 'pfeifer'; my $server = '0xdef.net'; print "*** unseen emails for user $username for imap-server $server ***\n\n"; print "Password: "; ReadMode('noecho'); my $password = ReadLine(0); print "\n"; chomp $password; ReadMode('normal'); my $ssl = IO::Socket::SSL->new("0xdef.net:imaps") or die $@; my $imap = <$ssl>; $imap = Mail::IMAPClient->new( Socket=>$ssl, User=>$username, Password=>$password, Peek => 1 ); unless($imap) { die "Couldn't log in - $@\n"; } $imap->State($imap->Connected()); $imap->login() or die 'login failed'; $imap->select('INBOX'); my @mails = ($imap->unseen); foreach my $id (@mails) { print "\n\tSubject: "; print color("red"), $imap->parse_headers($id,"Subject")->{"Subject"}->[0]; print color("reset") . "\n"; print "\tFrom: "; print color("magenta"), $imap->parse_headers($id,"From")->{"From"}->[0]; print color("reset") . "\n"; print "\tDate: "; print color("green"), $imap->parse_headers($id,"Date")->{"Date"}->[0]; print color("reset"). "\n"; } exit 0; print "\nShow for which message id?\n"; my $mid = <>; chomp $mid; print "\n\n"; print "imap->message_string yields:\n\n"; print $imap->message_string($mid); print "\n\n"; print "imap->parse_headers yields:\n\n"; my %headers = %{$imap->parse_headers( $mid,"ALL" )}; for my $h ( keys %headers ) { my @hdrs = @{$headers{$h}}; print "$h (".scalar @hdrs." entries)\n"; foreach(@hdrs) { print "\t$_\n"; } } END { print color("reset") }