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

PHP 8 compatibility / undefined function get_magic_quotes_runtime() #1256

Closed dneuhaeuser closed 1 year ago

dneuhaeuser commented 1 year ago

As major distros are starting to discontinue PHP 7 (which is EOS next month anyway) I think MailWatch should be made compatible with PHP 8.

My first tests with MailWatch 1.2.18 and PHP 8.1.2 look quite good, but there is one major problem when trying to release quarantined mails. The following error is thrown in apache/error.log and the mail is NOT released:

PHP Fatal error:  Uncaught Error: Call to undefined function get_magic_quotes_runtime() in /var/www/html/mailscanner/lib/pear/Mail/mime.php:497
Stack trace:
#0 /var/www/html/mailscanner/lib/pear/Mail/mime.php(428): Mail_mime->file2str()
#1 /var/www/html/mailscanner/functions.php(3576): Mail_mime->addAttachment()
#2 /var/www/html/mailscanner/detail.php(418): quarantine_release()
#3 {main}
thrown in /var/www/html/mailscanner/lib/pear/Mail/mime.php on line 497

The function "get_magic_quotes_runtime()" which does not exist in PHP 8 anymore is used several times in "lib/pear/Mail/mime.php" and "lib/pear/Mail/mimePart.php". The magic_quotes feature and its ini-setting was even removed in PHP 5.4, some 20 years ago.

So can we remove the according lines?

        // Temporarily reset magic_quotes_runtime and read file contents
        if ($magic_quote_setting = get_magic_quotes_runtime()) {
            @ini_set('magic_quotes_runtime', 0);
        }

        [...]

        if ($magic_quote_setting) {
            @ini_set('magic_quotes_runtime', $magic_quote_setting);
        }
endelwar commented 1 year ago

Pear Mail libs was updated on Nov 24, 2021 on 1.2 branch that should run without errors on PHP 8; it's time for a maintenance release.

dneuhaeuser commented 1 year ago

as I see this was solved with release 1.2.19. I think the readme still needs an update to also mention PHP 8.