This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: MIMEMultipart _subparts constructor unusable
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: barry Nosy List: amitar, barry
Priority: normal Keywords:

Created on 2004-01-25 07:19 by amitar, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
MIMEMultipart_2.3.3.diff amitar, 2004-01-25 07:19 suggested fix (diff patch)
Messages (3)
msg19819 - (view) Author: Amit Aronovitch (amitar) Date: 2004-01-25 07:19
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'
>>>                                                   
         
msg19820 - (view) Author: Amit Aronovitch (amitar) Date: 2004-01-25 07:28
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
msg19821 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2004-05-09 18:01
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).
History
Date User Action Args
2022-04-11 14:56:02adminsetgithub: 39866
2004-01-25 07:19:42amitarcreate