Changeset 4105 in subversion
- Timestamp:
- Oct 19, 2010 3:19:27 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/include/rcube_imap_generic.php
r4102 r4105 162 162 if ($this->prefs['literal+']) 163 163 $parts[$i+1] = preg_replace('/([0-9]+)/', '\\1+', $parts[$i+1]); 164 164 165 165 $bytes = $this->putLine($parts[$i].$parts[$i+1], false); 166 166 if ($bytes === false) … … 237 237 } 238 238 239 $line = $a[1][0] . '"' . ($escape ? $this->Escape($out) : $out) . '"';239 $line = $a[1][0] . ($escape ? $this->escape($out) : $out); 240 240 } 241 241 … … 416 416 function login($user, $password) 417 417 { 418 $this->putLine('a001 LOGIN "'.$this->escape($user).'" "'.$this->escape($password).'"'); 418 $this->putLine(sprintf("a001 LOGIN %s %s", 419 $this->escape($user), $this->escape($password))); 419 420 420 421 $line = $this->readReply($untagged); … … 734 735 } 735 736 736 $command = "sel1 SELECT \"".$this->escape($mailbox).'"';737 $command = "sel1 SELECT " . $this->escape($mailbox); 737 738 738 739 if (!$this->putLine($command)) { … … 1473 1474 } 1474 1475 1475 $command = "cpy1 UID COPY $messages \"".$this->escape($to)."\"";1476 $command = "cpy1 UID COPY $messages ".$this->escape($to); 1476 1477 1477 1478 if (!$this->putLine($command)) { … … 1667 1668 } 1668 1669 1669 $ref = $this->escape($ref); 1670 $mailbox = $this->escape($mailbox); 1671 $query = $key." ".$command." \"". $ref ."\" \"". $mailbox ."\""; 1670 $query = sprintf("%s %s %s %s", $key, $command, $this->escape($ref), $this->escape($mailbox)); 1672 1671 1673 1672 // send command … … 1905 1904 function createFolder($folder) 1906 1905 { 1907 $command = 'c CREATE "' . $this->escape($folder) . '"';1908 1906 $command = sprintf("c CREATE %s", $this->escape($folder)); 1907 1909 1908 if (!$this->putLine($command)) { 1910 1909 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); … … 1921 1920 function renameFolder($from, $to) 1922 1921 { 1923 $command = 'r RENAME "' . $this->escape($from) . '" "' . $this->escape($to) . '"';1924 1922 $command = sprintf("r RENAME %s %s", $this->escape($from), $this->escape($to)); 1923 1925 1924 if (!$this->putLine($command)) { 1926 1925 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); … … 1936 1935 function deleteFolder($folder) 1937 1936 { 1938 $command = 'd DELETE "' . $this->escape($folder). '"';1939 1937 $command = sprintf("d DELETE %s", $this->escape($folder)); 1938 1940 1939 if (!$this->putLine($command)) { 1941 1940 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); … … 1960 1959 function subscribe($folder) 1961 1960 { 1962 $command = 'sub1 SUBSCRIBE "' . $this->escape($folder). '"';1961 $command = sprintf("sub1 SUBSCRIBE %s", $this->escape($folder)); 1963 1962 1964 1963 if (!$this->putLine($command)) { … … 1973 1972 function unsubscribe($folder) 1974 1973 { 1975 $command = 'usub1 UNSUBSCRIBE "' . $this->escape($folder) . '"';1974 $command = sprintf("usub1 UNSUBSCRIBE %s", $this->escape($folder)); 1976 1975 1977 1976 if (!$this->putLine($command)) { … … 1998 1997 } 1999 1998 2000 $request = sprintf("a APPEND \"%s\"(\\Seen) {%d%s}", $this->escape($folder),1999 $request = sprintf("a APPEND %s (\\Seen) {%d%s}", $this->escape($folder), 2001 2000 $len, ($this->prefs['literal+'] ? '+' : '')); 2002 2001 … … 2058 2057 2059 2058 // send APPEND command 2060 $request = sprintf("a APPEND \"%s\"(\\Seen) {%d%s}", $this->escape($folder),2059 $request = sprintf("a APPEND %s (\\Seen) {%d%s}", $this->escape($folder), 2061 2060 $len, ($this->prefs['literal+'] ? '+' : '')); 2062 2061 … … 2093 2092 } while (!$this->startsWith($line, 'a ', true, true)); 2094 2093 2095 2094 2096 2095 return ($this->parseResult($line, 'APPEND: ') == self::ERROR_OK); 2097 2096 } … … 2201 2200 2202 2201 $key = 'acl1'; 2203 $command = sprintf("%s SETACL \"%s\" \"%s\"%s",2202 $command = sprintf("%s SETACL %s %s %s", 2204 2203 $key, $this->escape($mailbox), $this->escape($user), strtolower($acl)); 2205 2204 2206 2205 if (!$this->putLine($command)) { 2207 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2206 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2208 2207 return false; 2209 2208 } … … 2227 2226 { 2228 2227 $key = 'acl2'; 2229 $command = sprintf("%s DELETEACL \"%s\" \"%s\"",2228 $command = sprintf("%s DELETEACL %s %s", 2230 2229 $key, $this->escape($mailbox), $this->escape($user)); 2231 2230 2232 2231 if (!$this->putLine($command)) { 2233 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2232 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2234 2233 return false; 2235 2234 } … … 2251 2250 { 2252 2251 $key = 'acl3'; 2253 $command = sprintf("%s GETACL \"%s\"", $key, $this->escape($mailbox));2252 $command = sprintf("%s GETACL %s", $key, $this->escape($mailbox)); 2254 2253 2255 2254 if (!$this->putLine($command)) { … … 2264 2263 $response .= $line; 2265 2264 } while (!$this->startsWith($line, $key, true, true)); 2266 2265 2267 2266 if ($this->parseResult($line, 'GETACL: ') == self::ERROR_OK) { 2268 2267 // Parse server response (remove "* ACL " and "\r\nacl3 OK...") … … 2305 2304 { 2306 2305 $key = 'acl4'; 2307 $command = sprintf("%s LISTRIGHTS \"%s\" \"%s\"",2306 $command = sprintf("%s LISTRIGHTS %s %s", 2308 2307 $key, $this->escape($mailbox), $this->escape($user)); 2309 2308 2310 2309 if (!$this->putLine($command)) { 2311 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2310 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2312 2311 return NULL; 2313 2312 } … … 2350 2349 { 2351 2350 $key = 'acl5'; 2352 $command = sprintf("%s MYRIGHTS \"%s\"", $key, $this->escape(mailbox));2351 $command = sprintf("%s MYRIGHTS %s", $key, $this->escape(mailbox)); 2353 2352 2354 2353 if (!$this->putLine($command)) { 2355 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2354 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2356 2355 return NULL; 2357 2356 } … … 2390 2389 { 2391 2390 if (!is_array($entries) || empty($entries)) { 2392 $this->set_error(self::ERROR_COMMAND, "Wrong argument for SETMETADATA command"); 2391 $this->set_error(self::ERROR_COMMAND, "Wrong argument for SETMETADATA command"); 2393 2392 return false; 2394 2393 } … … 2400 2399 $value = sprintf("{%d}\r\n%s", strlen($value), $value); 2401 2400 2402 $entries[$name] = '"' . $this->escape($name) . '"' . $value;2401 $entries[$name] = $this->escape($name) . ' ' . $value; 2403 2402 } 2404 2403 2405 2404 $entries = implode(' ', $entries); 2406 2405 $key = 'md1'; 2407 $command = sprintf("%s SETMETADATA \"%s\" (%s)",2406 $command = sprintf("%s SETMETADATA %s (%s)", 2408 2407 $key, $this->escape($mailbox), $entries); 2409 2408 2410 2409 if (!$this->putLineC($command)) { 2411 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2410 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2412 2411 return false; 2413 2412 } … … 2440 2439 foreach ($entries as $entry) 2441 2440 $data[$entry] = NULL; 2442 2441 2443 2442 return $this->setMetadata($mailbox, $data); 2444 2443 } … … 2464 2463 // create entries string 2465 2464 foreach ($entries as $idx => $name) { 2466 $entries[$idx] = '"' . $this->escape($name) . '"';2465 $entries[$idx] = $this->escape($name); 2467 2466 } 2468 2467 … … 2487 2486 2488 2487 $key = 'md2'; 2489 $command = sprintf("%s GETMETADATA \"%s\"%s",2488 $command = sprintf("%s GETMETADATA %s %s", 2490 2489 $key, $this->escape($mailbox), $optlist); 2491 2490 2492 2491 if (!$this->putLine($command)) { 2493 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2492 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2494 2493 return NULL; 2495 2494 } … … 2515 2514 $size_sub = count($data[$i]); 2516 2515 for ($x=0; $x<$size_sub; $x++) { 2517 $data[$data[$i][$x]] = $data[$i][++$x]; 2516 $data[$data[$i][$x]] = $data[$i][++$x]; 2518 2517 } 2519 2518 unset($data[$i]); … … 2552 2551 { 2553 2552 if (!is_array($data) || empty($data)) { 2554 $this->set_error(self::ERROR_COMMAND, "Wrong argument for SETANNOTATION command"); 2553 $this->set_error(self::ERROR_COMMAND, "Wrong argument for SETANNOTATION command"); 2555 2554 return false; 2556 2555 } … … 2566 2565 $value = sprintf("{%d}\r\n%s", strlen($value), $value); 2567 2566 2568 $entries[] = sprintf(' "%s" ("%s"%s)',2567 $entries[] = sprintf('%s (%s %s)', 2569 2568 $this->escape($name), $this->escape($attr), $value); 2570 2569 } … … 2572 2571 $entries = implode(' ', $entries); 2573 2572 $key = 'an1'; 2574 $command = sprintf("%s SETANNOTATION \"%s\"%s",2573 $command = sprintf("%s SETANNOTATION %s %s", 2575 2574 $key, $this->escape($mailbox), $entries); 2576 2575 2577 2576 if (!$this->putLineC($command)) { 2578 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2577 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2579 2578 return false; 2580 2579 } … … 2625 2624 // create entries string 2626 2625 foreach ($entries as $idx => $name) { 2627 $entries[$idx] = '"' . $this->escape($name) . '"';2626 $entries[$idx] = $this->escape($name); 2628 2627 } 2629 2628 $entries = '(' . implode(' ', $entries) . ')'; … … 2634 2633 // create entries string 2635 2634 foreach ($attribs as $idx => $name) { 2636 $attribs[$idx] = '"' . $this->escape($name) . '"';2635 $attribs[$idx] = $this->escape($name); 2637 2636 } 2638 2637 $attribs = '(' . implode(' ', $attribs) . ')'; 2639 2638 2640 2639 $key = 'an2'; 2641 $command = sprintf("%s GETANNOTATION \"%s\"%s %s",2640 $command = sprintf("%s GETANNOTATION %s %s %s", 2642 2641 $key, $this->escape($mailbox), $entries, $attribs); 2643 2642 2644 2643 if (!$this->putLine($command)) { 2645 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2644 $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command"); 2646 2645 return NULL; 2647 2646 } … … 2690 2689 return $res; 2691 2690 } 2692 2691 2693 2692 return NULL; 2694 2693 } … … 2761 2760 // String atom, number, NIL, *, % 2762 2761 default: 2763 // empty or one character 2762 // empty or one character 2764 2763 if ($str === '') { 2765 2764 break 2; … … 2876 2875 } 2877 2876 2878 private function escape($string) 2879 { 2880 return strtr($string, array('"'=>'\\"', '\\' => '\\\\')); 2881 } 2882 2883 private function unEscape($string) 2877 /** 2878 * Escapes a string when it contains special characters (RFC3501) 2879 * 2880 * @param string $string IMAP string 2881 * 2882 * @return string Escaped string 2883 * @todo String literals, lists 2884 */ 2885 static function escape($string) 2886 { 2887 // NIL 2888 if ($string === null) { 2889 return 'NIL'; 2890 } 2891 // empty string 2892 else if ($string === '') { 2893 return '""'; 2894 } 2895 // string: special chars: SP, CTL, (, ), {, %, *, ", \, ] 2896 else if (preg_match('/([\x00-\x20\x28-\x29\x7B\x25\x2A\x22\x5C\x5D\x7F]+)/', $string)) { 2897 return '"' . strtr($string, array('"'=>'\\"', '\\' => '\\\\')) . '"'; 2898 } 2899 2900 // atom 2901 return $string; 2902 } 2903 2904 static function unEscape($string) 2884 2905 { 2885 2906 return strtr($string, array('\\"'=>'"', '\\\\' => '\\'));
Note: See TracChangeset
for help on using the changeset viewer.
