|
9 | 9 |
|
10 | 10 | use Nette; |
11 | 11 | use Nette\Utils\Strings; |
12 | | -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; |
| 12 | +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; |
13 | 13 | use const FILEINFO_MIME_TYPE; |
14 | 14 |
|
15 | 15 |
|
@@ -76,7 +76,8 @@ public function setFrom(string $email, ?string $name = null): static |
76 | 76 | */ |
77 | 77 | public function getFrom(): ?array |
78 | 78 | { |
79 | | - return $this->getHeader('From'); |
| 79 | + $value = $this->getHeader('From'); |
| 80 | + return is_array($value) ? $value : null; |
80 | 81 | } |
81 | 82 |
|
82 | 83 |
|
@@ -105,7 +106,8 @@ public function setSubject(string $subject): static |
105 | 106 | */ |
106 | 107 | public function getSubject(): ?string |
107 | 108 | { |
108 | | - return $this->getHeader('Subject'); |
| 109 | + $value = $this->getHeader('Subject'); |
| 110 | + return is_string($value) ? $value : null; |
109 | 111 | } |
110 | 112 |
|
111 | 113 |
|
@@ -173,7 +175,8 @@ public function setReturnPath(string $email): static |
173 | 175 | */ |
174 | 176 | public function getReturnPath(): ?string |
175 | 177 | { |
176 | | - return $this->getHeader('Return-Path'); |
| 178 | + $value = $this->getHeader('Return-Path'); |
| 179 | + return is_string($value) ? $value : null; |
177 | 180 | } |
178 | 181 |
|
179 | 182 |
|
@@ -219,7 +222,8 @@ public function setHtmlBody(string $html, ?string $basePath = null): static |
219 | 222 | foreach (array_reverse($matches) as $m) { |
220 | 223 | $file = rtrim($basePath, '/\\') . '/' . (isset($m[4]) ? $m[4][0] : urldecode($m[3][0])); |
221 | 224 | if (!isset($cids[$file])) { |
222 | | - $cids[$file] = substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1); |
| 225 | + $contentId = $this->addEmbeddedFile($file)->getHeader('Content-ID'); |
| 226 | + $cids[$file] = is_string($contentId) ? substr($contentId, 1, -1) : ''; |
223 | 227 | } |
224 | 228 |
|
225 | 229 | $html = substr_replace( |
@@ -312,7 +316,9 @@ private function createAttachment( |
312 | 316 | } |
313 | 317 |
|
314 | 318 | if (!$contentType) { |
315 | | - $contentType = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content); |
| 319 | + $finfo = finfo_open(FILEINFO_MIME_TYPE); |
| 320 | + $contentType = $finfo ? finfo_buffer($finfo, $content) : false; |
| 321 | + $contentType = $contentType ?: 'application/octet-stream'; |
316 | 322 | } |
317 | 323 |
|
318 | 324 | if (!strcasecmp($contentType, 'message/rfc822')) { // not allowed for attached files |
|
0 commit comments