use Perl's function for this. Don't know what I was thinking.
[squirrelmail.git] / src / compose.php
index 83e111e13a0edf4cc3434b988544f5a823e37c97..e53592f376c00e0d719d09039427810432066757 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.
@@ -28,6 +28,7 @@ require_once(SM_PATH . 'functions/mime.php');
 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');
 
 /* --------------------- Get globals ------------------------------------- */
 $username = $_SESSION['username'];
@@ -218,7 +219,6 @@ if (sqsession_is_registered('session_expired_post')) {
     if (!isset($mailbox)) {
         $mailbox = '';
     }
-
     if ($compose_new_win == '1') {
         compose_Header($color, $mailbox);
     } else {
@@ -297,6 +297,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;
@@ -820,7 +824,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) {
@@ -863,7 +867,7 @@ function showInputForm ($session, $values=false) {
     echo '<TABLE 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";
+             '   <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
     }
     if ($location_of_buttons == 'top') {
         showComposeButtonRow();
@@ -872,9 +876,9 @@ 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>' .
+                    html_tag( 'td', '', 'right', $color[4], 'WIDTH="10%"' ) .
                     _("From:") . '</TD>' . "\n" .
-             '      <TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
+                    html_tag( 'td', '', 'left', $color[4], 'WIDTH="90%"' ) .
              '         <select name=identity>' . "\n" .
              '         <option value=default>' .
                        htmlspecialchars(getPref($data_dir, $username, 'full_name'));
@@ -900,33 +904,33 @@ function showInputForm ($session, $values=false) {
              '   </TR>' . "\n";
     }
     echo '   <TR>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
+                html_tag( 'td', '', 'right', $color[4], 'WIDTH="10%"' ) .
                 _("To:") . '</TD>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
+                html_tag( 'td', '', 'left', $color[4], 'WIDTH="90%"' ) .
          '         <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>' .
+                html_tag( 'td', '', 'right', $color[4] ) .
                 _("CC:") . '</TD>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
+                html_tag( 'td', '', 'left', $color[4] ) .
          '         <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>' .
+                html_tag( 'td', '', 'right', $color[4] ) .
                 _("BCC:") . '</TD>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
+                html_tag( 'td', '', 'left', $color[4] ) .
          '         <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>' .
+                html_tag( 'td', '', 'right', $color[4] ) .
                 _("Subject:") . '</TD>' . "\n" .
-         '      <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
+                html_tag( 'td', '', 'left', $color[4] ) . "\n";
     echo '         <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
                    htmlspecialchars($subject) . '">' . "\n" .
          '      </TD>' . "\n" .
@@ -949,6 +953,15 @@ function showInputForm ($session, $values=false) {
                       $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');
@@ -977,7 +990,7 @@ function showInputForm ($session, $values=false) {
         showComposeButtonRow();
     } else {
         echo '   <TR>' . "\n" .
-             '      <TD COLSPAN=2 ALIGN=RIGHT>' . "\n" .
+                    html_tag( 'td', '', 'right', '', 'COLSPAN=2' ) . "\n" .
              '         <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' . "\n" .
              '         &nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>' . "\n" .
              '      </TD>' . "\n" .
@@ -995,9 +1008,9 @@ function showInputForm ($session, $values=false) {
          '                 <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
                            ' border="0">' . "\n" .
          '                    <TR>' . "\n" .
-         '                       <TD VALIGN=MIDDLE ALIGN=RIGHT>' .
+                                 html_tag( 'td', '', 'right', '', 'VALIGN=MIDDLE' ) .
                                  _("Attach:") . '</TD>' . "\n" .
-         '                       <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
+                                 html_tag( 'td', '', 'left', '', 'VALIGN=MIDDLE' ) .
          '                          <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
          '                          &nbsp;&nbsp;<input type="submit" name="attach"' .
                                     ' value="' . _("Add") .'">' . "\n" .
@@ -1013,16 +1026,18 @@ 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 bgcolor="'.$color[0].'" border="0"><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>';
+          echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
        }         
        echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
             _("Delete selected attachments") . "\">\n" .
@@ -1163,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']);
@@ -1245,9 +1256,12 @@ function deliverMessage($composeMessage, $draft=false) {
     global $imapServerAddress, $imapPort, $sent_folder, $key;
 
     $rfc822_header = $composeMessage->rfc822_header;
-    $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain);
-    $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain);
-    $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain);
+
+    $abook = addressbook_init(false, true);
+    
+    $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
+    $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
+    $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
     $rfc822_header->priority = $mailprio;
     $rfc822_header->subject = $subject;
     $special_encoding='';
@@ -1378,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);