M.-A. Lemburg wrote:
I guess some simple email address mangling trick would give you
the same effect, e.g. base64 encoding:

 >>> print 'mm(' + base64.encodestring('[EMAIL PROTECTED]') + ')'
mm(bWFsQGxlbWJ1cmcuY29t)

These kind of encodings could even be used in URLs and survive
text->HTML->text conversion.

Here's some code and an example:


import base64, re

def encode_email_address(address, note=''):
    encoded = base64.encodestring(address + ' ' + note)[:-1]
    encoded = encoded.replace('=', '-')
    encoded = encoded.replace('+', '.')
    encoded = encoded.replace('/', '_')
    return 'mm(%s)' % encoded

def decode_email_address_part(mangled_address):
    mangled_address = mangled_address.replace('-', '=')
    mangled_address = mangled_address.replace('.', '+')
    mangled_address = mangled_address.replace('_', '/')
    decoded = base64.decodestring(mangled_address)
    return decoded.split()

message = """
From: [EMAIL PROTECTED]
Date: Tue Feb 25, 2003  12:58:07  AM US/Pacific
To: [EMAIL PROTECTED]
Subject: Bounce action notification

The following message bounced.

   From: [EMAIL PROTECTED]
   To: [EMAIL PROTECTED]
   ...

   _______________________________________________
   %s
   %s
""" % (encode_email_address('[EMAIL PROTECTED]', 'sender'),
       encode_email_address('[EMAIL PROTECTED]', 'rcpt'))

print 'Message:'
print message
print

parser = re.compile('mm\(([0-9a-zA-Z-._]+)\)')

def find_email_addresses(message, start=0, end=None):
    l = []
    if end is None:
        end = len(message)
    while start < end:
        m = parser.search(message, start, end)
        if m is not None:
            address, note = decode_email_address_part(m.group(1))
            l.append((note, address))
            start = m.end()
        else:
            break
    return l

addrs = find_email_addresses(message)
print 'Found these email address in message:'
for addr in addrs:
    print ' ', addr

--

lemburg/tmp> python mangle_email_address.py
Message:

From: [EMAIL PROTECTED]
Date: Tue Feb 25, 2003  12:58:07  AM US/Pacific
To: [EMAIL PROTECTED]
Subject: Bounce action notification

The following message bounced.

   From: [EMAIL PROTECTED]
   To: [EMAIL PROTECTED]
   ...

   _______________________________________________
   mm(bWFpbG1hbkBsZW1idXJnLmNvbSBzZW5kZXI-)
   mm(aW5mb0BlZ2VuaXguY29tIHJjcHQ-)


Found these email address in message: ('sender', '[EMAIL PROTECTED]') ('rcpt', '[EMAIL PROTECTED]')

--
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source  (#1, Feb 27 2003)
>>> Python/Zope Products & Consulting ...         http://www.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
Python UK 2003, Oxford:                                     33 days left
EuroPython 2003, Charleroi, Belgium:                       117 days left


_______________________________________________ Mailman-Developers mailing list [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/mailman-developers

Reply via email to