diff options
author | Barry Warsaw <barry@python.org> | 2002-10-14 15:09:30 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2002-10-14 15:09:30 (GMT) |
commit | 6c2bc4635539765dc267094b95e0ef8f0ce9053a (patch) | |
tree | e8a7c50a844dfaab2f70e1af276f887633e6c68d /Lib/email/Generator.py | |
parent | 7cd724049f3d6c741dc3d7d3b652ba9a83481e5d (diff) | |
download | cpython-6c2bc4635539765dc267094b95e0ef8f0ce9053a.zip cpython-6c2bc4635539765dc267094b95e0ef8f0ce9053a.tar.gz cpython-6c2bc4635539765dc267094b95e0ef8f0ce9053a.tar.bz2 |
_split_header(): If we have a header which is a byte string containing
8-bit data, we cannot split it safely, so return the original string
unchanged.
_is8bitstring(): Helper function which returns True when we have a
byte string that contains non-ascii characters (i.e. mysterious 8-bit
data).
Diffstat (limited to 'Lib/email/Generator.py')
-rw-r--r-- | Lib/email/Generator.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/email/Generator.py b/Lib/email/Generator.py index 7f05218..58e2f91 100644 --- a/Lib/email/Generator.py +++ b/Lib/email/Generator.py @@ -8,7 +8,7 @@ import time import re import random -from types import ListType +from types import ListType, StringType from cStringIO import StringIO from email.Header import Header @@ -35,6 +35,14 @@ SPACE8 = ' ' * 8 fcre = re.compile(r'^From ', re.MULTILINE) +def _is8bitstring(s): + if isinstance(s, StringType): + try: + unicode(s, 'us-ascii') + except UnicodeError: + return True + return False + class Generator: @@ -174,6 +182,14 @@ class Generator: # No line was actually longer than maxheaderlen characters, so # just return the original unchanged. return text + # If we have raw 8bit data in a byte string, we have no idea what the + # encoding is. I think there is no safe way to split this string. If + # it's ascii-subset, then we could do a normal ascii split, but if + # it's multibyte then we could break the string. There's no way to + # know so the least harm seems to be to not split the string and risk + # it being too long. + if _is8bitstring(text): + return text # The `text' argument already has the field name prepended, so don't # provide it here or the first line will get folded too short. h = Header(text, maxlinelen=maxheaderlen, |