connectToImap($folder)) { $this->templateName = 'imaperror'; } } protected function readEmailHeaders(): array { $cleanedHeaders = []; try { $mailsIds = $this->mbox->searchMailbox('ALL'); } catch(PhpImap\Exceptions\ConnectionException $ex) { echo "IMAP connection failed: " . implode(",", $ex->getErrors('all')); die(); } if(!$mailsIds) { die('Mailbox is empty'); } $headers = $this->mbox->getMailsInfo($mailsIds); foreach ($headers as $header) { try { $date = \DateTime::createFromFormat('D, d M Y H:i:s O', str_replace([' (CET)', ' [ CEST]',] , $header->date)); if (!$date) { var_dump($header->date); } $date = $date ? $date->setTimezone(new DateTimeZone('Europe/Berlin')) : new DateTime(); $cleanedHeaders[trim($header->msgno)] = [ 'title' => $header->subject, 'date' => $date, 'from' => $header->from, 'unread' => !$header->seen, ]; } catch (\exception $err) { } } return $cleanedHeaders; } protected function generateContent(): void { $this->generateHeaders(); $this->generateFolders(); } protected function generateHeaders(): void { $headers = $this->readEmailHeaders(); uasort($headers, ['Emailinbox', 'compareDateTimes']); array_walk($headers, function(&$item, $key) { $newItem = '