Sponsored Content
Top Forums Shell Programming and Scripting perl (conky) and gmail/IMAP unread message count Post 302337795 by gxmsgx on Saturday 25th of July 2009 09:28:55 AM
Old 07-25-2009
perl (conky) and gmail/IMAP unread message count

Hi all,
I use Conky monitor (Conky - Home) for my laptop and I needed a script to see the count of new messages on gmail/IMAP, then I made this small perl script
(I hope they can be useful to someone Smilie)

gimap.pl
Code:
#!/usr/bin/perl

# gimap.pl by gxmsgx
# description: get the count of unread messages on gmail imap

use strict;
use Mail::IMAPClient;
use IO::Socket::SSL;

my $username = 'example.username'; # example.username@gmail.com
my $password = 'password123';

my $socket = IO::Socket::SSL->new(
   PeerAddr => 'imap.gmail.com',
   PeerPort => 993,
  )
  or die "socket(): $@";

my $client = Mail::IMAPClient->new(
   Socket   => $socket,
   User     => $username,
   Password => $password,
  )
  or die "new(): $@";

if ($client->IsAuthenticated()) {
    my $msgct;

    $client->select("INBOX");
    $msgct = $client->unseen_count||'0';
    print "$msgct\n";
}

$client->logout();

on crontab:
Code:
* * * * * ~/scripts/gimap.pl > ~/.email/gimap.ct

on conky file configuration (~/.conky/conky.conf):
Code:
${color1}E-mail: ${color2}gmail ${color1}(imap): ${color3}${execi 20 cat ~/.email/gimap.ct} ${color2}new

conky screenshot:
Image

Last edited by gxmsgx; 07-25-2009 at 11:38 AM..
This User Gave Thanks to gxmsgx For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mark messages as unread

Hi Does anyone know how to mark messages as unread either in Pine or from a Terminal or some such ? Thanks, James (1 Reply)
Discussion started by: Rylann
1 Replies

2. UNIX for Dummies Questions & Answers

fetchmail imap gmail certificate

Guys, could you tell me how to create an imap gmail ssl certificate? in my .fetchmailrc file I have poll imap.gmail.com protocol IMAP user "xxxxx@gmail.com" there with password "xxxx" nofetchall keep ssl but I'm getting an error fetchmail: Server certificate verification error:... (13 Replies)
Discussion started by: c19h28O2
13 Replies

3. Shell Programming and Scripting

Shell script to manipulate a message count for the same IP @ diff session

I have a file as like below, 10:20:30.45 START 10.20.30.40 10:20:31.46 HELLO 10.20.30.40 10:20:32.46 START 10.20.30.41 10:20:33.44 END 10.20.30.40 10:20:35.44 HELLO 10.20.30.41 10:20:36.56 HELLO 10.20.30.41 10:20:37.78 HELLO 10.20.30.41 10:20:38.99 START 10.20.30.40... (1 Reply)
Discussion started by: gobinath
1 Replies

4. Post Here to Contact Site Administrators and Moderators

Does replying to your own message count as an additional post?

There used to be a feature whereby when one would reply to one's own post the response would be added to the previous post as opposed to posted as an additional post. This seems to have been lifted, ie a reply to one's own post is in fact an additional post. What exactly is the rule? And is it true... (2 Replies)
Discussion started by: figaro
2 Replies

5. UNIX for Dummies Questions & Answers

Pine continuously marks old messages as unread

Hi, I have been having problem with pine for the past few weeks. I use email clinet Thunderbird to view my emails. Every time I open the thunderbird, all my emails were marked as unread. So, I logged into our email server to see what's wrong. even when I opened pine, all messages are labeled as... (0 Replies)
Discussion started by: veepine
0 Replies

6. UNIX for Dummies Questions & Answers

How to see unread e-mails only in Alpine?

Does anyone have any idea how to see only unread (new) e-mails in the Alpine client when using IMAP? I finally have a fast IMAP client, but don't want to go over all the e-mails I've already read through other clients... Thanks in advance for any hints. ---------- Post updated at 01:21 PM... (0 Replies)
Discussion started by: JamesR404
0 Replies

7. Linux

CrunchBang: Conky stops updating

Hey I have a problem in CrunchBang with Conky (I user openBox as DE) When I open OpenOffice and it only happens with openOffice, the Conky stops updating every 5th second, and I can acctualy understand why 'cause even if I reset Conky it will not update, I have to sudo halt - not even sudo reboot... (0 Replies)
Discussion started by: looop
0 Replies

8. Shell Programming and Scripting

shell script for conky getting errors....

