Description: Remove use of deprecated /e modifier in preg_replace.
Author: Thijs Kinkhorst <thijs@debian.org>
Origin: upstream, https://sourceforge.net/p/squirrelmail/code/14347/
Origin: upstream, https://sourceforge.net/p/squirrelmail/code/14359/
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1636333
Forwarded: not-needed
Last-Update: 2016-11-29

--- squirrelmail-1.4.23~svn20120406.orig/functions/decode/iso_8859_1.php
+++ squirrelmail-1.4.23~svn20120406/functions/decode/iso_8859_1.php
@@ -23,12 +23,16 @@ function charset_decode_iso_8859_1 ($str
     if (! sq_is8bit($string,'iso-8859-1'))
         return $string;
 
-    $string = preg_replace("/([\201-\237])/e","'&#' . ord('\\1') . ';'",$string);
+    $string = preg_replace_callback("/([\201-\237])/",
+    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("/([\241-\377])/e","'&#' . ord('\\1') . ';'",$string);
+    $string = preg_replace_callback("/([\241-\377])/",
+    create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';'),
+    $string);
     return $string;
 }
 
--- squirrelmail-1.4.23~svn20120406.orig/functions/decode/us_ascii.php
+++ squirrelmail-1.4.23~svn20120406/functions/decode/us_ascii.php
@@ -26,11 +26,11 @@ function charset_decode_us_ascii ($strin
     if (! sq_is8bit($string,'us-ascii'))
         return $string;
 
-    $string = preg_replace("/([\201-\237])/e","'?'",$string);
+    $string = preg_replace("/([\201-\237])/","'?'",$string);
 
     /* I don't want to use 0xA0 (\240) in any ranges. RH73 may dislike it */
     $string = str_replace("\240", '?', $string);
 
-    $string = preg_replace("/([\241-\377])/e","'?'",$string);
+    $string = preg_replace("/([\241-\377])/","'?'",$string);
     return $string;
 }
--- squirrelmail-1.4.23~svn20120406.orig/functions/decode/utf_8.php
+++ squirrelmail-1.4.23~svn20120406/functions/decode/utf_8.php
@@ -60,31 +60,31 @@ function charset_decode_utf_8 ($string)
 
     // decode six byte unicode characters
     /* (i think currently there is no such symbol)
-    $string = preg_replace("/([\374-\375])([\200-\277])([\200-\277])([\200-\277])([\200-\277])([\200-\277])/e",
-    "'&#'.((ord('\\1')-252)*1073741824+(ord('\\2')-200)*16777216+(ord('\\3')-200)*262144+(ord('\\4')-128)*4096+(ord('\\5')-128)*64+(ord('\\6')-128)).';'",
+    $string = preg_replace_callback("/([\374-\375])([\200-\277])([\200-\277])([\200-\277])([\200-\277])([\200-\277])/",
+    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-252)*1073741824+(ord($matches[2])-200)*16777216+(ord($matches[3])-200)*262144+(ord($matches[4])-128)*4096+(ord($matches[5])-128)*64+(ord($matches[6])-128)).\';\';'),
     $string);
     */
 
     // decode five byte unicode characters
     /* (i think currently there is no such symbol)
-    $string = preg_replace("/([\370-\373])([\200-\277])([\200-\277])([\200-\277])([\200-\277])/e",
-    "'&#'.((ord('\\1')-248)*16777216+(ord('\\2')-200)*262144+(ord('\\3')-128)*4096+(ord('\\4')-128)*64+(ord('\\5')-128)).';'",
+    $string = preg_replace_callback("/([\370-\373])([\200-\277])([\200-\277])([\200-\277])([\200-\277])/",
+    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-248)*16777216+(ord($matches[2])-200)*262144+(ord($matches[3])-128)*4096+(ord($matches[4])-128)*64+(ord($matches[5])-128)).\';\';'),
     $string);
     */
-
+    
     // decode four byte unicode characters
-    $string = preg_replace("/([\360-\367])([\200-\277])([\200-\277])([\200-\277])/e",
-    "'&#'.((ord('\\1')-240)*262144+(ord('\\2')-128)*4096+(ord('\\3')-128)*64+(ord('\\4')-128)).';'",
+    $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);
 
     // decode three byte unicode characters
