aboutsummaryrefslogtreecommitdiffstats
path: root/archivemail.py
diff options
context:
space:
mode:
authorPaul Rodger <paul@paulrodger.com>2002-09-15 06:14:57 +0000
committerPaul Rodger <paul@paulrodger.com>2002-09-15 06:14:57 +0000
commit3939c4851857a3691ea7d6689009d633769af642 (patch)
tree453ed11be16d9514a321eda9933762c0ff350990 /archivemail.py
parent5264ab35cdf5c3f0aca660f3d5e3ed52290e6007 (diff)
downloadarchivemail-3939c4851857a3691ea7d6689009d633769af642.tar.gz
archivemail-3939c4851857a3691ea7d6689009d633769af642.tar.bz2
archivemail-3939c4851857a3691ea7d6689009d633769af642.zip
Fixed a bug where mailbox locking would fail under Solaris, also fixed
a bug where archiving maildir mailboxes without a 'Received Date' or 'From' header would fail. Removed another assert() statement that would crash on the unix epoch.
Diffstat (limited to 'archivemail.py')
-rwxr-xr-xarchivemail.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/archivemail.py b/archivemail.py
index a9c882a..ea7c5e5 100755
--- a/archivemail.py
+++ b/archivemail.py
@@ -22,7 +22,7 @@ Website: http://archivemail.sourceforge.net/
"""
# global administrivia
-__version__ = "archivemail v0.4.9"
+__version__ = "archivemail v0.5.0"
__cvs_id__ = "$Id$"
__copyright__ = """Copyright (C) 2002 Paul Rodger <paul@paulrodger.com>
This is free software; see the source for copying conditions. There is NO
@@ -51,6 +51,7 @@ import getopt
import gzip
import mailbox
import os
+import pwd
import re
import rfc822
import shutil
@@ -274,13 +275,13 @@ class Mbox(mailbox.UnixMailbox):
original_mode = None # file permissions to preserve
starting_size = None # file size of mailbox on open
- def __init__(self, path, mode="r"):
+ def __init__(self, path, mode="r+"):
"""Constructor for opening an existing 'mbox' mailbox.
Extends constructor for mailbox.UnixMailbox()
Named Arguments:
path -- file name of the 'mbox' file to be opened
- mode -- mode to open the file in (default is read-only)
+ mode -- mode to open the file in (default is read-write)
"""
assert(path)
@@ -653,22 +654,32 @@ def make_mbox_from(message):
"""
assert(message)
- address_header = message.get('Return-path')
- if not address_header:
- vprint("make_mbox_from: no Return-path -- using 'From:' instead!")
- address_header = message.get('From')
- (name, address) = rfc822.parseaddr(address_header)
-
+ address = guess_return_path(message)
time_message = guess_delivery_time(message)
- assert(time_message)
gm_date = time.gmtime(time_message)
assert(gm_date)
date_string = time.asctime(gm_date)
-
mbox_from = "From %s %s\n" % (address, date_string)
return mbox_from
+def guess_return_path(message):
+ """Return a guess at the Return Path address of an rfc822 message"""
+ assert(message)
+
+ for header in ('Return-path', 'From'):
+ address_header = message.get('header')
+ if address_header:
+ (name, address) = rfc822.parseaddr(address_header)
+ if address:
+ return address
+ # argh, we can't find any valid 'Return-path' guesses - just
+ # just use the current unix username like mutt does
+ login = pwd.getpwuid(os.getuid())[0]
+ assert(login)
+ return login
+
+
def guess_delivery_time(message):
"""Return a guess at the delivery date of an rfc822 message"""
assert(message)
@@ -691,7 +702,6 @@ def guess_delivery_time(message):
if date:
try:
time_message = time.mktime(date)
- assert(time_message)
vprint("using valid time found from unix 'From_' header")
return time_message
except (ValueError, OverflowError): pass