1
0
Fork 0
mirror of https://git.code.sf.net/p/archivemail/code synced 2024-12-23 00:06:43 +00:00

IMAP: first fetch message flags, then the body. Doing it together always

returns the \Seen flag set.  
Closes: Debian bug #434807 (well, the outstanding part of it).
This commit is contained in:
Nikolaus Schulz 2007-11-02 13:21:18 +00:00
parent 130a5ef117
commit 0eba452d93

View file

@ -1388,14 +1388,19 @@ def _archive_imap(mailbox_name, final_archive_name):
if not options.dry_run: if not options.dry_run:
if not options.delete_old_mail: if not options.delete_old_mail:
for msn in message_list: for msn in message_list:
result, response = imap_srv.fetch(msn, '(RFC822 FLAGS)') # Fetching message flags and body together always finds \Seen
# set. To check \Seen, we must fetch the flags first.
result, response = imap_srv.fetch(msn, '(FLAGS)')
if result != 'OK': unexpected_error("Failed to fetch message "
"flags; server says '%s'" % response[0])
msg_flags = imaplib.ParseFlags(response[0])
result, response = imap_srv.fetch(msn, '(RFC822)')
if result != 'OK': unexpected_error("Failed to fetch message; " if result != 'OK': unexpected_error("Failed to fetch message; "
"server says '%s'" % response[0]) "server says '%s'" % response[0])
if "\r\n" == os.linesep: if "\r\n" == os.linesep:
msg_str = response[0][1] msg_str = response[0][1]
else: else:
msg_str = response[0][1].replace("\r\n", os.linesep) msg_str = response[0][1].replace("\r\n", os.linesep)
msg_flags = imaplib.ParseFlags(response[0][0])
msg = rfc822.Message(cStringIO.StringIO(msg_str)) msg = rfc822.Message(cStringIO.StringIO(msg_str))
add_status_headers_imap(msg, msg_flags) add_status_headers_imap(msg, msg_flags)
vprint("processing message '%s'" % msg.get('Message-ID')) vprint("processing message '%s'" % msg.get('Message-ID'))