[ python-Bugs-884030 ] MIMEMultipart _subparts constructor unusable

SourceForge.net noreply at sourceforge.net
Sun May 9 14:01:16 EDT 2004


Bugs item #884030, was opened at 2004-01-25 02:19
Message generated for change (Comment added) made by bwarsaw
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=884030&group_id=5470

Category: Python Library
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Amit Aronovitch (amitar)
Assigned to: Barry A. Warsaw (bwarsaw)
Summary: MIMEMultipart _subparts constructor unusable

Initial Comment:
It is not clear how to pass initial list of messages to
MIMEMultipart. 
>From doc it seems that _subparts should be a single
list-like object, from source it seems that it expects
seperate parameters - neither work...

 My suggested patch implemets the single parameter way
(after applying it, the second try in the example below
does work).

((to apply the patch, use :
cp MIMEMultipart.py MIMEMultipart_orig.py
patch -i MIMEMultipart_2.3.3.diff -o MIMEMultipart.py
MIMEMultipart_orig.py
))

example:

>>> msgs = [MIMEText('a'),MIMEText('b')]
>>> MIMEMultipart('mixed',None,msgs[0],msgs[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/email/MIMEMultipart.py",
line 35, in __init__
    self.attach(*list(_subparts))
TypeError: attach() takes exactly 2 arguments (3 given)
>>> MIMEMultipart('mixed',None,msgs).as_string() 
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/email/Message.py", line 130,
in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib/python2.3/email/Generator.py", line
102, in flatten
    self._write(msg)
  File "/usr/lib/python2.3/email/Generator.py", line
130, in _write
    self._dispatch(msg)
  File "/usr/lib/python2.3/email/Generator.py", line
156, in _dispatch
    meth(msg)
  File "/usr/lib/python2.3/email/Generator.py", line
230, in _handle_multipart
    g.flatten(part, unixfrom=False)
  File "/usr/lib/python2.3/email/Generator.py", line
102, in flatten
    self._write(msg)
  File "/usr/lib/python2.3/email/Generator.py", line
130, in _write
    self._dispatch(msg)
  File "/usr/lib/python2.3/email/Generator.py", line
147, in _dispatch
    main = msg.get_content_maintype()
AttributeError: 'list' object has no attribute
'get_content_maintype'
>>>                                                   
         


----------------------------------------------------------------------

>Comment By: Barry A. Warsaw (bwarsaw)
Date: 2004-05-09 14:01

Message:
Logged In: YES 
user_id=12800

Your patch seems right since it implements what's
documented.  I'll apply this for Python 2.3.4 and Python 2.4
(with a bit of reformatting and a test case).

----------------------------------------------------------------------

Comment By: Amit Aronovitch (amitar)
Date: 2004-01-25 02:28

Message:
Logged In: YES 
user_id=564711

This refers to the email package...

To my example I should have added at the beginning:

>>> from email.MIMEText import MIMEText
>>> from email.MIMEMultipart import MIMEMultipart


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=884030&group_id=5470



More information about the Python-bugs-list mailing list