From 35d3e4ff127b0213fa4d34f630c4a019e533a4df Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sun, 2 Aug 2026 17:27:07 +0200 Subject: feat: add MimeParser with GMime and safe attachment naming --- tests/fixtures/alternative.eml | 16 ++++++++++++++++ tests/fixtures/attachment.eml | 18 ++++++++++++++++++ tests/fixtures/encoded_subject.eml | 7 +++++++ tests/fixtures/hostile_filename.eml | 17 +++++++++++++++++ tests/fixtures/inline_image.eml | 19 +++++++++++++++++++ tests/fixtures/plain.eml | 12 ++++++++++++ tests/fixtures/truncated.eml | 11 +++++++++++ 7 files changed, 100 insertions(+) create mode 100644 tests/fixtures/alternative.eml create mode 100644 tests/fixtures/attachment.eml create mode 100644 tests/fixtures/encoded_subject.eml create mode 100644 tests/fixtures/hostile_filename.eml create mode 100644 tests/fixtures/inline_image.eml create mode 100644 tests/fixtures/plain.eml create mode 100644 tests/fixtures/truncated.eml (limited to 'tests/fixtures') diff --git a/tests/fixtures/alternative.eml b/tests/fixtures/alternative.eml new file mode 100644 index 0000000..1c35d79 --- /dev/null +++ b/tests/fixtures/alternative.eml @@ -0,0 +1,16 @@ +From: Alice +Subject: Both parts +Date: Sat, 01 Aug 2026 10:00:00 +0000 +Message-ID: +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="BOUND" + +--BOUND +Content-Type: text/plain; charset=utf-8 + +plain version +--BOUND +Content-Type: text/html; charset=utf-8 + +

html version

+--BOUND-- diff --git a/tests/fixtures/attachment.eml b/tests/fixtures/attachment.eml new file mode 100644 index 0000000..a0410e4 --- /dev/null +++ b/tests/fixtures/attachment.eml @@ -0,0 +1,18 @@ +From: Alice +Subject: With attachment +Date: Sat, 01 Aug 2026 10:00:00 +0000 +Message-ID: +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="MIX" + +--MIX +Content-Type: text/plain; charset=utf-8 + +see attached +--MIX +Content-Type: text/plain; charset=utf-8; name="notes.txt" +Content-Disposition: attachment; filename="notes.txt" +Content-Transfer-Encoding: quoted-printable + +caf=C3=A9 notes +--MIX-- diff --git a/tests/fixtures/encoded_subject.eml b/tests/fixtures/encoded_subject.eml new file mode 100644 index 0000000..7dcb6f8 --- /dev/null +++ b/tests/fixtures/encoded_subject.eml @@ -0,0 +1,7 @@ +From: =?utf-8?B?w4RsaWNl?= +Subject: =?utf-8?Q?Caf=C3=A9_meeting?= +Date: Sat, 01 Aug 2026 10:00:00 +0000 +Message-ID: +Content-Type: text/plain; charset=utf-8 + +body diff --git a/tests/fixtures/hostile_filename.eml b/tests/fixtures/hostile_filename.eml new file mode 100644 index 0000000..4dc79b6 --- /dev/null +++ b/tests/fixtures/hostile_filename.eml @@ -0,0 +1,17 @@ +From: Attacker +Subject: Hostile attachment name +Date: Sat, 01 Aug 2026 10:00:00 +0000 +Message-ID: +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="EVIL" + +--EVIL +Content-Type: text/plain; charset=utf-8 + +body +--EVIL +Content-Type: text/plain; name="../../../../tmp/pwned.txt" +Content-Disposition: attachment; filename="../../../../tmp/pwned.txt" + +owned +--EVIL-- diff --git a/tests/fixtures/inline_image.eml b/tests/fixtures/inline_image.eml new file mode 100644 index 0000000..a9dd24b --- /dev/null +++ b/tests/fixtures/inline_image.eml @@ -0,0 +1,19 @@ +From: Alice +Subject: Inline image +Date: Sat, 01 Aug 2026 10:00:00 +0000 +Message-ID: +MIME-Version: 1.0 +Content-Type: multipart/related; boundary="REL" + +--REL +Content-Type: text/html; charset=utf-8 + + +--REL +Content-Type: image/png +Content-Transfer-Encoding: base64 +Content-ID: + +iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9 +awAAAABJRU5ErkJggg== +--REL-- diff --git a/tests/fixtures/plain.eml b/tests/fixtures/plain.eml new file mode 100644 index 0000000..81f06b4 --- /dev/null +++ b/tests/fixtures/plain.eml @@ -0,0 +1,12 @@ +From: Alice +To: Bob +Subject: Plain hello +Date: Sat, 01 Aug 2026 10:00:00 +0000 +Message-ID: +Content-Type: text/plain; charset=utf-8 + +Hello Bob. + +> quoted line +Regards, +Alice diff --git a/tests/fixtures/truncated.eml b/tests/fixtures/truncated.eml new file mode 100644 index 0000000..912a522 --- /dev/null +++ b/tests/fixtures/truncated.eml @@ -0,0 +1,11 @@ +From: Alice +Subject: Truncated +Date: Sat, 01 Aug 2026 10:00:00 +0000 +Message-ID: +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="CUT" + +--CUT +Content-Type: text/plain; charset=utf-8 + +this part never closes -- cgit v1.2.3