2 $mailbox = 'mail/inbox';
3 @list ($msgid) = explode('/', ltrim($Page->path, '/'));
5 function parsemailhead($headerdata)
7 $headlist = iconv_mime_decode_headers($headerdata, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
8 $headlist['date'] = DateTime::createFromFormat(DateTimeInterface::RFC2822.'+', $headlist['Date']);
9 $headlist['from'] = imap_rfc822_parse_adrlist($headlist['From'], '');
10 array_walk($headlist['from'], function ($row) {
11 $row->display = $row->personal ?? $row->mailbox;
17 $filename = "$mailbox/$msgid";
18 list ($headerdata, $rawbody) = explode("\n\n", file_get_contents($filename), 2);
19 $head = parsemailhead($headerdata);
21 $Page->title = 'Mailbericht ' . $head['date']->format('Y-m-d H:i');
22 printf("<h2>%s</h2>\n", htmlspecialchars($head['Subject'] ?? 'Mailbericht zonder onderwerp'));
24 print '<dl class="terse">';
25 printf('<dt>Ontvangen:</dt><dd>%s</dd>', $head['date']->format('c'));
26 printf('<dt>Verzender:</dt><dd>%s</dd>', htmlspecialchars($head['From']));
29 if (preg_match('{^text/plain}', $head['Content-Type'] ?? 'text/plain')) {
31 if (($head['Content-Transfer-Encoding'] ?? '') === 'quoted-printable') {
32 $body = quoted_printable_decode($body);
34 printf('<pre>%s</pre>', htmlspecialchars($body));
37 printf('<p>Geen ondersteuning voor <em>%s</em>.</p>', htmlspecialchars($head['Content-Type']));
40 $mime = mailparse_msg_parse_file($filename);
41 $part = mailparse_msg_get_part($mime, '1');
42 mailparse_msg_extract_part_file($part, $filename);
48 if (!$User->admin('user')) {
49 http_response_code(403);
50 $Page->place['warn'] = "Geen gebruikersrechten om e-mails in te zien.";
51 $Page->place['maillist'] = '';
55 $rows = glob("$mailbox/*");
57 throw new Exception('Kon inbox niet openen.');
59 array_splice($rows, 0, -50);
63 foreach (array_reverse($rows) as $filename) {
64 if (!is_readable($filename)) {
68 printf('<li><a href="%s">', "/{$Page->handler}/".basename($filename));
70 list ($headerdata) = explode("\n\n", file_get_contents($filename));
71 $head = parsemailhead($headerdata);
73 print $head['Subject'];
74 printf(' <small class="date">%s</small>',
75 showdate(explode('-', $head['date']->format('Y-m-d')))
77 printf(' <em class="right">%s</em>',
78 htmlspecialchars(implode(', ', array_column($head['from'], 'display')))
83 $Page->place['maillist'] = ob_get_clean();