Skip to content

Commit 302427b

Browse files
authored
Merge pull request #551 from felix-goecking/fix-detect-textPlain-encoding
Fix for #525 How to detect textPlain encoding
2 parents 7ca3d19 + 859610a commit 302427b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/PhpImap/DataPartInfo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ protected function convertEncodingAfterFetch(): string
109109
{
110110
if (isset($this->charset) and !empty(\trim($this->charset))) {
111111
$this->data = $this->mail->decodeMimeStr(
112-
(string) $this->data // Data to convert
112+
(string) $this->data, // Data to convert
113+
(string) \trim($this->charset)
113114
);
114115
}
115116

src/PhpImap/Mailbox.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,14 +1333,15 @@ public function downloadAttachment(DataPartInfo $dataInfo, array $params, object
13331333
* Decodes a mime string.
13341334
*
13351335
* @param string $string MIME string to decode
1336+
* @param string|null $charsetPreferred The charset of the data part info if it was set
13361337
*
13371338
* @return string Converted string if conversion was successful, or the original string if not
13381339
*
13391340
* @throws Exception
13401341
*
13411342
* @todo update implementation pending resolution of https://github.com/vimeo/psalm/issues/2619 & https://github.com/vimeo/psalm/issues/2620
13421343
*/
1343-
public function decodeMimeStr(string $string): string
1344+
public function decodeMimeStr(string $string, ?string $charsetPreferred = null): string
13441345
{
13451346
$newString = '';
13461347
/** @var list<object{charset?:string, text?:string}>|false */
@@ -1354,7 +1355,7 @@ public function decodeMimeStr(string $string): string
13541355
$charset = \strtolower($element->charset);
13551356

13561357
if ('default' === $charset) {
1357-
$charset = $this->decodeMimeStrDefaultCharset;
1358+
$charset = !empty($charsetPreferred) ? $charsetPreferred : $this->decodeMimeStrDefaultCharset;
13581359
}
13591360

13601361
switch ($charset) {

0 commit comments

Comments
 (0)