X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Finclude%2Frcube_imap.php;h=9b65846bfa7184db218690a03ba5dbb3d55b05d3;hb=6dc2542287385920eb1cd666328aba4502206001;hp=e22bbfc579a99956fd91d7008a96d916e93c7ee3;hpb=4212156c5c79d2f58342feb0d3ed1893f177bcab;p=roundcube.git diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index e22bbfc..9b65846 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -16,7 +16,7 @@ | Author: Aleksander Machniak | +-----------------------------------------------------------------------+ - $Id: rcube_imap.php 4389 2011-01-04 11:16:54Z alec $ + $Id: rcube_imap.php 4516 2011-02-09 12:46:46Z alec $ */ @@ -148,9 +148,18 @@ class rcube_imap $this->options['port'] = $port; - if ($this->options['debug']) + if ($this->options['debug']) { $this->conn->setDebug(true, array($this, 'debug_handler')); + $this->options['ident'] = array( + 'name' => 'Roundcube Webmail', + 'version' => RCMAIL_VERSION, + 'php' => PHP_VERSION, + 'os' => PHP_OS, + 'command' => $_SERVER['REQUEST_URI'], + ); + } + $attempt = 0; do { $data = rcmail::get_instance()->plugins->exec_hook('imap_connect', @@ -2053,7 +2062,7 @@ class rcube_imap return false; } - $struct = &$this->_structure_part($structure); + $struct = &$this->_structure_part($structure, 0, '', $headers); $struct->headers = get_object_vars($headers); // don't trust given content-type @@ -2185,6 +2194,11 @@ class rcube_imap $struct->charset = $struct->ctype_parameters['charset']; } + // #1487700: workaround for lack of charset in malformed structure + if (empty($struct->charset) && !empty($mime_headers) && $mime_headers->charset) { + $struct->charset = $mime_headers->charset; + } + // read content encoding if (!empty($part[5]) && $part[5]!='NIL') { $struct->encoding = strtolower($part[5]); @@ -2233,7 +2247,11 @@ class rcube_imap $mime_headers = $this->conn->fetchPartHeader( $this->mailbox, $this->_msg_id, false, $struct->mime_id); } - $struct->headers = $this->_parse_headers($mime_headers) + $struct->headers; + + if (is_string($mime_headers)) + $struct->headers = $this->_parse_headers($mime_headers) + $struct->headers; + else if (is_object($mime_headers)) + $struct->headers = get_object_vars($mime_headers) + $struct->headers; // get real content-type of message/rfc822 if ($struct->mimetype == 'message/rfc822') { @@ -4691,10 +4709,13 @@ class rcube_imap private function _parse_address_list($str, $decode=true) { // remove any newlines and carriage returns before - $a = rcube_explode_quoted_string('[,;]', preg_replace( "/[\r\n]/", " ", $str)); + $str = preg_replace('/\r?\n(\s|\t)?/', ' ', $str); + + // extract list items, remove comments + $str = self::explode_header_string(',;', $str, true); $result = array(); - foreach ($a as $key => $val) { + foreach ($str as $key => $val) { $name = ''; $address = ''; $val = trim($val); @@ -4735,6 +4756,81 @@ class rcube_imap } + /** + * Explodes header (e.g. address-list) string into array of strings + * using specified separator characters with proper handling + * of quoted-strings and comments (RFC2822) + * + * @param string $separator String containing separator characters + * @param string $str Header string + * @param bool $remove_comments Enable to remove comments + * + * @return array Header items + */ + static function explode_header_string($separator, $str, $remove_comments=false) + { + $length = strlen($str); + $result = array(); + $quoted = false; + $comment = 0; + $out = ''; + + for ($i=0; $i<$length; $i++) { + // we're inside a quoted string + if ($quoted) { + if ($str[$i] == '"') { + $quoted = false; + } + else if ($str[$i] == '\\') { + if ($comment <= 0) { + $out .= '\\'; + } + $i++; + } + } + // we're inside a comment string + else if ($comment > 0) { + if ($str[$i] == ')') { + $comment--; + } + else if ($str[$i] == '(') { + $comment++; + } + else if ($str[$i] == '\\') { + $i++; + } + continue; + } + // separator, add to result array + else if (strpos($separator, $str[$i]) !== false) { + if ($out) { + $result[] = $out; + } + $out = ''; + continue; + } + // start of quoted string + else if ($str[$i] == '"') { + $quoted = true; + } + // start of comment + else if ($remove_comments && $str[$i] == '(') { + $comment++; + } + + if ($comment <= 0) { + $out .= $str[$i]; + } + } + + if ($out && $comment <= 0) { + $result[] = $out; + } + + return $result; + } + + /** * This is our own debug handler for the IMAP connection * @access public