Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/usr/bin/env perl -W
- use strict;
- use Net::IMAP::Client;
- use Email::Simple;
- use Config::INI::Simple;
- use Perl6::Parameters;
- use Win32::GUI;
- # read the config
- my $conf = new Config::INI::Simple;
- $conf->read('config.ini');
- my $totalCount = $conf->{General}->{count};
- # go through each account
- for(my $i = 1; $i <= $totalCount; $i++) {
- my $account = $conf->{"Account" . $i};
- checkMail($account->{server},
- $account->{username},
- $account->{password});
- }
- print "Done\n";
- my $TRAY_ICON;
- my $TRAY_WINDOW;
- sub checkMail($server, $user, $password) {
- print "Connect to $server with $user/ $password\n";
- # open a connection to the IMAP server
- my $imap = new Net::IMAP::Client(server => $server);
- $imap->login($user, $password);
- my $inbox = $imap->status('INBOX');
- print "Inbox is ", $inbox, "\n";
- print "Unseen: ", $inbox->{UNSEEN}, "\n";
- if($inbox->{UNSEEN}) {
- showNotification("Unread email!\n");
- }
- }
- sub closeApp() {
- $TRAY_ICON->Remove();
- exit;
- }
- sub tray_Click {
- #Win32::GUI::MessageBox(0, "This should open outlook");
- my $ret = Win32::GUI::ShellExecute($TRAY_WINDOW, 'open', 'outlook.exe', '', '', 10);
- print "ShellExecute ret: $ret\n";
- closeApp();
- }
- sub timer_Timer() {
- print "timer _ TIMER\n";
- closeApp();
- }
- sub showNotification($message){
- my $window = new Win32::GUI::Window(
- -name => "W1",
- -title => "First Window",
- -pos => [ 100, 100 ],
- -size => [ 300, 200 ],
- );
- $TRAY_WINDOW = $window;
- my $timer = $window->AddTimer('timer', 30000);
- my $icon = new Win32::GUI::Icon("tray.ico");
- my $notifyIcon = new Win32::GUI::NotifyIcon($window,
- -name => "Mail Checker",
- -icon => $icon,
- -tip => "Mail Checker",
- -onClick => 'tray_Click'
- );
- $TRAY_ICON = $notifyIcon;
- #my $notifyIcon = $window->addNotifyIcon(-name => "Mail Checker", -tip->"Mail Checker", -icon=>$icon);
- Win32::GUI::Dialog();
- }
Add Comment
Please, Sign In to add comment