cypht icon indicating copy to clipboard operation
cypht copied to clipboard

bugs remaining in 1.4.2 with php8.2

Open mcbmcb0 opened this issue 2 months ago • 5 comments

🐛 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

mcbmcb0 avatar May 09 '24 09:05 mcbmcb0