Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions problem_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def _create_compressed_attachment(name: str, value: bytes) -> email.mime.base.MI
return attachment


def _create_text_attachment(name: str, value: str) -> email.mime.base.MIMEBase:
filename = _add_extension_if_missing(name, ".txt")
attachment = email.mime.text.MIMEText(value, _charset="UTF-8")
attachment.add_header("Content-Disposition", "attachment", filename=filename)
return attachment


def _derive_compression(name: str, value: bytes) -> tuple[str, str]:
if value.startswith(GZIP_HEADER_START):
return ("gzip", ".gz")
Expand Down Expand Up @@ -903,11 +910,7 @@ def write_mime(
text += v.strip().replace("\n", "\n ") + "\n"
else:
# too large, separate attachment
att = email.mime.text.MIMEText(v, _charset="UTF-8")
att.add_header(
"Content-Disposition", "attachment", filename=k + ".txt"
)
attachments.append(att)
attachments.append(_create_text_attachment(k, v))

# create initial text attachment
att = email.mime.text.MIMEText(text, _charset="UTF-8")
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_problem_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def test_write_mime_text(self) -> None:
pr["SimpleLineEnd"] = "bar\n"
pr["TwoLine"] = "first\nsecond\n"
pr["InlineMargin"] = "first\nsecond\nthird\nfourth\nfifth\n"
pr["Multiline"] = " foo bar\nbaz\n blip \nline4\nline♥5!!\nłıµ€ ⅝\n"
pr["Multiline.txt"] = " foo bar\nbaz\n blip \nline4\nline♥5!!\nłıµ€ ⅝\n"

# still small enough for inline text
pr["Largeline"] = "A" * 999
Expand Down
Loading