[Python-checkins] python/dist/src/Lib/email Parser.py,1.7,1.8
bwarsaw@sourceforge.net
bwarsaw@sourceforge.net
2002年5月19日 16:51:52 -0700
Update of /cvsroot/python/python/dist/src/Lib/email
In directory usw-pr-cvs1:/tmp/cvs-serv27733/Lib/email
Modified Files:
Parser.py
Log Message:
I've thought about it some more, and I believe it is proper for the
email package's Parser to handle the three common line endings.
Certain protocols such as IMAP define CRLF line endings and it doesn't
make sense for the client app to have to normalize the line endings
before handing it message off to the Parser.
_parsebody(): Be more flexible in the matching of line endings for
finding the MIME separators. Accept any of \r, \n and \r\n. Note
that we do /not/ change the line endings in the payloads, we just
accept any of those three around MIME boundaries.
Index: Parser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Parser.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Parser.py 10 Apr 2002 21:01:30 -0000 1.7
--- Parser.py 19 May 2002 23:51:50 -0000 1.8
***************
*** 5,8 ****
--- 5,9 ----
"""
+ import re
from cStringIO import StringIO
from types import ListType
***************
*** 118,129 ****
# there's some pre-MIME boundary preamble
preamble = payload[0:start]
! start += len(separator) + 1 + isdigest
! terminator = payload.find('\n' + separator + '--', start)
! if terminator < 0:
raise Errors.BoundaryError(
"Couldn't find terminating boundary: %s" % boundary)
! if terminator+len(separator)+3 < len(payload):
# there's some post-MIME boundary epilogue
! epilogue = payload[terminator+len(separator)+3:]
# We split the textual payload on the boundary separator, which
# includes the trailing newline. If the container is a
--- 119,142 ----
# there's some pre-MIME boundary preamble
preamble = payload[0:start]
! # Find out what kind of line endings we're using
! start += len(separator)
! cre = re.compile('\r\n|\r|\n')
! mo = cre.search(payload, start)
! if mo:
! start += len(mo.group(0)) * (1 + isdigest)
! # We create a compiled regexp first because we need to be able to
! # specify the start position, and the module function doesn't
! # support this signature. :(
! cre = re.compile('(?P<sep>\r\n|\r|\n)' +
! re.escape(separator) + '--')
! mo = cre.search(payload, start)
! if not mo:
raise Errors.BoundaryError(
"Couldn't find terminating boundary: %s" % boundary)
! terminator = mo.start()
! linesep = mo.group('sep')
! if mo.end() < len(payload):
# there's some post-MIME boundary epilogue
! epilogue = payload[mo.end():]
# We split the textual payload on the boundary separator, which
# includes the trailing newline. If the container is a
***************
*** 132,140 ****
# newline before the headers to distinguish the message's headers
# from the subpart headers.
! if isdigest:
! separator += '\n\n'
! else:
! separator += '\n'
! parts = payload[start:terminator].split('\n' + separator)
for part in parts:
msgobj = self.parsestr(part)
--- 145,150 ----
# newline before the headers to distinguish the message's headers
# from the subpart headers.
! separator += linesep * (1 + isdigest)
! parts = payload[start:terminator].split(linesep + separator)
for part in parts:
msgobj = self.parsestr(part)