[Email-SIG] Problem with get_all

Barry Warsaw barry at python.org
Thu Feb 26 21:55:07 EST 2004


On Thu, 2004-02-26 at 19:40, Andrew Veitch wrote:
> One of our users has reported a problem with MailManager which I've traced
> back to the email library.
> 
> He's got some very strangely formatted headers looking like this:
> 
> Cc: Gsandtner Michael <gsa at adv.magwien.gv.at>, "'Gsandtner Fam.'"
>       <michael.gsandtner at web.de>, "'Gsandtner priv.'"
>       <michael.gsandtner at airwave.at>
> 
> And running get_all on the headers just returns one fairly mangled string.
> 
> I'm not 100% sure that this is a valid format for headers but it is coming
> from a Microsoft client to I guess it's something we have to live with.
> There also seems to be a fairly excessive amount of quoting going on.
> 
> The full text of the email is at:
> https://sourceforge.net/tracker/index.php?func=detail&aid=904033&group_id=85
> 788&atid=577305

AFAICT, everything's working the way it's intended to work.  Note that
get_all() is a red herring because there's only one CC header in the
message.  You're getting back a list of one string element from
get_all() -- you'd get just that string back from msg['cc'].

First, it's the parser that groks each header and sticks the values on
the Message object; it doesn't really examine the contents of the
headers.  So msg['cc'] is going to return the contents of the CC header
of the message.  You're right that there's some 'weird' quoting going
on, but it's not in violation of RFC 2822 and is a perfectly legal,
wrapped header.

Perhaps the backslashes in the repr of the string are throwing you off?

If what you want are the constituent realname/address pairs contained
within the CC value, you should look at email.Utils.getaddresses().  For
example, if I saved your message in /tmp/message.txt:

>>> email.message_from_file(open('/tmp/message.txt'))
>>> getaddresses(msg.get_all('cc'))
[('Gsandtner Michael', 'gsa at adv.magwien.gv.at'), ("'Gsandtner Fam.'", 'michael.gsandtner at web.de'), ("'Gsandtner priv.'", 'michael.gsandtner at airwave.at')]

which looks pretty correct to me.

> By the way - is this the right place to report problems with the email
> library or is it better to open a ticket on the Python project?

If this were actually a bug, it would be better to open a ticket, but
since there's no bug here that I can see, I suppose this SIG is a better
place to post. :)

Hope that helps,
-Barry





More information about the Email-SIG mailing list