Decoding 'funky' e-mail subjects
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Tue Jun 8 05:36:42 EDT 2004
On 07 Jun 2004 17:20:02 -0700, rumours say that Paul Rubin
<http://phr.cx@NOSPAM.invalid> might have written:
>"Jonas Galvez" <jg at jonasgalvez.com> writes:
>> Thanks, that works. The problem is that I need to make it compatible
>> with Python 1.5.2. I improved my regex-based method and it has worked
>> fine with all my test cases so far. But if anyone has any other
>> suggestion, I'm still interested. Anyway, here's my code:
>A lot of those funny subjects come from spammers. Never eval anything
>from anyone like that!!!
(The part of the code that caused Paul's comment):
try: return eval('"\\x%s"' % str)
except: return "?"
A sound advice by Paul. However, lots of those funny subjects come in
legitimate e-mails from countries where the ascii range is not enough.
So, a safer alternative to the code above is:
try: return string.atoi(str, 16)
except: return '?'
# int(s, base) was not available in 1.5.2
--
TZOTZIOY, I speak England very best,
"I have a cunning plan, m'lord" --Sean Bean as Odysseus/Ulysses
More information about the Python-list
mailing list