diff options
Diffstat (limited to 'program/include/rcube_imap.php')
-rw-r--r-- | program/include/rcube_imap.php | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index 8a1c65bbe..1e6cf360b 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2219,10 +2219,12 @@ class rcube_imap extends rcube_storage * @param string $message The message source string or filename * @param string $headers Headers string if $message contains only the body * @param boolean $is_file True if $message is a filename + * @param array $flags Message flags + * @param mixed $date Message internal date * * @return int|bool Appended message UID or True on success, False on error */ - public function save_message($folder, &$message, $headers='', $is_file=false) + public function save_message($folder, &$message, $headers='', $is_file=false, $flags = array(), $date = null) { if (!strlen($folder)) { $folder = $this->folder; @@ -2232,16 +2234,18 @@ class rcube_imap extends rcube_storage return false; } - $flags = array('SEEN'); - // make sure folder exists - if ($this->folder_exists($folder)) { - if ($is_file) { - $saved = $this->conn->appendFromFile($folder, $message, $headers, $flags); - } - else { - $saved = $this->conn->append($folder, $message, $flags); - } + if (!$this->folder_exists($folder)) { + return false; + } + + $date = $this->date_format($date); + + if ($is_file) { + $saved = $this->conn->appendFromFile($folder, $message, $headers, $flags, $date); + } + else { + $saved = $this->conn->append($folder, $message, $flags, $date); } if ($saved) { @@ -3984,6 +3988,29 @@ class rcube_imap extends rcube_storage /** + * Converts date string/object into IMAP date/time format + */ + protected function date_format($date) + { + if (empty($date)) { + return null; + } + + if (!is_object($date) || !is_a($date, 'DateTime')) { + try { + $timestamp = rcube_utils::strtotime($date); + $date = new DateTime("@".$timestamp); + } + catch (Exception $e) { + return null; + } + } + + return $date->format('d-M-Y H:i:s O'); + } + + + /** * This is our own debug handler for the IMAP connection * @access public */ |