Migrate away from using create_function as long as PHP 5.3+ is available
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 8 Feb 2021 21:59:46 +0000 (21:59 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 8 Feb 2021 21:59:46 +0000 (21:59 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14900 7612ce4b-ef26-0410-bec9-ea0150e637f0

doc/ChangeLog
functions/decode/iso_8859_1.php
functions/decode/utf_8.php
functions/imap_messages.php
functions/mime.php

index 28c5c182746c74558e8c58ba569cef2c8a7b929d..9f188b42951bb1bc903ee852fcb11c8e1dc95cd6 100644 (file)
@@ -443,6 +443,7 @@ Version 1.5.2 - SVN
     attachments (when reading a message)
   - Added fixes for PHP version 8 compatibility (thanks to Marcel Pol for
     bringing this to our attention)
+  - Migrate away from create_function() as long as we have PHP 5.3+
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------
index d8d52553471cc369960831208aa8f02c9f4e894c..7a549765b5968dc5cee87f6ebc9a7d372f24255d 100644 (file)
@@ -24,14 +24,20 @@ function charset_decode_iso_8859_1 ($string) {
         return $string;
 
     $string = preg_replace_callback("/([\201-\237])/",
-    create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';'),
-    $string);
+                                    (check_php_version(5, 3, 0)
+                                     ? function($matches) { return '&#' . ord($matches[1]) . ';'; }
+                                     : create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';')
+                                    ),
+                                    $string);
 
     /* I don't want to use 0xA0 (\240) in any ranges. RH73 may dislike it */
     $string = str_replace("\240", '&#160;', $string);
 
     $string = preg_replace_callback("/([\241-\377])/",
-    create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';'),
-    $string);
+                                    (check_php_version(5, 3, 0)
+                                     ? function($matches) { return '&#' . ord($matches[1]) . ';'; }
+                                     : create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';')
+                                    ),
+                                    $string);
     return $string;
 }
index b0fe4b28253aa941f913ed92a9fe7d1b5416106d..2df3c23d6e09eca41824e2ce4df1730075492ccd 100644 (file)
@@ -74,18 +74,27 @@ function charset_decode_utf_8 ($string) {
     
     // decode four byte unicode characters
     $string = preg_replace_callback("/([\360-\367])([\200-\277])([\200-\277])([\200-\277])/",
-    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-240)*262144+(ord($matches[2])-128)*4096+(ord($matches[3])-128)*64+(ord($matches[4])-128)).\';\';'),
-    $string);
+                                    (check_php_version(5, 3, 0)
+                                     ? function($matches) { return '&#'.((ord($matches[1])-240)*262144+(ord($matches[2])-128)*4096+(ord($matches[3])-128)*64+(ord($matches[4])-128)).';'; }
+                                     : create_function ('$matches', 'return \'&#\'.((ord($matches[1])-240)*262144+(ord($matches[2])-128)*4096+(ord($matches[3])-128)*64+(ord($matches[4])-128)).\';\';')
+                                    ),
+                                    $string);
 
     // decode three byte unicode characters
     $string = preg_replace_callback("/([\340-\357])([\200-\277])([\200-\277])/",
-    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-224)*4096+(ord($matches[2])-128)*64+(ord($matches[3])-128)).\';\';'),
-    $string);
+                                    (check_php_version(5, 3, 0)
+                                     ? function($matches) { return '&#'.((ord($matches[1])-224)*4096+(ord($matches[2])-128)*64+(ord($matches[3])-128)).';'; }
+                                     : create_function ('$matches', 'return \'&#\'.((ord($matches[1])-224)*4096+(ord($matches[2])-128)*64+(ord($matches[3])-128)).\';\';')
+                                    ),
+                                    $string);
 
     // decode two byte unicode characters
     $string = preg_replace_callback("/([\300-\337])([\200-\277])/",
-    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-192)*64+(ord($matches[2])-128)).\';\';'),
-    $string);
+                                    (check_php_version(5, 3, 0)
+                                     ? function($matches) { return '&#'.((ord($matches[1])-192)*64+(ord($matches[2])-128)).';'; }
+                                     : create_function ('$matches', 'return \'&#\'.((ord($matches[1])-192)*64+(ord($matches[2])-128)).\';\';')
+                                    ),
+                                    $string);
 
     // remove broken unicode
     $string = preg_replace("/[\200-\237]|\240|[\241-\377]/",'?',$string);
