summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2002-08-20 14:50:09 (GMT)
committerBarry Warsaw <barry@python.org>2002-08-20 14:50:09 (GMT)
commitf36d804b3b5a73814287535bbc840c3df33d9e2d (patch)
tree717a49b56b3295d13899180d5f777d38f7cd97e4 /Lib/email
parentdfea3b3963228fc149c586463b01fcaf39510902 (diff)
downloadcpython-f36d804b3b5a73814287535bbc840c3df33d9e2d.zip
cpython-f36d804b3b5a73814287535bbc840c3df33d9e2d.tar.gz
cpython-f36d804b3b5a73814287535bbc840c3df33d9e2d.tar.bz2
get_content_type(), get_content_maintype(), get_content_subtype(): RFC
2045, section 5.2 states that if the Content-Type: header is syntactically invalid, the default type should be text/plain. Implement minimal sanity checking of the header -- it must have exactly one slash in it. This closes SF patch #597593 by Skip, but in a different way. Note that these methods used to raise ValueError for invalid ctypes, but now they won't.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/Message.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/email/Message.py b/Lib/email/Message.py
index 89ace24..40e4785 100644
--- a/Lib/email/Message.py
+++ b/Lib/email/Message.py
@@ -422,7 +422,11 @@ class Message:
if value is missing:
# This should have no parameters
return self.get_default_type()
- return paramre.split(value)[0].lower().strip()
+ ctype = paramre.split(value)[0].lower().strip()
+ # RFC 2045, section 5.2 says if its invalid, use text/plain
+ if ctype.count('/') <> 1:
+ return 'text/plain'
+ return ctype
def get_content_maintype(self):
"""Returns the message's main content type.
@@ -432,8 +436,6 @@ class Message:
ValueError is raised.
"""
ctype = self.get_content_type()
- if ctype.count('/') <> 1:
- raise ValueError, 'No maintype found in: %s' % ctype
return ctype.split('/')[0]
def get_content_subtype(self):
@@ -444,8 +446,6 @@ class Message:
ValueError is raised.
"""
ctype = self.get_content_type()
- if ctype.count('/') <> 1:
- raise ValueError, 'No subtype found in: %s' % ctype
return ctype.split('/')[1]
def get_default_type(self):