فهرست منبع

Added "CC" to read_body.php, and rewrote the code to handle getting TO and CC

Luke Ehresman 25 سال پیش
والد
کامیت
e47298cba5
3فایلهای تغییر یافته به همراه89 افزوده شده و 51 حذف شده
  1. 1 0
      functions/imap.php
  2. 47 35
      functions/mailbox.php
  3. 41 16
      src/read_body.php

+ 1 - 0
functions/imap.php

@@ -28,6 +28,7 @@
          $temp .= $char;
          $char = substr($mailbox, $i, 1);
       }
+      echo $tmp;
       return strrev($temp);
    }
 

+ 47 - 35
functions/mailbox.php

@@ -363,51 +363,63 @@
       return $line;
    }
 
-/*
-         $start = strpos(strtolower($line), "http://");
-         $text = substr($line, $start, strlen($line));
-         $linktext = substr($link, 0, $end);
-         $link = trim(ereg_replace("<BR>", "", $linktext));
-
+   function getMessageHeadersTo($imapConnection, $i, &$to) {
+      $pos = 0;
+      fputs($imapConnection, "messageFetch FETCH $i:$i RFC822.HEADER.LINES (To)\n");
+      $read = fgets($imapConnection, 1024);
 
-//         $line = str_replace($text, "<A HREF=\"$link\" TARGET=_top>$link</A>", $line);
-*/
+      $firstline = true;
+      while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
+         if ($firstline == true) {
+            $firstline = false;
+            $read = fgets($imapConnection, 1024);
+         } else if (strlen(trim($read)) <= 1) {
+            $firstline = false;
+            $read = fgets($imapConnection, 1024);
+         } else if ($read == ")") {
+            $firstline = false;
+            $read = fgets($imapConnection, 1024);
+         } else {
+            $firstline = false;
+            $read = ereg_replace("<", "&lt;", $read);
+            $read = ereg_replace(">", "&gt;", $read);
+            if (strlen(trim($read)) != 0)
+               $to[$pos] = substr($read, 3, strlen($read));
 
-   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++;
+            $read = fgets($imapConnection, 1024);
+         }
       }
+   }
 
+   function getMessageHeadersCc($imapConnection, $i, &$cc) {
       $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);
+      fputs($imapConnection, "messageFetch FETCH $i:$i RFC822.HEADER.LINES (Cc)\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++;
-            }
+      $firstline = true;
+      while ((strlen(trim($read)) > 0) && (substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
+         if ($firstline == true) {
+            $firstline = false;
+            $read = fgets($imapConnection, 1024);
+         } else if (strlen(trim($read)) <= 1) {
+            $firstline = false;
+            $read = fgets($imapConnection, 1024);
+         } else if ($read == ")") {
+            $firstline = false;
+            $read = fgets($imapConnection, 1024);
+         } else {
+            $read = ereg_replace("<", "&lt;", $read);
+            $read = ereg_replace(">", "&gt;", $read);
+            if (strlen(trim($read)) != 0)
+               $cc[$pos] = substr($read, 3, strlen($read));
 
+            $pos++;
             $read = fgets($imapConnection, 1024);
          }
-         $rel_start = $rel_start + 50;
       }
+      $read = fgets($imapConnection, 1024); // get rid of the last line
    }
 
+
 ?>

+ 41 - 16
src/read_body.php

@@ -13,7 +13,8 @@
    displayPageHeader($mailbox);
    $body = fetchBody($imapConnection, $passed_id);
    getMessageHeaders($imapConnection, $passed_id, $passed_id, $f, $s, $d);
-   getMessageHeadersTo($imapConnection, $passed_id, $passed_id, $t);
+   getMessageHeadersTo($imapConnection, $passed_id, $t);
+   getMessageHeadersCc($imapConnection, $passed_id, $c);
 
    $subject = $s[0];
    $url_subj = urlencode(trim($subject));
@@ -28,20 +29,10 @@
    $url_from = trim(decodeEmailAddr($f[0]));
    $url_from = urlencode($url_from);
 
-   $to_left = trim($t[0]);
-   for ($i = 0; $to_left;$i++) {
-      if (strpos($to_left, ",")) {
-         $to_ary[$i] = trim(substr($to_left, 0, strpos($to_left, ",")));
-         $to_left = substr($to_left, strpos($to_left, ",")+1, strlen($to_left));
-      }
-      else {
-         $to_ary[$i] = trim($to_left);
-         $to_left = "";
-      }
-   }
-
+   /** FORMAT THE TO STRING **/
    $i = 0;
    $to_string = "";
+   $to_ary = $t;
    while ($i < count($to_ary)) {
       if ($to_string)
          $to_string = "$to_string<BR>$to_ary[$i]";
@@ -52,15 +43,40 @@
       if (count($to_ary) > 1) {
          if ($show_more == false) {
             if ($i == 1) {
-               $to_string = "$to_string&nbsp;&nbsp;&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=1\">more</A>)";
+               $to_string = "$to_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=1&show_more_cc=$show_more_cc\">more</A>)";
                $i = count($to_ary);
             }
          } else if ($i == 1) {
-            $to_string = "$to_string&nbsp;&nbsp;&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=0\">less</A>)";
+            $to_string = "$to_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=0&show_more_cc=$show_more_cc\">less</A>)";
          }
       }
    }
 
+   /** FORMAT THE CC STRING **/
+   $i = 0;
+   $cc_string = "";
+   $cc_ary = $c;
+   while ($i < count($cc_ary)) {
+      if ($cc_string)
+         $cc_string = "$cc_string<BR>$cc_ary[$i]";
+      else
+         $cc_string = "$cc_ary[$i]";
+
+      $i++;
+      if (count($cc_ary) > 1) {
+         if ($show_more_cc == false) {
+            if ($i == 1) {
+               $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more_cc=1&show_more=$show_more\">more</A>)";
+               $i = count($cc_ary);
+            }
+         } else if ($i == 1) {
+            $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more_cc=0&show_more=$show_more\">less</A>)";
+         }
+      }
+   }
+
+
+
    echo "<BR>";
    echo "<TABLE COLS=1 WIDTH=95% BORDER=0 ALIGN=CENTER CELLPADDING=2>\n";
    echo "   <TR><TD BGCOLOR=DCDCDC WIDTH=100%>";
@@ -114,7 +130,16 @@
    echo "            <FONT FACE=\"Arial,Helvetica\"><B>$to_string</B></FONT>\n";
    echo "         </TD>\n";
    echo "      </TR>\n";
-
+   /** cc **/
+   if ($c[0]) {
+      echo "      <TR>\n";
+      echo "         <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
+      echo "            <FONT FACE=\"Arial,Helvetica\">Cc:</FONT>\n";
+      echo "         </TD><TD BGCOLOR=FFFFFF WIDTH=85% VALIGN=TOP>\n";
+      echo "            <FONT FACE=\"Arial,Helvetica\"><B>$cc_string</B></FONT>\n";
+      echo "         </TD>\n";
+      echo "      </TR>\n";
+   }
    echo "   </TABLE></TD></TR>\n";
 
    echo "   <TR><TD BGCOLOR=FFFFFF WIDTH=100%><BR>\n";