Fixed bug: Encoding was not set correctly when message was not multipart.
[squirrelmail.git] / functions / mailbox.php
index 9a49839898294373a0c49da092e02b9dd4b664ed..cb0a071bd6fb7549e6e02f543e474cb061422ccc 100644 (file)
@@ -49,7 +49,7 @@
    function getMessageHeaders($imapConnection, $start, $end, &$from, &$subject, &$date) {
       $rel_start = $start;
       if (($start > $end) || ($start < 1)) {
-         echo "Error in message header fetching.  Start message: $start, End message: $end<BR>";
+         echo _("Error in message header fetching.  Start message: "). $start, _("End message: "). "$end<BR>";
          exit;
       }
 
@@ -60,7 +60,7 @@
          } else {
             $rel_end = $end;
          }
-         fputs($imapConnection, "messageFetch FETCH $rel_start:$rel_end RFC822.HEADER.LINES (From Subject Date)\n");
+         fputs($imapConnection, "messageFetch FETCH $rel_start:$rel_end BODY[HEADER.FIELDS (From Subject Date)]\n");
          $read = fgets($imapConnection, 1024);
 
          while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
     **  individually.  I'm not sure why it happens like that, but that's what my
     **  testing found.  Perhaps later I will be proven wrong and this will change.
     **/
-   function getMessageFlags($imapConnection, $j, &$flags) {
+   function getMessageFlags($imapConnection, $low, $high, &$flags) {
       /**   * 2 FETCH (FLAGS (\Answered \Seen))   */
-      fputs($imapConnection, "messageFetch FETCH $j:$j FLAGS\n");
+      fputs($imapConnection, "messageFetch FETCH $low:$high FLAGS\n");
       $read = fgets($imapConnection, 1024);
       $count = 0;
       while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
          if (strpos($read, "FLAGS")) {
             $read = ereg_replace("\(", "", $read);
             $read = ereg_replace("\)", "", $read);
+            $read = str_replace("\\", "", $read);
             $read = substr($read, strpos($read, "FLAGS")+6, strlen($read));
             $read = trim($read);
-            $flags = explode(" ", $read);;
-            $s = 0;
-            while ($s < count($flags)) {
-               $flags[$s] = substr($flags[$s], 1, strlen($flags[$s]));
-               $s++;
-            }
+            $flags[$count] = explode(" ", $read);;
          } else {
-            $flags[0] = "None";
+            $flags[$count][0] = "None";
          }
          $count++;
          $read = fgets($imapConnection, 1024);
          $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr);
          $from = $emailAddr;
       }
-      else if (strlen($name) > 0) {
+      else if (strlen(trim($name)) > 0) {
          $from = $name;
       }
       else if (strlen($emailAddr > 0)) {