cypht-org / cypht

Cypht: Lightweight Open Source webmail aggregator [PHP, JS]
http://cypht.org
GNU Lesser General Public License v2.1
949 stars 146 forks source link

bugs remaining in 1.4.2 with php8.2 #1013

Open mcbmcb0 opened 1 month ago

mcbmcb0 commented 1 month ago

šŸ› Bugreport

Hi I know 1.4.2 is now maintenance, but Iā€™ve updated to it recently due to the comments re likelihood of 2.0 have 'paper cut' bugs. There are still a number of bugs in 1.4.2 on php 8.2. Iā€™m listing some here thatā€™s Iā€™ve patched (hacked) as it may help someone else and possibly it may be relevant to 2.0. I get some of these as appear to have some emails with less common windows encodings. Iā€™m not claiming these are elegant of efficient fixes, but work for me, for now. Iā€™ve posted up a couple before in previous issues. I'm not suggestinganyone resolves these - just TBA for the next 1.4.2 user. Looking forward to a stable 2.x!

PHP Warning: DOMDocument::loadHTML(): Tag o:p invalid in Entity, line: 45 in /ā€¦/cypht/modules/core/message_functions.php on line 436

        $doc = new DOMDocument();
        //$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); // WAS original line - warnings when invalid entities
        // so HACK to suppress errors when malformed html
        $doc->strictErrorChecking=false; 
        $previous_value = libxml_use_internal_errors(true); // MB hack
        $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
        libxml_clear_errors(); // MB
        libxml_use_internal_errors($previous_value);//MB
        // end hack

PHP Fatal error: Uncaught ValueError: mb_convert_encoding(): Argument # 3 ($from_encoding) contains invalid encoding "windows-1256" in ā€¦/cypht/modules/core/message_functions.php:416

$fld = substr($fld, (strpos($fld, '?') + 1));
// HACK - as breaks with windows-1257 charset and others
$alt_charset = ['UTF-7'=>"UTF7-IMAP", 'WINDOWS-1256'=> "ISO-8859-6",'WINDOWS-1257'=> "ISO-8859-13"]; 
if(array_key_exists(strtoupper($charset), $alt_charset)){// MB
     $charset = $alt_charset[strtoupper($charset)];
} // end of hack
if (strtoupper($encoding) == 'B') { // existingā€¦

Fatal error: Uncaught ValueError: mb_convert_encoding(): Argument # 3 ($from_encoding) contains invalid encoding "windows-1257" in /ā€¦/cypht/modules/imap/hm-imap.php:968

if ($struct['attributes']['charset'] != 'us-ascii') {
//$res = mb_convert_encoding($res, 'UTF-8', $struct['attributes']['charset']); //original line
// hack as breaks with windows-1257 charset, and others
$charset_mb = $struct['attributes']['charset'] ??'';
$alt_charset = ['UTF-7'=>"UTF7-IMAP", 'WINDOWS-1256'=> "ISO-8859-6", 'WINDOWS-1257'=> "ISO-8859-13"];  // not super sure about 1256 equiv
if(array_key_exists(strtoupper($charset_mb), $alt_charset)){// MB
$charset_mb = $alt_charset[strtoupper($charset_mb)];
}
$res = mb_convert_encoding($res, 'UTF-8', $charset_mb); // modified line
// end of hack

PHP Fatal error: Uncaught TypeError: count(): Argument # 1 ($value) must be of type Countable|array, bool given inā€¦ /cypht/modules/imap/functions.php:965

if (array_key_exists('disposition', $struct) && is_array($struct['disposition']) && array_key_exists('attachment', $struct['disposition'])) {
//mb_hack - breaks sometimes on next line -  Argument #1 ($value) must be of type Countable|array, bool given
//for ($i=0;$i<count($struct['disposition']['attachment']);$i++) { // original line
$count_1 = is_countable($struct['disposition']['attachment']) ? count($struct['disposition']['attachment']) : 0;
for ($i=0;$i< $count_1;$i++) {
// end of hack
if (strtolower(trim($struct['disposition']['attachment'][$i])) == 'filename') { // existingā€¦

I hope this helps someone

marclaporte commented 1 month ago

Thank you @mcbmcb0 !

marclaporte commented 1 week ago

Looking forward to a stable 2.x!

2.x is getting pretty stable now, but we should still fix fatal errors for Cypht 1.4.x on PHP 8.2. If this is too risky difficult, we should publicize which versions are not supported. https://github.com/cypht-org/cypht/wiki/Lifecycle

marclaporte commented 1 week ago

I updated https://github.com/cypht-org/cypht/wiki/Lifecycle to indicate to avoid PHP 8.2 with Cypht 1.4.x, for now anyways.

marclaporte commented 1 week ago

I updated expectations: https://github.com/cypht-org/cypht-website/commit/21f80cf0ee36cb4aad504b0eebf2d2048a6a4970

marclaporte commented 1 week ago

Here as well: https://github.com/cypht-org/cypht/wiki/Lifecycle