| | |
| | | |
| | | /** |
| | | +-----------------------------------------------------------------------+ |
| | | | program/include/rcube_imap_generic.php | |
| | | | | |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2005-2012, The Roundcube Dev Team | |
| | | | Copyright (C) 2011-2012, Kolab Systems AG | |
| | |
| | | | functionality built-in. | |
| | | | | |
| | | | Based on Iloha IMAP Library. See http://ilohamail.org/ for details | |
| | | | | |
| | | +-----------------------------------------------------------------------+ |
| | | | Author: Aleksander Machniak <alec@alec.pl> | |
| | | | Author: Ryo Chijiiwa <Ryo@IlohaMail.org> | |
| | | +-----------------------------------------------------------------------+ |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * PHP based wrapper class to connect to an IMAP server |
| | |
| | | $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr, $this->prefs['timeout']); |
| | | |
| | | if (!$this->fp) { |
| | | if (!$errstr) { |
| | | $errstr = "Unknown reason (fsockopen() function disabled?)"; |
| | | } |
| | | $this->setError(self::ERROR_BAD, sprintf("Could not connect to %s:%d: %s", $host, $this->prefs['port'], $errstr)); |
| | | return false; |
| | | } |
| | | |
| | | if ($this->prefs['timeout'] > 0) |
| | | if ($this->prefs['timeout'] > 0) { |
| | | stream_set_timeout($this->fp, $this->prefs['timeout']); |
| | | } |
| | | |
| | | $line = trim(fgets($this->fp, 8192)); |
| | | |
| | |
| | | */ |
| | | function closeConnection() |
| | | { |
| | | if ($this->putLine($this->nextTag() . ' LOGOUT')) { |
| | | if ($this->logged && $this->putLine($this->nextTag() . ' LOGOUT')) { |
| | | $this->readReply(); |
| | | } |
| | | |
| | |
| | | /** |
| | | * Executes EXPUNGE command |
| | | * |
| | | * @param string $mailbox Mailbox name |
| | | * @param string $messages Message UIDs to expunge |
| | | * @param string $mailbox Mailbox name |
| | | * @param string|array $messages Message UIDs to expunge |
| | | * |
| | | * @return boolean True on success, False on error |
| | | */ |
| | |
| | | // Clear internal status cache |
| | | unset($this->data['STATUS:'.$mailbox]); |
| | | |
| | | if ($messages) |
| | | $result = $this->execute('UID EXPUNGE', array($messages), self::COMMAND_NORESPONSE); |
| | | else |
| | | if (!empty($messages) && $messages != '*' && $this->hasCapability('UIDPLUS')) { |
| | | $messages = self::compressMessageSet($messages); |
| | | $result = $this->execute('UID EXPUNGE', array($messages), self::COMMAND_NORESPONSE); |
| | | } |
| | | else { |
| | | $result = $this->execute('EXPUNGE', null, self::COMMAND_NORESPONSE); |
| | | } |
| | | |
| | | if ($result == self::ERROR_OK) { |
| | | $this->selected = null; // state has changed, need to reselect |
| | |
| | | // * LIST (<options>) <delimiter> <mailbox> |
| | | if ($cmd == 'LIST' || $cmd == 'LSUB') { |
| | | list($opts, $delim, $mailbox) = $this->tokenizeResponse($line, 3); |
| | | |
| | | // Remove redundant separator at the end of folder name, UW-IMAP bug? (#1488879) |
| | | if ($delim) { |
| | | $mailbox = rtrim($mailbox, $delim); |
| | | } |
| | | |
| | | // Add to result array |
| | | if (!$lstatus) { |
| | |
| | | |
| | | /** |
| | | * Moves message(s) from one folder to another. |
| | | * Original message(s) will be marked as deleted. |
| | | * |
| | | * @param string|array $messages Message UID(s) |
| | | * @param string $from Mailbox name |
| | |
| | | return false; |
| | | } |
| | | |
| | | $r = $this->copy($messages, $from, $to); |
| | | // use MOVE command (RFC 6851) |
| | | if ($this->hasCapability('MOVE')) { |
| | | // Clear last COPYUID data |
| | | unset($this->data['COPYUID']); |
| | | |
| | | if ($r) { |
| | | // Clear internal status cache |
| | | unset($this->data['STATUS:'.$to]); |
| | | unset($this->data['STATUS:'.$from]); |
| | | |
| | | $result = $this->execute('UID MOVE', array( |
| | | $this->compressMessageSet($messages), $this->escape($to)), |
| | | self::COMMAND_NORESPONSE); |
| | | |
| | | return ($result == self::ERROR_OK); |
| | | } |
| | | |
| | | // use COPY + STORE +FLAGS.SILENT \Deleted + EXPUNGE |
| | | $result = $this->copy($messages, $from, $to); |
| | | |
| | | if ($result) { |
| | | // Clear internal status cache |
| | | unset($this->data['STATUS:'.$from]); |
| | | |
| | | return $this->flag($from, $messages, 'DELETED'); |
| | | $result = $this->flag($from, $messages, 'DELETED'); |
| | | |
| | | if ($messages == '*') { |
| | | // CLOSE+SELECT should be faster than EXPUNGE |
| | | $this->close(); |
| | | } |
| | | else { |
| | | $this->expunge($from, $messages); |
| | | } |
| | | } |
| | | return $r; |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param string $message Message content |
| | | * @param array $flags Message flags |
| | | * @param string $date Message internal date |
| | | * @param bool $binary Enable BINARY append (RFC3516) |
| | | * |
| | | * @return string|bool On success APPENDUID response (if available) or True, False on failure |
| | | */ |
| | | function append($mailbox, &$message, $flags = array(), $date = null) |
| | | function append($mailbox, &$message, $flags = array(), $date = null, $binary = false) |
| | | { |
| | | unset($this->data['APPENDUID']); |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | $message = str_replace("\r", '', $message); |
| | | $message = str_replace("\n", "\r\n", $message); |
| | | $binary = $binary && $this->getCapability('BINARY'); |
| | | $literal_plus = !$binary && $this->prefs['literal+']; |
| | | |
| | | if (!$binary) { |
| | | $message = str_replace("\r", '', $message); |
| | | $message = str_replace("\n", "\r\n", $message); |
| | | } |
| | | |
| | | $len = strlen($message); |
| | | if (!$len) { |
| | |
| | | if (!empty($date)) { |
| | | $request .= ' ' . $this->escape($date); |
| | | } |
| | | $request .= ' {' . $len . ($this->prefs['literal+'] ? '+' : '') . '}'; |
| | | $request .= ' ' . ($binary ? '~' : '') . '{' . $len . ($literal_plus ? '+' : '') . '}'; |
| | | |
| | | // send APPEND command |
| | | if ($this->putLine($request)) { |
| | | // Do not wait when LITERAL+ is supported |
| | | if (!$this->prefs['literal+']) { |
| | | if (!$literal_plus) { |
| | | $line = $this->readReply(); |
| | | |
| | | if ($line[0] != '+') { |
| | |
| | | * @param string $headers Message headers |
| | | * @param array $flags Message flags |
| | | * @param string $date Message internal date |
| | | * @param bool $binary Enable BINARY append (RFC3516) |
| | | * |
| | | * @return string|bool On success APPENDUID response (if available) or True, False on failure |
| | | */ |
| | | function appendFromFile($mailbox, $path, $headers=null, $flags = array(), $date = null) |
| | | function appendFromFile($mailbox, $path, $headers=null, $flags = array(), $date = null, $binary = false) |
| | | { |
| | | unset($this->data['APPENDUID']); |
| | | |
| | |
| | | $len += strlen($headers) + strlen($body_separator); |
| | | } |
| | | |
| | | $binary = $binary && $this->getCapability('BINARY'); |
| | | $literal_plus = !$binary && $this->prefs['literal+']; |
| | | |
| | | // build APPEND command |
| | | $key = $this->nextTag(); |
| | | $request = "$key APPEND " . $this->escape($mailbox) . ' (' . $this->flagsToStr($flags) . ')'; |
| | | if (!empty($date)) { |
| | | $request .= ' ' . $this->escape($date); |
| | | } |
| | | $request .= ' {' . $len . ($this->prefs['literal+'] ? '+' : '') . '}'; |
| | | $request .= ' ' . ($binary ? '~' : '') . '{' . $len . ($literal_plus ? '+' : '') . '}'; |
| | | |
| | | // send APPEND command |
| | | if ($this->putLine($request)) { |
| | | // Don't wait when LITERAL+ is supported |
| | | if (!$this->prefs['literal+']) { |
| | | if (!$literal_plus) { |
| | | $line = $this->readReply(); |
| | | |
| | | if ($line[0] != '+') { |
| | |
| | | // if less than 255 bytes long, let's not bother |
| | | if (!$force && strlen($messages)<255) { |
| | | return $messages; |
| | | } |
| | | } |
| | | |
| | | // see if it's already been compressed |
| | | if (strpos($messages, ':') !== false) { |