473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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

Jul 18 '05 #1
1 4911
Raghul said the following on 2/22/2005 11:24 PM:
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

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
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bill Sneddon | last post by:
Anyone have an example they are willing to share that shows how to use the store command in imaplib? store( message_set, command, flag_list) Alters flag dispositions for messages in mailbox. ...
0
by: Mr. Magoo | last post by:
I'm working with imaplib. I'm trying to flag (or move or copy - anything that takes a message_set as an argument) a bunch of messages with one command and am having trouble. === def...
1
by: Colin Brown | last post by:
The Python 2.3 documentation in imaplib says: Internaldate2tuple( datestr) Converts an IMAP4 INTERNALDATE string to Coordinated Universal Time. Returns a time module tuple. Time2Internaldate(...
0
by: Wolfgang Kohnen | last post by:
Hello out there! I am new to python and so far I like it a lot. Now I want to create some IMAP mailboxes on my cyrus imapd, with quotas and each user should be subscribed to her/his own spam...
2
by: huw.lynes | last post by:
So I have the unfortunate task of migrating several hundred users from local mail (mbox and mh) up to an exchange server as part of wearisome SOX compliance nonsense. I thought the best path...
5
by: Antoon Pardon | last post by:
This little program gives IMO a strange result. import imaplib user = "cpapen" cyr = imaplib.IMAP4("imap.vub.ac.be") cyr.login("cyrus", "cOn-A1r") rc, lst = cyr.list('""', "user/%s/*" %...
1
by: csselo | last post by:
Hi I am looking for a code sample which searches mail by date with imaplib example: get email from 01.01.2007 to now how can I change imaplib search parameters?
1
by: aspineux | last post by:
imaplib use exception to report errors, but some problems must be detected by checking the return value ! For example, when trying to append into a mailbox with wrong ACL, imaplib return 'NO',...
0
by: aspineux | last post by:
setacl and getacl look to be already "Cyrus" specific (according the doc), why not to extend imaplib a little bit more ? Here are some code I wrote and tested to support cyrus "expire" that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.