Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Doc/library/email.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ of the new API.
.. function:: encode_rfc2231(s, charset=None, language=None)

Encode the string *s* according to :rfc:`2231`. Optional *charset* and
*language*, if given, are the character set name and language name to use. If
neither is given, *s* is returned as-is. If *charset* is given but *language*
is not, the string is encoded using the empty string for *language*.
*language*, if given, are the character set name and language name to use.
The string is always percent-encoded. If neither is given, the encoded
string is returned without the character set and language prefix. If
*charset* is given but *language* is not, the string is encoded using the
empty string for *language*.


.. function:: collapse_rfc2231_value(value, errors='replace', fallback_charset='us-ascii')
Expand Down
7 changes: 4 additions & 3 deletions Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ def decode_rfc2231(s):
def encode_rfc2231(s, charset=None, language=None):
"""Encode string according to RFC 2231.

If neither charset nor language is given, then s is returned as-is. If
charset is given but not language, the string is encoded using the empty
string for language.
The string is always percent-encoded. If neither charset nor language is
given, then the encoded string is returned without the charset and
language prefix. If charset is given but not language, the string is
encoded using the empty string for language.
"""
s = urllib.parse.quote(s, safe='', encoding=charset or 'ascii')
if charset is None and language is None:
Expand Down
Loading