X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/772961fd4e9be46ad340cad1e55ee5f28cc5b968..2013f7a1c3ef61a66f5b158823d19c8e6ade8886:/mail/index.php diff --git a/mail/index.php b/mail/index.php index 67a076e..2b6e600 100644 --- a/mail/index.php +++ b/mail/index.php @@ -2,26 +2,38 @@ $mailbox = 'mail/inbox'; @list ($msgid) = explode('/', ltrim($Page->path, '/')); +if (!function_exists('parsemailhead')) { function parsemailhead($headerdata) { $headlist = iconv_mime_decode_headers($headerdata, ICONV_MIME_DECODE_CONTINUE_ON_ERROR); $headlist['date'] = DateTime::createFromFormat(DateTimeInterface::RFC2822.'+', $headlist['Date']); - $headlist['from'] = mailparse_rfc822_parse_addresses($headlist['From']); - //TODO: imap_rfc822_parse_adrlist() alternative + $headlist['from'] = imap_rfc822_parse_adrlist($headlist['From'], ''); + array_walk($headlist['from'], function ($row) { + $row->display = $row->personal ?? $row->mailbox; + }); return $headlist; } +} if ($msgid) { $filename = "$mailbox/$msgid"; + if (!is_readable($filename)) { + return TRUE; + } + list ($headerdata, $rawbody) = explode("\n\n", file_get_contents($filename), 2); $head = parsemailhead($headerdata); + $head['date']->setTimezone(new DateTimeZone(date_default_timezone_get())); $Page->title = 'Mailbericht ' . $head['date']->format('Y-m-d H:i'); printf("

%s

\n", htmlspecialchars($head['Subject'] ?? 'Mailbericht zonder onderwerp')); - print '
'; - printf('
Ontvangen:
%s
', $head['date']->format('c')); - printf('
Verzender:
%s
', htmlspecialchars($head['from'][0]['display'])); + printf('

%s %s

'."\n", + htmlspecialchars($head['From']), + htmlspecialchars(implode(', ', array_column($head['from'], 'display'))), + htmlspecialchars($head['Date']), + showdate(preg_split('/\D/', $head['date']->format('c'))) + ); print '
'; if (preg_match('{^text/plain}', $head['Content-Type'] ?? 'text/plain')) { @@ -43,10 +55,13 @@ if ($msgid) { return; } +if (!$User) { + return; +} if (!$User->admin('user')) { http_response_code(403); - $Place['warn'] = "Geen gebruikersrechten om e-mails in te zien."; - $Place['maillist'] = ''; + $Page->place['warn'] = "Geen gebruikersrechten om e-mails in te zien."; + $Page->place['maillist'] = ''; return TRUE; } @@ -54,22 +69,39 @@ $rows = glob("$mailbox/*"); if (!$rows) { throw new Exception('Kon inbox niet openen.'); } -array_splice($rows, 0, -50); + +$nav = [ + 'start' => $_GET['start'] ?? 0, + 'n' => $_GET['n'] ?? 10, + 'total' => count($rows), +]; +$rows = array_slice(array_reverse($rows), $nav['start'], $nav['n']); ob_start(); print '\n"; -$Place['maillist'] = ob_get_clean(); + +print $Page->widget('nav', $nav); + +$Page->place['maillist'] = ob_get_clean();