Rewrote sqimap_find_displayable_name() to use regular expressions.
authorantipode <antipode@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 28 Dec 2001 21:14:43 +0000 (21:14 +0000)
committerantipode <antipode@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 28 Dec 2001 21:14:43 +0000 (21:14 +0000)
The parsing of the email address is far from perfect, and the regular
expressions need to be improved.  This version of the function is
equivallent in functionality to the previous one.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1994 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_general.php

index e07bbc99590aaf7770f0b22abdcf04d40ca9c6e5..691eb0112ac3058db36fd9d864b032b3feac2f9b 100755 (executable)
@@ -341,28 +341,19 @@ function sqimap_find_email ($string) {
 *           becomes:   lkehresman@yahoo.com
 */
 function sqimap_find_displayable_name ($string) {
-    $string = ' '.trim($string);
-    $orig_string = $string;
-    if (($angle1 = strpos($string, '<')) && strpos($string, '>')) {
-        if ($angle1 == 1) {
-            $string = sqimap_find_email($string);
-        } else {
-            $string = trim($string);
-            $string = substr($string, 0, $angle1-1);
-            $string = ereg_replace ('"', '', $string);
-        }
-        
-        if (trim($string) == '') {
-            $string = sqimap_find_email($orig_string);
-        }
-    } else if ( ($paren1 = strpos($string, '('))
-                && ($paren2 = strpos($string, ')'))) {
-        $string = substr($string, $paren1 + 1, $paren2 - $paren1 - 1);
+    if ( ereg('^(.+)<.*>', $string, $regs) ) {
+        $string = ereg_replace ('"', '', $regs[1] );
+    }
+    elseif ( ereg('\((.*)\)', $string, $regs) ) {
+        $string = $regs[1];
+    }
+    else {
+        $string = sqimap_find_email($string);
     }
-    return $string;
-}
-
 
+    return trim($string);
+}
+    
 /*
 *  Returns the number of unseen messages in this folder
 */