From 67e2900cb5bade76711ef8143d380dfd7d567b95 Mon Sep 17 00:00:00 2001 From: Basil Suter Date: Tue, 29 Jan 2019 17:02:41 +0100 Subject: [PATCH] use basename for mail attachment closes #1900 --- core/CHANGELOG.md | 1 + core/components/Mail.php | 2 +- tests/core/components/MailTest.php | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 32f4e947c..dd9c87401 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. This projec ### Fixed ++ [#1900](https://github.com/luyadev/luya/issues/1900) Fixed issue when attachment file name is not provided. + [#1902](https://github.com/luyadev/luya/pull/1902) Composition component hides alternate url lang codes when hideDefaultPrefixOnly is true and current lang code is default. + [#1898](https://github.com/luyadev/luya/issues/1898) Telephone link raises an exception if an invalid telephone number is provided. + [#1897](https://github.com/luyadev/luya/issues/1897) Yii_* constants where not available in config files as Yii entry script was loaded after config files. diff --git a/core/components/Mail.php b/core/components/Mail.php index ba3b5f063..a61932987 100644 --- a/core/components/Mail.php +++ b/core/components/Mail.php @@ -432,7 +432,7 @@ public function bccAddress($email, $name = null) */ public function addAttachment($filePath, $name = null) { - $this->getMailer()->addAttachment($filePath, empty($name) ? '' : $name); + $this->getMailer()->addAttachment($filePath, empty($name) ? pathinfo($filePath, PATHINFO_BASENAME) : $name); return $this; } diff --git a/tests/core/components/MailTest.php b/tests/core/components/MailTest.php index 1d0dea4e0..2987f569f 100644 --- a/tests/core/components/MailTest.php +++ b/tests/core/components/MailTest.php @@ -161,4 +161,14 @@ public function testAltBodySetBySetter() $this->assertSame('Bar', $mail->convertMessageToAltBody('

Bar

')); } + + public function testAttachementPathInfo() + { + $mail = new Mail(); + $mail->compose('bar', 'foo'); + $file = Yii::getAlias('@app/hashfile.txt'); + $mail->addAttachment($file); + + $this->assertNotEmpty($mail->getMailer()->getAttachments()); + } }