email: msg.add_payload not synonymous with msg.attach?

Quinn Dunkan quinn at lira.ugcs.caltech.edu
Sat Jun 8 23:36:07 EDT 2002


On Fri, 7 Jun 2002 00:01:10 +0000 (UTC), Magnus Lie Hetland
<mlh at vier.idi.ntnu.no> wrote:
>I've been fiddling with the email package, and tried to construct a
>Message object, using add_payload to add the email body (It's a
>text/plain message). This worked fine, except for a deprecation
>warning telling me to use attach instead. But when I did, my program

In 1.0 (comes with python 2.2.1), attach is defined as 'attach = add_payload'
so it's synonymous.  It also doesn't have any mention of 'add_payload" being
deprecated.  I hope it's not really, since I use it all the time.

CVS is probably not at 1.0 anymore.

>crashed with the message "TypeError: string payload expected: <type
>'list'>" (from Generator.py). Well... My payload was indeed simply a
>string, so I don't understand the error message. Also, I don't
>understand how this discrepancy could have occurred if, as the docs
>claim, add_payload and attach are synonymous.

Well, at least the 1.0 verson of email.Message.Message has an annoying bug that
relates _payload being either a string or list depending on how many times
add_payload() has been called (not a great design, IMO).  The bug arises
because Message assumes a list _payload in the presence of the multipart/*
type, which leads to trouble because some multipart/* messages only have one
part (I'm not sure if this is legal according to the RFCs, but many messages
out there do that, including Crispin's MIME torture test (which I would
recommend be used in the testing of the package).

What the error msg probably means is that your message somehow has multiple
payloads, but doesn't have a multipart/* type.  Maybe they changed attach
to always make _payload a list or something.

>(The code is very simple -- basically just instantiating Message and
>adding a payload.)
>
>I'm using the email package from CVS (downloaded everything a day or
>two ago).

I wouldn't be surprised if the docs are not up to date with the latest CVS.
You should probably either use 1.0 or check the Message.py source.



More information about the Python-list mailing list