So I have a script that does a greater than or less than with a variable. My problem is that when I checked the script from the command line I was getting this error.. I am not really familiar with shell scripting. I am trying to get this script to work with conky so that it will do the... (8 Replies)
Discussion started by: krisdeniseriley
8 Replies

9. Emergency UNIX and Linux Support

Find Unread Files

Hi I have requirement to read only unread files from the directory and load into database. Scenario: I do receive bunch of files into my unix directory for every 15 mins. My ETL Process every once in a day and reads the files and loads into db table. I cannot move these file into different... (9 Replies)
Discussion started by: cnrj
9 Replies
IMAP(3) 						User Contributed Perl Documentation						   IMAP(3)

NAME
Cyrus::IMAP - Interface to Cyrus imclient library SYNOPSIS
use Cyrus::IMAP; my $client = Cyrus::IMAP->new('mailhost'[, $flags]); $flags = Cyrus::IMAP::CONN_NONSYNCLITERAL; ($server, $mailbox) = Cyrus::IMAP->fromURL($url); $url = Cyrus::IMAP->toURL($server, $mailbox); $client->setflags($flags); $client->clearflags(Cyrus::IMAP::CONN_INITIALRESPONSE); $flags = $client->flags; $server = $client->servername; $client->authenticate; $flags = Cyrus::IMAP::CALLBACK_NUMBERED || Cyrus::IMAP::CALLBACK_NOLITERAL; $client->addcallback({-trigger => $str, -flags => $flags, -callback => &cb, -rock => $var}, ...); $client->send(&callback, &cbdata, $format, ...); $client->processoneevent; ($result, $text) = $client->send(undef, undef, $format, ...); ($fd, $writepending) = $client->getselectinfo; DESCRIPTION
The Cyrus::IMAP module provides an interface to the Cyrus imclient library. These are primarily useful for implementing cyradm operations within a Perl script; there are easier ways to implement general client operations, although they may be more limited in terms of authentication options when talking to a Cyrus imapd. In the normal case, one will attach to a Cyrus server and authenticate using the best available method: my $client = Cyrus::IMAP::new('imap'); $client->authenticate; if (!$client->send('', '', 'CREATE %s', 'user.' . $username)) { warn "createmailbox user.$username: $@"; } In simple mode as used above, "send()" is invoked with "undef", 0, or '' for the callback and rock (callback data) arguments; it returns a list of "($result, $text)" from the command. If invoked in scalar context, it returns $result and places $text in $@. In this mode, there is no need to use "processoneevent()". If more control is desired, use the callback and rock arguments and invoke "processoneevent()" regularly to receive results from the IMAP server. If still more control is needed, the "getselectinfo()" method returns a list containing a file descriptor (not Perl filehandle) which can be passed to select(); if the second element of the list is true, you should include it in the write mask as well as the read mask because the imclient library needs to perform queued output. For more information, consult the Cyrus documentation. NOTES
"send()" behaves as if the "Cyrus::IMAP::CONN_NONSYNCLITERAL" flag is always set. This is because it is a wrapper for the C version, which cannot be made directly available from Perl, and synchronous literals require interaction with the IMAP server while parsing the format string. This is planned to be fixed in the future. The 'LOGIN' mechanism can be used to authenticate with a plaintext username and password. This is intended as a workaround for a bug in early SASL implementations; use of Cyrus::IMAP with non-Cyrus servers is not recommended, primarily because there are easier ways to implement IMAP client functionality in Perl. (However, if you need SASL support, "Cyrus::IMAP" is currently the only way to get it.) The file descriptor returned by "getselectinfo()" should not be used for anything other than "select()". In particular, I/O on the file descriptor will almost certainly cause more problems than whatever problem you think you are trying to solve. The toURL and fromURL routines are to ease conversion between URLs and IMAP mailbox and server combinations, and are a simple frontend for the libcyrus functions of the same name. The imparse library routines are not implemented, because they are little more than a (failed) attempt to make parsing as simple in C as it is in Perl. This module exists primarily so we can integrate Cyrus administration into our Perl-based account management system, and secondarily so that we can rewrite cyradm in a sensible language instead of Tcl. Usability for other purposes is not guaranteed. AUTHORs Brandon S. Allbery <allbery@ece.cmu.edu>, Rob Siemborski <rjs3+@andrew.cmu.edu> SEE ALSO
Cyrus::IMAP::Admin perl(1), cyradm(1), imclient(3), imapd(8). perl v5.12.1 2008-04-04 IMAP(3)
All times are GMT -4. The time now is 09:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy