| 208 | MIMEText.__setitem__(self, name, val) |
| 209 | |
| 210 | def set_payload(self, payload, charset=None): |
| 211 | if charset == "utf-8" and not isinstance(charset, Charset.Charset): |
| 212 | has_long_lines = any( |
| 213 | len(line.encode(errors="surrogateescape")) |
| 214 | > RFC5322_EMAIL_LINE_LENGTH_LIMIT |
| 215 | for line in payload.splitlines() |
| 216 | ) |
| 217 | # Quoted-Printable encoding has the side effect of shortening long |
| 218 | # lines, if any (#22561). |
| 219 | charset = utf8_charset_qp if has_long_lines else utf8_charset |
| 220 | MIMEText.set_payload(self, payload, charset=charset) |
| 221 | |
| 222 | |
| 223 | # RemovedInDjango70Warning. |