Package: archivemail
Version: 0.7.0-1
Severity: normal
Hi,
I have been working on archivemail lately :)
Flags are not correctly stored, when archiving mails with IMAP. All
my mails are archived with flag 'O'.
Attached is a patch that fixes that behaviour (Look for the difference
with the following statement:
imaplib.ParseFlags(response[1])
).
It also changes how archivemail determines the flags (and allows the
setting of 'OLD' flag).
I have been using it locally and it works using Dovecot. Please
consider adding the patch.
regards,
Christian
-- System Information:
Debian Release: 4.0
APT prefers stable
APT policy: (990, 'stable'), (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-4-686
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Versions of packages archivemail depends on:
ii python 2.4.4-2 An interactive high-level object-o
archivemail recommends no packages.
-- no debconf information
--- archivemail 2007-07-26 21:42:05.000000000 +0200
+++ archivemail_imap 2007-07-28 22:44:35.000000000 +0200
@@ -869,13 +869,19 @@
status = status + "R"
elif flag == "\\Deleted": # (trashed): user has moved this message to trash
pass # is this Status: D ?
+ elif flag == "Old": # (trashed): user has moved this message to trash
+ status = "O"
else:
pass # no whingeing here, although it could be a good experiment
if flags.count("\\Seen") == 0:
if flags.count("\\Recent") == 1:
status = status + "N"
else:
- status = status + "O"
+ if status != "O":
+ # A mail cannot have status "read" and "old"
+ status = status + "R"
+ if len(flags) == 0:
+ status = "N"
# As with maildir folders, preserve Status and X-Status headers
# if they exist (they shouldn't)
@@ -1387,14 +1393,30 @@
if not options.dry_run:
if not options.delete_old_mail:
for msn in message_list:
- result, response = imap_srv.fetch(msn, '(RFC822 FLAGS)')
+ # RFC 3501 states, that \Seen is automatically set, when
+ # message is fetched, so wee need to first fetch a list of
+ # flags, before fetching the actual message
+ result, response = imap_srv.fetch(msn, '(FLAGS)')
+ if result != 'OK': unexpected_error("Failed to fetch flags; "
+ "server says '%s'" % response[0])
+ print "Flags: %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; "
"server says '%s'" % response[0])
if "\r\n" == os.linesep:
msg_str = response[0][1]
else:
msg_str = response[0][1].replace("\r\n", os.linesep)
- msg_flags = imaplib.ParseFlags(response[1])
+ # the fetching did set \Seen, so unsetting it now, if
+ # it was not set before
+ # This needs only to be done, if option --keep is set
+ # uncomment, when --keep is supported
+ # if options.keep:
+ #if '\\Seen' not in msg_flags or 'Old' in msg_flags:
+ # result, response = imap_srv.store(msn, '-FLAGS', '\\Seen')
+ # if result != 'OK': unexpected_error("Failed to store message flag; "
+ # "server says '%s'" % response[0])
msg = rfc822.Message(cStringIO.StringIO(msg_str))
add_status_headers_imap(msg, msg_flags)
vprint("processing message '%s'" % msg.get('Message-ID'))