Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch an email with imaplib but do not mark it as SEEN

I want to parse some emails from a user 's inbox but when I do:

typ, msg_data = imap_conn.fetch(uid, '(RFC822)')

It marks the email as SEEN or read. This is not the desired functionality. Do you know how can I keep the email at its previous stare either SEEN or NOT SEEN?

like image 408
PanosJee Avatar asked Jul 19 '10 17:07

PanosJee


3 Answers

You might also set read_only to true when selecting the folder:

imap_conn.select('Inbox', readonly=True)
like image 185
lezardo Avatar answered Oct 22 '22 14:10

lezardo


The following should work:

typ, msg_data = imap_conn.fetch(uid, '(BODY.PEEK[HEADER])')

or BODY.PEEK[TEXT], etc.

like image 43
ars Avatar answered Oct 22 '22 12:10

ars


You can use (RFC822.PEEK) as the "message-parts" argument, according to RFC 1730 (I have not verified which servers actually implement that correctly, but it doesn't seem hard for them to).

like image 32
Alex Martelli Avatar answered Oct 22 '22 12:10

Alex Martelli