mirror of
https://git.code.sf.net/p/archivemail/code
synced 2025-01-03 13:44:46 +00:00
Added MH mailbox support.
This commit is contained in:
parent
57ed36ea53
commit
f90bd01a74
1 changed files with 30 additions and 9 deletions
|
@ -50,7 +50,7 @@ import tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# global administrivia
|
# global administrivia
|
||||||
__version__ = "archivemail v0.1.0"
|
__version__ = "archivemail v0.2.0"
|
||||||
__cvs_id__ = "$Id$"
|
__cvs_id__ = "$Id$"
|
||||||
__copyright__ = """Copyright (C) 2002 Paul Rodger <paul@paulrodger.com>
|
__copyright__ = """Copyright (C) 2002 Paul Rodger <paul@paulrodger.com>
|
||||||
This is free software; see the source for copying conditions. There is NO
|
This is free software; see the source for copying conditions. There is NO
|
||||||
|
@ -451,11 +451,15 @@ manually, and try running me again.""" % final_name)
|
||||||
class IdentityCache:
|
class IdentityCache:
|
||||||
seen_ids = {}
|
seen_ids = {}
|
||||||
mailbox_name = None
|
mailbox_name = None
|
||||||
|
|
||||||
def __init__(self, mailbox_name):
|
def __init__(self, mailbox_name):
|
||||||
assert(mailbox_name)
|
assert(mailbox_name)
|
||||||
self.mailbox_name = mailbox_name
|
self.mailbox_name = mailbox_name
|
||||||
|
|
||||||
def warn_if_dupe(self, msg):
|
def warn_if_dupe(self, msg):
|
||||||
|
assert(msg)
|
||||||
message_id = msg.get('Message-ID')
|
message_id = msg.get('Message-ID')
|
||||||
|
assert(message_id)
|
||||||
if self.seen_ids.has_key(message_id):
|
if self.seen_ids.has_key(message_id):
|
||||||
user_warning("duplicate message id: '%s' in mailbox '%s'" %
|
user_warning("duplicate message id: '%s' in mailbox '%s'" %
|
||||||
(message_id, self.mailbox_name))
|
(message_id, self.mailbox_name))
|
||||||
|
@ -573,11 +577,13 @@ def make_mbox_from(message):
|
||||||
|
|
||||||
def get_date_mtime(message):
|
def get_date_mtime(message):
|
||||||
"""Return the delivery date of an rfc822 message in a maildir mailbox"""
|
"""Return the delivery date of an rfc822 message in a maildir mailbox"""
|
||||||
|
assert(message)
|
||||||
vprint("using last-modification time of message file")
|
vprint("using last-modification time of message file")
|
||||||
return os.path.getmtime(message.fp.name)
|
return os.path.getmtime(message.fp.name)
|
||||||
|
|
||||||
def get_date_headers(message):
|
def get_date_headers(message):
|
||||||
"""Return the delivery date of an rfc822 message in a mbox mailbox"""
|
"""Return the delivery date of an rfc822 message in a mbox mailbox"""
|
||||||
|
assert(message)
|
||||||
date = message.getdate('Date')
|
date = message.getdate('Date')
|
||||||
delivery_date = message.getdate('Delivery-date')
|
delivery_date = message.getdate('Delivery-date')
|
||||||
use_date = None
|
use_date = None
|
||||||
|
@ -635,6 +641,8 @@ def archive(mailbox_name):
|
||||||
already exists
|
already exists
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
assert(mailbox_name)
|
||||||
|
|
||||||
tempfile.tempdir = choose_temp_dir(mailbox_name)
|
tempfile.tempdir = choose_temp_dir(mailbox_name)
|
||||||
vprint("set tempfile directory to '%s'" % tempfile.tempdir)
|
vprint("set tempfile directory to '%s'" % tempfile.tempdir)
|
||||||
|
|
||||||
|
@ -655,10 +663,10 @@ def archive(mailbox_name):
|
||||||
new_path = os.path.join(mailbox_name, "new")
|
new_path = os.path.join(mailbox_name, "new")
|
||||||
if os.path.isdir(cur_path) and os.path.isdir(new_path):
|
if os.path.isdir(cur_path) and os.path.isdir(new_path):
|
||||||
vprint("guessing mailbox is of type: maildir")
|
vprint("guessing mailbox is of type: maildir")
|
||||||
_archive_maildir(mailbox_name, final_archive_name)
|
_archive_dir(mailbox_name, final_archive_name, "maildir")
|
||||||
else:
|
else:
|
||||||
vprint("guessing mailbox is of type: MH")
|
vprint("guessing mailbox is of type: MH")
|
||||||
_archive_mh(mailbox_name, final_archive_name)
|
_archive_dir(mailbox_name, final_archive_name, "mh")
|
||||||
else:
|
else:
|
||||||
user_error("'%s': no such file or directory" % mailbox_name)
|
user_error("'%s': no such file or directory" % mailbox_name)
|
||||||
|
|
||||||
|
@ -672,6 +680,9 @@ def _archive_mbox(mailbox_name, final_archive_name):
|
||||||
old messages to - appending if the archive
|
old messages to - appending if the archive
|
||||||
already exists
|
already exists
|
||||||
"""
|
"""
|
||||||
|
assert(mailbox_name)
|
||||||
|
assert(final_archive_name)
|
||||||
|
|
||||||
archive = None
|
archive = None
|
||||||
retain = None
|
retain = None
|
||||||
stats = Stats(mailbox_name, final_archive_name)
|
stats = Stats(mailbox_name, final_archive_name)
|
||||||
|
@ -734,13 +745,24 @@ def _archive_mbox(mailbox_name, final_archive_name):
|
||||||
stats.display()
|
stats.display()
|
||||||
|
|
||||||
|
|
||||||
def _archive_maildir(mailbox_name, final_archive_name):
|
def _archive_dir(mailbox_name, final_archive_name, type):
|
||||||
"""Archive a 'maildir' style mailbox - used by archive_mailbox()"""
|
"""Archive a 'maildir' or 'MH' style mailbox - used by archive_mailbox()"""
|
||||||
|
assert(mailbox_name)
|
||||||
|
assert(final_archive_name)
|
||||||
|
assert(type)
|
||||||
|
original = None
|
||||||
archive = None
|
archive = None
|
||||||
stats = Stats(mailbox_name, final_archive_name)
|
stats = Stats(mailbox_name, final_archive_name)
|
||||||
delete_queue = []
|
delete_queue = []
|
||||||
original = mailbox.Maildir(mailbox_name)
|
|
||||||
|
if type == "maildir":
|
||||||
|
original = mailbox.Maildir(mailbox_name)
|
||||||
|
elif type == "mh":
|
||||||
|
original = mailbox.MHMailbox(mailbox_name)
|
||||||
|
else:
|
||||||
|
unexpected_error("unknown type: %s" % type)
|
||||||
assert(original)
|
assert(original)
|
||||||
|
|
||||||
cache = IdentityCache(mailbox_name)
|
cache = IdentityCache(mailbox_name)
|
||||||
|
|
||||||
msg = original.next()
|
msg = original.next()
|
||||||
|
@ -779,9 +801,6 @@ def _archive_maildir(mailbox_name, final_archive_name):
|
||||||
if not _options.quiet:
|
if not _options.quiet:
|
||||||
stats.display()
|
stats.display()
|
||||||
|
|
||||||
def _archive_mh(mailbox_name, final_archive_name):
|
|
||||||
"""Archive a 'MH' style mailbox - see archive_mailbox()"""
|
|
||||||
unexpected_error("'MH' type mailbox support not yet implemented")
|
|
||||||
|
|
||||||
############### misc functions ###############
|
############### misc functions ###############
|
||||||
|
|
||||||
|
@ -812,6 +831,7 @@ def choose_temp_dir(mailbox_path):
|
||||||
mailbox_path -- path name to the original mailbox
|
mailbox_path -- path name to the original mailbox
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
assert(mailbox_path)
|
||||||
temp_dir = os.path.dirname(mailbox_path)
|
temp_dir = os.path.dirname(mailbox_path)
|
||||||
if _options.output_dir:
|
if _options.output_dir:
|
||||||
temp_dir = _options.output_dir
|
temp_dir = _options.output_dir
|
||||||
|
@ -821,6 +841,7 @@ def choose_temp_dir(mailbox_path):
|
||||||
|
|
||||||
def system_or_die(command):
|
def system_or_die(command):
|
||||||
"""Run the command with os.system(), aborting on non-zero exit"""
|
"""Run the command with os.system(), aborting on non-zero exit"""
|
||||||
|
assert(command)
|
||||||
rv = os.system(command)
|
rv = os.system(command)
|
||||||
if (rv != 0):
|
if (rv != 0):
|
||||||
status = os.WEXITSTATUS(rv)
|
status = os.WEXITSTATUS(rv)
|
||||||
|
|
Loading…
Reference in a new issue