diff --git a/include/mail.php b/include/mail.php index c8a72e5..a60df03 100644 --- a/include/mail.php +++ b/include/mail.php @@ -20,9 +20,8 @@ class Mail extends Mailhandling { } protected function generateContent(): void { -// $messageStructure = imap_fetchstructure($this->mbox, $this->uid); - $this->fetchEmailHeader($this->content); - $this->fetchEmailBody($messageStructure, $this->content, 'INBOX', FT_PEEK); + $this->mail = $this->fetchEmail(); + $this->content['sender'] = $this->mail->headers->senderaddress; $this->renderAttachments($messageStructure); } diff --git a/include/mailhandling.php b/include/mailhandling.php index 545efbf..3a5e959 100644 --- a/include/mailhandling.php +++ b/include/mailhandling.php @@ -11,30 +11,12 @@ class Mailhandling extends Renderer { } } - protected function fetchEmailHeader(array &$content): void { + protected function fetchEmail(array &$content): PhpImap\IncomingMail { $mailsIds = $this->mbox->searchMailbox('ALL'); $mail = $this->mbox->getMail($mailsIds[0]); //$this->uid, false); - var_dump($mail);die; - $content['sender'] = imap_utf8($header->fromaddress); - $content['receiver'] = imap_utf8($header->toaddress); - $content['subject'] = imap_utf8($header->subject); - $content['senddate'] = date('d.m.Y H:i:s', strtotime($header->date)); + return $mail; } - protected function fetchEmailBody($messageStructure, array &$content): void { - $message = imap_fetchbody($this->mbox, $this->uid, 1.1, FT_PEEK); - if($message == '') { - $message = imap_fetchbody($this->mbox, $this->uid, 1, FT_PEEK); - } - $decodedMessage = quoted_printable_decode($message); - if (isset($messageStructure->parts) && isset($messageStructure->parts[1]) && isset($messageStructure->parts[1]->parameters) - && isset($messageStructure->parts[1]->parameters) && is_array($messageStructure->parts[1]->parameters) && isset($messageStructure->parts[1]->parameters[0]->value) && strtolower($messageStructure->parts[1]->parameters[0]->value) != 'utf-8') { - $decodedMessage = utf8_encode($decodedMessage); - } - $content['emailbody'] = nl2br($decodedMessage); - } - - protected function getAttachments($structure): array { $attachments = []; if(isset($structure->parts) && count($structure->parts)) {