- did decodeHeader on to_ary and cc_ary
[squirrelmail.git] / src / compose.php
index 9e894364cb1f4fb162e2a4d6590e3e1c41e17875..5617da79e13599fa36313e5d466e2e3dc7bfc7ce 100644 (file)
@@ -1,5 +1,11 @@
 <?php
-   /** This code sends a mail.
+   /** 
+    ** compose.php
+    **
+    **  Copyright (c) 1999-2000 The SquirrelMail development team
+    **  Licensed under the GNU GPL. For full terms see the file COPYING.
+    **
+    ** This code sends a mail.
     **
     ** There are 3 modes of operation:
     **  - Start new mail
@@ -27,6 +33,8 @@
       include("../functions/display_messages.php");
    if (!isset($auth_php))
       include ("../functions/auth.php");
+   if (!isset($plugin_php))
+      include ("../functions/plugin.php");
 
    include("../src/load_prefs.php");
 
       global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
          $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc;
 
-      $send_to = decodeHeader($send_to);
-      $send_to_cc = decodeHeader($send_to_cc);
+      $send_to = stripslashes(decodeHeader($send_to));
+      $send_to_cc = stripslashes(decodeHeader($send_to_cc));
 
       if ($forward_id)
          $id = $forward_id;
       else if ($reply_id)
          $id = $reply_id;
 
+
       if ($id) {
          sqimap_mailbox_select($imapConnection, $mailbox);
          $message = sqimap_get_message($imapConnection, $id, $mailbox);
-         $message = getEntity($message, $ent_num);
+         $orig_header = $message->header;
+         if ($ent_num)
+            $message = getEntity($message, $ent_num);
 
          if ($message->header->type0 == "text" || $message->header->type1 == "message") {
-            $body = decodeBody(mime_fetch_body($imapConnection, $id, $message->header->entity_id), $message->header->encoding);
+            if ($ent_num)
+               $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header->encoding);
+            else
+               $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header->encoding);
          } else {
             $body = "";
          }
          
-         if ($forward_id)
-            $tmp = _("-------- Original Message ---------\n");
          if ($message->header->type1 == "html")
             $body = strip_tags($body);
             
          $body_ary = explode("\n", $body);
          $body = "";
          for ($i=0; $i < count($body_ary); $i++) {
-            $tmp = $body_ary[$i];
-            
+            if ($i==0 && $forward_id) {
+               $tmp = "-------- " . _("Original Message") . " --------\n";
+               $tmp .= _("Subject") . ": " . $orig_header->subject . "\n"; 
+               $tmp .= "   " . _("From") . ": " . $orig_header->from . "\n"; 
+               $tmp .= "     " . _("To") . ": " . $orig_header->to[0] . "\n"; 
+               if (count($orig_header->to) > 1) {
+                  for ($x=1; $x < count($orig_header->to); $x++) {
+                     $tmp .= "         " . $orig_header->to[$x] . "\n";
+                  }
+               }
+               $tmp .= "\n" . $body_ary[$i];
+            } else {
+               $tmp = $body_ary[$i];
+            }
             if ($forward_id)
                $body = "$body$tmp\n";
             else
                $body = "$body> $tmp\n";
          }
-            
+         return $body;   
       }
 
+      $send_to = stripslashes($send_to);
+      
       if (!$send_to) {
          $send_to = sqimap_find_email($send_to);
       }
 
-//      $send_to = ereg_replace("\"", "", $send_to);
-      $send_to = stripslashes($send_to);
-      
       /** This formats a CC string if they hit "reply all" **/
       if ($send_to_cc != "") {
          $send_to_cc = ereg_replace(";", ",", $send_to_cc);
          echo "      <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
       }   
       echo "\n    <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
+      
+      do_hook("compose_button_row");
+
       echo "   </TD>\n";
       echo "   </TR>\n\n";
 
       //      echo "      <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
       //      echo "      value=\"10000\">\n";
       echo "      <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
-      echo "      &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"\n";
-      echo "      value=\"" . _("Add") ."\">\n";
+      echo "      &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"";
+      echo " value=\"" . _("Add") ."\">\n";
       echo "     </td>\n";
       echo "   </tr>\n";
       if (isset($attachments) && count($attachments)>0) {
           error message, show=true **/
       global $body, $send_to, $subject, $color;
 
-      if ($body == "" && $subject == "") {
-         if ($show)
-            plain_error_message(_("You have not entered a message body or a subject."), $color);
-         return false;
-      } else if ($send_to == "") {
+      if ($send_to == "") {
          if ($show)
             plain_error_message(_("You have not filled in the \"To:\" field."), $color);
          return false;
          checkInput(true);
          
          showInputForm();
+         sqimap_logout($imapConnection);
       }
    } else if ($html_addr_search_done) {
       is_logged_in();
       $newmail = true;
       newMail();
       showInputForm();
+      sqimap_logout($imapConnection);
    }
 ?>