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'] = mailparse_rfc822_parse_addresses($headlist['From']);
10 //TODO: imap_rfc822_parse_adrlist() alternative
15 $filename = "$mailbox/$msgid";
16 list ($headerdata, $rawbody) = explode("\n\n", file_get_contents($filename), 2);
17 $head = parsemailhead($headerdata);
19 $Page->title = 'Mailbericht ' . $head['date']->format('Y-m-d H:i');
20 printf("<h2>%s</h2>\n", htmlspecialchars($head['Subject'] ?? 'Mailbericht zonder onderwerp'));
22 print '<dl class="terse">';
23 printf('<dt>Ontvangen:</dt><dd>%s</dd>', $head['date']->format('c'));
24 printf('<dt>Verzender:</dt><dd>%s</dd>', htmlspecialchars($head['from'][0]['display']));
27 if (preg_match('{^text/plain}', $head['Content-Type'] ?? 'text/plain')) {
29 if (($head['Content-Transfer-Encoding'] ?? '') === 'quoted-printable') {
30 $body = quoted_printable_decode($body);
32 printf('<pre>%s</pre>', htmlspecialchars($body));
35 printf('<p>Geen ondersteuning voor <em>%s</em>.</p>', htmlspecialchars($head['Content-Type']));
38 $mime = mailparse_msg_parse_file($filename);
39 $part = mailparse_msg_get_part($mime, '1');
40 mailparse_msg_extract_part_file($part, $filename);
46 if (!$User->admin('user')) {
47 http_response_code(403);
48 $Page->place['warn'] = "Geen gebruikersrechten om e-mails in te zien.";
49 $Page->place['maillist'] = '';
53 $rows = glob("$mailbox/*");
55 throw new Exception('Kon inbox niet openen.');
57 array_splice($rows, 0, -50);
61 foreach (array_reverse($rows) as $filename) {
62 list ($headerdata) = explode("\n\n", file_get_contents($filename));
63 $head = parsemailhead($headerdata);
65 printf('<li><a href="%s">', "/{$Page->handler}/".basename($filename));
67 print $head['Subject'];
68 printf(' <small class="date">%s</small>',
69 showdate(explode('-', $head['date']->format('Y-m-d')))
71 print ' <em class="right">'.htmlspecialchars($head['from'][0]['display']).'</em>';
75 $Page->place['maillist'] = ob_get_clean();