diff --git a/apps/dav/lib/CardDAV/ImageExportPlugin.php b/apps/dav/lib/CardDAV/ImageExportPlugin.php index 192c1e69ed13e..fa4d5ea23f253 100644 --- a/apps/dav/lib/CardDAV/ImageExportPlugin.php +++ b/apps/dav/lib/CardDAV/ImageExportPlugin.php @@ -103,7 +103,8 @@ public function httpGet(RequestInterface $request, ResponseInterface $response) try { $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node); $response->setHeader('Content-Type', $file->getMimeType()); - $response->setHeader('Content-Disposition', 'attachment'); + $fileName = $node->getName() . '.' . PhotoCache::ALLOWED_CONTENT_TYPES[$file->getMimeType()]; + $response->setHeader('Content-Disposition', "attachment; filename=$fileName"); $response->setStatus(200); $response->setBody($file->getContent()); diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index ca3853c76e687..6ea999444af02 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -43,7 +43,7 @@ class PhotoCache { /** @var array */ - protected const ALLOWED_CONTENT_TYPES = [ + public const ALLOWED_CONTENT_TYPES = [ 'image/png' => 'png', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', diff --git a/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php b/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php index c3698a24a7862..c116a5ff7757d 100644 --- a/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php +++ b/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php @@ -166,7 +166,7 @@ public function testCard($size, $photo) { if ($photo) { $file = $this->createMock(ISimpleFile::class); $file->method('getMimeType') - ->willReturn('imgtype'); + ->willReturn('image/jpeg'); $file->method('getContent') ->willReturn('imgdata'); @@ -176,10 +176,10 @@ public function testCard($size, $photo) { $this->response->expects($this->at(3)) ->method('setHeader') - ->with('Content-Type', 'imgtype'); + ->with('Content-Type', 'image/jpeg'); $this->response->expects($this->at(4)) ->method('setHeader') - ->with('Content-Disposition', 'attachment'); + ->with('Content-Disposition', 'attachment; filename=card.jpg'); $this->response->expects($this->once()) ->method('setStatus') diff --git a/build/integration/features/carddav.feature b/build/integration/features/carddav.feature index 57fd8cd7da44f..16c165b6bab67 100644 --- a/build/integration/features/carddav.feature +++ b/build/integration/features/carddav.feature @@ -55,7 +55,7 @@ Feature: carddav Given "admin" uploads the contact "bjoern.vcf" to the addressbook "MyAddressbook" When Exporting the picture of contact "bjoern.vcf" from addressbook "MyAddressbook" as user "admin" Then The following HTTP headers should be set - |Content-Disposition|attachment| + |Content-Disposition|attachment; filename=bjoern.vcf.jpg| |Content-Type|image/jpeg| |Content-Security-Policy|default-src 'none';| |X-Content-Type-Options |nosniff|