- PHP 8.2.17, Phorge at 713188bf1710fdd1328d58b394ea5ccba52dfb3c
- Have a local text file called email.txt with a valid mbox email message in it and place it in ./phorge/scripts/mail/
- In https://we.phorge.it/source/phorge/browse/master/scripts/mail/mail_handler.php, replace the line $parser->setText(file_get_contents('php://stdin')); with $parser->setText(file_get_contents('email.txt'));
- Intentionally bug function parse() in https://we.phorge.it/source/phorge/browse/master/externals/mimemailparser/MimeMailParser.class.php$137 by adding the line $this->resource = mailparse_msg_create(); right after $this->parts = array(); - this basically emulates a buggy email with no message headers getting into Phorge.
- Run php ./mail_handler.php.
As a result, we end up with EXCEPTION: (RuntimeException) Undefined index: subject triggered in https://we.phorge.it/source/phorge/browse/master/scripts/mail/mail_handler.php$58 (and seen in downstream https://phabricator.wikimedia.org/T356077#9520174 for unknown reasons).
That is misleading as the code found no headers at all, not only a missing subject header:
$this->parts[1] includes the array headers which is empty due to bugging it, then getPartHeaders() at https://we.phorge.it/source/phorge/browse/master/externals/mimemailparser/MimeMailParser.class.php$311 is called which only runs isset but does not check for an empty array (but should).
Furthermore, per RFC 2822 §3.6, a subject header is optional anyway while the code expects it to always exist.