diff --git a/include/emailinbox.php b/include/emailinbox.php index d644d47..28c46b7 100644 --- a/include/emailinbox.php +++ b/include/emailinbox.php @@ -24,10 +24,10 @@ class Emailinbox extends Renderer { $date = $header->getDate()->toDate(); $flags = $message->getFlags(); $cleanedHeaders[$message->getUid()] = [ - 'title' => $header->subject, + 'title' => $message->subject, 'date' => $date, 'unread' => !isset($flags['seen']) || $flags['seen'] != 'Seen', - 'from' => $header->from, + 'from' => $header->decode($header->from), ]; } catch (\exception $err) { } diff --git a/include/mail.php b/include/mail.php index 1ce9cdb..e7a700c 100644 --- a/include/mail.php +++ b/include/mail.php @@ -20,19 +20,21 @@ class Mail extends Mailhandling { } protected function generateContent(): void { - $this->mail = $this->fetchEmail(); - $textHtml = $this->mail->textHtml; - $textPlain = $this->mail->textPlain; - $this->content['sender'] = $this->mail->headers->senderaddress; - $this->content['receiver'] = $this->mail->headers->toaddress; - $this->content['senddate'] = (new DateTime($this->mail->date))->format('d.m.Y'); - $this->content['emailbody'] = $this->mail->textHtml ?? $this->mail->textPlain; - $this->content['subject'] = $this->mail->subject; - $this->renderAttachments(); + $folder = $this->mbox->getFolderByName($this->folder); + $message = $folder->query()->getMessageByUid($this->uid); + if (!$message) { + return; + } + $this->content['subject'] = $message->subject; + $this->content['sender'] = $message->getHeader()->decode($message->from); + $this->content['receiver'] = $message->getHeader()->decode($message->to); + $this->content['senddate'] = $message->date->toDate()->format('d.m.Y'); + $this->content['emailbody'] = $message->hasHTMLBody() ? $message->getHTMLBody() : $message->getTextBody(); + $this->renderAttachments($message); } - protected function renderAttachments(): void { - $attachments = $this->mail->getAttachments(); + protected function renderAttachments($message): void { + $attachments = $message->getAttachments(); $contentArray = []; foreach ($attachments as $attachment) { $contentArray[] = $attachment->name; diff --git a/include/renderer.php b/include/renderer.php index 9dd6aab..53eab6e 100644 --- a/include/renderer.php +++ b/include/renderer.php @@ -508,4 +508,29 @@ class Renderer { return htmlspecialchars($name . ' (' . $row['description'] . ')'); } + function decodeSubject($subject) { + return $subject; + // Match the encoding and encoded string using a regular expression + preg_match_all('/=\?([^?]+)\?([QB])\?([^?]+)\?=/i', $subject, $matches, PREG_SET_ORDER); + + $decoded = ''; + foreach ($matches as $match) { + $encoding = $match[1]; + $type = $match[2]; + $encoded_string = $match[3]; + if ($type == 'Q') { + $decoded_part = quoted_printable_decode($encoded_string); + } elseif ($type == 'B') { + $decoded_part = base64_decode($encoded_string); + } + var_dump($match); + if (strtolower($encoding) != 'utf-8') { + $decoded_part = iconv($encoding, 'UTF-8', $decoded_part); + } + $decoded .= str_replace('_', ' ', $decoded_part); + } + + return $decoded; + } + }