Overworked mailbox

This commit is contained in:
Torsten Schulz
2023-10-16 19:12:08 +02:00
parent f70d6d1224
commit c97239f1fc
3 changed files with 40 additions and 13 deletions

View File

@@ -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) {
}

View File

@@ -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;

View File

@@ -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;
}
}