Use a wrapper around rfc822.Message.fp to find the filename for Maildir/MH
emails. Python 2.5 broke backward compatibility for Maildirs. :-/ Closes: #1670422
This commit is contained in:
parent
c67a75c2f7
commit
255a475978
|
@ -1,3 +1,7 @@
|
||||||
|
Version 0.7.1 - UNRELEASED
|
||||||
|
|
||||||
|
* Fixed incompatibility with Python 2.5 which broke Maildir handling.
|
||||||
|
Closes: #1670422
|
||||||
|
|
||||||
Version 0.7.0 - 2 November 2006
|
Version 0.7.0 - 2 November 2006
|
||||||
* Fixed long options --filter-append and --pwfile to accept their arguments.
|
* Fixed long options --filter-append and --pwfile to accept their arguments.
|
||||||
|
|
|
@ -779,7 +779,7 @@ def guess_delivery_time(message):
|
||||||
# the headers have no valid dates -- last resort, try the file timestamp
|
# the headers have no valid dates -- last resort, try the file timestamp
|
||||||
# this will not work for mbox mailboxes
|
# this will not work for mbox mailboxes
|
||||||
try:
|
try:
|
||||||
file_name = message.fp.name
|
file_name = get_filename(message)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# we are looking at a 'mbox' mailbox - argh!
|
# we are looking at a 'mbox' mailbox - argh!
|
||||||
# Just return the current time - this will never get archived :(
|
# Just return the current time - this will never get archived :(
|
||||||
|
@ -788,7 +788,7 @@ def guess_delivery_time(message):
|
||||||
if not os.path.isfile(file_name):
|
if not os.path.isfile(file_name):
|
||||||
unexpected_error("mailbox file name '%s' has gone missing" % \
|
unexpected_error("mailbox file name '%s' has gone missing" % \
|
||||||
file_name)
|
file_name)
|
||||||
time_message = os.path.getmtime(message.fp.name)
|
time_message = os.path.getmtime(file_name)
|
||||||
vprint("using valid time found from '%s' last-modification time" % \
|
vprint("using valid time found from '%s' last-modification time" % \
|
||||||
file_name)
|
file_name)
|
||||||
return time_message
|
return time_message
|
||||||
|
@ -806,7 +806,8 @@ def add_status_headers(message):
|
||||||
"""
|
"""
|
||||||
status = ""
|
status = ""
|
||||||
x_status = ""
|
x_status = ""
|
||||||
match = re.search(":2,(.+)$", message.fp.name)
|
file_name = get_filename(message)
|
||||||
|
match = re.search(":2,(.+)$", file_name)
|
||||||
if match:
|
if match:
|
||||||
flags = match.group(1)
|
flags = match.group(1)
|
||||||
for flag in flags:
|
for flag in flags:
|
||||||
|
@ -825,7 +826,7 @@ def add_status_headers(message):
|
||||||
|
|
||||||
# files in the maildir 'cur' directory are no longer new,
|
# files in the maildir 'cur' directory are no longer new,
|
||||||
# they are the same as messages with 'Status: O' headers in mbox
|
# they are the same as messages with 'Status: O' headers in mbox
|
||||||
last_dir = os.path.basename(os.path.dirname(message.fp.name))
|
last_dir = os.path.basename(os.path.dirname(file_name))
|
||||||
if last_dir == "cur":
|
if last_dir == "cur":
|
||||||
status = status + "O"
|
status = status + "O"
|
||||||
|
|
||||||
|
@ -881,7 +882,7 @@ def is_flagged(message):
|
||||||
return 1
|
return 1
|
||||||
file_name = None
|
file_name = None
|
||||||
try:
|
try:
|
||||||
file_name = message.fp.name
|
file_name = get_filename(message)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
# maildir mailboxes use the filename suffix to indicate flagged status
|
# maildir mailboxes use the filename suffix to indicate flagged status
|
||||||
|
@ -901,7 +902,7 @@ def is_unread(message):
|
||||||
return 0
|
return 0
|
||||||
file_name = None
|
file_name = None
|
||||||
try:
|
try:
|
||||||
file_name = message.fp.name
|
file_name = get_filename(message)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
# maildir mailboxes use the filename suffix to indicate read status
|
# maildir mailboxes use the filename suffix to indicate read status
|
||||||
|
@ -918,7 +919,7 @@ def sizeof_message(message):
|
||||||
file_name = None
|
file_name = None
|
||||||
message_size = None
|
message_size = None
|
||||||
try:
|
try:
|
||||||
file_name = message.fp.name
|
file_name = get_filename(message)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
if file_name:
|
if file_name:
|
||||||
|
@ -1269,7 +1270,7 @@ def _archive_dir(mailbox_name, final_archive_name, type):
|
||||||
if type == "maildir":
|
if type == "maildir":
|
||||||
add_status_headers(msg)
|
add_status_headers(msg)
|
||||||
archive.write(msg)
|
archive.write(msg)
|
||||||
if not options.dry_run: delete_queue.append(msg.fp.name)
|
if not options.dry_run: delete_queue.append(get_filename(msg))
|
||||||
else:
|
else:
|
||||||
vprint("decision: retain message")
|
vprint("decision: retain message")
|
||||||
msg = original.next()
|
msg = original.next()
|
||||||
|
@ -1463,6 +1464,27 @@ def nice_size_str(size):
|
||||||
if kb >= 1.0: return str(round(kb)) + 'kB'
|
if kb >= 1.0: return str(round(kb)) + 'kB'
|
||||||
return str(size) + 'B'
|
return str(size) + 'B'
|
||||||
|
|
||||||
|
def get_filename(msg):
|
||||||
|
"""If the given rfc822.Message can be identified with a file (no mbox),
|
||||||
|
return the filename, otherwise raise AttributeError."""
|
||||||
|
try:
|
||||||
|
return msg.fp.name
|
||||||
|
except AttributeError:
|
||||||
|
# Ugh, that's ugly. msg.fp is not a plain file, it may be an
|
||||||
|
# instance of
|
||||||
|
# a. mailbox._Subfile
|
||||||
|
# (msg from mailbox.UnixMailbox, Python <= 2.4)
|
||||||
|
# File object is msg.fp.fp, we don't want that
|
||||||
|
# b. mailbox._PartialFile, subclass of mailbox._ProxyFile
|
||||||
|
# (msg from mailbox.UnixMailbox, Python >= 2.5)
|
||||||
|
# File object is msg.fp._file, we don't want that
|
||||||
|
# c. mailbox._ProxyFile
|
||||||
|
# (msg from mailbox.Maildir, Python >= 2.5)
|
||||||
|
# File object is msg.fp._file, we do want that.
|
||||||
|
if msg.fp.__class__ == mailbox._ProxyFile:
|
||||||
|
assert(hasattr(mailbox, "_PartialFile"))
|
||||||
|
return msg.fp._file.name
|
||||||
|
raise
|
||||||
|
|
||||||
# this is where it all happens, folks
|
# this is where it all happens, folks
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue