summaryrefslogtreecommitdiffstats
path: root/Lib/email
Commit message (Collapse)AuthorAgeFilesLines
* gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233)Petr Viktorin2024-07-304-4/+33
| | | | | | | | | | | | | | | | | | | | | | | | | ## Encode header parts that contain newlines Per RFC 2047: > [...] these encoding schemes allow the > encoding of arbitrary octet values, mail readers that implement this > decoding should also ensure that display of the decoded data on the > recipient's terminal will not cause unwanted side-effects It seems that the "quoted-word" scheme is a valid way to include a newline character in a header value, just like we already allow undecodable bytes or control characters. They do need to be properly quoted when serialized to text, though. ## Verify that email headers are well-formed This should fail for custom fold() implementations that aren't careful about newlines. Co-authored-by: Bas Bloemsaat <bas@bloemsaat.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-121905: Consistently use "floating-point" instead of "floating point" ↵Serhiy Storchaka2024-07-191-1/+1
| | | | (GH-121907)
* gh-120930: Remove extra blank occuring in wrapped encoded words in email ↵Matthieu Caneill2024-07-181-0/+1
| | | | headers (GH-121747)
* Remove almost all unpaired backticks in docstrings (#119231)Geoffrey Thomas2024-05-2211-39/+39
| | | | | | | | | | | | | | | | | | As reported in #117847 and #115366, an unpaired backtick in a docstring tends to confuse e.g. Sphinx running on subclasses of standard library objects, and the typographic style of using a backtick as an opening quote is no longer in favor. Convert almost all uses of the form The variable `foo' should do xyz to The variable 'foo' should do xyz and also fix up miscellaneous other unpaired backticks (extraneous / missing characters). No functional change is intended here other than in human-readable docstrings.
* gh-118643: Fix AttributeError in the email module (GH-119099)Serhiy Storchaka2024-05-221-3/+12
| | | | | | | | Fix regression introduced in gh-100884: AttributeError when re-fold a long address list. Also fix more cases of incorrect encoding of the address separator in the address list missed in gh-100884.
* gh-92081: Fix for email.generator.Generator with whitespace between encoded ↵Toshio Kuratomi2024-05-201-7/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | words. (#92281) * Fix for email.generator.Generator with whitespace between encoded words. email.generator.Generator currently does not handle whitespace between encoded words correctly when the encoded words span multiple lines. The current generator will create an encoded word for each line. If the end of the line happens to correspond with the end real word in the plaintext, the generator will place an unencoded space at the start of the subsequent lines to represent the whitespace between the plaintext words. A compliant decoder will strip all the whitespace from between two encoded words which leads to missing spaces in the round-tripped output. The fix for this is to make sure that whitespace between two encoded words ends up inside of one or the other of the encoded words. This fix places the space inside of the second encoded word. A second problem happens with continuation lines. A continuation line that starts with whitespace and is followed by a non-encoded word is fine because the newline between such continuation lines is defined as condensing to a single space character. When the continuation line starts with whitespace followed by an encoded word, however, the RFCs specify that the word is run together with the encoded word on the previous line. This is because normal words are filded on syntactic breaks by encoded words are not. The solution to this is to add the whitespace to the start of the encoded word on the continuation line. Test cases are from #92081 * Rename a variable so it's not confused with the final variable.
* gh-118798: Remove deprecated isdst parameter from `email.utils.localtime` ↵Hugo van Kemenade2024-05-091-9/+1
| | | | (#118799)
* gh-118455: Fix mangle_from_ default value in email.policy.Policy.__doc__ ↵wim glenn2024-05-051-1/+1
| | | | | | | | | | | | (#118456) * Fix mangle_from_ default value in email.policy.Policy.__doc__ The docstring says it defaults to True, but it actually defaults to False. Only the Compat32 subclass overrides that. --------- Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* gh-80361: Fix TypeError in email.Message.get_payload() (GH-117994)Serhiy Storchaka2024-04-171-1/+1
| | | | | It was raised when the charset is rfc2231 encoded, e.g.: Content-Type: text/plain; charset*=ansi-x3.4-1968''utf-8
* bpo-40944: Fix IndexError when parse emails with truncated Message-ID, ↵Ivan Savin2024-04-171-5/+10
| | | | | address, routes, etc (GH-20790) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-117313: Fix re-folding email messages containing non-standard line ↵Serhiy Storchaka2024-04-171-2/+3
| | | | | | | separators (GH-117369) Only treat '\n', '\r' and '\r\n' as line separators in re-folding the email messages. Preserve control characters '\v', '\f', '\x1c', '\x1d' and '\x1e' and Unicode line separators '\x85', '\u2028' and '\u2029' as is.
* gh-86650: Fix IndexError when parse emails with invalid Message-ID (GH-117934)Serhiy Storchaka2024-04-171-0/+5
| | | | | | | In particularly, one-off addresses generated by Microsoft Outlook: https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/one-off-addresses Co-authored-by: fsc-eriker <72394365+fsc-eriker@users.noreply.github.com>
* gh-75171: Fix parsing invalid email address headers starting or ending with ↵tsufeki2024-04-171-5/+14
| | | | | | a dot (GH-15600) Co-authored-by: Tim Bell <timothybell@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-76511: Fix email.Message.as_string() for non-ASCII message with ASCII ↵Serhiy Storchaka2024-03-052-2/+2
| | | | charset (GH-116125)
* gh-100884: email/_header_value_parser: don't encode list separators (GH-100885)Thomas Weißschuh2024-02-171-1/+2
| | | | | ListSeparator should not be encoded. This could happen when a long line pushes its separator to the next line, which would have been encoded.
* gh-109653: Improve import time of importlib.metadata / email.utils (#114664)Shantanu2024-01-291-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | My criterion for delayed imports is that they're only worth it if the majority of users of the module would benefit from it, otherwise you're just moving latency around unpredictably. mktime_tz is not used anywhere in the standard library and grep.app indicates it's not got much use in the ecosystem either. Distribution.files is not nearly as widely used as other importlib.metadata APIs, so we defer the csv import. Before: ``` λ hyperfine -w 8 './python -c "import importlib.metadata"' Benchmark 1: ./python -c "import importlib.metadata" Time (mean ± σ): 65.1 ms ± 0.5 ms [User: 55.3 ms, System: 9.8 ms] Range (min … max): 64.4 ms … 66.4 ms 44 runs ``` After: ``` λ hyperfine -w 8 './python -c "import importlib.metadata"' Benchmark 1: ./python -c "import importlib.metadata" Time (mean ± σ): 62.0 ms ± 0.3 ms [User: 52.5 ms, System: 9.6 ms] Range (min … max): 61.3 ms … 62.8 ms 46 runs ``` for about a 3ms saving with warm disk cache, maybe 7-11ms with cold disk cache.
* gh-77749: Fix inconsistent behavior of non-ASCII handling in ↵Rito Takeuchi2024-01-261-1/+8
| | | | | | | EmailPolicy.fold() (GH-6986) It now always encodes non-ASCII characters in headers if utf8 is false. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-113594: Fix UnicodeEncodeError in TokenList.fold() (GH-113730)Serhiy Storchaka2024-01-101-0/+7
| | | It occurred when try to re-encode an unknown-8bit part combined with non-unknown-8bit part.
* [CVE-2023-27043] gh-102988: Reject malformed addresses in email.parseaddr() ↵Victor Stinner2023-12-151-9/+142
| | | | | | | | | | (#111116) Detect email address parsing errors and return empty tuple to indicate the parsing error (old API). Add an optional 'strict' parameter to getaddresses() and parseaddr() functions. Patch by Thomas Dwyer. Co-Authored-By: Thomas Dwyer <github@tomd.tel>
* gh-94606: Fix error when message with Unicode surrogate not surrogateescaped ↵Sidney Markowitz2023-12-112-16/+17
| | | | | string (GH-94641) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-109653: Improve the import time of `email.utils` (#109824)Alex Waygood2023-10-121-5/+7
|
* gh-106186: Don't report MultipartInvariantViolationDefect for valid ↵htsedebenham2023-07-231-1/+1
| | | | multipart emails when parsing header only (#107016)
* gh-106669: Revert "gh-102988: Detect email address parsing errors ... ↵Gregory P. Smith2023-07-211-57/+6
| | | | | | | | (#105127)" (#106733) This reverts commit 18dfbd035775c15533d13a98e56b1d2bf5c65f00. Adds a regression test from the issue. See https://github.com/python/cpython/issues/106669.
* gh-106628: email parsing speedup (gh-106629)CF Bolz-Tereick2023-07-131-6/+9
|
* gh-102988: Detect email address parsing errors and return empty tuple to ↵Thomas Dwyer2023-07-101-6/+57
| | | | | | | | | indicate the parsing error (old API) (#105127) Detect email address parsing errors and return empty tuple to indicate the parsing error (old API). This fixes or at least ameliorates CVE-2023-27043. --------- Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-102542 Remove unused bytes object and bytes slicing (#106433)JosephSBoyle2023-07-051-7/+4
| | | | | Remove unused bytes object and bytes slicing Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* GH-103857: Deprecate utcnow and utcfromtimestamp (#103858)Paul Ganssle2023-04-271-4/+4
| | | | | Using `datetime.datetime.utcnow()` and `datetime.datetime.utcfromtimestamp()` will now raise a `DeprecationWarning`. We also have removed our internal uses of these functions and documented the change.
* gh-102498 Clean up unused variables and imports in the email module (#102482)JosephSBoyle2023-04-245-10/+6
| | | | | | | | | | | | | | | | | | | | | * Clean up unused variables and imports in the email module * Remove extra newline char * Remove superflous dict+unpacking syntax * Remove unused 'msg' var * Clean up unused variables and imports in the email module * Remove extra newline char * Remove superflous dict+unpacking syntax * Remove unused 'msg' var --------- Co-authored-by: Barry Warsaw <barry@python.org>
* gh-72346: Added isdst deprecation warning to email.utils.localtime (GH-91450)Alan Williams2023-03-201-29/+11
|
* gh-102507 Remove invisible pagebreak characters (#102531)JosephSBoyle2023-03-0814-35/+2
| | | Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
* gh-101021: Document binary parameters as bytes (#101024)Bob Kline2023-01-143-3/+3
|
* gh-100792: Make `email.message.Message.__contains__` twice as fast (#100793)Nikita Sobolev2023-01-071-1/+5
|
* bpo-45975: Simplify some while-loops with walrus operator (GH-29347)Nick Drozd2022-11-261-4/+1
|
* Fix typo on inline comment for email.generator (GH-98210)Gary Donovan2022-11-251-1/+1
| | | Trivial change to comment - no issue or new entry necessary
* gh-95087: Fix IndexError in parsing invalid date in the email module (GH-95201)Serhiy Storchaka2022-07-251-0/+4
| | | | Co-authored-by: wouter bolsterlee <wouter@bolsterl.ee>
* gh-93010: InvalidHeaderError used but nonexistent (#93015)oda-gitso2022-05-231-1/+1
| | | | | * fix issue 93010 Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* gh-77630: Change Charset to charset (GH-92439)slateny2022-05-081-5/+5
|
* bpo-43323: Fix UnicodeEncodeError in the email module (GH-32137)Serhiy Storchaka2022-04-302-6/+6
| | | | | 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).
* gh-91217: deprecate uu (GH-92009)Brett Cannon2022-04-281-9/+36
| | | Automerge-Triggered-By: GH:brettcannon
* Rewrite audio.py to jive with image.py (#91886)Barry Warsaw2022-04-241-53/+55
| | | | | | | Similar to the rewrite of email/mime/image.py and associated test after the deprecation of imghdr.py, thisrewrites email/mime/audio.py and associated tests after the deprecation of sndhdr.py. Closes #91885
* gh-91217: deprecate-sndhdr (#91806)Brett Cannon2022-04-221-13/+37
| | | | | Also inline necessary functionality from `sndhdr` into `email.mime.audio` for `MIMEAudio`. Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
* gh-91520: Rewrite imghdr inlining for clarity and completeness (#91521)Barry Warsaw2022-04-151-67/+73
| | | | | | | | | | | | | | | | | | | | * Rewrite imghdr inlining for clarity and completeness * Move MIMEImage class back closer to the top of the file since it's the important thing. * Use a decorate to mark a given rule function and simplify the rule function names for clarity. * Copy over all the imghdr test data files into the email package's test data directory. This way when imghdr is actually removed, it won't affect the MIMEImage guessing tests. * Rewrite and extend the MIMEImage tests to test for all supported auto-detected MIME image subtypes. * Remove the now redundant PyBanner048.gif data file. * See https://github.com/python/cpython/pull/91461#discussion_r850313336 Co-authored-by: Oleg Iarygin <dralife@yandex.ru> Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
* gh-91217: deprecate imghdr (#91461)Brett Cannon2022-04-131-11/+110
| | | | | | | | | | | | | | * Deprecate imghdr Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> * Update Doc/whatsnew/3.11.rst Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> * Inline `imghdr` into `email.mime.image` Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Barry Warsaw <barry@python.org>
* bpo-26579: Add object.__getstate__(). (GH-2821)Serhiy Storchaka2022-04-061-1/+1
| | | | | | | Copying and pickling instances of subclasses of builtin types bytearray, set, frozenset, collections.OrderedDict, collections.deque, weakref.WeakSet, and datetime.tzinfo now copies and pickles instance attributes implemented as slots.
* bpo-46565: `del` loop vars that are leaking into module namespaces (GH-30993)Nikita Sobolev2022-02-032-0/+4
|
* bpo-45239: Fix parsedate_tz when time has more than 2 dots in it (GH-28452)Ben Hoyt2021-10-131-0/+2
| | | Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* Fix typos in the Lib directory (GH-28775)Christian Clauss2021-10-061-1/+1
| | | | | Fix typos in the Lib directory as identified by codespell. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-45060: Get rid of few uses of the equality operators with None (GH-28087)Serhiy Storchaka2021-08-311-1/+1
|
* bpo-45001: Make email date parsing more robust against malformed input ↵wouter bolsterlee2021-08-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-27946) Various date parsing utilities in the email module, such as email.utils.parsedate(), are supposed to gracefully handle invalid input, typically by raising an appropriate exception or by returning None. The internal email._parseaddr._parsedate_tz() helper used by some of these date parsing routines tries to be robust against malformed input, but unfortunately it can still crash ungracefully when a non-empty but whitespace-only input is passed. This manifests as an unexpected IndexError. In practice, this can happen when parsing an email with only a newline inside a ‘Date:’ header, which unfortunately happens occasionally in the real world. Here's a minimal example: $ python Python 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import email.utils >>> email.utils.parsedate('foo') >>> email.utils.parsedate(' ') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.9/email/_parseaddr.py", line 176, in parsedate t = parsedate_tz(data) File "/usr/lib/python3.9/email/_parseaddr.py", line 50, in parsedate_tz res = _parsedate_tz(data) File "/usr/lib/python3.9/email/_parseaddr.py", line 72, in _parsedate_tz if data[0].endswith(',') or data[0].lower() in _daynames: IndexError: list index out of range The fix is rather straight-forward: guard against empty lists, after splitting on whitespace, but before accessing the first element.
* bpo-41402: Fix email ContentManager calling .encode() on bytes (GH-21631)Johannes Reiff2021-08-091-3/+1
|