(msg, data, maintype, subtype, cte='base64',
disposition=None, filename=None, cid=None,
params=None, headers=None)
| 217 | |
| 218 | |
| 219 | def set_bytes_content(msg, data, maintype, subtype, cte='base64', |
| 220 | disposition=None, filename=None, cid=None, |
| 221 | params=None, headers=None): |
| 222 | _prepare_set(msg, maintype, subtype, headers) |
| 223 | if cte == 'base64': |
| 224 | data = binascii.b2a_base64(data, wrapcol=msg.policy.max_line_length) |
| 225 | data = data.decode('ascii') |
| 226 | elif cte == 'quoted-printable': |
| 227 | # XXX: quoprimime.body_encode won't encode newline characters in data, |
| 228 | # so we can't use it. This means max_line_length is ignored. Another |
| 229 | # bug to fix later. (Note: encoders.quopri is broken on line ends.) |
| 230 | data = binascii.b2a_qp(data, istext=False, header=False, quotetabs=True) |
| 231 | data = data.decode('ascii') |
| 232 | elif cte == '7bit': |
| 233 | data = data.decode('ascii') |
| 234 | elif cte in ('8bit', 'binary'): |
| 235 | data = data.decode('ascii', 'surrogateescape') |
| 236 | msg.set_payload(data) |
| 237 | msg['Content-Transfer-Encoding'] = cte |
| 238 | _finalize_set(msg, disposition, filename, cid, params) |
| 239 | for typ in (bytes, bytearray, memoryview): |
| 240 | raw_data_manager.add_set_handler(typ, set_bytes_content) |
| 241 | del typ |
nothing calls this directly
no test coverage detected
searching dependent graphs…