summaryrefslogtreecommitdiff
path: root/Mailman/Mailbox.py
diff options
context:
space:
mode:
authorbwarsaw2000-09-14 04:04:17 +0000
committerbwarsaw2000-09-14 04:04:17 +0000
commitc9286082111b1a5b33219ceef0643d3bb2efcfcf (patch)
tree7c58f9c1d6baef740f098b133cc18a3efe1369f2 /Mailman/Mailbox.py
parentfb6258d849f2cca9bd1e789e6f509b35d511f218 (diff)
downloadmailman-c9286082111b1a5b33219ceef0643d3bb2efcfcf.tar.gz
mailman-c9286082111b1a5b33219ceef0643d3bb2efcfcf.tar.zst
mailman-c9286082111b1a5b33219ceef0643d3bb2efcfcf.zip
Diffstat (limited to 'Mailman/Mailbox.py')
-rw-r--r--Mailman/Mailbox.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/Mailman/Mailbox.py b/Mailman/Mailbox.py
index 47f18ea0b..290c0715c 100644
--- a/Mailman/Mailbox.py
+++ b/Mailman/Mailbox.py
@@ -17,20 +17,29 @@
"Extend mailbox.UnixMailbox."
-
+import errno
import mailbox
+
+
class Mailbox(mailbox.UnixMailbox):
# msg should be an rfc822 message or a subclass.
def AppendMessage(self, msg):
- # seek to the last char of the mailbox
- self.fp.seek(1,2)
- if self.fp.read(1) <> '\n':
- self.fp.write('\n')
+ # Check the last character of the file and write a newline if it isn't
+ # a newline (but not at the beginning of an empty file.
+ try:
+ self.fp.seek(-1, 2)
+ except IOError, e:
+ if e.errno <> errno.EINVAL: raise
+ # the file must be empty
+ else:
+ if self.fp.read(1) <> '\n':
+ self.fp.write('\n')
+ # seek to the last char of the mailbox
+ self.fp.seek(1, 2)
self.fp.write(msg.unixfrom)
for line in msg.headers:
self.fp.write(line)
if not msg.body or msg.body[0] <> '\n':
self.fp.write('\n')
self.fp.write(msg.body)
-