homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author invisibleroads
Recipients invisibleroads
Date 2010年11月29日.05:59:32
SpamBayes Score 0.0047780173
Marked as misclassified No
Message-id <1291010374.27.0.926082536926.issue10574@psf.upfronthosting.co.za>
In-reply-to
Content
Improved workaround to handle another degenerate case where the encoded string is in between non-encoded strings.
import re
import email.header
pattern_ecre = re.compile(r'((=\?.*?\?[qb]\?).*\?=)', re.VERBOSE | re.IGNORECASE | re.MULTILINE)
def decodeSafely(x):
 match = pattern_ecre.search(x)
 if not match:
 return x
 string, encoding = match.groups()
 stringBefore, string, stringAfter = x.partition(string)
 return stringBefore + email.header.decode_header('%s%s==?=' % (encoding, string.replace(encoding, '').replace('?', '').replace('=', '')))[0][0] + stringAfter
print decodeSafely('=?UTF-8?B?MjAxMSBBVVRNIENBTEwgZm9yIE5PTUlO?==?UTF-8?B?QVRJT05TIG9mIFZQIGZvciBNZW1iZXJz?==?UTF-8?B?aGlw?=')
print decodeSafely('"=?UTF-8?B?QVVUTSBIZWFkcXVhcnRlcnM=?="<info@autm.net>')
History
Date User Action Args
2010年11月29日 05:59:34invisibleroadssetrecipients: + invisibleroads
2010年11月29日 05:59:34invisibleroadssetmessageid: <1291010374.27.0.926082536926.issue10574@psf.upfronthosting.co.za>
2010年11月29日 05:59:32invisibleroadslinkissue10574 messages
2010年11月29日 05:59:32invisibleroadscreate

AltStyle によって変換されたページ (->オリジナル) /