summaryrefslogtreecommitdiffstats
path: root/Lib/email
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* bpo-42892: fix email multipart attribute error (GH-26903)andrei kulakov2021-07-301-2/+2
|
* bpo-27513: email.utils.getaddresses() now handles Header objects (#13797)Zackery Spytz2021-07-191-1/+1
| | | | | | getaddresses() should be able to handle a Header object if passed one. Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-44395: Fix MIMEPart.as_string to pass unixfrom properly (GH-26685)Dong-hee Na2021-06-211-2/+2
|
* bpo-43125: Fix: return expected type (str), not original value (bytes) in ↵Grégory Starck2021-03-301-1/+1
| | | | email/base64mime.py::body_encode (GH-24476)
* Remove comment about a private email.headerregistry (GH-24233)Florian Bruhin2021-02-241-4/+0
| | | It's been public since 2012: ea9766897bf1d2ccf610ff9ce805acca7c4cce6f
* bpo-30681: Support invalid date format or value in email Date header (GH-22090)Georges Toth2020-10-274-3/+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-27321 Fix email.generator.py to not replace a non-existent header. ↵Mark Sapiro2020-10-191-1/+5
| | | | | | | | | | | (GH-18074) This PR replaces #1977. The reason for the replacement is two-fold. The fix itself is different is that if the CTE header doesn't exist in the original message, it is inserted. This is important because the new CTE could be quoted-printable whereas the original is implicit 8bit. Also the tests are different. The test_nonascii_as_string_without_cte test in #1977 doesn't actually test the issue in that it passes without the fix. The test_nonascii_as_string_without_content_type_and_cte test is improved here, and even though it doesn't fail without the fix, it is included for completeness. Automerge-Triggered-By: @warsaw
* Typo fix - "mesasge" should be "message" (GH-22498)Hansraj Das2020-10-021-2/+2
| | | * Correct at 2 places in email module
* bpo-40597: Allow email.contextmanager set_content() to set a null string. ↵Mark Sapiro2020-07-081-1/+1
| | | | (GH-20542)
* Improve readability of `formataddr` docstring (GH-20963)Jürgen Gmach2020-06-191-1/+1
| | | | | | | For me as a non native English speaker, the sentence with its embedded clause was very hard to understand. modified: Lib/email/utils.py Automerge-Triggered-By: @csabella
* 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-40597: email: Use CTE if lines are longer than max_line_length ↵Arkadiusz Hiler2020-05-141-7/+7
| | | | | | | | | | | | | | | consistently (gh-20038) raw_data_manager (default for EmailPolicy, EmailMessage) does correct wrapping of 'text' parts as long as the message contains characters outside of 7bit US-ASCII set: base64 or qp Content-Transfer-Encoding is applied if the lines would be too long without it. It did not, however, do this for ascii-only text, which could result in lines that were longer than policy.max_line_length or even the rfc 998 maximum. This changeset fixes the heuristic so that if lines are longer than policy.max_line_length, it will always apply a content-transfer-encoding so that the lines are wrapped correctly.
* bpo-39073: validate Address parts to disallow CRLF (#19007)Ashwin Ramaswami2020-03-301-0/+5
| | | Disallow CR or LF in email.headerregistry.Address arguments to guard against header injection attacks.
* 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-34002: Minor efficiency and clarity improvements in email package. (GH-7999)Michael Selik2019-09-202-25/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Check intersection of two sets explicitly Comparing ``len(a) > ``len(a - b)`` is essentially looking for an intersection between the two sets. If set ``b`` does not intersect ``a`` then ``len(a - b)`` will be equal to ``len(a)``. This logic is more clearly expressed as ``a & b``. * Change while/pop to a for-loop Copying the list, then repeatedly popping the first element was unnecessarily slow. I also cleaned up a couple other inefficiencies. There's no need to unpack a tuple, then re-pack and append it. The list can be created with the first element instead of empty. Secondly, the ``endswith`` method returns a bool, so there's no need for an if- statement to set ``encoding`` to True or False. * Use set.intersection to check for intersections ``a.intersection(b)`` method is more clear of purpose than ``not a.isdisjoint(b)`` and avoids an unnecessary set construction that ``a & set(b)`` performs. * Use not isdisjoint instead of intersection While it reads slightly worse, the isdisjoint method will stop when it finds a counterexample and returns a bool, rather than looping over the entire iterable and constructing a new set.
* 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-37685: Fixed __eq__, __lt__ etc implementations in some classes. (GH-14952)Serhiy Storchaka2019-08-081-4/+4
| | | | They now return NotImplemented for unsupported type of the other operand.
* Fix typos in docs, comments and test assert messages (#14872)Min ho Kim2019-07-211-1/+1
|
* bpo-34155: Dont parse domains containing @ (GH-13079)jpic2019-07-172-1/+12
| | | | | | | | | | | | | | | | | | | | | | 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.