r"""Encode a string with base64. Each line will be wrapped at, at most, maxlinelen characters (defaults to 76 characters). Each line of encoded text will end with eol, which defaults to "\n". Set this to "\r\n" if you will be using the result of this function directly in an em
(s, maxlinelen=76, eol=NL)
| 71 | |
| 72 | |
| 73 | def body_encode(s, maxlinelen=76, eol=NL): |
| 74 | r"""Encode a string with base64. |
| 75 | |
| 76 | Each line will be wrapped at, at most, maxlinelen characters (defaults to |
| 77 | 76 characters). |
| 78 | |
| 79 | Each line of encoded text will end with eol, which defaults to "\n". Set |
| 80 | this to "\r\n" if you will be using the result of this function directly |
| 81 | in an email. |
| 82 | """ |
| 83 | if not s: |
| 84 | return "" |
| 85 | |
| 86 | if not eol: |
| 87 | return b2a_base64(s, newline=False).decode("ascii") |
| 88 | |
| 89 | # BAW: should encode() inherit b2a_base64()'s dubious behavior in |
| 90 | # adding a newline to the encoded string? |
| 91 | enc = b2a_base64(s, wrapcol=maxlinelen).decode("ascii") |
| 92 | if eol != NL: |
| 93 | enc = enc.replace(NL, eol) |
| 94 | return enc |
| 95 | |
| 96 | |
| 97 | def decode(string): |