allow_call_time_pass_reference = Off
[squirrelmail.git] / src / compose.php
index e19db4404cb89d33a0d6b94b4edfc04cfe4379d4..b14871015dcae1ac9ace0aeede2cede6e2932719 100644 (file)
@@ -76,6 +76,8 @@ function replyAllString($header) {
 }
 
 function getforwardHeader($orig_header) {
+    global $editor_size;
+
    $display = array(
                      _("Subject") => strlen(_("Subject")),
                      _("From")    => strlen(_("From")),                     
@@ -88,15 +90,15 @@ function getforwardHeader($orig_header) {
    foreach($display as $key => $val) {
       $display[$key] = $key .': '. str_pad('', $maxsize - $val);
    }      
-   $bodyTop =  str_pad(' '._("Original Message").' ',78, '-',STR_PAD_BOTH);
-   $bodyTop .=  "\n". $display[_("Subject")] . $orig_header->subject . "\n" .
-        $display[_("From")] . $orig_header->getAddr_s('from',"\n$indent") . "\n" .
+   $bodyTop =  str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH);
+   $bodyTop .=  "\n". $display[_("Subject")] . decodeHeader($orig_header->subject) . "\n" .
+        $display[_("From")] . decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" .
         $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" .
-        $display[_("To")] . $orig_header->getAddr_s('to',"\n$indent") ."\n";
+        $display[_("To")] . decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n";
   if ($orig_header->cc != array() && $orig_header->cc !='') {
-     $bodyTop .= $display[_("Cc")] . $orig_header->getAddr_s('cc',"\n$indent") . "\n";
+     $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n";
   }
-  $bodyTop .= str_pad('',78, '-');
+  $bodyTop .= str_pad('', $editor_size -2 , '-');
   $bodyTop .= "\n";
   return $bodyTop;
 }
@@ -463,11 +465,11 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
         $encoding = $message->header->encoding;
        $type0 = $message->type0;
        $type1 = $message->type1;
-
         foreach ($entities as $ent) {
-           $bodypart = decodeBody(
-                     mime_fetch_body($imapConnection, $passed_id, $ent),
-                      $encoding);
+           $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
+          $body_part_entity = $message->getEntity($ent);
+          $bodypart = decodeBody($unencoded_bodypart,
+                                 $body_part_entity->header->encoding);
           if ($type1 == 'html') {
               $bodypart = strip_tags($bodypart);
           }
@@ -547,7 +549,11 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
            }
           $body = getforwardHeader($orig_header) . $body;
           sqUnWordWrap($body);
-           getAttachments($message, $session, $passed_id, $entities, $imapConnection);      
+           getAttachments($message, $session, $passed_id, $entities, $imapConnection);
+          break;
+       case ('forward_as_attachment'):
+           getMessage_RFC822_Attachment($message, $session, $passed_id, $imapConnection);
+          $body = '';
           break;
         case ('reply_all'):
           $send_to_cc = replyAllString($orig_header);
@@ -611,9 +617,14 @@ function getAttachments($message, $session, $passed_id, $entities, $imapConnecti
                   $filename = "untitled-".$message->entity_id.'.eml';
                }
            } else {
-               $filename = decodeHeader($message->header->filename);
-               if ($filename == "") {
-                  $filename = "untitled-".$message->entity_id;
+               $filename = decodeHeader($message->header->getParameter('filename'));
+               if ($filename == '') {
+                 $name = decodeHeader($message->header->getParameter('name'));
+                 if ($name == '') {
+                     $filename = "untitled-".$message->entity_id;
+                 } else {
+                    $filename = $name;
+                 }
                }
             }
             $localfilename = GenerateRandomString(32, '', 7);
@@ -649,6 +660,32 @@ function getAttachments($message, $session, $passed_id, $entities, $imapConnecti
     return;
 }
 
+function getMessage_RFC822_Attachment($message, $session, $passed_id, $imapConnection) {
+    global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
+    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+    $body_a = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, $uid_support);
+    if ($response = 'OK') {
+       $subject = encodeHeader($message->rfc822_header->subject);
+       array_shift($body_a);
+       $body = implode('', $body_a);
+       $body .= "\r\n";
+                       
+       $localfilename = GenerateRandomString(32, 'FILE', 7);
+       $full_localfilename = "$hashed_attachment_dir/$localfilename";
+               
+       $fp = fopen( $full_localfilename, 'w');
+       fwrite ($fp, $body);
+       fclose($fp);
+       $newAttachment = array();
+       $newAttachment['localfilename'] = $localfilename;
+       $newAttachment['type'] = "message/rfc822";
+       $newAttachment['remotefilename'] = $subject.'.eml';
+       $newAttachment['session'] = $session;
+       $attachments[] = $newAttachment;
+    }
+    return;
+}
+
 function showInputForm ($session, $values=false) {
     global $send_to, $send_to_cc, $body,
            $passed_body, $color, $use_signature, $signature, $prefix_sig,
@@ -698,7 +735,10 @@ function showInputForm ($session, $values=false) {
     if (isset($session)) {
         echo '<input type="hidden" name="session" value="' . $session . "\">\n";
     }
-
+    
+    if (isset($passed_id)) {
+        echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
+    }
 
     if ($saved_draft == 'yes') {
         echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
@@ -1021,7 +1061,8 @@ function getReplyCitation($orig_from)
         $end   = '">';
         break;
     case 'user-defined':
-        $start = $reply_citation_start . ' ';
+        $start = $reply_citation_start . 
+                ($reply_citation_start == '' ? '' : ' ');
         $end   = $reply_citation_end;
         break;
     default: