{
$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;
}
$filename = "$mailbox/$msgid";
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("<h2>%s</h2>\n", htmlspecialchars($head['Subject'] ?? 'Mailbericht zonder onderwerp'));
- print '<dl class="terse">';
- printf('<dt>Ontvangen:</dt><dd>%s</dd>', $head['date']->format('c'));
- printf('<dt>Verzender:</dt><dd>%s</dd>', htmlspecialchars($head['from'][0]['display']));
+ printf('<h3><a href="mailto:%s">%s</a> <small class="date" title="%s">%s</small></h3>'."\n",
+ htmlspecialchars($head['From']),
+ htmlspecialchars(implode(', ', array_column($head['from'], 'display'))),
+ htmlspecialchars($head['Date']),
+ showdate(preg_split('/\D/', $head['date']->format('c')))
+ );
print '</dl>';
if (preg_match('{^text/plain}', $head['Content-Type'] ?? 'text/plain')) {
ob_start();
print '<ul>';
foreach (array_reverse($rows) as $filename) {
- list ($headerdata) = explode("\n\n", file_get_contents($filename));
- $head = parsemailhead($headerdata);
+ if (!is_readable($filename)) {
+ continue;
+ }
printf('<li><a href="%s">', "/{$Page->handler}/".basename($filename));
+ list ($headerdata) = explode("\n\n", file_get_contents($filename));
+ $head = parsemailhead($headerdata);
+
print $head['Subject'];
- printf(' <small class="date">%s</small>',
+ printf(' <small class="date" title="%s">%s</small>',
+ htmlspecialchars($head['Date']),
showdate(explode('-', $head['date']->format('Y-m-d')))
);
- print ' <em class="right">'.htmlspecialchars($head['from'][0]['display']).'</em>';
+ printf(' <em class="right" title="%s">%s</em>',
+ htmlspecialchars($head['From']),
+ htmlspecialchars(implode(', ', array_column($head['from'], 'display')))
+ );
print "</a></li>\n";
}
print "</ul>\n";