fix: Validate file name length (#463)

* fix: Validate file name length

$message could contain a large email text that if sent to is_file it could break with this error:
` is_file(): File name is longer than the maximum allowed path `
This validation prevents using is_file if the $message is longer than the allowed path.

* style: Fix extra space

* Added a small test

* cs

* cs
This commit is contained in:
Matias Barletta 2019-01-05 08:44:50 -03:00 committed by Tobias Nyholm
parent 7b24312f6c
commit 07da83776a
2 changed files with 12 additions and 1 deletions

View File

@ -82,7 +82,7 @@ class Message extends HttpApi
$params['to'] = $recipients; $params['to'] = $recipients;
$postDataMultipart = $this->prepareMultipartParameters($params); $postDataMultipart = $this->prepareMultipartParameters($params);
if (is_file($message)) { if (strlen($message) < PHP_MAXPATHLEN && is_file($message)) {
$fileData = ['filePath' => $message]; $fileData = ['filePath' => $message];
} else { } else {
$fileData = [ $fileData = [

View File

@ -111,6 +111,17 @@ class MessageTest extends TestCase
$api->show('url', true); $api->show('url', true);
} }
public function testSendMimeWithLongMessage()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('httpPostRaw')
->willReturn(new Response());
$message = str_repeat('a', PHP_MAXPATHLEN).' and some more';
$api->sendMime('foo', ['mailbox@myapp.com'], $message, []);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */