|
11 | 11 |
|
12 | 12 | use Nette; |
13 | 13 | use Nette\Utils\Strings; |
14 | | -use function addcslashes, array_map, array_reverse, basename, date, explode, finfo_buffer, finfo_open, implode, is_numeric, ltrim, php_uname, preg_match, preg_replace, rtrim, str_replace, strcasecmp, stripslashes, strlen, substr, substr_replace, trim, urldecode; |
| 14 | +use function addcslashes, array_map, array_reverse, basename, date, explode, finfo_buffer, finfo_open, implode, is_array, is_numeric, is_string, ltrim, php_uname, preg_match, preg_replace, rtrim, str_replace, strcasecmp, stripslashes, strlen, substr, substr_replace, trim, urldecode; |
15 | 15 | use const FILEINFO_MIME_TYPE; |
16 | 16 |
|
17 | 17 |
|
@@ -78,7 +78,8 @@ public function setFrom(string $email, ?string $name = null): static |
78 | 78 | */ |
79 | 79 | public function getFrom(): ?array |
80 | 80 | { |
81 | | - return $this->getHeader('From'); |
| 81 | + $value = $this->getHeader('From'); |
| 82 | + return is_array($value) ? $value : null; |
82 | 83 | } |
83 | 84 |
|
84 | 85 |
|
@@ -107,7 +108,8 @@ public function setSubject(string $subject): static |
107 | 108 | */ |
108 | 109 | public function getSubject(): ?string |
109 | 110 | { |
110 | | - return $this->getHeader('Subject'); |
| 111 | + $value = $this->getHeader('Subject'); |
| 112 | + return is_string($value) ? $value : null; |
111 | 113 | } |
112 | 114 |
|
113 | 115 |
|
@@ -175,7 +177,8 @@ public function setReturnPath(string $email): static |
175 | 177 | */ |
176 | 178 | public function getReturnPath(): ?string |
177 | 179 | { |
178 | | - return $this->getHeader('Return-Path'); |
| 180 | + $value = $this->getHeader('Return-Path'); |
| 181 | + return is_string($value) ? $value : null; |
179 | 182 | } |
180 | 183 |
|
181 | 184 |
|
@@ -221,7 +224,8 @@ public function setHtmlBody(string $html, ?string $basePath = null): static |
221 | 224 | foreach (array_reverse($matches) as $m) { |
222 | 225 | $file = rtrim($basePath, '/\\') . '/' . (isset($m[4]) ? $m[4][0] : urldecode($m[3][0])); |
223 | 226 | if (!isset($cids[$file])) { |
224 | | - $cids[$file] = substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1); |
| 227 | + $contentId = $this->addEmbeddedFile($file)->getHeader('Content-ID'); |
| 228 | + $cids[$file] = is_string($contentId) ? substr($contentId, 1, -1) : ''; |
225 | 229 | } |
226 | 230 |
|
227 | 231 | $html = substr_replace( |
@@ -314,7 +318,9 @@ private function createAttachment( |
314 | 318 | } |
315 | 319 |
|
316 | 320 | if (!$contentType) { |
317 | | - $contentType = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content); |
| 321 | + $finfo = finfo_open(FILEINFO_MIME_TYPE); |
| 322 | + $contentType = $finfo ? finfo_buffer($finfo, $content) : false; |
| 323 | + $contentType = $contentType ?: 'application/octet-stream'; |
318 | 324 | } |
319 | 325 |
|
320 | 326 | if (!strcasecmp($contentType, 'message/rfc822')) { // not allowed for attached files |
|
0 commit comments