ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: Script to fetch IMAP unread / unseen message counts?
by Donn Cave other posts by this author
Feb 18 2003 4:48AM messages near this date
Script to fetch IMAP unread / unseen message counts? | Re: Script to fetch IMAP unread / unseen message counts?
Quoth Gerhard Hring <gerhard.haering@[...].de> :
| * John J Lee <jjl@[...].com>  [2003-02-17 20:51 +0000]:
| >  Anybody have one?
| >  
| >  Google found a couple on a newsgroup, but the URLs given are broken.
|
| Here's a one that I used on my home intranet ;-)
|
| #v+
| #!/usr/bin/env python
|
| import imaplib
|
| class ImapCheckResult:
|     def __init__(self):
| 	self.unseen_messages= 0
| 	self.new_messages = 0
|     
|     def __repr__(self):
| 	return "Unseen: %i, New: %i" % (self.unseen_messages, self.new_messages)
|
| def check_imap_folder(host, user, passwd, foldername):
|     result = ImapCheckResult()
|     imap = imaplib.IMAP4(host)
|     imap.login(user, passwd)
|     typ, data = imap.select(foldername, 1)
|     typ, data = imap.search(None, 'UNSEEN')
|     result.unseen_messages = len(data[0].split())
|     typ, data = imap.search(None, 'NEW')
|     result.new_messages = len(data[0].split())
|     imap.logout()
|     return result
|
| def main():
|     print check_imap_folder("myhost", "myuser", "mypass", "INBOX")

You can also get these particular facts with

    imap.status(foldername, '(UNSEEN RECENT)')
        ->  ('OK', ['folder (RECENT 5 UNSEEN 0)'])

parsing left as an exercise, as usual.

	Donn Cave, donn@[...].com
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
John J Lee
Donn Cave
Michael Budash
Gerhard =?unknown-8bit?Q?H=E4ring?=

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved