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);
20 $head['date']->setTimezone(new DateTimeZone(date_default_timezone_get()));
22 $Page->title = 'Mailbericht ' . $head['date']->format('Y-m-d H:i');
23 printf("<h2>%s</h2>\n", htmlspecialchars($head['Subject'] ?? 'Mailbericht zonder onderwerp'));
25 printf('<h3><a href="mailto:%s">%s</a> <small class="date" title="%s">%s</small></h3>'."\n",
26 htmlspecialchars($head['From']),
27 htmlspecialchars(implode(', ', array_column($head['from'], 'display'))),
28 htmlspecialchars($head['Date']),
29 showdate(preg_split('/\D/', $head['date']->format('c')))
33 if (preg_match('{^text/plain}', $head['Content-Type'] ?? 'text/plain')) {
35 if (($head['Content-Transfer-Encoding'] ?? '') === 'quoted-printable') {
36 $body = quoted_printable_decode($body);
38 printf('<pre>%s</pre>', htmlspecialchars($body));
41 printf('<p>Geen ondersteuning voor <em>%s</em>.</p>', htmlspecialchars($head['Content-Type']));
44 $mime = mailparse_msg_parse_file($filename);
45 $part = mailparse_msg_get_part($mime, '1');
46 mailparse_msg_extract_part_file($part, $filename);
52 if (!$User->admin('user')) {
53 http_response_code(403);
54 $Page->place['warn'] = "Geen gebruikersrechten om e-mails in te zien.";
55 $Page->place['maillist'] = '';
59 $rows = glob("$mailbox/*");
61 throw new Exception('Kon inbox niet openen.');
65 'start' => $_GET['start'] ?? 0,
66 'n' => $_GET['n'] ?? 10,
67 'total' => count($rows),
69 $rows = array_slice(array_reverse($rows), $nav['start'], $nav['n']);
73 foreach (array_reverse($rows) as $filename) {
74 if (!is_readable($filename)) {
78 printf('<li><a href="%s">', "/{$Page->handler}/".basename($filename));
80 list ($headerdata) = explode("\n\n", file_get_contents($filename));
81 $head = parsemailhead($headerdata);
83 print $head['Subject'];
84 printf(' <small class="date" title="%s">%s</small>',
85 htmlspecialchars($head['Date']),
86 showdate(explode('-', $head['date']->format('Y-m-d')))
88 printf(' <em class="right" title="%s">%s</em>',
89 htmlspecialchars($head['From']),
90 htmlspecialchars(implode(', ', array_column($head['from'], 'display')))
96 print $Page->widget('nav', $nav);
98 $Page->place['maillist'] = ob_get_clean();