From: pdontthink Date: Wed, 29 Jul 2009 01:55:21 +0000 (+0000) Subject: Stop using deprecated ereg() functions (#2820952) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b7910e12e76a7976ec5bdd722d4a51ed73b4e941;p=squirrelmail.git Stop using deprecated ereg() functions (#2820952) git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@13799 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/class/l10n/gettext.class.php b/class/l10n/gettext.class.php index 76f02004..a6de17ca 100644 --- a/class/l10n/gettext.class.php +++ b/class/l10n/gettext.class.php @@ -229,7 +229,7 @@ class gettext_reader { else { $header = $this->get_translation_number(0); - if (eregi("plural-forms: (.*)\n",$header,$regs)) { + if (preg_match('/plural-forms: (.*)\n/i',$header,$regs)) { $expr = $regs[1]; } else { $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; diff --git a/doc/ChangeLog b/doc/ChangeLog index 663ce72a..e880b68a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -320,6 +320,7 @@ Version 1.5.2 - SVN (#2796007). - Removed the shut down DSBL blocklists (#2796734). - Fixed broken RFC1918 reference in contrib/.htaccess and doc/.htaccess (#2798839). + - Stop using deprecated ereg functions. (#2820952) Version 1.5.1 (branched on 2006-02-12) -------------------------------------- diff --git a/functions/abook_local_file.php b/functions/abook_local_file.php index 1c1901f7..0c235e36 100644 --- a/functions/abook_local_file.php +++ b/functions/abook_local_file.php @@ -300,8 +300,8 @@ class abook_local_file extends addressbook_backend { * TODO: regexp search is supported only in local_file backend. * Do we check format of regexp or ignore errors? */ - // errors on eregi call are suppressed in order to prevent display of regexp compilation errors - if(@eregi($expr, $line)) { + // errors on preg_match call are suppressed in order to prevent display of regexp compilation errors + if(@preg_match('/' . $expr . '/i', $line)) { array_push($res, array('nickname' => $row[0], 'name' => $this->fullname($row[1], $row[2]), 'firstname' => $row[1], @@ -433,7 +433,8 @@ class abook_local_file extends addressbook_backend { $this->quotevalue((!empty($userdata['label'])?$userdata['label']:'')); /* Strip linefeeds */ - $data = ereg_replace("[\r\n]", ' ', $data); + $nl_str = array("\r","\n"); + $data = str_replace($nl_str, ' ', $data); /** * Make sure that entry fits into allocated record space. @@ -588,7 +589,7 @@ class abook_local_file extends addressbook_backend { function quotevalue($value) { /* Quote the field if it contains | or ". Double quotes need to * be replaced with "" */ - if(ereg("[|\"]", $value)) { + if(stristr('"', $value) || stristr('|', $value)) { $value = '"' . str_replace('"', '""', $value) . '"'; } return $value; diff --git a/functions/addressbook.php b/functions/addressbook.php index 7103d6a1..d9b7aa79 100644 --- a/functions/addressbook.php +++ b/functions/addressbook.php @@ -731,7 +731,7 @@ class AddressBook { } /* Blocks use of space, :, |, #, " and ! in nickname */ - if (eregi('[ \\:\\|\\#\\"\\!]', $userdata['nickname'])) { + if (preg_match('/[ :|#"!]/', $userdata['nickname'])) { $this->error = _("Nickname contains illegal characters"); return false; } @@ -831,7 +831,7 @@ class AddressBook { return false; } - if (eregi('[\\: \\|\\#"\\!]', $userdata['nickname'])) { + if (preg_match('/[: |#"!]/', $userdata['nickname'])) { $this->error = _("Nickname contains illegal characters"); return false; } diff --git a/functions/attachment_common.php b/functions/attachment_common.php index 35038eeb..5cb395e4 100644 --- a/functions/attachment_common.php +++ b/functions/attachment_common.php @@ -265,7 +265,12 @@ function attachment_common_octet_stream(&$Args) { //FIXME: or at least we can move this hook up to the top of this file where $FileExtensionToMimeType is defined. What else is this hook here for? What plugins use it? do_hook('attachment_common-load_mime_types', $null); - ereg('\\.([^\\.]+)$', $Args[6], $Regs); + preg_match('/\.([^.]+)$/', $Args[7], $Regs); + + $Ext = ''; + if (is_array($Regs) && isset($Regs[1])) { + $Ext = $Regs[1]; + } $Ext = strtolower($Regs[1]); diff --git a/functions/folder_manip.php b/functions/folder_manip.php index 0756ce06..c93d6750 100644 --- a/functions/folder_manip.php +++ b/functions/folder_manip.php @@ -226,7 +226,7 @@ function folders_delete_do ($imapConnection, $delimiter, $folder_name) /** lets see if we CAN move folders to the trash.. otherwise, ** just delete them **/ - if ($delete_folder || eregi('^'.$trash_folder.'.+', $folder_name) ) { + if ($delete_folder || preg_match('/^' . $trash_folder . '.+/i', $folder_name) ) { $can_move_to_trash = FALSE; } else { /* Otherwise, check if trash folder exits and support sub-folders */ diff --git a/functions/imap_asearch.php b/functions/imap_asearch.php index 7ffe3ea4..6ed46669 100644 --- a/functions/imap_asearch.php +++ b/functions/imap_asearch.php @@ -190,7 +190,7 @@ function sqimap_asearch_parse_date($what) global $imap_asearch_months; $what = trim($what); - $what = ereg_replace('[ /\\.,]+', '-', $what); + $what = preg_replace('/[ \/\\.,]+/', '-', $what); if ($what) { preg_match('/^([0-9]+)-+([^\-]+)-+([0-9]+)$/', $what, $what_parts); if (count($what_parts) == 4) { @@ -232,7 +232,7 @@ function sqimap_asearch_build_criteria($opcode, $what, $charset) default: case 'anum': $what = str_replace(' ', '', $what); - $what = ereg_replace('[^0-9]+[^KMG]$', '', strtoupper($what)); + $what = preg_replace('/[^0-9]+[^KMG]$/', '', strtoupper($what)); if ($what != '') { switch (substr($what, -1)) { case 'G': @@ -268,7 +268,7 @@ function sqimap_asearch_build_criteria($opcode, $what, $charset) $criteria = $opcode . ' ' . sqimap_asearch_encode_string($what, $charset) . ' '; break; case 'asequence': - $what = ereg_replace('[^0-9:\(\)]+', '', $what); + $what = preg_replace('/[^0-9:()]+/', '', $what); if ($what != '') $criteria = $opcode . ' ' . $what . ' '; break; diff --git a/functions/imap_general.php b/functions/imap_general.php index 2b0b0cf6..0485a3c9 100755 --- a/functions/imap_general.php +++ b/functions/imap_general.php @@ -1075,8 +1075,8 @@ function sqimap_get_delimiter ($imap_stream = false) { * TODO: remove this in favour of the information from sqimap_get_namespace() */ $read = sqimap_run_command($imap_stream, 'NAMESPACE', true, $a, $b); - if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) { - if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2)) { + if (preg_match('/\* NAMESPACE +(\( *\(.+\) *\)|NIL) +(\( *\(.+\) *\)|NIL) +(\( *\(.+\) *\)|NIL)/i', $read[0], $data)) { + if (preg_match('/^\( *\((.*)\) *\)/', $data[1], $data2)) { $pn = $data2[1]; } $pna = explode(')(', $pn); @@ -1138,7 +1138,7 @@ function sqimap_parse_namespace(&$input) { $ns_strings = array(1=>'personal', 2=>'users', 3=>'shared'); $namespace = array(); - if(ereg('NAMESPACE (\(\(.*\)\)|NIL) (\(\(.*\)\)|NIL) (\(\(.*\)\)|NIL)', $input, $regs) !== false) { + if (preg_match('/NAMESPACE (\(\(.*\)\)|NIL) (\(\(.*\)\)|NIL) (\(\(.*\)\)|NIL)/', $input, $regs)) { for($i=1; $i<=3; $i++) { if($regs[$i] == 'NIL') { $namespace[$ns_strings[$i]] = array(); @@ -1174,7 +1174,7 @@ function sqimap_parse_namespace(&$input) { */ function sqimap_encode_mailbox_name($what) { - if (ereg("[\"\\\r\n]", $what)) + if (preg_match('/["\\\r\n]/', $what)) return '{' . strlen($what) . "}\r\n" . $what; /* 4.3 literal form */ return '"' . $what . '"'; /* 4.3 quoted string form */ } diff --git a/functions/mime.php b/functions/mime.php index 349b3bd2..2f48c8b4 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -140,7 +140,7 @@ function mime_fetch_body($imap_stream, $id, $ent_id=1, $fetch_size=0) { } while($topline && ($topline[0] == '*') && !preg_match('/\* [0-9]+ FETCH.*/i', $topline)) ; $wholemessage = implode('', $data); - if (ereg('\\{([^\\}]*)\\}', $topline, $regs)) { + if (preg_match('/\{([^\}]*)\}/', $topline, $regs)) { $ret = substr($wholemessage, 0, $regs[1]); /* There is some information in the content info header that could be important * in order to parse html messages. Let's get them here. @@ -148,7 +148,7 @@ function mime_fetch_body($imap_stream, $id, $ent_id=1, $fetch_size=0) { // if ($ret{0} == '<') { // $data = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent_id.MIME]", true, $response, $message, TRUE); // } - } else if (ereg('"([^"]*)"', $topline, $regs)) { + } else if (preg_match('/"([^"]*)"/', $topline, $regs)) { $ret = $regs[1]; } else if ((stristr($topline, 'nil') !== false) && (empty($wholemessage))) { $ret = $wholemessage; @@ -2734,7 +2734,7 @@ function SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0) { $filename = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_downloadfilename', $filename, $HTTP_USER_AGENT); } else { - $filename = ereg_replace('[\\/:\*\?"<>\|;]', '_', str_replace(' ', ' ', $filename)); + $filename = preg_replace('/[\\\/:*?"<>|;]/', '_', str_replace(' ', ' ', $filename)); } // A Pox on Microsoft and it's Internet Explorer! diff --git a/functions/strings.php b/functions/strings.php index 999fe1a9..ca09684a 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -349,7 +349,7 @@ function sqWordWrap(&$line, $wrap, $charset='') { } } - ereg("^([\t >]*)([^\t >].*)?$", $line, $regs); + preg_match('/^([\t >]*)([^\t >].*)?$/', $line, $regs); $beginning_spaces = $regs[1]; if (isset($regs[2])) { $words = explode(' ', $regs[2]); diff --git a/functions/url_parser.php b/functions/url_parser.php index 3aff9f7e..73ef9843 100644 --- a/functions/url_parser.php +++ b/functions/url_parser.php @@ -55,7 +55,7 @@ function parseEmail (&$body) { $addresses = array(); /* Find all the email addresses in the body */ - while(eregi($Email_RegExp_Match, $sbody, $regs)) { + while (preg_match('/' . $Email_RegExp_Match . '/i', $sbody, $regs)) { $addresses[$regs[0]] = strtr($regs[0], array('&' => '&')); $start = strpos($sbody, $regs[0]) + strlen($regs[0]); $sbody = substr($sbody, $start); @@ -183,7 +183,7 @@ function parseUrl (&$body) { $url = substr($body, $target_pos, $end-$target_pos); /* Needed since lines are not passed with \n or \r */ - while ( ereg("[,\.]$", $url) ) { + while ( preg_match('/[,.]$/', $url) ) { $url = substr( $url, 0, -1 ); $end--; } @@ -217,7 +217,7 @@ function getEmail($string) { $addresses = array(); /* Find all the email addresses in the body */ - while (eregi($Email_RegExp_Match, $string, $regs)) { + while (preg_match('/' . $Email_RegExp_Match . '/i', $string, $regs)) { $addresses[$regs[0]] = strtr($regs[0], array('&' => '&')); $start = strpos($string, $regs[0]) + strlen($regs[0]); $string = substr($string, $start); diff --git a/plugins/squirrelspell/sqspell_config.php b/plugins/squirrelspell/sqspell_config.php index a9be7354..ff43e52e 100644 --- a/plugins/squirrelspell/sqspell_config.php +++ b/plugins/squirrelspell/sqspell_config.php @@ -105,9 +105,3 @@ $SQSPELL_APP_DEFAULT = 'English'; $SQSPELL_WORDS_FILE = getHashedFile($username, $data_dir, "$username.words"); -/** - * Function used for checking words in user's dictionary - * @global string $SQSPELL_EREG - * @deprecated It is not used since 1.5.1 (sqspell 0.5) - */ -$SQSPELL_EREG = 'ereg'; diff --git a/src/addressbook.php b/src/addressbook.php index 3a7977f9..0abf138b 100644 --- a/src/addressbook.php +++ b/src/addressbook.php @@ -111,7 +111,7 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P if (!$r) { /* Remove backend name from error string */ $errstr = $abook->error; - $errstr = ereg_replace('^\[.*\] *', '', $errstr); + $errstr = preg_replace('/^\[.*\] */', '', $errstr); $formerror = $errstr; $showaddrlist = false; diff --git a/src/view_header.php b/src/view_header.php index fd43a16a..ab92e2d4 100644 --- a/src/view_header.php +++ b/src/view_header.php @@ -41,16 +41,17 @@ function parse_viewheader($imapConnection,$id, $passed_ent_id) { for ($i=1; $i < count($read); $i++) { $line = htmlspecialchars($read[$i]); switch (true) { - case (eregi("^>", $line)): + case (preg_match('/^>/i', $line)): $second[$i] = $line; $first[$i] = ' '; $cnum++; break; - case (eregi("^[ |\t]", $line)): +// FIXME: is the pipe character below a mistake? I think the original author might have thought it carried special meaning in the character class, which it does not... but then again, I am not currently trying to understand what this code actually does + case (preg_match('/^[ |\t]/', $line)): $second[$i] = $line; $first[$i] = ''; break; - case (eregi("^([^:]+):(.+)", $line, $regs)): + case (preg_match('/^([^:]+):(.+)/', $line, $regs)): $first[$i] = $regs[1] . ':'; $second[$i] = $regs[2]; $cnum++;