Update of /cvsroot/tmda/tmda/TMDA/pythonlib/email
In directory usw-pr-cvs1:/tmp/cvs-serv18765
Modified Files:
Parser.py _parseaddr.py
Log Message:
Sync up with email to fix some outstanding bugs.
Fixes problem where a message lacking a newline between header and
body would raise an exception. Reported by Cory Wright in
<[EMAIL PROTECTED]> on tmda-users.
Fixes problem where ezmlm digests were throwing a TypeError. Reported
by Joe Sotham in <[EMAIL PROTECTED]> on tmda-users.
Index: Parser.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/pythonlib/email/Parser.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Parser.py 10 Oct 2002 17:27:35 -0000 1.3
+++ Parser.py 5 Nov 2002 23:18:28 -0000 1.4
@@ -59,9 +59,9 @@
meaning it parses the entire contents of the file.
"""
root = self._class()
- self._parseheaders(root, fp)
+ firstbodyline = self._parseheaders(root, fp)
if not headersonly:
- self._parsebody(root, fp)
+ self._parsebody(root, fp, firstbodyline)
return root
def parsestr(self, text, headersonly=False):
@@ -80,6 +80,7 @@
lastheader = ''
lastvalue = []
lineno = 0
+ firstbodyline = None
while True:
# Don't strip the line before we test for the end condition,
# because whitespace-only header lines are RFC compliant
@@ -120,13 +121,16 @@
if i < 0:
if self._strict:
raise Errors.HeaderParseError(
- "Not a header, not a continuation: ``%s''"%line)
+ "Not a header, not a continuation: ``%s''" % line)
elif lineno == 1 and line.startswith('--'):
# allow through duplicate boundary tags.
continue
else:
- raise Errors.HeaderParseError(
- "Not a header, not a continuation: ``%s''"%line)
+ # There was no separating blank line as mandated by RFC
+ # 2822, but we're in non-strict mode. So just offer up
+ # this current line as the first body line.
+ firstbodyline = line
+ break
if lastheader:
container[lastheader] = NL.join(lastvalue)
lastheader = line[:i]
@@ -134,8 +138,9 @@
# Make sure we retain the last header
if lastheader:
container[lastheader] = NL.join(lastvalue)
+ return firstbodyline
- def _parsebody(self, container, fp):
+ def _parsebody(self, container, fp, firstbodyline=None):
# Parse the body, but first split the payload on the content-type
# boundary if present.
boundary = container.get_boundary()
@@ -152,6 +157,8 @@
# boundary.
separator = '--' + boundary
payload = fp.read()
+ if firstbodyline is not None:
+ payload = firstbodyline + '\n' + payload
# We use an RE here because boundaries can have trailing
# whitespace.
mo = re.search(
@@ -221,9 +228,13 @@
# msgobj in this case is the "message/rfc822" container
msgobj = self.parsestr(parthdrs, headersonly=1)
# while submsgobj is the message itself
- submsgobj = self.parsestr(part)
- msgobj.attach(submsgobj)
msgobj.set_default_type('message/rfc822')
+ maintype = msgobj.get_content_maintype()
+ if maintype in ('message', 'multipart'):
+ submsgobj = self.parsestr(part)
+ msgobj.attach(submsgobj)
+ else:
+ msgobj.set_payload(part)
else:
msgobj = self.parsestr(part)
container.preamble = preamble
@@ -256,7 +267,10 @@
self._parsebody(msg, fp)
container.attach(msg)
else:
- container.set_payload(fp.read())
+ text = fp.read()
+ if firstbodyline is not None:
+ text = firstbodyline + '\n' + text
+ container.set_payload(text)
@@ -270,6 +284,9 @@
Parsing with this subclass can be considerably faster if all you're
interested in is the message headers.
"""
- def _parsebody(self, container, fp):
+ def _parsebody(self, container, fp, firstbodyline=None):
# Consume but do not parse, the body
- container.set_payload(fp.read())
+ text = fp.read()
+ if firstbodyline is not None:
+ text = firstbodyline + '\n' + text
+ container.set_payload(text)
Index: _parseaddr.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/pythonlib/email/_parseaddr.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- _parseaddr.py 28 Oct 2002 19:41:21 -0000 1.1
+++ _parseaddr.py 5 Nov 2002 23:18:28 -0000 1.2
@@ -1,18 +1,18 @@
# Copyright (C) 2002 Python Software Foundation
-"""Module containing address parsing code lifted directly from
-rfc822.py. Should eventually be rewritten.
+"""Email address parsing code.
+
+Lifted directly from rfc822.py. This should eventually be rewritten.
"""
import time
-
# Parse a date field
-
_monthnames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul',
'aug', 'sep', 'oct', 'nov', 'dec',
'january', 'february', 'march', 'april', 'may', 'june', 'july',
'august', 'september', 'october', 'november', 'december']
+
_daynames = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
# The timezone table does not include the military time zones defined
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs