Skip to content

Commit

Permalink
Create gmail-checker-improved.1m.pl
Browse files Browse the repository at this point in the history
Adding an improved Gmail checker plugins which counts and lists the unread messages. 
You can click on an email link which will open the given email in your default browser. 
Written in Perl, it requires some dependencies:
- LWP::Simple
- LWP::UserAgent
- Mozilla::CA
- XML::Simple
- Encode
- POSIX

You must set your Gmail username and password. 
Optionally you should enable applications with lower security level in your Google Account
  • Loading branch information
axeloz authored and tresni committed Mar 20, 2016
1 parent 56d82a9 commit 5307b57
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Email/gmail-checker-improved.1m.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/perl -w
# <bitbar.title>Gmail Checker Improved</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author.github>axeloz</bitbar.author.github>
# <bitbar.author>Axel</bitbar.author>
# <bitbar.desc>Gmail unread emails checker.</bitbar.desc>
# <bitbar.dependencies>perl,gmail</bitbar.dependencies>
# <bitbar.image>https://imgur.com/gYYJB7U</bitbar.image>

use strict;
use LWP::Simple;
use LWP::UserAgent;
use Mozilla::CA;
use XML::Simple;
use Encode;
use POSIX;

my $url = 'https://mail.google.com/mail/feed/atom';
my $user = '<username>';
my $password = '<password>';
my $output;

my $ua = LWP::UserAgent->new;
$ua->credentials('mail.google.com:443', 'mail.google.com', $user, $password);

my $content = $ua->get($url);
die "Couldn't get $url" unless defined $content;

sub clevercut {
my ($txt, $max) = @_;

if (length($txt) > $max) {
return (substr $txt, 0, $max ).' [...]';
}
return $txt;
}


if ($content->status_line eq '200 OK') {
my $xs = XML::Simple->new();
my $ref = XMLin($content->content, ForceArray=>'entry');

if ($ref->{fullcount}->[0] > 0) {
$output .= "📬\n";
$output .= "---\n";

if ($ref->{fullcount}->[0] == 1) {
$output .= "You have 1 new message | size=16 \n";
}
else {
$output .= "You have ".$ref->{fullcount}->[0]." new messages | size=16 \n";
}
$output .= " | size=14 color=black \n";

foreach my $email (@{ $ref->{entry} }) {
$output .= "» ".clevercut(encode("utf8", $email->{title}->[0]), 30)." | href=".$email->{link}->[0]->{href}."\n";
}

}
else {
$output .= "📪\n";
$output .= "---\n";
$output .= "No new message | size=16 \n";
}
}
$output .= "---\n";
$output .= "➤ Open Mailbox |href=https://www.gmail.com\n";
print $output."\n";

0 comments on commit 5307b57

Please sign in to comment.