path, '/')); if (!function_exists('parsemailhead')) { function parsemailhead($headerdata) { $headlist = iconv_mime_decode_headers($headerdata, ICONV_MIME_DECODE_CONTINUE_ON_ERROR); $headlist['date'] = DateTime::createFromFormat(DateTimeInterface::RFC2822.'+', $headlist['Date']); $headlist['from'] = imap_rfc822_parse_adrlist($headlist['From'], ''); array_walk($headlist['from'], function ($row) { $row->display = $row->personal ?? $row->mailbox; }); return $headlist; } } if ($msgid) { $filename = "$mailbox/$msgid"; if (!is_readable($filename)) { return TRUE; } 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("
$body
\n"; break; case 'multipart/alternative': $mime = mailparse_msg_parse_file($filename); foreach (mailparse_msg_get_structure($mime) as $section) { print "%s', htmlspecialchars(print_r($pinfo,TRUE))); $phead = $pinfo['headers']; list ($ptype) = explode(';', strtolower($phead['content-type'])); list ($pmedia) = explode('/', $ptype); switch ($pmedia) { case 'multipart': continue 2; case 'text': $body = mailparse_msg_extract_part_file($part, $filename, NULL); #iconv($pinfo['charset'], 'UTF-8', $body); #TODO test if needed switch ($ptype) { case 'text/plain': $body = htmlspecialchars($body); print "
\n"; break; case 'text/html': $body = preg_replace('{ ($body
$body
\n"; break; } break; case 'image': if (!preg_match('/^inline;/', $phead['content-disposition'])) { continue 2; } $name = iconv_mime_decode($phead['disposition-filename']); $body = mailparse_msg_extract_part_file($part, $filename, NULL); printf('', $ptype, base64_encode($body), htmlspecialchars($phead['name'] ?? '-') ); break; } } mailparse_msg_free($mime); break; default: printf('Geen ondersteuning voor %s.
', htmlspecialchars($type)); } return; } if ($Page->api) { return; } if (!$User->admin('user')) { http_response_code(403); $Page->place['warn'] = "Geen gebruikersrechten om e-mails in te zien."; $Page->place['maillist'] = ''; return TRUE; } $rows = glob("$mailbox/*"); if (!$rows) { throw new Exception('Kon inbox niet openen.'); } $nav = [ 'start' => $_GET['start'] ?? 0, 'n' => $_GET['n'] ?? 10, 'total' => count($rows), ]; $rows = array_slice(array_reverse($rows), $nav['start'], $nav['n']); ob_start(); print '