alecpl
2011-10-24 b407e797c20f8d06a85fc90a831f9a8ec6237298
program/include/rcube_imap_generic.php
@@ -310,6 +310,10 @@
                }
                else {
                    $this->resultcode = null;
                    // parse response for [APPENDUID 1204196876 3456]
                    if (preg_match("/^\[APPENDUID [0-9]+ ([0-9,:*]+)\]/i", $str, $m)) {
                        $this->data['APPENDUID'] = $m[1];
                    }
                }
                $this->result = $str;
@@ -2296,12 +2300,11 @@
        $result = false;
        $parts  = (array) $parts;
        $key    = $this->nextTag();
        $peeks  = '';
        $idx    = 0;
        $peeks  = array();
        $type   = $mime ? 'MIME' : 'HEADER';
        // format request
        foreach($parts as $part) {
        foreach ($parts as $part) {
            $peeks[] = "BODY.PEEK[$part.$type]";
        }
@@ -2315,13 +2318,25 @@
        do {
            $line = $this->readLine(1024);
            $line = $this->multLine($line);
            if (preg_match('/BODY\[([0-9\.]+)\.'.$type.'\]/', $line, $matches)) {
                $idx = $matches[1];
                $result[$idx] = preg_replace('/^(\* [0-9]+ FETCH \()?\s*BODY\['.$idx.'\.'.$type.'\]\s+/', '', $line);
                $result[$idx] = trim($result[$idx], '"');
                $result[$idx] = rtrim($result[$idx], "\t\r\n\0\x0B");
            if (preg_match('/^\* [0-9]+ FETCH [0-9UID( ]+BODY\[([0-9\.]+)\.'.$type.'\]/', $line, $matches)) {
                $idx     = $matches[1];
                $headers = '';
                // get complete entry
                if (preg_match('/\{([0-9]+)\}\r\n$/', $line, $m)) {
                    $bytes = $m[1];
                    $out   = '';
                    while (strlen($out) < $bytes) {
                        $out = $this->readBytes($bytes);
                        if ($out === null)
                            break;
                        $headers .= $out;
                    }
                }
                $result[$idx] = trim($headers);
            }
        } while (!$this->startsWith($line, $key, true));
@@ -2498,8 +2513,18 @@
        return ($result == self::ERROR_OK);
    }
    /**
     * Handler for IMAP APPEND command
     *
     * @param string $mailbox Mailbox name
     * @param string $message Message content
     *
     * @return string|bool On success APPENDUID response (if available) or True, False on failure
     */
    function append($mailbox, &$message)
    {
        unset($this->data['APPENDUID']);
        if (!$mailbox) {
            return false;
        }
@@ -2538,7 +2563,12 @@
            // Clear internal status cache
            unset($this->data['STATUS:'.$mailbox]);
            return ($this->parseResult($line, 'APPEND: ') == self::ERROR_OK);
            if ($this->parseResult($line, 'APPEND: ') != self::ERROR_OK)
                return false;
            else if (!empty($this->data['APPENDUID']))
                return $this->data['APPENDUID'];
            else
                return true;
        }
        else {
            $this->setError(self::ERROR_COMMAND, "Unable to send command: $request");
@@ -2547,8 +2577,19 @@
        return false;
    }
    /**
     * Handler for IMAP APPEND command.
     *
     * @param string $mailbox Mailbox name
     * @param string $path    Path to the file with message body
     * @param string $headers Message headers
     *
     * @return string|bool On success APPENDUID response (if available) or True, False on failure
     */
    function appendFromFile($mailbox, $path, $headers=null)
    {
        unset($this->data['APPENDUID']);
        if (!$mailbox) {
            return false;
        }
@@ -2615,7 +2656,12 @@
            // Clear internal status cache
            unset($this->data['STATUS:'.$mailbox]);
            return ($this->parseResult($line, 'APPEND: ') == self::ERROR_OK);
            if ($this->parseResult($line, 'APPEND: ') != self::ERROR_OK)
                return false;
            else if (!empty($this->data['APPENDUID']))
                return $this->data['APPENDUID'];
            else
                return true;
        }
        else {
            $this->setError(self::ERROR_COMMAND, "Unable to send command: $request");