Commits

Xu Xiaodong committed ad3a1c3

update gmailcount.pl

  • Participants
  • Parent commits 2ea3817

Comments (0)

Files changed (1)

File gmailcount.pl

 #!/usr/bin/env perl
 #
-# name:      gmail unread count for conky
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Feb  7
-# modified:  2011 Apr 27
+# name     : gmailcount, gmail unread count for conky
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : MIT
+# created  : 2011 Feb  7
+# modified : 2012 May 12
 #
 
 use strict;
 use warnings;
-
 use Config::Tiny;
 use Mail::IMAPClient;
 
-my $conf = Config::Tiny->read("$ENV{HOME}/.gaccountrc");
-
-# Account information
+# Read Gmail account information
+my $conf = Config::Tiny->read("$ENV{HOME}/.secret")
+  or die Config::Tiny->errstr;
 my $user = $conf->{gmail}->{user};
 my $pass = $conf->{gmail}->{pass};
 
 # Gmail unread count
-my $imap = Mail::IMAPClient->new(
-    Server   => 'imap.gmail.com',
-    User     => $user,
-    Password => $pass,
-    Port     => 993,
-    Ssl      => 1,
+my $count = 0;
+my $imap  = Mail::IMAPClient->new(
+  Server   => 'imap.gmail.com',
+  User     => $user,
+  Password => $pass,
+  Port     => 993,
+  Ssl      => 1,
 );
 
-my $gmail_count = $imap->unseen_count('Inbox') || 0;
-
-$imap->logout();
+if ( defined $imap ) {
+  $count = $imap->unseen_count('Inbox');
+  $imap->logout();
+}
 
 # Output result
-print $gmail_count;
+print $count;