Get unread email text without affecting unread state

This is now a gmail field, but sooner or later I want it to scale.

I want to synchronize a copy of my personal personal mailbox (incoming and outgoing) elsewhere, but I do not want to affect the unread state of any unread messages.

What type of access will make this the easiest? I can’t find any information if IMAP affects read status, but it looks like I can manually reset to send an unread message. Pop by definition does not affect unread state, but no one uses pop to access their gmail, why?

+4
source share
6 answers

if this helps anyone, GAE allows you to receive emails as an HTTP request , so now I just forward the emails there.

0
source

In the IMAP world, every message has flags. You can set separate flags for each message. When you select a message, you can actually read the message without using the \ Seen flag.

Most email clients will use the \ Seen flag when reading a message. So, if the message has already been read outside your application, you will need to remove the \ Seen flag.

Just like fyi ... here is the relevant part about flags from the RFC:

A system flag is the name of a flag that is predefined in this specification. All system flags begin with "\". A specific flags system (\ Deleted and \ Seen) describes special semantics elsewhere. Currently, system flags are:

  \Seen Message has been read \Answered Message has been answered \Flagged Message is "flagged" for urgent/special attention \Deleted Message is "deleted" for removal by later EXPUNGE \Draft Message has not completed composition (marked as a draft). \Recent Message is "recently" arrived in this mailbox. This session is the first session to have been notified about this message; if the session is read-write, subsequent sessions will not see \Recent set for this message. This flag can not be altered by the client. If it is not possible to determine whether or not this session is the first session to be notified about a message, then that message SHOULD be considered recent. If multiple connections have the same mailbox selected simultaneously, it is undefined which of these connections will see newly-arrived messages with \Recent set and which will see it without \Recent set. 
+5
source

The IMET FETCH command has the .PEEK option, which does not explicitly set the / Seen flag.

Look at the FETCH command in RFC 3501 and scroll a little to page 57 or search for "BODY.PEEK".

+3
source

You need to specify the section when you use BODY.PEEK. Sections are explained in the IMAP Fetch Command in the BODY [<section>] section <partial →

 import getpass, imaplib M = imaplib.IMAP4() M.login(getpass.getuser(), getpass.getpass()) M.select() typ, data = M.search(None, 'ALL') for num in data[0].split(): typ, data = M.fetch(num, '(BODY.PEEK[])') print 'Message %s\n%s\n' % (num, data[0][5]) M.close() M.logout() 

PS: I wanted to correct the answer received by Gene Wood , but was not allowed, because editing was less than 6 characters (BODY.PEEK → BODY.PEEK [])

+2
source

No one uses POP because they usually require additional IMAP functionality, such as message tracking status. When this functionality only bothers you and requires workarounds, I think using POP is your best bet! -)

+1
source

To answer Dan Goldstein’s answer above , in python, the syntax for using the .PEEK option would be to call IMAP4.fetch and pass it to BODY.PEEK "

To apply this for example in python docs :

 import getpass, imaplib M = imaplib.IMAP4() M.login(getpass.getuser(), getpass.getpass()) M.select() typ, data = M.search(None, 'ALL') for num in data[0].split(): typ, data = M.fetch(num, '(BODY.PEEK)') print 'Message %s\n%s\n' % (num, data[0][5]) M.close() M.logout() 
0
source

All Articles