Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(24)

Unified Diff: Lib/email/message.py

Issue 10839: email module should not allow some header field repetitions
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Doc/library/email.policy.rst ('k') | Lib/email/_policybase.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -346,6 +346,16 @@
Note: this does not overwrite an existing header with the same field
name. Use __delitem__() first to delete any existing headers.
"""
+ max_count = self.policy.header_max_count(name)
+ if max_count:
+ lname = name.lower()
+ found = 0
+ for k, v in self._headers:
+ if k.lower() == lname:
+ found += 1
+ if found >= max_count:
+ raise ValueError("There may be at most {} {} headers "
+ "in a message".format(max_count, name))
self._headers.append(self.policy.header_store_parse(name, val))
def __delitem__(self, name):
« no previous file with comments | « Doc/library/email.policy.rst ('k') | Lib/email/_policybase.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+