2 $mailbox = 'mail/inbox';
3 @list ($msgid) = explode('/', ltrim($Page->path, '/'));
5 if (!function_exists('parsemailhead')) {
6 function parsemailhead($headerdata)
8 $headlist = iconv_mime_decode_headers($headerdata, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
9 $headlist['date'] = DateTime::createFromFormat(DateTimeInterface::RFC2822.'+', $headlist['Date']);
10 $headlist['from'] = imap_rfc822_parse_adrlist($headlist['From'], '');
11 array_walk($headlist['from'], function ($row) {
12 $row->display = $row->personal ?? $row->mailbox;
19 $filename = "$mailbox/$msgid";
20 if (!is_readable($filename)) {
24 list ($headerdata, $rawbody) = explode("\n\n", file_get_contents($filename), 2);
25 $head = parsemailhead($headerdata);
26 $head['date']->setTimezone(new DateTimeZone(date_default_timezone_get()));
28 $Page->title = 'Mailbericht ' . $head['date']->format('Y-m-d H:i');
29 printf("<h2>%s</h2>\n", htmlspecialchars($head['Subject'] ?? 'Mailbericht zonder onderwerp'));
31 printf('<h3><a href="mailto:%s">%s</a> <small class="date" title="%s">%s</small></h3>'."\n",
32 htmlspecialchars($head['From']),
33 htmlspecialchars(implode(', ', array_column($head['from'], 'display'))),
34 htmlspecialchars($head['Date']),
35 showdate(preg_split('/\D/', $head['date']->format('c')))
39 if (preg_match('{^text/plain}', $head['Content-Type'] ?? 'text/plain')) {
41 if (($head['Content-Transfer-Encoding'] ?? '') === 'quoted-printable') {
42 $body = quoted_printable_decode($body);
44 printf('<pre>%s</pre>', htmlspecialchars($body));
47 printf('<p>Geen ondersteuning voor <em>%s</em>.</p>', htmlspecialchars($head['Content-Type']));
50 $mime = mailparse_msg_parse_file($filename);
51 $part = mailparse_msg_get_part($mime, '1');
52 mailparse_msg_extract_part_file($part, $filename);
61 if (!$User->admin('user')) {
62 http_response_code(403);
63 $Page->place['warn'] = "Geen gebruikersrechten om e-mails in te zien.";
64 $Page->place['maillist'] = '';
68 $rows = glob("$mailbox/*");
70 throw new Exception('Kon inbox niet openen.');
74 'start' => $_GET['start'] ?? 0,
75 'n' => $_GET['n'] ?? 10,
76 'total' => count($rows),
78 $rows = array_slice(array_reverse($rows), $nav['start'], $nav['n']);
82 foreach (array_reverse($rows) as $filename) {
83 if (!is_readable($filename)) {
87 printf('<li><a href="%s">', "/{$Page->handler}/".basename($filename));
89 list ($headerdata) = explode("\n\n", file_get_contents($filename));
90 $head = parsemailhead($headerdata);
92 print $head['Subject'];
93 printf(' <small class="date" title="%s">%s</small>',
94 htmlspecialchars($head['Date']),
95 showdate(explode('-', $head['date']->format('Y-m-d')))
97 printf(' <em class="right" title="%s">%s</em>',
98 htmlspecialchars($head['From']),
99 htmlspecialchars(implode(', ', array_column($head['from'], 'display')))
105 print $Page->widget('nav', $nav);
107 $Page->place['maillist'] = ob_get_clean();