Re: Script to fetch IMAP unread / unseen message counts?
by Gerhard =?unknown-8bit?Q?H=E4ring?= other posts by this author
Feb 17 2003 9:39PM messages near this date
Re: Script to fetch IMAP unread / unseen message counts?
|
Tkinter: drag-and-drop files (filenames) onto application?
* 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")
if __name__ == '__main__':
main()
#v-
Gerhard
--
Favourite database: http://www.postgresql.org/
Favourite programming language: http://www.python.org/
Combine the two: http://pypgsql.sf.net/
Embedded database for Python: http://pysqlite.sf.net/
--
http://mail.python.org/mailman/listinfo/python-list
Thread:
John J Lee
Donn Cave
Michael Budash
Gerhard =?unknown-8bit?Q?H=E4ring?=
|