[Mailman-Developers] Fwd: Bounce action notification
M.-A. Lemburg
mal at lemburg.com
Thu Feb 27 15:38:37 EST 2003
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('mal at lemburg.com') + ')'
> 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: postmaster at lemburg.com
Date: Tue Feb 25, 2003 12:58:07 AM US/Pacific
To: list-bounce at lists.egenix.com
Subject: Bounce action notification
The following message bounced.
From: mailman at lemburg.com
To: info at egenix.com
...
_______________________________________________
%s
%s
""" % (encode_email_address('mailman at lemburg.com', 'sender'),
encode_email_address('info at egenix.com', '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: postmaster at lemburg.com
Date: Tue Feb 25, 2003 12:58:07 AM US/Pacific
To: list-bounce at lists.egenix.com
Subject: Bounce action notification
The following message bounced.
From: mailman at lemburg.com
To: info at egenix.com
...
_______________________________________________
mm(bWFpbG1hbkBsZW1idXJnLmNvbSBzZW5kZXI-)
mm(aW5mb0BlZ2VuaXguY29tIHJjcHQ-)
Found these email address in message:
('sender', 'mailman at lemburg.com')
('rcpt', 'info at egenix.com')
--
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
More information about the Mailman-Developers
mailing list