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.
Created on 2012年05月07日 13:36 by Bob.Glickstein, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg160144 - (view) | Author: Bob Glickstein (Bob.Glickstein) * | Date: 2012年05月07日 13:36 | |
Passing both a value for i and decode=True to email.message.Message.get_payload(), when self is a multipart, returns None when it should return a string. The reason is that an is_multipart() test is done on self when it should instead be done on the selected payload part. Here's a patch that fixes this:
--- /usr/lib64/python2.7/email/message.py 2011年10月26日 18:40:36.000000000 -0700
+++ /home/bobg/tmp/message.py 2012年05月07日 06:34:28.579401481 -0700
@@ -192,9 +192,9 @@
else:
payload = self._payload[i]
if decode:
- if self.is_multipart():
+ if payload.is_multipart():
return None
- cte = self.get('content-transfer-encoding', '').lower()
+ cte = payload.get('content-transfer-encoding', '').lower()
if cte == 'quoted-printable':
return utils._qdecode(payload)
elif cte == 'base64':
|
|||
| msg160145 - (view) | Author: Bob Glickstein (Bob.Glickstein) * | Date: 2012年05月07日 13:37 | |
Incidentally, a workaround is: msg.get_payload(n).get_payload(decode=True) |
|||
| msg160146 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2012年05月07日 13:57 | |
Thanks for the report and patch suggestion, but... This is actually the way it is designed to work. get_payload(i) returns the ith element of a multipart payload. Your workaround is in fact the correct way to do this operation. decode=True is documented to return None if is_multipart is True. You will note that if decode=False, you get back the Message sub-object, not a string. Since decoding a Message object (as opposed to its payload) is not a meaningful operation, None is returned for decode=True. Arguably we should raise a TypeError or ValueError instead, but we don't for historical reasons. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:29 | admin | set | github: 58945 |
| 2012年05月07日 13:57:47 | r.david.murray | set | status: open -> closed nosy: + r.david.murray messages: + msg160146 resolution: not a bug stage: resolved |
| 2012年05月07日 13:37:44 | Bob.Glickstein | set | messages: + msg160145 |
| 2012年05月07日 13:36:32 | Bob.Glickstein | create | |