Right-to-left fixes from Saleh Madi <webmail@p-i-s.com> (part 2)
[squirrelmail.git] / src / compose.php
index 2a2db00ba701981b28d87f349fed067be386d02a..0e2e83a6d269d9f201a6e3ee2ee688779e0085a9 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * compose.php
  *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This code sends a mail.
@@ -29,6 +29,7 @@ require_once(SM_PATH . 'functions/plugin.php');
 require_once(SM_PATH . 'functions/display_messages.php');
 require_once(SM_PATH . 'class/deliver/Deliver.class.php');
 require_once(SM_PATH . 'functions/addressbook.php');
+require_once(SM_PATH . 'functions/set_language_align.php');
 
 /* --------------------- Get globals ------------------------------------- */
 $username = $_SESSION['username'];
@@ -36,6 +37,8 @@ $onetimepad = $_SESSION['onetimepad'];
 $base_uri = $_SESSION['base_uri'];
 $delimiter = $_SESSION['delimiter'];
 
+$language_align = set_language_align();
+
 if (isset($_POST['return'])) {
     $html_addr_search_done = 'Use Addresses';
 }
@@ -219,7 +222,6 @@ if (sqsession_is_registered('session_expired_post')) {
     if (!isset($mailbox)) {
         $mailbox = '';
     }
-
     if ($compose_new_win == '1') {
         compose_Header($color, $mailbox);
     } else {
@@ -298,6 +300,10 @@ if ($send) {
         $AttachFailure = saveAttachedFiles($session);
     }
     if (checkInput(false) && !isset($AttachFailure)) {
+               if ($mailbox == "All Folders") {
+                       /* We entered compose via the search results page */
+                       $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
+               }
         $urlMailbox = urlencode (trim($mailbox));
         if (! isset($passed_id)) {
             $passed_id = 0;
@@ -801,7 +807,7 @@ function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
 }
 
 function showInputForm ($session, $values=false) {
-    global $send_to, $send_to_cc, $body,
+    global $send_to, $send_to_cc, $body, $language_align, 
            $passed_body, $color, $use_signature, $signature, $prefix_sig,
            $editor_size, $attachments, $subject, $newmail,
            $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
@@ -821,7 +827,7 @@ function showInputForm ($session, $values=false) {
        $subject = $values['subject'];       
        $mailprio = $values['mailprio'];
        $body = $values['body'];
-       $identity = $values['identity'];
+       $identity = (int) $values['identity'];
     }
     
     if ($use_javascript_addr_book) {
@@ -835,6 +841,7 @@ function showInputForm ($session, $values=false) {
              '// --></SCRIPT>' . "\n\n";
     }
 
+
     echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
          'ENCTYPE="multipart/form-data"';
     do_hook("compose_form");
@@ -861,10 +868,10 @@ function showInputForm ($session, $values=false) {
     if ($mail_sent == 'yes') {
         echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
     }
-    echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
+    echo '<TABLE dir="' . $language_align['dir'] . '" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
     if ($compose_new_win == '1') {
-        echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
-             '   <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
+        echo '<TABLE dir="' . $language_align['dir'] . '" ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
+             '   <TR dir="' . $language_align['dir'] . '"><TD dir="' . $language_align['dir'] . '"></TD><TD dir="' . $language_align['dir'] . '" ALIGN="' . $language_align['right'] . '"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
     }
     if ($location_of_buttons == 'top') {
         showComposeButtonRow();
@@ -872,10 +879,10 @@ function showInputForm ($session, $values=false) {
 
     $idents = getPref($data_dir, $username, 'identities', 0);
     if ($idents > 1) {
-        echo '   <TR>' . "\n" .
-             '      <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
+        echo '   <TR dir="' . $language_align['dir'] . '">' . "\n" .
+             '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN="' . $language_align['right'] . '">' .
                     _("From:") . '</TD>' . "\n" .
-             '      <TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
+             '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" WIDTH="90%" ALIGN="' . $language_align['left'] . '">' . "\n" .
              '         <select name=identity>' . "\n" .
              '         <option value=default>' .
                        htmlspecialchars(getPref($data_dir, $username, 'full_name'));
@@ -900,34 +907,34 @@ function showInputForm ($session, $values=false) {
              '      </TD>' . "\n" .
              '   </TR>' . "\n";
     }
-    echo '   <TR>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
+    echo '   <TR dir="' . $language_align['dir'] . '">' . "\n" .
+         '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN="' . $language_align['right'] . '">' .
                 _("To:") . '</TD>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
+         '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" WIDTH="90%" ALIGN="' . $language_align['left'] . '">' . "\n" .
          '         <INPUT TYPE=text NAME="send_to" VALUE="' .
                    htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
          '      </TD>' . "\n" .
          '   </TR>' . "\n" .
-         '   <TR>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' .
+         '   <TR dir="' . $language_align['dir'] . '">' . "\n" .
+         '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" ALIGN="' . $language_align['right'] . '">' .
                 _("CC:") . '</TD>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
+         '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" ALIGN="' . $language_align['left'] . '">' . "\n" .
          '         <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
                    htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
          '      </TD>' . "\n" .
          '   </TR>' . "\n" .
-         '   <TR>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' .
+         '   <TR dir="' . $language_align['dir'] . '">' . "\n" .
+         '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" ALIGN="' . $language_align['right'] . '">' .
                 _("BCC:") . '</TD>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
+         '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" ALIGN="' . $language_align['left'] . '">' . "\n" .
          '         <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
                 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
          '      </TD>' . "\n" .
          '   </TR>' . "\n" .
-         '   <TR>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' .
+         '   <TR dir="' . $language_align['dir'] . '">' . "\n" .
+         '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" ALIGN="' . $language_align['right'] . '">' .
                 _("Subject:") . '</TD>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
+         '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" ALIGN="' . $language_align['left'] . '">' . "\n";
     echo '         <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
                    htmlspecialchars($subject) . '">' . "\n" .
          '      </TD>' . "\n" .
@@ -938,18 +945,27 @@ function showInputForm ($session, $values=false) {
     }
 
     if ($compose_new_win == '1') {
-        echo '   <TR>' . "\n" .
-             '      <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
+        echo '   <TR dir="' . $language_align['dir'] . '">' . "\n" .
+             '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
              '         <TEXTAREA NAME=body ROWS=20 COLS="' .
                        $editor_size . '" WRAP="VIRTUAL">';
     }
     else {
-        echo '   <TR>' . "\n" .
-            '      <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
+        echo '   <TR dir="' . $language_align['dir'] . '">' . "\n" .
+            '      <TD dir="' . $language_align['dir'] . '" BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
             '         &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
                       $editor_size . '" WRAP="VIRTUAL">';
     }
     if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
+        if ($idents > 1) {
+            if ($identity == 'default') {
+                $no = 'g';
+        } else {
+            $no = $identity;
+        }
+        $signature = getSig($data_dir, $username, $no);
+    }
+
         if ($sig_first == '1') {
             if ($default_charset == 'iso-2022-jp') {
                 echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
@@ -989,11 +1005,11 @@ function showInputForm ($session, $values=false) {
        if ((bool) ini_get('file_uploads')) {
     echo '   <TR>' . "\n" .
          '      <TD COLSPAN=2>' . "\n" .
-         '         <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
+         '         <table dir="' . $language_align['dir'] . '" width="100%" cellpadding="1" cellspacing="0" align="center"'.
                    ' border="0" bgcolor="'.$color[9].'">' . "\n" .
          '            <TR>' . "\n" .
          '               <TD>' . "\n" .
-         '                 <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
+         '                 <table dir="' . $language_align['dir'] . '" width="100%" cellpadding="3" cellspacing="0" align="center"'.
                            ' border="0">' . "\n" .
          '                    <TR>' . "\n" .
          '                       <TD VALIGN=MIDDLE ALIGN=RIGHT>' .
@@ -1014,16 +1030,14 @@ function showInputForm ($session, $values=false) {
                $attached_filename = decodeHeader($attachment->mime_header->getParameter('name'));
                $type = $attachment->mime_header->type0.'/'.
                        $attachment->mime_header->type1;
-               $s_a[] = '<input type="checkbox" name="delete[]" value="' . 
-                        $key . "\">\n" . $attached_filename . ' - ' . $type . 
-                        ' ('.show_readable_size( filesize( $attached_file ) ) 
-                        . ')<br>'."\n";
+               $s_a[] = '<table><tr><td><input type="checkbox" name="delete[]" value="' . 
+                        $key . "\"></td><td>\n" . $attached_filename . '</td><td>-</td><td> ' . $type . '</td><td>('.show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
            }
         }
     }
     if (count($s_a)) {
-       foreach ($s_a as $s) {
-          echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
+     foreach ($s_a as $s) {
+       echo '<tr><td align="' . $language_align['left'] . '" colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
        }         
        echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
             _("Delete selected attachments") . "\">\n" .
@@ -1164,16 +1178,12 @@ function saveAttachedFiles($session) {
         $full_localfilename = "$hashed_attachment_dir/$localfilename";
     }
 
+    // FIXME: we SHOULD prefer move_uploaded_file over rename because
+    // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
     if (!@rename($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
-       if (function_exists("move_uploaded_file")) {
             if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
                return true;
            }
-       } else {
-           if (!@copy($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
-                return true;
-            }
-       }
     }
     $message = $compose_messages[$session];
     $type = strtolower($_FILES['attachfile']['type']);
@@ -1382,7 +1392,9 @@ function deliverMessage($composeMessage, $draft=false) {
        $succes = $deliver->finalizeStream($stream);
     }
     if (!$succes) {
-        $msg  = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr;
+        $msg  = $deliver->dlv_msg . '<br>' .
+                _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
+                $deliver->dlv_server_msg;
         plain_error_message($msg, $color);
     } else {
         unset ($deliver);