Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/PhpImap/DataPartInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ protected function convertEncodingAfterFetch(): string
{
if (isset($this->charset) and !empty(\trim($this->charset))) {
$this->data = $this->mail->decodeMimeStr(
(string) $this->data // Data to convert
(string) $this->data, // Data to convert
(string) \trim($this->charset)
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1333,14 +1333,15 @@ public function downloadAttachment(DataPartInfo $dataInfo, array $params, object
* Decodes a mime string.
*
* @param string $string MIME string to decode
* @param string|null $charsetPreferred The charset of the data part info if it was set
*
* @return string Converted string if conversion was successful, or the original string if not
*
* @throws Exception
*
* @todo update implementation pending resolution of https://github.com/vimeo/psalm/issues/2619 & https://github.com/vimeo/psalm/issues/2620
*/
public function decodeMimeStr(string $string): string
public function decodeMimeStr(string $string, ?string $charsetPreferred = null): string
{
$newString = '';
/** @var list<object{charset?:string, text?:string}>|false */
Expand All @@ -1354,7 +1355,7 @@ public function decodeMimeStr(string $string): string
$charset = \strtolower($element->charset);

if ('default' === $charset) {
$charset = $this->decodeMimeStrDefaultCharset;
$charset = !empty($charsetPreferred) ? $charsetPreferred : $this->decodeMimeStrDefaultCharset;
}

switch ($charset) {
Expand Down