Encode a single header line with Base64 encoding in a given charset. charset names the character set to use to encode the header. It defaults to iso-8859-1. Base64 encoding is defined in RFC 2045.
(header_bytes, charset='iso-8859-1')
| 57 | |
| 58 | |
| 59 | def header_encode(header_bytes, charset='iso-8859-1'): |
| 60 | """Encode a single header line with Base64 encoding in a given charset. |
| 61 | |
| 62 | charset names the character set to use to encode the header. It defaults |
| 63 | to iso-8859-1. Base64 encoding is defined in RFC 2045. |
| 64 | """ |
| 65 | if not header_bytes: |
| 66 | return "" |
| 67 | if isinstance(header_bytes, str): |
| 68 | header_bytes = header_bytes.encode(charset) |
| 69 | encoded = b64encode(header_bytes).decode("ascii") |
| 70 | return '=?%s?b?%s?=' % (charset, encoded) |
| 71 | |
| 72 | |
| 73 | def body_encode(s, maxlinelen=76, eol=NL): |
nothing calls this directly
no test coverage detected