From 644f179dd27a78b91c88366b9432f5faaeb2bbb4 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 1 Apr 2024 12:32:50 +0200 Subject: [PATCH] Make incoming mail handling more robust / correct Summary: * Properly handle when no mail headers at all can be parsed * Properly handle when mail headers can be parsed but no subject line can be found ``` EXCEPTION: (RuntimeException) Undefined index: subject ``` Closes T15769 Test Plan: See T15769 Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: 20after4, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15769 Differential Revision: https://we.phorge.it/D25565 --- externals/mimemailparser/MimeMailParser.class.php | 4 ++-- scripts/mail/mail_handler.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/externals/mimemailparser/MimeMailParser.class.php b/externals/mimemailparser/MimeMailParser.class.php index 40ab1640f5..dfd7a2fa11 100644 --- a/externals/mimemailparser/MimeMailParser.class.php +++ b/externals/mimemailparser/MimeMailParser.class.php @@ -308,10 +308,10 @@ class MimeMailParser { * @param $part Array */ private function getPartHeaders($part) { - if (isset($part['headers'])) { + if (isset($part['headers']) && $part['headers']) { return $part['headers']; } - return false; + throw new Exception('MimeMailParser::getHeaders() could not parse any email headers.'); } /** diff --git a/scripts/mail/mail_handler.php b/scripts/mail/mail_handler.php index bf6f315f3a..5631310a2b 100755 --- a/scripts/mail/mail_handler.php +++ b/scripts/mail/mail_handler.php @@ -55,7 +55,9 @@ foreach (array('text', 'html') as $part) { } $headers = $parser->getHeaders(); -$headers['subject'] = phutil_decode_mime_header($headers['subject']); +if (array_key_exists('subject', $headers)) { + $headers['subject'] = phutil_decode_mime_header($headers['subject']); +} $headers['from'] = phutil_decode_mime_header($headers['from']); if ($args->getArg('process-duplicates')) {