| | |
| | | <?php |
| | | |
| | | /* |
| | | /** |
| | | +-----------------------------------------------------------------------+ |
| | | | program/include/rcube_imap_generic.php | |
| | | | | |
| | |
| | | $parts_count = count($a); |
| | | if ($parts_count>=6) { |
| | | for ($i=0; $i<$parts_count; $i=$i+2) { |
| | | if ($a[$i] == 'UID') |
| | | if ($a[$i] == 'UID') { |
| | | $result[$id]->uid = intval($a[$i+1]); |
| | | else if ($a[$i] == 'RFC822.SIZE') |
| | | } |
| | | else if ($a[$i] == 'RFC822.SIZE') { |
| | | $result[$id]->size = intval($a[$i+1]); |
| | | else if ($a[$i] == 'INTERNALDATE') |
| | | } |
| | | else if ($a[$i] == 'INTERNALDATE') { |
| | | $time_str = $a[$i+1]; |
| | | else if ($a[$i] == 'FLAGS') |
| | | } |
| | | else if ($a[$i] == 'FLAGS') { |
| | | $flags_str = $a[$i+1]; |
| | | } |
| | | } |
| | | |
| | | $time_str = str_replace('"', '', $time_str); |
| | |
| | | } |
| | | |
| | | // the rest of the result |
| | | preg_match('/ BODY\[HEADER.FIELDS \(.*?\)\]\s*(.*)$/s', $line, $m); |
| | | if (preg_match('/ BODY\[HEADER.FIELDS \(.*?\)\]\s*(.*)$/s', $line, $m)) { |
| | | $reslines = explode("\n", trim($m[1], '"')); |
| | | // re-parse (see below) |
| | | foreach ($reslines as $resln) { |
| | |
| | | $lines[$ln] .= (empty($lines[$ln])?'':"\n").trim($resln); |
| | | } else { |
| | | $lines[++$ln] = trim($resln); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | $result[$id]->messageID = $string; |
| | | break; |
| | | case 'x-priority': |
| | | if (preg_match('/^(\d+)/', $string, $matches)) |
| | | if (preg_match('/^(\d+)/', $string, $matches)) { |
| | | $result[$id]->priority = intval($matches[1]); |
| | | } |
| | | break; |
| | | default: |
| | | if (strlen($field) > 2) |
| | | if (strlen($field) > 2) { |
| | | $result[$id]->others[$field] = $string; |
| | | } |
| | | break; |
| | | } // end switch () |
| | | } // end while () |
| | |
| | | while ($n > 0) { |
| | | $p = strpos($str, ')', $off); |
| | | if ($p === false) { |
| | | error_log('Mismatched brackets parsing IMAP THREAD response:'); |
| | | error_log("Mismatched brackets parsing IMAP THREAD response:"); |
| | | error_log(substr($str, ($begin < 10) ? 0 : ($begin - 10), $end - $begin + 20)); |
| | | error_log(str_repeat(' ', $off - (($begin < 10) ? 0 : ($begin - 10)))); |
| | | return $node; |
| | |
| | | |
| | | if (!empty($items)) { |
| | | $result = array(); |
| | | if (in_array('COUNT', $items)) |
| | | if (in_array('COUNT', $items)) { |
| | | $result['COUNT'] = count($response); |
| | | if (in_array('MIN', $items)) |
| | | } |
| | | if (in_array('MIN', $items)) { |
| | | $result['MIN'] = !empty($response) ? min($response) : 0; |
| | | if (in_array('MAX', $items)) |
| | | } |
| | | if (in_array('MAX', $items)) { |
| | | $result['MAX'] = !empty($response) ? max($response) : 0; |
| | | if (in_array('ALL', $items)) |
| | | } |
| | | if (in_array('ALL', $items)) { |
| | | $result['ALL'] = $this->compressMessageSet($response, true); |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | |
| | | $type = $mime ? 'MIME' : 'HEADER'; |
| | | |
| | | // format request |
| | | foreach($parts as $part) |
| | | foreach($parts as $part) { |
| | | $peeks[] = "BODY.PEEK[$part.$type]"; |
| | | } |
| | | |
| | | $request = "$key FETCH $id (" . implode(' ', $peeks) . ')'; |
| | | |
| | |
| | | $result = substr($line, $from, $len); |
| | | } |
| | | |
| | | if ($mode == 1) |
| | | if ($mode == 1) { |
| | | $result = base64_decode($result); |
| | | else if ($mode == 2) |
| | | } |
| | | else if ($mode == 2) { |
| | | $result = quoted_printable_decode($result); |
| | | else if ($mode == 3) |
| | | } |
| | | else if ($mode == 3) { |
| | | $result = convert_uudecode($result); |
| | | } |
| | | |
| | | } else if ($line[$len-1] == '}') { |
| | | // multi-line request, find sizes of content and receive that many bytes |
| | |
| | | while ($bytes > 0) { |
| | | $line = $this->readLine(4096); |
| | | |
| | | if ($line === NULL) |
| | | if ($line === NULL) { |
| | | break; |
| | | } |
| | | |
| | | $len = strlen($line); |
| | | |
| | |
| | | if ($this->putLine($request)) { |
| | | // Don't wait when LITERAL+ is supported |
| | | if (!$this->prefs['literal+']) { |
| | | $line = $this->readLine(512); |
| | | $line = $this->readReply(); |
| | | |
| | | if ($line[0] != '+') { |
| | | $this->parseResult($line, 'APPEND: '); |
| | |
| | | if ($this->putLine($request)) { |
| | | // Don't wait when LITERAL+ is supported |
| | | if (!$this->prefs['literal+']) { |
| | | $line = $this->readLine(512); |
| | | $line = $this->readReply(); |
| | | |
| | | if ($line[0] != '+') { |
| | | $this->parseResult($line, 'APPEND: '); |
| | |
| | | $parts = explode(' ', $quota_line); |
| | | $storage_part = array_search('STORAGE', $parts); |
| | | |
| | | if (!$storage_part) |
| | | if (!$storage_part) { |
| | | continue; |
| | | } |
| | | |
| | | $used = intval($parts[$storage_part+1]); |
| | | $total = intval($parts[$storage_part+2]); |
| | |
| | | } |
| | | |
| | | foreach ($entries as $name => $value) { |
| | | if ($value === null) |
| | | if ($value === null) { |
| | | $value = 'NIL'; |
| | | else |
| | | } |
| | | else { |
| | | $value = sprintf("{%d}\r\n%s", strlen($value), $value); |
| | | |
| | | } |
| | | $entries[$name] = $this->escape($name) . ' ' . $value; |
| | | } |
| | | |
| | |
| | | */ |
| | | function deleteMetadata($mailbox, $entries) |
| | | { |
| | | if (!is_array($entries) && !empty($entries)) |
| | | if (!is_array($entries) && !empty($entries)) { |
| | | $entries = explode(' ', $entries); |
| | | } |
| | | |
| | | if (empty($entries)) { |
| | | $this->setError(self::ERROR_COMMAND, "Wrong argument for SETMETADATA command"); |
| | | return false; |
| | | } |
| | | |
| | | foreach ($entries as $entry) |
| | | foreach ($entries as $entry) { |
| | | $data[$entry] = NULL; |
| | | } |
| | | |
| | | return $this->setMetadata($mailbox, $data); |
| | | } |
| | |
| | | $options = array_change_key_case($options, CASE_UPPER); |
| | | $opts = array(); |
| | | |
| | | if (!empty($options['MAXSIZE'])) |
| | | if (!empty($options['MAXSIZE'])) { |
| | | $opts[] = 'MAXSIZE '.intval($options['MAXSIZE']); |
| | | if (!empty($options['DEPTH'])) |
| | | } |
| | | if (!empty($options['DEPTH'])) { |
| | | $opts[] = 'DEPTH '.intval($options['DEPTH']); |
| | | } |
| | | |
| | | if ($opts) |
| | | if ($opts) { |
| | | $optlist = '(' . implode(' ', $opts) . ')'; |
| | | } |
| | | } |
| | | |
| | | $optlist .= ($optlist ? ' ' : '') . $entlist; |
| | |
| | | $attr = $entry[1]; |
| | | $value = $entry[2]; |
| | | |
| | | if ($value === null) |
| | | if ($value === null) { |
| | | $value = 'NIL'; |
| | | else |
| | | } |
| | | else { |
| | | $value = sprintf("{%d}\r\n%s", strlen($value), $value); |
| | | } |
| | | |
| | | $entries[] = sprintf('%s (%s %s)', |
| | | $this->escape($name), $this->escape($attr), $value); |
| | |
| | | for ($x=0, $len=count($attribs); $x<$len;) { |
| | | $attr = $attribs[$x++]; |
| | | $value = $attribs[$x++]; |
| | | if ($attr == 'value.priv') |
| | | if ($attr == 'value.priv') { |
| | | $res['/private' . $entry] = $value; |
| | | else if ($attr == 'value.shared') |
| | | } |
| | | else if ($attr == 'value.shared') { |
| | | $res['/shared' . $entry] = $value; |
| | | } |
| | | } |
| | | } |
| | | $last_entry = $entry; |
| | |
| | | $noresp = ($options & self::COMMAND_NORESPONSE); |
| | | $response = $noresp ? null : ''; |
| | | |
| | | if (!empty($arguments)) |
| | | if (!empty($arguments)) { |
| | | $query .= ' ' . implode(' ', $arguments); |
| | | } |
| | | |
| | | // Send command |
| | | if (!$this->putLineC($query)) { |
| | |
| | | // Parse response |
| | | do { |
| | | $line = $this->readLine(4096); |
| | | if ($response !== null) |
| | | if ($response !== null) { |
| | | $response .= $line; |
| | | } |
| | | } while (!$this->startsWith($line, $tag . ' ', true, true)); |
| | | |
| | | $code = $this->parseResult($line, $command . ': '); |
| | |
| | | { |
| | | $result = ''; |
| | | $size = strlen($string); |
| | | |
| | | for ($i=0; $i<$size; $i++) { |
| | | $result .= chr(ord($string[$i]) ^ ord($string2[$i])); |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | |
| | | while ((($ts = @strtotime($date))===false) || ($ts < 0)) { |
| | | $d = explode(' ', $date); |
| | | array_pop($d); |
| | | if (!$d) break; |
| | | if (!$d) { |
| | | break; |
| | | } |
| | | $date = implode(' ', $d); |
| | | } |
| | | |
| | |
| | | */ |
| | | static function escape($string) |
| | | { |
| | | // NIL |
| | | if ($string === null) { |
| | | return 'NIL'; |
| | | } |
| | | // empty string |
| | | else if ($string === '') { |
| | | return '""'; |
| | | } |
| | | // string: special chars: SP, CTL, (, ), {, %, *, ", \, ] |
| | | else if (preg_match('/([\x00-\x20\x28-\x29\x7B\x25\x2A\x22\x5C\x5D\x7F]+)/', $string)) { |
| | | // string: special chars: SP, CTL, (, ), {, %, *, ", \, ] |
| | | return '"' . strtr($string, array('"'=>'\\"', '\\' => '\\\\')) . '"'; |
| | | } |
| | | |