Changed regexps
[squirrelmail.git] / src / read_body.php
index e0777db5f625cb72a169aee92d16958866e18872..c29b9497b24a15e8c6bf237697bedea31db76e77 100644 (file)
    // add them to the list.  Remove duplicates.
    // This is somewhat messy, so I'll explain:
    // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
-   if (!is_array($message->header->to)) { $message->header->cc = array($message->header->to); }
-   if (!is_array($message->header->cc)) { $message->header->cc = array($message->header->cc); }
    $url_replytoall_extra_addrs = array_merge(array($message->header->from),
       $message->header->to, $message->header->cc);
 
    $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
    
    // 4) Make them unique -- weed out duplicates
-   if (function_exists("array_unique")) {
-      $url_replytoall_extra_addrs = array_unique($url_replytoall_extra_addrs);
-   }
+   // (Coded for PHP 4.0.0)
+   $url_replytoall_extra_addrs =
+      array_keys(array_flip($url_replytoall_extra_addrs));
    
    // 5) Remove the addresses we'll be sending the message 'to'
    $url_replytoall_avoid_addrs = parseAddrs($message->header->replyto);
 
    /** FORMAT THE CC STRING **/
    $i = 0;
-   $cc_string = "";
-   $cc_ary = $message->header->cc;
-   while ($i < count(decodeHeader($cc_ary))) {
-      $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
-      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) {
+   if (isset ($message->header->cc[0]) && trim($message->header->cc[0])){
+      $cc_string = "";
+      $cc_ary = $message->header->cc;
+      while ($i < count(decodeHeader($cc_ary))) {
+         $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
+         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) {
+                  if ($where && $what) {
+                     // from a search
+                     $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&what=".urlencode($what)."&where=".urlencode($where)."&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
+                  } else {
+                     $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\">$echo_more</A>)";
+                  }   
+                  $i = count($cc_ary);
+               }
+            } else if ($i == 1) {
                if ($where && $what) {
                   // from a search
-                  $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&what=".urlencode($what)."&where=".urlencode($where)."&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
+                  $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&what=".urlencode($what)."&where=".urlencode($where)."&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
                } else {
-                  $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\">$echo_more</A>)";
+                  $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\">$echo_less</A>)";
                }   
-               $i = count($cc_ary);
             }
-         } else if ($i == 1) {
-            if ($where && $what) {
-               // from a search
-               $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&what=".urlencode($what)."&where=".urlencode($where)."&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
-            } else {
-               $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\">$echo_less</A>)";
-            }   
          }
       }
    }
-
    /** make sure everything will display in HTML format **/
    $from_name = decodeHeader(htmlspecialchars($message->header->from));
    $subject = decodeHeader(htmlspecialchars($message->header->subject));
    echo "         </TD>\n";
    echo "      </TR>\n";
    /** cc **/
-   if ($message->header->cc) {
+   if (isset($cc_string)) {
       echo "      <TR>\n";
       echo "         <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
       echo "            Cc:\n";