Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 18th, 2005, 10:56 PM
Raghul
Guest
 
Posts: n/a
Default reading only new messages in imaplib

Is it posssible to read only the new messages or unread messages using
imaplib in python? If it is possible pls specify the module or give a
sample code.

Thanks in advance

  #2  
Old July 18th, 2005, 10:57 PM
Kartic
Guest
 
Posts: n/a
Default Re: reading only new messages in imaplib

Raghul said the following on 2/22/2005 11:24 PM:[color=blue]
> Is it posssible to read only the new messages or unread messages using
> imaplib in python? If it is possible pls specify the module or give a
> sample code.
>
> Thanks in advance
>[/color]


import imaplib, sys

conn = imaplib.IMAP4_SSL(host='mail.example.com')
# or conn =imaplib.IMAP4(host='mail.example.com') for no SSL

try:
(retcode, capabilities) = conn.login('user', 'pass')
except:
print sys.exc_info()[1]
sys.exit(1)
conn.select(readonly=1) # Select inbox or default namespace
(retcode, messages) = conn.search(None, '(UNSEEN)')
if retcode == 'OK':
for message in messages[0].split(' '):
print 'Processing :', message
(ret, mesginfo) = conn.fetch(message, '(BODY[HEADER.FIELDS (SUBJECT
FROM)])')
if ret == 'OK':
print mesginfo,'\n',30*'-'
conn.close()


Please also go thru the IMAP RFC to learn more about the flags field and
the IMAP protocol in general. If you're developing something serious
using IMAP, it will be very beneficial to you to understand the protocol.

http://www.imap.org/papers/biblio.html

Thanks,
-Kartic
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles