Code cleanup
[squirrelmail.git] / functions / imap_general.php
index 21672e144ddc8048bb05bd6bba731711f021f7d7..12a6c257072465bc35119c8d88e0b2a798ca4aac 100755 (executable)
@@ -69,7 +69,9 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
         $data = array();
         $total_size = 0;
         while (strpos($read, "\n") === false) {
-            $read .= fgets($imap_stream, 9096);
+            if(!($read .= fgets($imap_stream, 9096))) {
+                break;
+            }
         }
         
         if (ereg("^\\* [0-9]+ FETCH.*\\{([0-9]+)\\}", $read, $regs)) {
@@ -84,7 +86,9 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
         }
         while (1) {
             while (strpos($read, "\n") === false) {
-                $read .= fgets($imap_stream, 9096);
+                if(!($read .= fgets($imap_stream, 9096))) {
+                    break;
+                }
             }
             // If we know the size, no need to look at the end parameters
             if ($size > 0) {
@@ -354,15 +358,22 @@ function sqimap_find_email ($string) {
  *    Luke Ehresman   <lkehresman@yahoo.com>
  *    "Luke Ehresman" <lkehresman@yahoo.com>
  *    lkehresman@yahoo.com (Luke Ehresman)
- *           become:   Luke Ehresman
+ *           becomes:   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] );
+        $orig_string = $string;
+        $string = str_replace ('"', '', $regs[1] );
+        if (trim($string) == '') {
+             $string = sqimap_find_email($orig_string);
+        }
+        if( $string == '' || $string == ' ' ){
+            $string = '&nbsp';
+        }
     }
     elseif ( ereg('\((.*)\)', $string, $regs) ) {
         if( ( $regs[1] == '' ) || ( $regs[1] == ' ' ) ){
@@ -376,7 +387,7 @@ function sqimap_find_displayable_name ($string) {
         }
     }
     else {
-        $string = sqimap_find_email($string);
+        $string = str_replace ('"', '', sqimap_find_email($string));
     }
 
     return trim($string);