Encode a folder name using IMAP modified UTF-7 encoding. Despite the function's name, the output is still a unicode string.
(s)
| 28 | PRINTABLE = set(range(0x20, 0x26)) | set(range(0x27, 0x7f)) |
| 29 | |
| 30 | def encode(s): |
| 31 | """Encode a folder name using IMAP modified UTF-7 encoding. |
| 32 | |
| 33 | Despite the function's name, the output is still a unicode string. |
| 34 | """ |
| 35 | if not isinstance(s, text_type): |
| 36 | return s |
| 37 | |
| 38 | r = [] |
| 39 | _in = [] |
| 40 | |
| 41 | def extend_result_if_chars_buffered(): |
| 42 | if _in: |
| 43 | r.extend(['&', modified_utf7(''.join(_in)), '-']) |
| 44 | del _in[:] |
| 45 | |
| 46 | for c in s: |
| 47 | if ord(c) in PRINTABLE: |
| 48 | extend_result_if_chars_buffered() |
| 49 | r.append(c) |
| 50 | elif c == '&': |
| 51 | extend_result_if_chars_buffered() |
| 52 | r.append('&-') |
| 53 | else: |
| 54 | _in.append(c) |
| 55 | |
| 56 | extend_result_if_chars_buffered() |
| 57 | |
| 58 | return ''.join(r) |
| 59 | |
| 60 | def decode(s): |
| 61 | """Decode a folder name from IMAP modified UTF-7 encoding to unicode. |
nothing calls this directly
no test coverage detected
searching dependent graphs…