summaryrefslogtreecommitdiffstats
path: root/Lib/email/_header_value_parser.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-39040: Fix parsing of email mime headers with whitespace between ↵Abhilash Raj2020-05-291-0/+9
| | | | | | | | | | | | | | | 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-38708: email: Fix a potential IndexError when parsing Message-ID (GH-17504)Abhilash Raj2019-12-091-1/+1
| | | | Fix a potential IndexError when passing an empty value to the message-id parser. Instead, HeaderParseError should be raised.
* bpo-38698: Add a new InvalidMessageID token to email header parser. (GH-17503)Abhilash Raj2019-12-091-4/+16
| | | | This adds a new InvalidMessageID token to the email header parser which can be used to represent invalid message-id headers in the parse tree.
* bpo-38698: Prevent UnboundLocalError to pop up in parse_message_id (GH-17277)Claudiu Popa2019-12-051-1/+2
| | | | | | | | | parse_message_id() was improperly using a token defined inside an exception handler, which was raising `UnboundLocalError` on parsing an invalid value. https://bugs.python.org/issue38698
* bpo-38332: Catch KeyError from unknown cte in encoded-word. (GH-16503)Andrei Troie2019-10-051-1/+1
| | | KeyError should cause a failure in parsing the encoded word and should be caught and raised as a _InvalidEWError instead.
* bpo-37764: Fix infinite loop when parsing unstructured email headers. (GH-15239)Ashwin Ramaswami2019-08-311-3/+16
| | | | | | | | | | | | Fixes a case in which email._header_value_parser.get_unstructured hangs the system for some invalid headers. This covers the cases in which the header contains either: - a case without trailing whitespace - an invalid encoded word https://bugs.python.org/issue37764 This fix should also be backported to 3.7 and 3.8 https://bugs.python.org/issue37764
* bpo-37482: Fix email address name with encoded words and special chars ↵bsiem2019-08-211-0/+3
| | | | | | | | | | | | | | | | | | | | | | | (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-32178: Fix IndexError trying to parse 'To' header starting with ':'. ↵Abhilash Raj2019-08-111-1/+3
| | | | | | | | | | (GH-15044) This should fix the IndexError trying to retrieve `DisplayName.display_name` and `DisplayName.value` when the `value` is basically an empty string. https://bugs.python.org/issue32178
* bpo-34155: Dont parse domains containing @ (GH-13079)jpic2019-07-171-0/+2
| | | | | | | | | | | | | | | | | | | | | | Before: >>> email.message_from_string('From: a@malicious.org@important.com', policy=email.policy.default)['from'].addresses (Address(display_name='', username='a', domain='malicious.org'),) >>> parseaddr('a@malicious.org@important.com') ('', 'a@malicious.org') After: >>> email.message_from_string('From: a@malicious.org@important.com', policy=email.policy.default)['from'].addresses (Address(display_name='', username='', domain=''),) >>> parseaddr('a@malicious.org@important.com') ('', 'a@') https://bugs.python.org/issue34155
* Fix IndexError when parsing unexpectedly ending quoted-string. (GH-14813)Abhilash Raj2019-07-171-1/+1
| | | | This exception was caused because the input ended unexpectedly with only one single quote instead of a pair with some value inside it.
* bpo-37461: Fix infinite loop in parsing of specially crafted email headers ↵Abhilash Raj2019-07-171-0/+3
| | | | | | | | | | (GH-14794) * bpo-37461: Fix infinite loop in parsing of specially crafted email headers. Some crafted email header would cause the get_parameter method to run in an infinite loop causing a DoS attack surface when parsing those headers. This patch fixes that by making sure the DQUOTE character is handled to prevent going into an infinite loop.
* Fix infinite loop in email folding logic (GH-12732)Paul Ganssle2019-07-161-5/+12
| | | | | | | | | | As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564
* bpo-29412: Fix indexError when parsing a header value ending unexpectedly ↵Abhilash Raj2019-06-261-0/+3
| | | | | | | (GH-14387) * patched string index out of range error in get_word function of _header_value_parser.py and created tests in test__header_value_parser.py for CFWS. * Raise HeaderParseError instead of continuing when parsing a word.
* bpo-36520: Email header folded incorrectly (#13608)websurfer52019-06-061-0/+1
| | | | | | | | | | | | | | | | | * bpo-36520: reset the encoded word offset when starting a new line during an email header folding operation * 📜🤖 Added by blurb_it. * bpo-36520: add an additional test case, and provide descriptive comments for the test_folding_with_utf8_encoding_* tests * bpo-36520: fix whitespace issue * bpo-36520: changes per reviewer request -- remove extraneous backslashes; add whitespace between terminating quotes and line-continuation backslashes; use "bpo-" instead of "issue #" in comments
* bpo-21315: Fix parsing of encoded words with missing leading ws. (#13425)Abhilash Raj2019-06-051-0/+21
| | | | | | | | | | | | * 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-15/+122
| | | | | | | | | | | | | * 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.
* Fix typos in docs and docstrings (GH-13745)Xtreak2019-06-021-1/+1
|
* bpo-33524: Fix the folding of email header when max_line_length is 0 or None ↵Abhilash Raj2019-05-171-1/+2
| | | | | (#13391) and there are non-ascii characters in the header.
* bpo-33529, email: Fix infinite loop in email header encoding (GH-12020)Krzysztof Wojcik2019-05-141-10/+13
|
* bpo-34424: Handle different policy.linesep lengths correctly. (#8803)Jens Troeger2019-05-141-1/+1
|
* email: use dict instead of OrderedDict (GH-11709)Inada Naoki2019-02-051-2/+1
|
* bpo-35133: Fix mistakes when concatenate string literals on different lines. ↵Serhiy Storchaka2018-11-051-2/+2
| | | | | | | | | | (GH-10284) Two kind of mistakes: 1. Missed space. After concatenating there is no space between words. 2. Missed comma. Causes unintentional concatenating in a list of strings.
* bpo-33476: Fix _header_value_parser when address group is missing final ';' ↵Dong-hee Na2018-07-281-1/+1
| | | | (GH-7484)
* bpo-32746: Fix multiple typos (GH-5144)Leo Arias2018-02-041-2/+2
| | | Fix typos found by codespell in docs, docstrings, and comments.
* bpo-27931: Fix email address header parsing error (#5329)jayyyin2018-01-291-1/+7
| | | | Correctly handle addresses whose username is an empty quoted string.
* bpo-27240 Rewrite the email header folding algorithm. (#3488)R. David Murray2017-12-031-443/+286
| | | | | | | | | | | | | | | | | | | | | 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.
* bpo-30349: Raise FutureWarning for nested sets and set operations (#1553)Serhiy Storchaka2017-11-161-5/+4
| | | | in regular expressions.
* bpo-30532: Fix whitespace folding in certain casesJoel Hillacre2017-06-261-3/+1
| | | Leading whitespace was incorrectly dropped during folding of certain lines in the _header_value_parser's folding algorithm. This makes the whitespace handling code consistent.
* #27364: fix "incorrect" uses of escape character in the stdlib.R David Murray2016-09-081-8/+8
| | | | | | | And most of the tools. Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and Martin Panter.
* Issues #23147, #23148: Presumably fixed bugs in folding UnstructuredTokenList.Serhiy Storchaka2016-07-171-2/+2
|
* Issue #27076: Doc, comment and tests spelling fixesMartin Panter2016-05-261-1/+1
| | | | Most fixes to Doc/ and Lib/ directories by Ville Skyttä.
* Issue #26778: Fixed "a/an/and" typos in code comment and documentation.Serhiy Storchaka2016-04-171-3/+3
|
* #24211: Add RFC6532 support to the email library.R David Murray2015-05-171-4/+7
| | | | | | | | | This could use more edge case tests, but the basic functionality is tested. (Note that this changeset does not add tailored support for the RFC 6532 message/global MIME type, but the email package generic facilities will handle it.) Reviewed by Maciej Szulik.
* #23745: handle duplicate MIME parameter names in new parser.R David Murray2015-03-301-7/+27
| | | | | | | | | | This mimics get_param's error handling for the most part. It is slightly better in some regards as get_param can produce some really weird results for duplicate *0* parts. It departs from get_param slightly in that if we have a mix of non-extended and extended pieces for the same parameter name, the new parser assumes they were all supposed to be extended and concatenates all the values, whereas get_param always picks the non-extended parameter value. All of this error recovery is pretty much arbitrary decisions...
* #20977: fix undefined name in the email module. Patch by Rose Ames.Ezio Melotti2014-08-041-3/+3
|
* Issue #20976: pyflakes: Remove unused importsVictor Stinner2014-03-201-1/+1
|
* Merge: #16983: Apply postel's law to encoded words inside quoted strings.R David Murray2014-02-081-0/+7
|\
| * #16983: Apply postel's law to encoded words inside quoted strings.R David Murray2014-02-081-0/+7
| | | | | | | | | | | | | | | | | | | | 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.
* | Merge: #18431: Decode encoded words in atoms in new email parser.R David Murray2013-07-121-2/+21
|\ \ | |/
| * #18431: Decode encoded words in atoms in new email parser.R David Murray2013-07-121-2/+21
| | | | | | | | | | | | 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.
* | Merge: #18044: Fix parsing of encoded words of the form =?utf8?q?=XX...?=R David Murray2013-07-111-36/+7
|\ \ | |/
| * #18044: Fix parsing of encoded words of the form =?utf8?q?=XX...?=R David Murray2013-07-111-36/+7
| | | | | | | | | | | | | | | | | | | | 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.
* | Issue #17516: use comment syntax for comments, instead of multiline stringVictor Stinner2013-03-261-18/+16
| |
* | Merge with 3.3, issue #17047: remove doubled words added in 3.3,Terry Jan Reedy2013-03-111-1/+1
|\ \ | |/ | | | | as reported by Serhiy Storchaka and Matthew Barnett.
| * Issue #17047: remove doubled words added in 3.3Terry Jan Reedy2013-03-111-1/+1
| | | | | | | | as reported by Serhiy Storchaka and Matthew Barnett.
* | utilize yield fromPhilip Jenvey2012-10-011-2/+1
|/
* #15160: Extend the new email parser to handle MIME headers.R David Murray2012-06-241-3/+801
| | | | | | | | | | | | | | | | | | | | | | | 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.
* Recognize '<>' as a special case of an angle-addr in header_value_parser.R David Murray2012-05-261-1/+11
| | | | | | | Although '<>' is invalid according to RFC 5322, SMTP uses it for various things, and it sometimes ends up in email headers. This patch changes get_angle_addr to recognize it and just register a Defect instead of raising a parsing error.
* #12586: add provisional email policy with new header parsing and folding.R David Murray2012-05-251-0/+2145
When the new policies are used (and only when the new policies are explicitly used) headers turn into objects that have attributes based on their parsed values, and can be set using objects that encapsulate the values, as well as set directly from unicode strings. The folding algorithm then takes care of encoding unicode where needed, and folding according to the highest level syntactic objects. With this patch only date and time headers are parsed as anything other than unstructured, but that is all the helper methods in the existing API handle. I do plan to add more parsers, and complete the set specified in the RFC before the package becomes stable.