Correct mistaken use of rfc822_header->date field that was being treated as a date...
[squirrelmail.git] / class / deliver / Deliver.class.php
index 5fbba83b8542cd42e13494dd4e47c641496349a5..943823e639957a6b734f9f163c1428b8166f266f 100644 (file)
@@ -7,7 +7,7 @@
  * a delivery backend.
  *
  * @author Marc Groot Koerkamp
- * @copyright 1999-2012 The SquirrelMail Project Team
+ * @copyright 1999-2019 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -90,7 +90,7 @@ class Deliver {
         //
         if ($reply_id) {
             global $imapConnection, $username, $imapServerAddress, 
-                   $imapPort, $mailbox;
+                   $imapPort, $imap_stream_options, $mailbox;
 
             // try our best to use an existing IMAP handle
             //
@@ -103,8 +103,8 @@ class Deliver {
 
             } else {
                 $close_imap_stream = TRUE;
-                $my_imap_stream = sqimap_login($username, FALSE,
-                                               $imapServerAddress, $imapPort, 0);
+                $my_imap_stream = sqimap_login($username, FALSE, $imapServerAddress,
+                                               $imapPort, 0, $imap_stream_options);
             }
 
             sqimap_mailbox_select($my_imap_stream, $mailbox);
@@ -437,16 +437,27 @@ class Deliver {
      *
      * This function is not yet implemented.
      * Reserved for extended functionality.
+     * UPDATE: It is implemented in Deliver_SMTP and Deliver_SendMail classes,
+     *         but it remains unimplemented in this base class (and thus not
+     *         in Deliver_IMAP or other child classes that don't define it)
+     *
+     * NOTE: some parameters are specific to the child class
+     *       that is implementing this method
      *
      * @param Message $message  Message object
+     * @param string  $domain
+     * @param integer $length
      * @param string  $host     host name or IP to connect to
+     * @param integer $port
      * @param string  $user     username to log into the SMTP server with
      * @param string  $pass     password to log into the SMTP server with
-     * @param integer $length
+     * @param boolean $authpop  whether or not to use POP-before-SMTP authorization
+     * @param string  $pop_host host name or IP to connect to for POP-before-SMTP authorization
+     * @param array   $stream_options Stream context options, see config_local.example.php for more details (OPTIONAL)
      *
      * @return handle $stream file handle resource to SMTP stream
      */
-    function initStream($message, $length=0, $host='', $port='', $user='', $pass='') {
+    function initStream($message, $domain, $length=0, $host='', $port='', $user='', $pass='', $authpop=false, $pop_host='', $stream_options=array()) {
         return $stream;
     }
 
@@ -585,7 +596,15 @@ class Deliver {
         $rn = "\r\n";
 
         /* This creates an RFC 822 date */
-        $date = date('D, j M Y H:i:s ', time()) . $this->timezone();
+        $now = time();
+        $now_date = date('D, j M Y H:i:s ', $now) . $this->timezone();
+        // TODO: Do we really want to preserve possibly old date?  Date header should always have "now"... but here is not where this decision should be made -- the caller really should blank out $rfc822_header->date even for drafts being re-edited or sent
+        if (!empty($rfc822_header->date) && $rfc822_header->date != -1)
+            $message_date = date('D, j M Y H:i:s ', $rfc822_header->date) . $this->timezone();
+        else {
+            $message_date = $now_date;
+            $rfc822_header->date = $now;
+        }
 
         /* Create a message-id */
         $message_id = 'MESSAGE ID GENERATION ERROR! PLEASE CONTACT SQUIRRELMAIL DEVELOPERS';
@@ -642,7 +661,7 @@ class Deliver {
             if (!isset($hide_auth_header) || !$hide_auth_header)
                 $header[] = "        (SquirrelMail authenticated user $username)" . $rn;
             $header[] = "        by $SERVER_NAME with HTTP;" . $rn;
-            $header[] = "        $date" . $rn;
+            $header[] = "        $now_date" . $rn;
           }
         }
 
@@ -666,12 +685,7 @@ class Deliver {
             $rfc822_header->references = $references;
         }
 
-        if (!empty($rfc822_header->date) && $rfc822_header->date != -1) {
-            $header[] = 'Date: '. $rfc822_header->date . $rn;
-        } else {
-            $header[] = "Date: $date" . $rn;
-            $rfc822_header->date = $date;
-        }
+        $header[] = "Date: $message_date" . $rn;
 
         $header[] = 'Subject: '.encodeHeader($rfc822_header->subject) . $rn;
         $header[] = 'From: '. $rfc822_header->getAddr_s('from',",$rn ",true) . $rn;