forked from matryer/xbar-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |