MCPcopy Index your code
hub / github.com/python/cpython / header_encode

Function header_encode

Lib/email/quoprimime.py:127–145  ·  view source on GitHub ↗

Encode a single header line with quoted-printable (like) encoding. Defined in RFC 2045, this 'Q' encoding is similar to quoted-printable, but used specifically for email header fields to allow charsets with mostly 7 bit characters (and some 8 bit) to remain more or less readable in non-

(header_bytes, charset='iso-8859-1')

Source from the content-addressed store, hash-verified

125
126
127def header_encode(header_bytes, charset='iso-8859-1'):
128 """Encode a single header line with quoted-printable (like) encoding.
129
130 Defined in RFC 2045, this 'Q' encoding is similar to quoted-printable, but
131 used specifically for email header fields to allow charsets with mostly 7
132 bit characters (and some 8 bit) to remain more or less readable in non-RFC
133 2045 aware mail clients.
134
135 charset names the character set to use in the RFC 2046 header. It
136 defaults to iso-8859-1.
137 """
138 # Return empty headers as an empty string.
139 if not header_bytes:
140 return ''
141 # Iterate over every byte, encoding if necessary.
142 encoded = header_bytes.decode('latin1').translate(_QUOPRI_HEADER_MAP)
143 # Now add the RFC chrome to each encoded chunk and glue the chunks
144 # together.
145 return '=?%s?q?%s?=' % (charset, encoded)
146
147
148_QUOPRI_BODY_ENCODE_MAP = _QUOPRI_BODY_MAP[:]

Callers

nothing calls this directly

Calls 2

translateMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…