moved "empty trash" to the left bar so it's always visible
[squirrelmail.git] / functions / mailbox.php
index 846e1a60b39ea7313a5e49ef802e88d4ed5a92d5..a0f3d70d660b62c4026bdfd0e8a3f294c08bf8d5 100644 (file)
       }
    }
 
+   function decodeEmailAddr($sender) {
+      $emailAddr = getEmailAddr($sender);
+      $emailStart = strpos($emailAddr, "EMAILSTART--");
+      $emailEnd = strpos($emailAddr, "--EMAILEND") - 10;
+
+      $emailAddr = ereg_replace("EMAILSTART--", "", $emailAddr);
+      $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr);
+      return $emailAddr;
+   }
+
    function getEmailAddr($sender) {
       if (strpos($sender, "EMAILSTART--") == false)
          return "";
          $line = str_replace(">", ">", $line);
       }
 
-//      $line = wordWrap($line);
+      $wrap_at = 80; // Make this configurable int the config file some time
+      if (strlen($line) - 2 >= $wrap_at) // -2 because of the ^^ at the beginning
+         $line = wordWrap($line, $wrap_at);
+
       $line = str_replace(" ", " ", $line);
       $line = str_replace("\t", "        ", $line);
+      $line = str_replace("\n", "", $line);
+      $line = str_replace("\r", "", $line);
 
       /** if >> or > are found at the beginning of a line, I'll assume that was
           replied text, so make it different colors **/
       /** This translates "http://" into a link.  It could be made better to accept
           "www" and "mailto" also.  That should probably be added later. **/
       if (strpos(strtolower($line), "http://") != false) {
+         $line = ereg_replace("<BR>", "", $line);
          $start = strpos(strtolower($line), "http://");
          $link = substr($line, $start, strlen($line));
 
-         if (strpos($link, "&"))
-            $end = strpos($link, "&");
-         else if (strpos($link, "<"))
+         if (strpos($link, " ")) {
+            $end = strpos($link, " ")-1;
+         }
+         else if (strpos($link, "&nbsp;")) {
+            $end = strpos($link, "&nbsp;")-1;
+         }
+         else if (strpos($link, "<")) {
             $end = strpos($link, "<");
+         }
+         else if (strpos($link, ">")) {
+            $end = strpos($link, ">");
+         }
+         else if (strpos($link, "(")) {
+            $end = strpos($link, "(")-1;
+         }
+         else if (strpos($link, ")")) {
+            $end = strpos($link, ")")-1;
+         }
+         else if (strpos($link, "{")) {
+            $end = strpos($link, "{")-1;
+         }
+         else if (strpos($link, "}")) {
+            $end = strpos($link, "}")-1;
+         }
          else
             $end = strlen($link);
 
-         $link = substr($link, 0, $end);
+         $link = substr($line, $start, $end);
+         $end = $end + $start;
+         $before = substr($line, 0, $start);
+         $after  = substr($line, $end, strlen($line));
 
-         $line = str_replace($link, "<A HREF=\"$link\" TARGET=_top>$link</A>", $line);
+         $line = "$before<A HREF=\"$link\" TARGET=_top>$link</A>$after<BR>";
       }
 
       return $line;
    }
+
+/*
+         $start = strpos(strtolower($line), "http://");
+         $text = substr($line, $start, strlen($line));
+         $linktext = substr($link, 0, $end);
+         $link = trim(ereg_replace("<BR>", "", $linktext));
+
+
+//         $line = str_replace($text, "<A HREF=\"$link\" TARGET=_top>$link</A>", $line);
+*/
+
+   function getMessageHeadersTo($imapConnection, $start, $end, &$to) {
+      $rel_start = $start;
+      if (($start > $end) || ($start < 1)) {
+         echo "Error in message header fetching.  Start message: $start, End message: $end<BR>";
+         exit;
+      }
+
+      $pos = 0;
+      while ($rel_start <= $end) {
+         if ($end - $rel_start > 50) {
+            $rel_end = $rel_start + 49;
+         } else {
+            $rel_end = $end;
+         }
+         fputs($imapConnection, "messageFetch FETCH $rel_start:$rel_end RFC822.HEADER.LINES (To)\n");
+         $read = fgets($imapConnection, 1024);
+
+         while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
+            if (substr($read, 0, 3) == "To:") {
+               $read = ereg_replace("<", "&lt;", $read);
+               $read = ereg_replace(">", "&gt;", $read);
+               $to[$pos] = substr($read, 3, strlen($read));
+               if (strlen(Chop($to[$pos])) == 0)
+                  $to[$pos] = "Unknown Recipients";
+            }
+            else if (substr($read, 0, 1) == ")") {
+               if ($subject[$pos] == "")
+                  $subject[$pos] = "Unknown Recipients";
+               $pos++;
+            }
+
+            $read = fgets($imapConnection, 1024);
+         }
+         $rel_start = $rel_start + 50;
+      }
+   }
+
 ?>