-    $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
-    "'&#'.((ord('\\1')-224)*4096+(ord('\\2')-128)*64+(ord('\\3')-128)).';'",
+    $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);
 
     // decode two byte unicode characters
-    $string = preg_replace("/([\300-\337])([\200-\277])/e",
-    "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",
+    $string = preg_replace_callback("/([\300-\337])([\200-\277])/",
+    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-192)*64+(ord($matches[2])-128)).\';\';'),
     $string);
 
     // remove broken unicode
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/cp1251.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/cp1251.php
@@ -22,8 +22,7 @@ function charset_encode_cp1251 ($string)
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetocp1251('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetocp1251(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/", 'unicodetocp1251', $string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_cp1251 ($string)
  * Don't use it or make sure, that functions/encode/cp1251.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string cp1251 character
  */
-function unicodetocp1251($var) {
+function unicodetocp1251($matches) {
+    $var = $matches[1];
 
     $cp1251chars=array('160' => "\xA0",
                        '164' => "\xA4",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/cp1255.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/cp1255.php
@@ -22,8 +22,7 @@ function charset_encode_cp1255 ($string)
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetocp1255('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetocp1255(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetocp1255',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_cp1255 ($string)
  * Don't use it or make sure, that functions/encode/cp1255.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string cp1255 character
  */
-function unicodetocp1255($var) {
+function unicodetocp1255($matches) {
+    $var = $matches[1];
 
     $cp1255chars=array('160' => "\xA0",
                        '161' => "\xA1",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/cp1256.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/cp1256.php
@@ -22,8 +22,7 @@ function charset_encode_cp1256 ($string)
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetocp1256('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetocp1256(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetocp1256',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_cp1256 ($string)
  * Don't use it or make sure, that functions/encode/cp1256.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string cp1256 character
  */
-function unicodetocp1256($var) {
+function unicodetocp1256($matches) {
+    $var = $matches[1];
 
     $cp1256chars=array('160' => "\xA0",
                        '162' => "\xA2",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/iso_8859_1.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/iso_8859_1.php
@@ -22,8 +22,7 @@ function charset_encode_iso_8859_1 ($str
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88591('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88591(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso88591',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_iso_8859_1 ($str
  * Don't use it or make sure, that functions/encode/iso_8859_1.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string iso-8859-1 character
  */
-function unicodetoiso88591($var) {
+function unicodetoiso88591($matches) {
+    $var = $matches[1];
 
     if ($var < 256) {
         $ret = chr ($var);
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/iso_8859_15.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/iso_8859_15.php
@@ -22,8 +22,7 @@ function charset_encode_iso_8859_15 ($st
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetoiso885915('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso885915(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso885915',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_iso_8859_15 ($st
  * Don't use it or make sure, that functions/encode/iso_8859_15.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string iso-8859-15 character
  */
-function unicodetoiso885915($var) {
+function unicodetoiso885915($matches) {
+    $var = $matches[1];
 
     $iso885915chars=array('160' => "\xA0",
                           '161' => "\xA1",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/iso_8859_2.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/iso_8859_2.php
@@ -22,8 +22,7 @@ function charset_encode_iso_8859_2 ($str
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88592('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88592(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso88592',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_iso_8859_2 ($str
  * Don't use it or make sure, that functions/encode/iso_8859_2.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string iso-8859-2 character
  */
-function unicodetoiso88592($var) {
+function unicodetoiso88592($matches) {
+    $var = $matches[1];
 
     $iso88592chars=array('160' => "\xA0",
                         '164' => "\xA4",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/iso_8859_7.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/iso_8859_7.php
@@ -22,8 +22,7 @@ function charset_encode_iso_8859_7 ($str
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88597('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88597(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso88597',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_iso_8859_7 ($str
  * Don't use it or make sure, that functions/encode/iso_8859_7.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string iso-8859-7 character
  */
-function unicodetoiso88597($var) {
+function unicodetoiso88597($matches) {
+    $var = $matches[1];
 
     $iso88597chars=array('160' => "\xA0",
                          '163' => "\xA3",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/iso_8859_9.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/iso_8859_9.php
@@ -22,8 +22,7 @@ function charset_encode_iso_8859_9 ($str
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88599('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88599(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso88599',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_iso_8859_9 ($str
  * Don't use it or make sure, that functions/encode/iso_8859_9.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string iso-8859-9 character
  */
-function unicodetoiso88599($var) {
+function unicodetoiso88599($matches) {
+    $var = $matches[1];
 
     $iso88599chars=array('160' => "\xA0",
                          '161' => "\xA1",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/koi8_r.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/koi8_r.php
@@ -22,8 +22,7 @@ function charset_encode_koi8_r ($string)
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetokoi8r('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetokoi8r(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetokoi8r',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_koi8_r ($string)
  * Don't use it or make sure, that functions/encode/koi8_r.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string koi8-r character
  */
-function unicodetokoi8r($var) {
+function unicodetokoi8r($matches) {
+    $var = $matches[1];
 
     $koi8rchars=array('160' => "\x9A",
                       '169' => "\xBF",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/koi8_u.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/koi8_u.php
@@ -22,8 +22,7 @@ function charset_encode_koi8_u ($string)
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetokoi8u('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetokoi8u(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetokoi8u',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_koi8_u ($string)
  * Don't use it or make sure, that functions/encode/koi8_u.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string koi8-u character
  */
-function unicodetokoi8u($var) {
+function unicodetokoi8u($matches) {
+    $var = $matches[1];
 
     $koi8uchars=array('160' => "\x9A",
                       '169' => "\xBF",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/tis_620.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/tis_620.php
@@ -22,8 +22,7 @@ function charset_encode_tis_620 ($string
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetotis620('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetotis620(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetotis620',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_tis_620 ($string
  * Don't use it or make sure, that functions/encode/tis_620.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string tis-620 character
  */
-function unicodetotis620($var) {
+function unicodetotis620($matches) {
+    $var = $matches[1];
 
     $tis620chars=array('3585' => "\xA1",
                        '3586' => "\xA2",
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/us_ascii.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/us_ascii.php
@@ -22,8 +22,7 @@ function charset_encode_us_ascii ($strin
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetousascii('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetousascii(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetousascii',$string);
 
     return $string;
 }
@@ -36,10 +35,11 @@ function charset_encode_us_ascii ($strin
  * Don't use it or make sure, that functions/encode/us_ascii.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string us-ascii character
  */
-function unicodetousascii($var) {
+function unicodetousascii($matches) {
+    $var = $matches[1];
 
     if ($var < 128) {
         $ret = chr ($var);
--- squirrelmail-1.4.23~svn20120406.orig/functions/encode/utf_8.php
+++ squirrelmail-1.4.23~svn20120406/functions/encode/utf_8.php
@@ -26,8 +26,7 @@ function charset_encode_utf_8 ($string)
    // don't run encoding function, if there is no encoded characters
    if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
 
-    $string=preg_replace("/&#([0-9]+);/e","unicodetoutf8('\\1')",$string);
-    // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoutf8(hexdec('\\1'))",$string);
+    $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoutf8',$string);
 
     return $string;
 }
@@ -40,10 +39,11 @@ function charset_encode_utf_8 ($string)
  * Don't use it or make sure, that functions/encode/utf_8.php is
  * included.
  *
- * @param int $var decimal unicode value
+ * @param array $matches array with first element a decimal unicode value
  * @return string utf8 character
  */
-function unicodetoutf8($var) {
+function unicodetoutf8($matches) {
+    $var = $matches[1];
 
     if ($var < 128) {
         $ret = chr ($var);
--- squirrelmail-1.4.23~svn20120406.orig/functions/mime.php
+++ squirrelmail-1.4.23~svn20120406/functions/mime.php
@@ -702,7 +702,8 @@ function decodeHeader ($string, $utfenco
                     break;
                 case 'Q':
                     $replace = str_replace('_', ' ', $res[4]);
-                    $replace = preg_replace('/=([0-9a-f]{2})/ie', 'chr(hexdec("\1"))',
+                    $replace = preg_replace_callback('/=([0-9a-f]{2})/i',
+                            create_function ('$matches', 'return chr(hexdec($matches[1]));'),
                             $replace);
                     if ($can_be_encoded) {
                         // string is converted from one charset to another. sanitizing depends on $htmlsave
