Message122774
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>') |
|
Date |
User |
Action |
Args |
2010-11-29 05:59:34 | invisibleroads | set | recipients:
+ invisibleroads |
2010-11-29 05:59:34 | invisibleroads | set | messageid: <1291010374.27.0.926082536926.issue10574@psf.upfronthosting.co.za> |
2010-11-29 05:59:32 | invisibleroads | link | issue10574 messages |
2010-11-29 05:59:32 | invisibleroads | create | |
|