Commit 06fa0420 authored by Barry Warsaw's avatar Barry Warsaw

Test cases and fixes for bugs described in patch #873418: email/Message.py:

del_param fails when specifying a header.
parent d4ff2069
...@@ -664,7 +664,7 @@ class Message: ...@@ -664,7 +664,7 @@ class Message:
if not self.has_key(header): if not self.has_key(header):
return return
new_ctype = '' new_ctype = ''
for p, v in self.get_params(header, unquote=requote): for p, v in self.get_params(header=header, unquote=requote):
if p.lower() <> param.lower(): if p.lower() <> param.lower():
if not new_ctype: if not new_ctype:
new_ctype = _formatparam(p, v, requote) new_ctype = _formatparam(p, v, requote)
...@@ -700,7 +700,7 @@ class Message: ...@@ -700,7 +700,7 @@ class Message:
if not self.has_key(header): if not self.has_key(header):
self[header] = type self[header] = type
return return
params = self.get_params(header, unquote=requote) params = self.get_params(header=header, unquote=requote)
del self[header] del self[header]
self[header] = type self[header] = type
# Skip the first param; it's the old type. # Skip the first param; it's the old type.
......
...@@ -354,6 +354,12 @@ class TestMessageAPI(TestEmailBase): ...@@ -354,6 +354,12 @@ class TestMessageAPI(TestEmailBase):
('boundary', 'D1690A7AC1.996856090/mail.example.com'), ('boundary', 'D1690A7AC1.996856090/mail.example.com'),
('report-type', old_val)]) ('report-type', old_val)])
def test_del_param_on_other_header(self):
msg = Message()
msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')
msg.del_param('filename', 'content-disposition')
self.assertEqual(msg['content-disposition'], 'attachment')
def test_set_type(self): def test_set_type(self):
eq = self.assertEqual eq = self.assertEqual
msg = Message() msg = Message()
...@@ -365,6 +371,12 @@ class TestMessageAPI(TestEmailBase): ...@@ -365,6 +371,12 @@ class TestMessageAPI(TestEmailBase):
msg.set_type('text/html') msg.set_type('text/html')
eq(msg['content-type'], 'text/html; charset="us-ascii"') eq(msg['content-type'], 'text/html; charset="us-ascii"')
def test_set_type_on_other_header(self):
msg = Message()
msg['X-Content-Type'] = 'text/plain'
msg.set_type('application/octet-stream', 'X-Content-Type')
self.assertEqual(msg['x-content-type'], 'application/octet-stream')
def test_get_content_type_missing(self): def test_get_content_type_missing(self):
msg = Message() msg = Message()
self.assertEqual(msg.get_content_type(), 'text/plain') self.assertEqual(msg.get_content_type(), 'text/plain')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment