From 9344ad8df7b0f38dd7b08e28a7c0e1ded43eeca6 Mon Sep 17 00:00:00 2001 From: Lucas Feldtmann Date: Thu, 20 Aug 2026 10:53:15 +0200 Subject: [PATCH] Restore txt as preferred extension for text/plain elephox/mimey deliberately maps text/plain to the env extension first (elephox-dev/mimey@d72acba), so getExtension('text/plain') returned 'env' since the switch from the ralouphie/mimey fork. Consumers using the mime-to-extension direction to name files (AttachmentFilenameFixer in bipro-transfer) would have produced '*.env' instead of '*.txt' for text/plain attachments without a usable filename extension. Prepending txt restores the previous behavior; env remains a known extension. Co-Authored-By: Claude Fable 5 --- src/MimeTypesFactory.php | 1 + tests/MimeTypesFactoryTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/MimeTypesFactoryTest.php diff --git a/src/MimeTypesFactory.php b/src/MimeTypesFactory.php index 513cefb..1939835 100644 --- a/src/MimeTypesFactory.php +++ b/src/MimeTypesFactory.php @@ -21,6 +21,7 @@ public static function create(): MimeTypes $builder->add('application/gzip', 'gz'); $builder->add('application/vnd.ms-outlook', 'msg'); $builder->add('application/dat', 'dat'); + $builder->add('text/plain', 'txt'); return new MimeTypes($builder->getMapping()); } diff --git a/tests/MimeTypesFactoryTest.php b/tests/MimeTypesFactoryTest.php new file mode 100644 index 0000000..dfcbdda --- /dev/null +++ b/tests/MimeTypesFactoryTest.php @@ -0,0 +1,28 @@ +assertSame('application/gzip', $mimeTypes->getMimeType('gzip')); + $this->assertSame('application/gzip', $mimeTypes->getMimeType('gz')); + $this->assertSame('application/vnd.ms-outlook', $mimeTypes->getMimeType('msg')); + $this->assertSame('application/dat', $mimeTypes->getMimeType('dat')); + } + + public function testTextPlainPrefersTxtExtension(): void + { + $mimeTypes = MimeTypesFactory::create(); + + $this->assertSame('txt', $mimeTypes->getExtension('text/plain')); + $this->assertSame('text/plain', $mimeTypes->getMimeType('env')); + $this->assertSame('text/plain', $mimeTypes->getMimeType('txt')); + } +}