Fixed some string issues.
[squirrelmail.git] / src / compose.php
index 18438443bb179ebc7970710d9311c42be68a4368..3ad32e0e7e6ba7a8919159e59aba523de3d8cb59 100644 (file)
  * $Id$
  */
 
-require_once('../src/validate.php');
-require_once('../functions/imap.php');
-require_once('../functions/date.php');
-require_once('../functions/mime.php');
-//require_once('../functions/smtp.php');
-require_once('../functions/plugin.php');
-require_once('../functions/display_messages.php');
-require_once('../class/deliver/Deliver.class.php');
+/* Path for SquirrelMail required files. */
+define('SM_PATH','../');
+
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'include/validate.php');
+require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'functions/date.php');
+require_once(SM_PATH . 'functions/mime.php');
+//require_once(SM_PATH . 'functions/smtp.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');
 
 /* --------------------- Specific Functions ------------------------------ */
 
@@ -533,9 +537,9 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
         switch ($action) {
         case ('draft'):
             $use_signature = FALSE;
-            $send_to = $orig_header->getAddr_s('to');
-            $send_to_cc = $orig_header->getAddr_s('cc');
-            $send_to_bcc = $orig_header->getAddr_s('bcc');
+            $send_to = decodeHeader($orig_header->getAddr_s('to'));
+            $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'));
+            $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'));
             $subject = decodeHeader($orig_header->subject);
 
             $body_ary = explode("\n", $body);
@@ -552,9 +556,9 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
             $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
             break;
         case ('edit_as_new'):
-            $send_to = $orig_header->getAddr_s('to');
-            $send_to_cc = $orig_header->getAddr_s('cc');
-            $send_to_bcc = $orig_header->getAddr_s('bcc');
+            $send_to = decodeHeader($orig_header->getAddr_s('to'));
+            $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'));
+            $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'));
             $subject = decodeHeader($orig_header->subject);
             $mailprio = $orig_header->priority;
             $orig_from = '';
@@ -582,9 +586,9 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
         case ('reply'):
             $send_to = $orig_header->reply_to;
             if (is_object($send_to)) {
-                $send_to = $send_to->getAddr_s('reply_to');
+                $send_to = decodeHeader($send_to->getAddr_s('reply_to'));
             } else {
-                $send_to = $orig_header->getAddr_s('from');
+                $send_to = decodeHeader($orig_header->getAddr_s('from'));
             }
             $subject =  decodeHeader($orig_header->subject);
             $subject = str_replace('"', "'", $subject);
@@ -629,7 +633,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
 } /* function newMail() */
 
 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
-    global $attachment_dir, $username, $data_dir;
+    global $attachment_dir, $username, $data_dir, $squirrelmail_language;
     $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
     if (!count($message->entities) || 
        ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
@@ -1147,24 +1151,25 @@ function sendMessage($composeMessage, $draft=false) {
     }
     $reply_to = '';
     if (isset($identity) && $identity != 'default') {
-        $from_mail = getPref($data_dir, $username, 
-                     'email_address' . $identity);
-        $full_name = getPref($data_dir, $username, 
-                     'full_name' . $identity);
-        $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
-        $reply_to = getPref($data_dir, $username, 
-                     'reply_to' . $identity);
+        $from_mail = getPref($data_dir, $username,'email_address' . $identity);
+        $full_name = getPref($data_dir, $username,'full_name' . $identity);
+        $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
     } else {
         $from_mail = getPref($data_dir, $username, 'email_address');
         $full_name = getPref($data_dir, $username, 'full_name');
-        $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
         $reply_to = getPref($data_dir, $username,'reply_to');
     }
-    if (!$from_addr) {
-       $from_addr = "$popuser@$domain";
-       $from_mail = $from_addr;
+    if (!$from_mail) {
+       $from_mail = "$popuser@$domain";
+       $full_name = '';
+    }
+    $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true);
+    if ($full_name) {
+        $from = $rfc822_header->from[0];
+       if (!$from->host) $from->host = $domain;
+       $from_addr = $full_name .' <'.$from->mailbox.'@'.$from->host.'>';
+        $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
     }
-    $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
     if ($reply_to) {
        $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
     }
@@ -1206,7 +1211,7 @@ function sendMessage($composeMessage, $draft=false) {
     $composeMessage->rfc822_header = $rfc822_header;
 
     if (!$useSendmail && !$draft) {
-       require_once('../class/deliver/Deliver_SMTP.class.php');
+       require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
        $deliver = new Deliver_SMTP();
        global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
        if ($use_authenticated_smtp) {
@@ -1221,18 +1226,18 @@ function sendMessage($composeMessage, $draft=false) {
        $stream = $deliver->initStream($composeMessage,$domain,0,
                          $smtpServerAddress, $smtpPort, $authPop);
     } elseif (!$draft) {
-       require_once('../class/deliver/Deliver_SentMail.class.php');
+       require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
        global $sendmail_path;
        $deliver = new Deliver_SendMail();
        $stream = $deliver->initStream($composeMessage,$sendmail_path);
     } elseif ($draft) {
        global $draft_folder;
-       require_once('../class/deliver/Deliver_IMAP.class.php');
-       $imap_deliver = new Deliver_IMAP();
+       require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
+//       $imap_deliver = new Deliver_IMAP();
        $imap_stream = sqimap_login($username, $key, $imapServerAddress,
                       $imapPort, 0);
        if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
-           require_once('../class/deliver/Deliver_IMAP.class.php');
+           require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
            $imap_deliver = new Deliver_IMAP();
            $length = $imap_deliver->mail($composeMessage);
            sqimap_append ($imap_stream, $draft_folder, $length);        
@@ -1258,7 +1263,7 @@ function sendMessage($composeMessage, $draft=false) {
         $imapPort, 0);
        if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
            sqimap_append ($imap_stream, $sent_folder, $length);
-           require_once('../class/deliver/Deliver_IMAP.class.php');
+           require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
            $imap_deliver = new Deliver_IMAP();
            $imap_deliver->mail($composeMessage, $imap_stream);
            sqimap_append_done ($imap_stream);