Set the Content-Transfer-Encoding header to 7bit or 8bit.
(msg)
| 45 | |
| 46 | |
| 47 | def encode_7or8bit(msg): |
| 48 | """Set the Content-Transfer-Encoding header to 7bit or 8bit.""" |
| 49 | orig = msg.get_payload(decode=True) |
| 50 | if orig is None: |
| 51 | # There's no payload. For backwards compatibility we use 7bit |
| 52 | msg['Content-Transfer-Encoding'] = '7bit' |
| 53 | return |
| 54 | # We play a trick to make this go fast. If decoding from ASCII succeeds, |
| 55 | # we know the data must be 7bit, otherwise treat it as 8bit. |
| 56 | try: |
| 57 | orig.decode('ascii') |
| 58 | except UnicodeError: |
| 59 | msg['Content-Transfer-Encoding'] = '8bit' |
| 60 | else: |
| 61 | msg['Content-Transfer-Encoding'] = '7bit' |
| 62 | |
| 63 | |
| 64 | def encode_noop(msg): |
nothing calls this directly
no test coverage detected
searching dependent graphs…