luke bonham <[email protected]> writes:
> Hi folks,
> anyone here could share a generic mail widget for Awesome 3.5?
>
> I've been trying to use the ones in the User Contributed Widgets section on
> the site, but with no luck.
Hi Luke,
I have a couple of mail accounts, one of which gmail. I just get the
unread count through imap (needs to be enabled within GMail) with a perl
script. I have a small text widget in Awesome that displays the
unread count. Clicking the mail icon launches my mail client.
I have attached the perl script, it currently reads the .authinfo file
(used by gnus) for the server, username and password. It prints the
count to STDOUT. The format of the .authinfo file is:
machine <server> login <username> password <password>
Where each account on a different line. I think it is bad practise to
hardcode credentials into scripts.
How it is set-up it allows for any number of mail accounts.
I incorporate this into awesome as such:
mailbuttonscheme = awful.util.table.join(
awful.button({ }, 1, function () awful.util.spawn_with_shell("emacs -gnus")
end))
mailwidget = wibox.widget.textbox()
mailwidget:set_font(beautiful.widget_font)
vicious.register(mailwidget,
vicious.widgets.uptime,
function(widget,args)
local f = assert(io.popen(os.getenv("HOME") ..
'/.scripts/mailcheck/checkunread.pl', 'r'))
local unread = f:read('*all')
f:close()
return unread
end, 60)
mailicon = wibox.widget.imagebox()
mailicon:set_image("someicon.png")
mailicon:buttons(mailbuttonscheme)
mailwidget:buttons(mailbuttonscheme)
Hope it helps.
Cheers!
Jacco
#!/usr/bin/perl
# checkunread.pl by i_magnific0
# description: count number of unread messages on imap
use strict;
use Mail::IMAPClient;
use IO::Socket::SSL;
open(AUTHFILE, '<', $ENV{"HOME"} . '/.authinfo');
while (<AUTHFILE>)
{
my @config = split(' ', $_);
my $server = $config[1];
my $username = $config[3];
my $password = $config[5];
#print "Authenticating with $username @ $server\n";
my $socket = IO::Socket::SSL->new(
PeerAddr => $server,
PeerPort => 993
)
or sortofdie();
my $client = Mail::IMAPClient->new(
Socket => $socket,
User => $username,
Password => $password,
)
or sortofdie();
my $msgct = 'a';
if ($client->IsAuthenticated()) {
$client->select("INBOX");
$msgct = $client->unseen_count||'0';
}
print "$msgct ";
$client->logout();
}
close (AUTHFILE);
sub sortofdie {
print "e ";
next;
}