a smarter rfc822.dump_address_pair() ?

Jason R. Mastaler jason-dated-1008366492.09220b at mastaler.com
Thu Dec 6 22:48:10 CET 2001


I was looking for a Python function to take a "fullname" and
corresponding e-mail address and return a string suitable for a From:
header in an e-mail message.

I found rfc822.dump_address_pair() which seemed perfect, except that
all it does is throw double quotes around the fullname, and append the
e-mail address surrounded by angle brackets.  e.g,

Python 2.1.1 (#14, Sep 13 2001, 13:12:38) [C] on irix646
Type "copyright", "credits" or "license" for more information.
>>> import rfc822
>>> print rfc822.dump_address_pair(('Jason Mastaler','jason at mastaler.com'))
"Jason Mastaler" <jason at mastaler.com>
>>> 

The problem here is that according to rfc2822, is it not necessary to
double quote 'Jason Mastaler' as it contains no special tokens that
require double quoting.  It should be just:

Jason Mastaler <jason at mastaler.com>

What it should do is first look for a character that cannot appear
unquoted according to rfc2822 before it decides to double-quote the
fullname.  This is what most MUAs and MTAs do.

So, is there a way to do this in the Python library that I haven't
seen?  If not, has anyone out there written code that does this that I
could steal?  Perhaps if you are writing your own MUA in Python or
somesuch.

Also, this issue may sound trivial, and it is.  However, some e-mail
users are rather picky about aesthetics, and I've actually gotten
complaints about the unnecessary double-quoting from some users of my
apps.

Thanks.

-- 
(TMDA - http://tmda.sourceforge.net)
(Python-based SPAM reduction system)




More information about the Python-list mailing list