Search call back adjusted to fit new format
[squirrelmail.git] / src / read_body.php
index e4ee9458c33815ce9d25dd46b0cd69ac01890845..ba9be44d45ff93026a69e16e7e22811e13af26c7 100644 (file)
@@ -1,84 +1,39 @@
 <?php
-   /**
-    * read_body.php
-    *
-    * Copyright (c) 1999-2001 The SquirrelMail Development Team
-    * Licensed under the GNU GPL. For full terms see the file COPYING.
-    *
-    * This file is used for reading the msgs array and displaying
-    * the resulting emails in the right frame.
-    *
-    * $Id$
-    */
-
-    require_once('../src/validate.php');
-    require_once('../functions/imap.php');
-    require_once('../functions/mime.php');
-    require_once('../functions/date.php');
-    require_once('../functions/url_parser.php');
-   
-    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-    sqimap_mailbox_select($imapConnection, $mailbox);
-    do_hook('html_top');
-    displayPageHeader($color, $mailbox);
-
-    if (isset($view_hdr)) {
-        fputs ($imapConnection, sqimap_session_id() . " FETCH $passed_id BODY[HEADER]\r\n");
-        $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true, $a, $b); 
-      
-        echo '<BR>' .
-             '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0" ALIGN="CENTER">' . "\n" .
-             "   <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><CENTER><B>" . _("Viewing Full Header") . '</B> - ';
-        if (isset($where) && isset($what)) {
-            // Got here from a search
-            echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
-        } else {
-            echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
-        }
-        echo ''._("View message") . "</a></b></center></td></tr></table>\n" .
-             "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n" .
-             '<tr><td>';
-
-        $cnum = 0;
-        for ($i=1; $i < count($read); $i++) {
-            $line = htmlspecialchars($read[$i]);
-            if (eregi("^&gt;", $line)) {
-                $second[$i] = $line;
-                $first[$i] = '&nbsp;';
-                $cnum++;
-            } else if (eregi("^[ |\t]", $line)) {
-                $second[$i] = $line;
-                $first[$i] = '';
-            } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
-                $first[$i] = $regs[1] . ':';
-                $second[$i] = $regs[2];
-                $cnum++;
-            } else {
-                $second[$i] = trim($line);
-                $first[$i] = '';
-            }
-        }
-        for ($i=0; $i < count($second); $i = $j) {
-            if (isset($first[$i])) {
-                $f = $first[$i];
-            }
-            if (isset($second[$i])) {
-                $s = nl2br($second[$i]);
-            }
-            $j = $i + 1;
-            while (($first[$j] == '') && ($j < count($first))) {
-                $s .= '&nbsp;&nbsp;&nbsp;&nbsp;' . nl2br($second[$j]);
-                $j++;
-            }
-            parseEmail($s);
-            if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
-        }
-        echo "</td></tr></table>\n";
-        echo '</body></html>';
-        sqimap_logout($imapConnection);
-        exit;
-    }
 
+/**
+ * read_body.php
+ *
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This file is used for reading the msgs array and displaying
+ * the resulting emails in the right frame.
+ *
+ * $Id$
+ /
+
+/*****************************************************************/
+/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!!           ***/
+/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION.             ***/
+/***    + Base level indent should begin at left margin, as    ***/
+/***      the require_once below looks.                        ***/
+/***    + All identation should consist of four space blocks   ***/
+/***    + Tab characters are evil.                             ***/
+/***    + all comments should use "slash-star ... star-slash"  ***/
+/***      style -- no pound characters, no slash-slash style   ***/
+/***    + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD      ***/
+/***      ALWAYS USE { AND } CHARACTERS!!!                     ***/
+/***    + Please use ' instead of ", when possible. Note "     ***/
+/***      should always be used in _( ) function calls.        ***/
+/*** Thank you for your help making the SM code more readable. ***/
+/*****************************************************************/
+
+require_once('../src/validate.php');
+require_once('../functions/imap.php');
+require_once('../functions/mime.php');
+require_once('../functions/date.php');
+require_once('../functions/url_parser.php');
+   
     /**
      * Given an IMAP message id number, this will look it up in the cached
      * and sorted msgs array and return the index. Used for finding the next
     /*** Main of read_boby.php ***/
     /*****************************/
 
