mailwatch / MailWatch

MailWatch for MailScanner is a web-based front-end to MailScanner
http://mailwatch.org/
GNU General Public License v2.0
115 stars 66 forks source link

mailwatch_sendmail_queue.php does not accomodate SRS recipient addresses #1290

Closed andrewt918 closed 8 months ago

andrewt918 commented 8 months ago

The rcpts regex in mailwatch_sendmail_queue.php (line 82) does not allow for an equals sign as is present in SRS addresses. With PHP 8.0 and higher this will result in the following error since the case to set $output[$msgid]['rcpts'] is never met:

`Fatal error: Uncaught TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in /usr/local/bin/mailwatch_sendmail_queue.php:277 Stack trace:

0 /usr/local/bin/mailwatch_sendmail_queue.php(277): implode()

1 {main}

thrown in /usr/local/bin/mailwatch_sendmail_queue.php on line 277`

Prior to PHP 8.0, the @implode suppressed this issue per the PHP docs:

https://www.php.net/manual/en/language.operators.errorcontrol.php

Warning Prior to PHP 8.0.0, it was possible for the @ operator to disable critical errors that will terminate script execution. For example, prepending @ to a call of a function which did not exist, by being unavailable or mistyped, would cause the script to terminate with no indication as to why.

We ran into this after migrating our install to an updated OS with PHP 8.0 instead of PHP 7.2.

andrewt918 commented 8 months ago

Same issue with supporting plus addressing.

endelwar commented 8 months ago

I assume that you are using exim. I've added a pr with a better regex, could you test it (postfix user here 😄)?

andrewt918 commented 8 months ago

Yes, this is with Exim and that regex works fine. It's practically identical to the change I already made on our own instance. I just submitted the issue to get a fix added and as a heads up for anyone else that runs into this meanwhile.

Probably worth considering additional error handling for the @implode to prevent fatal errors on edge cases.