Applied a fix for some formatting issue with mail adresses in the
[squirrelmail.git] / functions / imap_general.php
index 691eb0112ac3058db36fd9d864b032b3feac2f9b..1c598fa9415ac412c0f7c2e318c0930a76b26d2a 100755 (executable)
@@ -334,18 +334,30 @@ function sqimap_find_email ($string) {
 
 
 /*
-*  Takes the From: field, and creates a displayable name.
-*    Luke Ehresman <lkehresman@yahoo.com>
-*           becomes:   Luke Ehresman
-*    <lkehresman@yahoo.com>
-*           becomes:   lkehresman@yahoo.com
-*/
+ *  Takes the From: field, and creates a displayable name.
+ *    Luke Ehresman   <lkehresman@yahoo.com>
+ *    "Luke Ehresman" <lkehresman@yahoo.com>
+ *    lkehresman@yahoo.com (Luke Ehresman)
+ *           become:   Luke Ehresman
+ *    <lkehresman@yahoo.com>
+ *           becomes:   lkehresman@yahoo.com
+ */
 function sqimap_find_displayable_name ($string) {
+    $string = trim($string);
+    
     if ( ereg('^(.+)<.*>', $string, $regs) ) {
         $string = ereg_replace ('"', '', $regs[1] );
     }
     elseif ( ereg('\((.*)\)', $string, $regs) ) {
-        $string = $regs[1];
+        if( ( $regs[1] == '' ) || ( $regs[1] == ' ' ) ){
+            if ( ereg('^(.+) \(', $string, $regs) ) {
+               $string = ereg_replace( ' \(\)$', '', $string );
+            } else {
+               $string = '&nbsp';
+            }
+        } else {
+            $string = $regs[1];
+        }
     }
     else {
         $string = sqimap_find_email($string);