index 2640ce641ce113806b0b99439ddeea7aec9445ea..af21b55bbb7acaf04d46bfff92fb08ead144de1d 100755 (executable)
@@ -241,25 +241,47 @@ function get_squirrel_sort($imap_stream, $sSortField, $reverse = false, $aUid =
       case 'TO':
       case 'CC':
         if(!$walk) {
-            array_walk($msgs, create_function('&$v,&$k,$f',
-                '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
-                 $addr = reset(parseRFC822Address($v[$f],1));
-                 $sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ?
-                   $addr[SQM_ADDR_PERSONAL] : "";
-                 $sEmail = ($addr[SQM_ADDR_HOST]) ?
-                      $addr[SQM_ADDR_MAILBOX] . "@".$addr[SQM_ADDR_HOST] :
-                      $addr[SQM_ADDR_HOST];
-                 $v[$f] = ($sPersonal) ? decodeHeader($sPersonal, true, false):$sEmail;'),$sSortField);
+            if (check_php_version(5, 3, 0))
+                $walk_function = function(&$v,&$k,$f) {
+                    $v[$f] = (isset($v[$f])) ? $v[$f] : "";
+                    $addr = reset(parseRFC822Address($v[$f],1));
+                    $sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ?
+                       $addr[SQM_ADDR_PERSONAL] : "";
+                    $sEmail = ($addr[SQM_ADDR_HOST]) ?
+                          $addr[SQM_ADDR_MAILBOX] . "@".$addr[SQM_ADDR_HOST] :
+                          $addr[SQM_ADDR_HOST];
+                    $v[$f] = ($sPersonal) ? decodeHeader($sPersonal, true, false):$sEmail;
+                };
+            else
+                $walk_function = create_function('&$v,&$k,$f',
+                    '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
+                     $addr = reset(parseRFC822Address($v[$f],1));
+                     $sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ?
+                       $addr[SQM_ADDR_PERSONAL] : "";
+                     $sEmail = ($addr[SQM_ADDR_HOST]) ?
+                          $addr[SQM_ADDR_MAILBOX] . "@".$addr[SQM_ADDR_HOST] :
+                          $addr[SQM_ADDR_HOST];
+                     $v[$f] = ($sPersonal) ? decodeHeader($sPersonal, true, false):$sEmail;');
+            array_walk($msgs, $walk_function, $sSortField);
             $walk = true;
         }
         // nobreak
       case 'SUBJECT':
         if(!$walk) {
-            array_walk($msgs, create_function('&$v,&$k,$f',
-                '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
-                 $v[$f] = strtolower(decodeHeader(trim($v[$f]), true, false));
-                 $v[$f] = (preg_match("/^(?:(?:vedr|sv|re|aw|fw|fwd|\[\w\]):\s*)*\s*(.*)$/si", $v[$f], $matches)) ?
-                                    $matches[1] : $v[$f];'),$sSortField);
+            if (check_php_version(5, 3, 0))
+                $walk_function = function(&$v,&$k,$f) {
+                    $v[$f] = (isset($v[$f])) ? $v[$f] : "";
+                    $v[$f] = strtolower(decodeHeader(trim($v[$f]), true, false));
+                    $v[$f] = (preg_match("/^(?:(?:vedr|sv|re|aw|fw|fwd|\[\w\]):\s*)*\s*(.*)$/si", $v[$f], $matches)) ?
+                                       $matches[1] : $v[$f];
+                };
+            else
+                $walk_function = create_function('&$v,&$k,$f',
+                    '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
+                     $v[$f] = strtolower(decodeHeader(trim($v[$f]), true, false));
+                     $v[$f] = (preg_match("/^(?:(?:vedr|sv|re|aw|fw|fwd|\[\w\]):\s*)*\s*(.*)$/si", $v[$f], $matches)) ?
+                                        $matches[1] : $v[$f];');
+            array_walk($msgs, $walk_function, $sSortField);
             $walk = true;
         }
         foreach ($msgs as $item) {
@@ -276,9 +298,16 @@ function get_squirrel_sort($imap_stream, $sSortField, $reverse = false, $aUid =
       case 'DATE':
       case 'INTERNALDATE':
         if(!$walk) {
-            array_walk($msgs, create_function('&$v,$k,$f',
-                '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
-                 $v[$f] = getTimeStamp(explode(" ",$v[$f]));'),$sSortField);
+            if (check_php_version(5, 3, 0))
+                $walk_function = function(&$v,$k,$f) {
+                    $v[$f] = (isset($v[$f])) ? $v[$f] : "";
+                    $v[$f] = getTimeStamp(explode(" ",$v[$f]));
+                };
+            else
+                $walk_function = create_function('&$v,$k,$f',
+                    '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
+                     $v[$f] = getTimeStamp(explode(" ",$v[$f]));');
+            array_walk($msgs, $walk_function, $sSortField);
             $walk = true;
         }
         // nobreak;
index 3102fc3c17ff9d1ac67fe4dfe0cbf5bb326b4d70..ae6b735a55611b59728f7570a9dc8f5b2622d298 100644 (file)
@@ -903,8 +903,11 @@ function decodeHeader ($string, $utfencode=true,$htmlsafe=true,$decide=false) {
                 case 'Q':
                     $replace = str_replace('_', ' ', $res[4]);
                     $replace = preg_replace_callback('/=([0-9a-f]{2})/i',
-                            create_function ('$matches', 'return chr(hexdec($matches[1]));'),
-                            $replace);
+                                             (check_php_version(5, 3, 0)
+                                              ? function($matches) { return chr(hexdec($matches[1])); }
+                                              : create_function ('$matches', 'return chr(hexdec($matches[1]));')
+                                             ),
+                                             $replace);
                     if ($utfencode) {
                         if ($can_be_encoded) {
                             /* convert string to different charset,