Guest User

Untitled

a guest
May 27th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #/usr/bin/env perl -W
  2.  
  3. use strict;
  4. use Net::IMAP::Client;
  5. use Email::Simple;
  6. use Config::INI::Simple;
  7. use Perl6::Parameters;
  8. use Win32::GUI;
  9.  
  10.  
  11. # read the config
  12. my $conf = new Config::INI::Simple;
  13. $conf->read('config.ini');
  14. my $totalCount = $conf->{General}->{count};
  15.  
  16. # go through each account
  17. for(my $i = 1; $i <= $totalCount; $i++) {
  18. my $account = $conf->{"Account" . $i};
  19.  
  20. checkMail($account->{server},
  21. $account->{username},
  22. $account->{password});
  23.  
  24. }
  25.  
  26. print "Done\n";
  27.  
  28. my $TRAY_ICON;
  29. my $TRAY_WINDOW;
  30.  
  31.  
  32. sub checkMail($server, $user, $password) {
  33. print "Connect to $server with $user/ $password\n";
  34.  
  35. # open a connection to the IMAP server
  36. my $imap = new Net::IMAP::Client(server => $server);
  37. $imap->login($user, $password);
  38.  
  39. my $inbox = $imap->status('INBOX');
  40. print "Inbox is ", $inbox, "\n";
  41. print "Unseen: ", $inbox->{UNSEEN}, "\n";
  42.  
  43. if($inbox->{UNSEEN}) {
  44. showNotification("Unread email!\n");
  45. }
  46.  
  47. }
  48.  
  49. sub closeApp() {
  50. $TRAY_ICON->Remove();
  51. exit;
  52. }
  53.  
  54. sub tray_Click {
  55. #Win32::GUI::MessageBox(0, "This should open outlook");
  56. my $ret = Win32::GUI::ShellExecute($TRAY_WINDOW, 'open', 'outlook.exe', '', '', 10);
  57. print "ShellExecute ret: $ret\n";
  58. closeApp();
  59. }
  60.  
  61. sub timer_Timer() {
  62. print "timer _ TIMER\n";
  63. closeApp();
  64. }
  65.  
  66.  
  67. sub showNotification($message){
  68. my $window = new Win32::GUI::Window(
  69. -name => "W1",
  70. -title => "First Window",
  71. -pos => [ 100, 100 ],
  72. -size => [ 300, 200 ],
  73. );
  74. $TRAY_WINDOW = $window;
  75.  
  76. my $timer = $window->AddTimer('timer', 30000);
  77.  
  78. my $icon = new Win32::GUI::Icon("tray.ico");
  79. my $notifyIcon = new Win32::GUI::NotifyIcon($window,
  80. -name => "Mail Checker",
  81. -icon => $icon,
  82. -tip => "Mail Checker",
  83. -onClick => 'tray_Click'
  84. );
  85. $TRAY_ICON = $notifyIcon;
  86. #my $notifyIcon = $window->addNotifyIcon(-name => "Mail Checker", -tip->"Mail Checker", -icon=>$icon);
  87.  
  88.  
  89. Win32::GUI::Dialog();
  90.  
  91.  
  92. }
Add Comment
Please, Sign In to add comment