From 1900f80a9ab5fe401d6901b8e17ee82131b1170d Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 6 Dec 2020 07:31:32 +0100 Subject: [PATCH] mail: imap function to parse sender addresses Require built-in imap module instead of the mailparse extension. Either can be installed on Debian (or enabled on Vimexx servers) so prefer the more complete solution. --- mail/index.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mail/index.php b/mail/index.php index ce133c5..b4846cc 100644 --- a/mail/index.php +++ b/mail/index.php @@ -6,8 +6,10 @@ 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'] = 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; } @@ -21,7 +23,7 @@ if ($msgid) { print '
'; printf('
Ontvangen:
%s
', $head['date']->format('c')); - printf('
Verzender:
%s
', htmlspecialchars($head['from'][0]['display'])); + printf('
Verzender:
%s
', htmlspecialchars($head['From'])); print '
'; if (preg_match('{^text/plain}', $head['Content-Type'] ?? 'text/plain')) { @@ -72,7 +74,9 @@ foreach (array_reverse($rows) as $filename) { printf(' %s', showdate(explode('-', $head['date']->format('Y-m-d'))) ); - print ' '.htmlspecialchars($head['from'][0]['display']).''; + printf(' %s', + htmlspecialchars(implode(', ', array_column($head['from'], 'display'))) + ); print "\n"; } print "\n"; -- 2.30.0