fixed comp_in_new handling
[squirrelmail.git] / src / compose.php
index c992a040013ada4005c3f6d15e8b2e254e7b08d0..4bebdebbf655822777b074f9729c5f9a1d0127d0 100644 (file)
@@ -70,10 +70,10 @@ if (!isset($composesession)) {
     session_register('composesession');
 }
 
-if (!isset($session)) {
+if (!isset($session) || (isset($newmessage) && $newmessage)) {
     $session = "$composesession" +1; 
     $composesession = $session;        
-}    
+}     
 
 if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
     $mailbox = 'INBOX';
@@ -179,7 +179,7 @@ if (isset($send)) {
             exit();
         }
         if ($compose_new_win == '1') {
-            Header("Location: compose.php?mail_sent=yes&session=$composesession");
+            Header("Location: compose.php?mail_sent=yes");
         }
         else {
             Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
@@ -344,6 +344,10 @@ elseif (isset($sigappend)) {
         getAttachments(0, $session);
     }
 
+    if (isset($passed_id) && $passed_id && isset($ent_num) && $ent_num) {
+        getAttachments(0, $session);
+    }
+
     newMail($session);
     showInputForm($session);
     sqimap_logout($imapConnection);
@@ -405,7 +409,22 @@ function newMail () {
             $body = strip_tags($body);
         }
 
-        //sqUnWordWrap($body);
+        sqUnWordWrap($body);
+        
+        /* this corrects some wrapping/quoting problems on replies */
+        if ($reply_id) {
+            $rewrap_body = explode("\n", $body);
+            for ($i=0;$i<count($rewrap_body);$i++) {
+                sqWordWrap($rewrap_body[$i], ($editor_size - 2));
+                if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
+                    $gt = $matches[1];
+                    $rewrap_body[$i] = str_replace("\n", "\n$gt ", $rewrap_body[$i]);
+                }
+                $rewrap_body[$i] .= "\n";
+            }
+            $body = implode("", $rewrap_body);
+        }
+
         $body_ary = explode("\n", $body);
         $i = count($body_ary) - 1;
         while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
@@ -415,14 +434,14 @@ function newMail () {
         $body = '';
         for ($i=0; isset($body_ary[$i]); $i++) {
             if ($reply_id) {
-                if (ereg('^[ >]+', $body_ary[$i])) {
+                if (preg_match("/^(>){1,}/", $body_ary[$i])) {
                     $body_ary[$i] = '>' . $body_ary[$i];
                 } else {
                     $body_ary[$i] = '> ' . $body_ary[$i];
                 }
             }
-            if (!$draft_id) {
-                sqWordWrap($body_ary[$i], $editor_size - 1);
+            if ($draft_id) {
+                sqWordWrap($body_ary[$i], $editor_size );
             }
             $body .= $body_ary[$i] . "\n";
             unset($body_ary[$i]);
@@ -495,12 +514,14 @@ function newMail () {
 
 function getAttachments($message, $session) {
     global $mailbox, $attachments, $attachment_dir, $imapConnection,
-           $ent_num, $forward_id, $draft_id, $username;
+           $ent_num, $forward_id, $draft_id, $username, $passed_id;
 
     if (isset($draft_id)) {
         $id = $draft_id;
-    } else {
+    } else if (isset($forward_id)) {
         $id = $forward_id;
+    } else {
+        $id = $passed_id;
     }
 
     if (!$message) {
@@ -557,7 +578,7 @@ function showInputForm ($session) {
            $from_htmladdr_search, $location_of_buttons, $attachment_dir,
            $username, $data_dir, $identity, $draft_id, $delete_draft,
            $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
-           $saved_draft, $mail_sent, $sig_first;
+           $saved_draft, $mail_sent, $sig_first, $edit_as_new;
 
     $subject = decodeHeader($subject, false);
     $reply_subj = decodeHeader($reply_subj, false);
@@ -581,7 +602,7 @@ function showInputForm ($session) {
     
     echo ">\n";
 
-    if (isset($draft_id)) {
+    if (isset($draft_id) && !$edit_as_new) {
         echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
     }
     if (isset($delete_draft)) {
@@ -745,12 +766,12 @@ function showInputForm ($session) {
              '&nbsp;' .
              '</td><td align=left bgcolor="' . $color[0] . '">';
         foreach ($attachments as $key => $info) {
-           if ($info['session'] == $session) { 
-               $attached_file = "$hashed_attachment_dir/$info[localfilename]";
-               echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
-                    $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
-                    show_readable_size(filesize($attached_file)) . ")<br>\n";
-           }
+           if ($info['session'] == $session) { 
+               $attached_file = "$hashed_attachment_dir/$info[localfilename]";
+               echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
+                        $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
+                        show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
+           }
         }
 
         echo '<input type="submit" name="do_delete" value="' .