Skip to content

Commit

Permalink
Fix interoperability of rfc822_escape with stblib's email library
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Aug 30, 2023
1 parent 157fbfe commit 0ece987
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,12 @@ def rfc822_escape(header):
"""Return a version of the string escaped for inclusion in an
RFC-822 header, by ensuring there are 8 spaces space after each newline.
"""
lines = header.split('\n')
sep = '\n' + 8 * ' '
return sep.join(lines)
indent = 8 * " "
lines = header.splitlines(keepends=True)

# Emulate the behaviour of `str.split`
# (the terminal line break in `splitlines` does not result in an extra line):
ends_in_newline = lines and lines[-1].splitlines()[0] != lines[-1]
suffix = indent if ends_in_newline else ""

return indent.join(lines) + suffix

0 comments on commit 0ece987

Please sign in to comment.