summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email/test_headerregistry.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-43323: Fix UnicodeEncodeError in the email module (GH-32137)Serhiy Storchaka2022-04-301-0/+12
| | | | | It was raised if the charset itself contains characters not encodable in UTF-8 (in particular \udcxx characters representing non-decodable bytes in the source).
* bpo-30681: Support invalid date format or value in email Date header (GH-22090)Georges Toth2020-10-271-0/+16
| | | | | | | | | | | | | | | | | | | | I am re-submitting an older PR which was abandoned but is still relevant, #10783 by @timb07. The issue being solved () is still relevant. The original PR #10783 was closed as the final request changes were not applied and since abandoned. In this new PR I have re-used the original patch plus applied both comments from the review, by @maxking and @pganssle. For reference, here is the original PR description: In email.utils.parsedate_to_datetime(), a failure to parse the date, or invalid date components (such as hour outside 0..23) raises an exception. Document this behaviour, and add tests to test_email/test_utils.py to confirm this behaviour. In email.headerregistry.DateHeader.parse(), check when parsedate_to_datetime() raises an exception and add a new defect InvalidDateDefect; preserve the invalid value as the string value of the header, but set the datetime attribute to None. Add tests to test_email/test_headerregistry.py to confirm this behaviour; also added test to test_email/test_inversion.py to confirm emails with such defective date headers round trip successfully. This pull request incorporates feedback gratefully received from @bitdancer, @brettcannon, @Mariatta and @warsaw, and replaces the earlier PR #2254. Automerge-Triggered-By: GH:warsaw
* bpo-39040: Fix parsing of email mime headers with whitespace between ↵Abhilash Raj2020-05-291-0/+19
| | | | | | | | | | | | | | | encoded-words. (gh-17620) * bpo-39040: Fix parsing of email headers with encoded-words inside a quoted string. It is fairly common to find malformed mime headers (especially content-disposition headers) where the parameter values, instead of being encoded to RFC standards, are "encoded" by doing RFC 2047 "encoded word" encoding, and then enclosing the whole thing in quotes. The processing of these malformed headers was incorrectly leaving the spaces between encoded words in the decoded text (whitespace between adjacent encoded words is supposed to be stripped on decoding). This changeset fixes the encoded word processing inside quoted strings (bare-quoted-string) to do correct RFC 2047 decoding by stripping that whitespace.
* bpo-39073: validate Address parts to disallow CRLF (#19007)Ashwin Ramaswami2020-03-301-0/+19
| | | Disallow CR or LF in email.headerregistry.Address arguments to guard against header injection attacks.
* bpo-37482: Fix email address name with encoded words and special chars ↵bsiem2019-08-211-0/+24
| | | | | | | | | | | | | | | | | | | | | | | (GH-14561) Special characters in email address header display names are normally put within double quotes. However, encoded words (=?charset?x?...?=) are not allowed withing double quotes. When the header contains a word with special characters and another word that must be encoded, the first one must also be encoded. In the next example, the display name in the From header is quoted and therefore the comma is allowed; in the To header, the comma is not within quotes and not encoded, which is not allowed and therefore rejected by some mail servers. From: "Foo Bar, France" <foo@example.com> To: Foo Bar, =?utf-8?q?Espa=C3=B1a?= <foo@example.com> https://bugs.python.org/issue37482
* bpo-37685: Fixed __eq__, __lt__ etc implementations in some classes. (GH-14952)Serhiy Storchaka2019-08-081-0/+19
| | | | They now return NotImplemented for unsupported type of the other operand.
* bpo-21315: Fix parsing of encoded words with missing leading ws. (#13425)Abhilash Raj2019-06-051-1/+2
| | | | | | | | | | | | * bpo-21315: Fix parsing of encoded words with missing leading ws. Because of missing leading whitespace, encoded word would get parsed as unstructured token. This patch fixes that by looking for encoded words when splitting tokens with whitespace. Missing trailing whitespace around encoded word now register a defect instead. Original patch suggestion by David R. Murray on bpo-21315.
* bpo-35805: Add parser for Message-ID email header. (GH-13397)Abhilash Raj2019-06-041-0/+28
| | | | | | | | | | | | | * bpo-35805: Add parser for Message-ID header. This parser is based on the definition of Identification Fields from RFC 5322 Sec 3.6.4. This should also prevent folding of Message-ID header using RFC 2047 encoded words and hence fix bpo-35805. * Prevent folding of non-ascii message-id headers. * Add fold method to MsgID token to prevent folding.
* bpo-33529, email: Fix infinite loop in email header encoding (GH-12020)Krzysztof Wojcik2019-05-141-4/+4
|
* bpo-27240 Rewrite the email header folding algorithm. (#3488)R. David Murray2017-12-031-86/+143
| | | | | | | | | | | | | | | | | | | | | The original algorithm tried to delegate the folding to the tokens so that those tokens whose folding rules differed could specify the differences. However, this resulted in a lot of duplicated code because most of the rules were the same. The new algorithm moves all folding logic into a set of functions external to the token classes, but puts the information about which tokens can be folded in which ways on the tokens...with the exception of mime-parameters, which are a special case (which was not even implemented in the old folder). This algorithm can still probably be improved and hopefully simplified somewhat. Note that some of the test expectations are changed. I believe the changes are toward more desirable and consistent behavior: in general when (re) folding a line the canonical version of the tokens is generated, rather than preserving errors or extra whitespace.
* Issue #23277: Remove unused imports in tests.Serhiy Storchaka2016-04-241-1/+0
|
* #21991: make headerregistry params property MappingProxyType.R David Murray2014-10-171-0/+3
| | | | | | | | | It is unlikely anyone is using the fact that the dictionary returned by the 'params' attribute was previously writable, but even if someone is the API is provisional so this kind of change is acceptable (and needed, to get the API "right" before it becomes official). Patch by Stéphane Wirtel.
* Merge: #16983: Apply postel's law to encoded words inside quoted strings.R David Murray2014-02-081-0/+10
|\
| * #16983: Apply postel's law to encoded words inside quoted strings.R David Murray2014-02-081-0/+10
| | | | | | | | | | | | | | | | | | | | This applies only to the new parser. The old parser decodes encoded words inside quoted strings already, although it gets the whitespace wrong when it does so. This version of the patch only handles the most common case (a single encoded word surrounded by quotes), but I haven't seen any other variations of this in the wild yet, so its good enough for now.
* | #18891: Complete new provisional email API.R David Murray2013-10-171-1/+13
|/ | | | | | | | | | | | This adds EmailMessage and, MIMEPart subclasses of Message with new API methods, and a ContentManager class used by the new methods. Also a new policy setting, content_manager. Patch was reviewed by Stephen J. Turnbull and Serhiy Storchaka, and reflects their feedback. I will ideally add some examples of using the new API to the documentation before the final release.
* #18741: fix more typos. Patch by Févry Thibault.Ezio Melotti2013-08-171-6/+6
|
* #18431: Decode encoded words in atoms in new email parser.R David Murray2013-07-121-0/+24
| | | | | | There is more to be done here in terms of accepting RFC invalid input that some mailers accept, but this covers the valid RFC places where encoded words can occur in structured headers.
* #18044: Fix parsing of encoded words of the form =?utf8?q?=XX...?=R David Murray2013-07-111-4/+37
| | | | | | | | | | The problem was I was only checking for decimal digits after the third '?', not for *hex* digits :(. This changeset also fixes a couple of comment typos, deletes an unused function relating to encoded word parsing, and removed an invalid 'if' test from the folding function that was revealed by the tests written to validate this issue.
* Fix a few typos and a double semicolon. Patch by Eitan Adler.Ezio Melotti2013-01-271-1/+1
|
* #15160: Extend the new email parser to handle MIME headers.R David Murray2012-06-241-0/+786
| | | | | | | | | | | | | | | | | | | | | | | This code passes all the same tests that the existing RFC mime header parser passes, plus a bunch of additional ones. There are a couple of commented out tests where there are issues with the folding. The folding doesn't normally get invoked for headers parsed from source, and the cases are marginal anyway (headers with invalid binary data) so I'm not worried about them, but will fix them after the beta. There are things that can be done to make this API even more convenient, but I think this is a solid foundation worth having. And the parser is a full RFC parser, so it handles cases that the current parser doesn't. (There are also probably cases where it fails when the current parser doesn't, but I haven't found them yet ;) Oh, yeah, and there are some really ugly bits in the parser for handling some 'postel' cases that are unfortunately common. I hope/plan to to eventually refactor a lot of the code in the parser which should reduce the line count...but there is no escaping the fact that the error recovery is welter of special cases.
* Don't use metaclasses when class decorators can do the job.R David Murray2012-05-311-2/+3
| | | | | Thanks to Nick Coghlan for pointing out that I'd forgotten about class decorators.
* Make parameterized tests in email less hackish.R David Murray2012-05-311-18/+8
| | | | | Or perhaps more hackish, depending on your perspective. But at least this way it is now possible to run the individual tests using the unittest CLI.
* Regularize test_email/test_headerregistry's references to policy.R David Murray2012-05-291-6/+6
|
* Make headerregistry fully part of the provisional api.R David Murray2012-05-271-0/+738
When I made the checkin of the provisional email policy, I knew that Address and Group needed to be made accessible from somewhere. The more I looked at it, though, the more it became clear that since this is a provisional API anyway, there's no good reason to hide headerregistry as a private API. It was designed to ultimately be part of the public API, and so it should be part of the provisional API. This patch fully documents the headerregistry API, and deletes the abbreviated version of those docs I had added to the provisional policy docs.