Thomas Bruederli
2012-11-17 be9aacaa5296dfca63fb3a01c2dc52538d1546aa
program/include/rcube_imap.php
@@ -25,10 +25,10 @@
/**
 * Interface class for accessing an IMAP server
 *
 * @package    Mail
 * @package    Framework
 * @subpackage Storage
 * @author     Thomas Bruederli <roundcube@gmail.com>
 * @author     Aleksander Machniak <alec@alec.pl>
 * @version    2.0
 */
class rcube_imap extends rcube_storage
{
@@ -1434,6 +1434,12 @@
            $criteria = 'UNDELETED '.$criteria;
        }
        // unset CHARSET if criteria string is ASCII, this way
        // SEARCH won't be re-sent after "unsupported charset" response
        if ($charset && $charset != 'US-ASCII' && is_ascii($criteria)) {
            $charset = 'US-ASCII';
        }
        if ($this->threading) {
            $threads = $this->conn->thread($folder, $this->threading, $criteria, true, $charset);
@@ -1465,7 +1471,7 @@
        }
        $messages = $this->conn->search($folder,
            ($charset ? "CHARSET $charset " : '') . $criteria, true);
            ($charset && $charset != 'US-ASCII' ? "CHARSET $charset " : '') . $criteria, true);
        // Error, try with US-ASCII (some servers may support only US-ASCII)
        if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
@@ -2068,7 +2074,7 @@
        if ($o_part && $o_part->size) {
            $body = $this->conn->handlePartBody($this->folder, $uid, true,
                $part ? $part : 'TEXT', $o_part->encoding, $print, $fp);
                $part ? $part : 'TEXT', $o_part->encoding, $print, $fp, $o_part->ctype_primary == 'text');
        }
        if ($fp || $print) {
@@ -2213,23 +2219,33 @@
     * @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;
        }
        if (!$this->check_connection()) {
            return false;
        }
        // make sure folder exists
        if ($this->folder_exists($folder)) {
            if ($is_file) {
                $saved = $this->conn->appendFromFile($folder, $message, $headers);
            }
            else {
                $saved = $this->conn->append($folder, $message);
            }
        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) {
@@ -3287,11 +3303,8 @@
        }
        // Get folder rights (MYRIGHTS)
        if ($acl && !$options['noselect']) {
            // skip shared roots
            if (!$options['is_root'] || $options['namespace'] == 'personal') {
                $options['rights'] =  (array)$this->my_rights($folder);
            }
        if ($acl && ($rights = $this->my_rights($folder))) {
            $options['rights'] = $rights;
        }
        // Set 'norename' flag
@@ -3975,6 +3988,29 @@
    /**
     * 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
     */
@@ -4083,6 +4119,11 @@
        return $this->delete_folder($folder);
    }
    function clear_mailbox($folder = null)
    {
        return $this->clear_folder($folder);
    }
    public function mailbox_exists($folder, $subscription=false)
    {
        return $this->folder_exists($folder, $subscription);