use strict; use warnings; use feature ':5.10'; use Config::Pit; use Mail::IMAPClient; use IO::Socket::SSL; use Email::Simple; use Net::Growl; use Time::HiRes; &main;exit; sub DEBUG (@) { say @_ if $ENV{DEBUG}; } sub conf { state $conf = pit_get( 'gmail2growl.pl', require => { gmail => { username => 'username', password => 'password', folder => 'target folder', }, growl => { host => 'growl host', password => 'growl password', } } ); $conf; } sub main { my $conf = conf; DEBUG "CONNECTING"; my $socket = IO::Socket::SSL->new( PeerAddr => 'imap.gmail.com', PeerPort => 993, ) or die "socket(): $@"; my $imap = Mail::IMAPClient->new( Socket => $socket, User => $conf->{gmail}->{username}, Password => $conf->{gmail}->{password}, ) or die "Cannot connect to gmail as $conf->{gmail}->{username}: $@"; DEBUG "SELECT FOLDER"; $imap->select($conf->{gmail}->{folder}) or die "cannot select $conf->{gmail}->{folder}: $@\n"; DEBUG "GET MESSAGE LIST"; my @unseen = $imap->unseen; DEBUG "UNSEEN COUNT IS : @{[ scalar @unseen ]}"; for my $uid (@unseen) { my $message = $imap->message_string($uid) or die "cannot get message_string($uid), $@"; my $mail = Email::Simple->new($message); DEBUG "DO GROWL"; growl($mail->header('Subject'), $mail->body); sleep 0.1; } DEBUG "APPLY seen FLAG"; $imap->set_flag('seen', @unseen); DEBUG "DISCONNECT"; $imap->disconnect; } sub growl { my ($title, $description) = @_; my $conf = conf; warn "GROWLING $title.... $description---"; state $registered = 0; unless ($registered) { register( application => $0, host => $conf->{growl}->{host}, password => $conf->{growl}->{password}, ); $registered++; } notify( application => $0, title => $title, description => $description, priority => 2, sticky => 'True', host => $conf->{growl}->{host}, password => $conf->{growl}->{password}, ); } __END__ =head1 AUTHOR Tokuhiro Matsuno =head1 LICENSE same as perl5.10 =head1 SEE ALSO L L L