-    if (isset($msgs)) {
-        $currentArrayIndex = $passed_id;
-/*** START OF COMMENTED OUT CODE - PHILIPPE, CAN THIS BE REMOVED?
-        for ($i=0; $i < count($msgs); $i++) {
-        if ($msgs[$i]["ID"] == $passed_id) {
-            $currentArrayIndex = $i;
-            break;
+    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+    sqimap_mailbox_select($imapConnection, $mailbox);
+    do_hook('html_top');
+    displayPageHeader($color, $mailbox);
+
+    if (isset($view_hdr)) {
+        fputs ($imapConnection, sqimap_session_id() . " FETCH $passed_id BODY[HEADER]\r\n");
+        $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true, $a, $b);
+
+        echo '<BR>' .
+             '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0" ALIGN="CENTER">' . "\n" .
+             "   <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\"><CENTER><B>" . _("Viewing Full Header") . '</B> - ';
+        if (isset($where) && isset($what)) {
+            // Got here from a search
+            echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
+        } else {
+            echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
+        }
+        echo ''._("View message") . "</a></b></center></td></tr></table>\n" .
+             "<table width=\"99%\" cellpadding=2 cellspacing=0 border=0 align=center>\n" .
+             '<tr><td>';
+
+        $cnum = 0;
+        for ($i=1; $i < count($read); $i++) {
+            $line = htmlspecialchars($read[$i]);
+            if (eregi("^&gt;", $line)) {
+                $second[$i] = $line;
+                $first[$i] = '&nbsp;';
+                $cnum++;
+            } else if (eregi("^[ |\t]", $line)) {
+                $second[$i] = $line;
+                $first[$i] = '';
+            } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
+                $first[$i] = $regs[1] . ':';
+                $second[$i] = $regs[2];
+                $cnum++;
+            } else {
+                $second[$i] = trim($line);
+                $first[$i] = '';
+            }
         }
+        for ($i=0; $i < count($second); $i = $j) {
+            if (isset($first[$i])) {
+                $f = $first[$i];
+            }
+            if (isset($second[$i])) {
+                $s = nl2br($second[$i]);
+            }
+            $j = $i + 1;
+            while (($first[$j] == '') && ($j < count($first))) {
+                $s .= '&nbsp;&nbsp;&nbsp;&nbsp;' . nl2br($second[$j]);
+                $j++;
+            }
+            parseEmail($s);
+            if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
+        }
+        echo "</td></tr></table>\n";
+        echo '</body></html>';
+        sqimap_logout($imapConnection);
+        exit;
     }
-*** END OF COMMENTED OUT CODE */
+
+    if (isset($msgs)) {
+        $currentArrayIndex = $passed_id;
     } else {
         $currentArrayIndex = -1;
     }
                 RemoveAddress($url_replytoall_extra_addrs, $cur_email_address);
             }
         }
-    } 
+    }
    
     // 7) Smoosh back into one nice line
     $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
                 if ($show_more_cc == false) {
                     if ($i == 1) {
                         /* From a search... */
+                        $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id";
                         if (isset($where) && isset($what)) {
-                            $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 .= "&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>)";
+                            $cc_string = "&sort=$sort&startMessage=$startMessage&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
                         }   
                         $i = count($cc_ary);
                     }
                 } else if ($i == 1) {
                     /* From a search... */
                     if (isset($where) && isset($what)) {
-                        $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>)";
+                        $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>)";
+                        $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>)";
                     }   
                 }
             }
          '         <TR>' . "\n" .
          '            <TD ALIGN="LEFT" WIDTH="33%">' . "\n" .
          '               <SMALL>' . "\n";
+         
     if ($where && $what) {
-        echo "               <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
+        if( $pos == '' ) {
+            $pos = 0;
+        }
+        echo "               <A HREF=\"search.php?where$pos=".urlencode($where)."&pos=$pos&what$pos=".urlencode($what)."&mailbox=$urlMailbox\">";
     } else {
         echo "               <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
     }
          "         </TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" .
          "            <B>$subject</B>&nbsp;\n" .
          "         </TD>\n" .
-         '         <TD ROWSPAN="4" width=10% BGCOLOR="'.$color[0].'" ALIGN=right VALIGN=top NOWRAP><small>' . "\n";
+         '         <TD ROWSPAN="4" width="10%" BGCOLOR="'.$color[0].'" ALIGN=right VALIGN=top NOWRAP><small>' . "\n";
 
     /* From a search... */
     if ($where && $what) {
 
     if ($show_xmailer_default) {
         fputs ($imapConnection, sqimap_session_id() .
-               " FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer)]\r\n");
+               " FETCH $passed_id BODY.PEEK[HEADER.FIELDS (X-Mailer User-Agent)]\r\n");
         $read = sqimap_read_data ($imapConnection, sqimap_session_id(), true, 
                                   $response, $readmessage);
         $mailer = substr($read[1], strpos($read[1], " "));
          '   </TD></TR>' .
          '</TABLE>';
     flush();        
-    echo "<TABLE CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" .
-         "   <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n" .
+    echo "<TABLE CELLSPACING=0 WIDTH=\"97%\" BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" .
+         "   <TR><TD BGCOLOR=\"$color[4]\" WIDTH=\"100%\">\n" .
          '<BR>';
-   
+
     $body = formatBody($imapConnection, $message, $color, $wrap_at);
 
     echo $body .
     do_hook('read_body_bottom');
     do_hook('html_bottom');
     sqimap_logout($imapConnection);
-?>
+?>
\ No newline at end of file