From cb2bc809ef29f349d38c89e202d821e67bb4c947 Mon Sep 17 00:00:00 2001 From: thomascube <thomas@roundcube.net> Date: Tue, 21 Sep 2010 14:47:55 -0400 Subject: [PATCH] Fix db_mode check in insert_id() --- program/include/rcube_imap.php | 75 ++++++++++++++++++------------------- 1 files changed, 37 insertions(+), 38 deletions(-) diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index cdc52a4..2151f5c 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -138,9 +138,10 @@ // write error log else if ($this->conn->error) { $this->error_code = $this->conn->errornum; - raise_error(array('code' => 403, 'type' => 'imap', - 'file' => __FILE__, 'line' => __LINE__, - 'message' => $this->conn->error), true, false); + if ($pass && $user) + raise_error(array('code' => 403, 'type' => 'imap', + 'file' => __FILE__, 'line' => __LINE__, + 'message' => $this->conn->error), true, false); } return false; @@ -155,8 +156,7 @@ */ function close() { - if ($this->conn && $this->conn->connected()) - $this->conn->close(); + $this->conn->close(); $this->write_cache(); } @@ -1704,14 +1704,22 @@ else $this->struct_charset = $this->_structure_charset($structure); + $headers->ctype = strtolower($headers->ctype); + // Here we can recognize malformed BODYSTRUCTURE and // 1. [@TODO] parse the message in other way to create our own message structure // 2. or just show the raw message body. // Example of structure for malformed MIME message: - // ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 2154 70 NIL NIL NIL) - if ($headers->ctype && $headers->ctype != 'text/plain' - && $structure[0] == 'text' && $structure[1] == 'plain') { - return false; + // ("text" "plain" NIL NIL NIL "7bit" 2154 70 NIL NIL NIL) + if ($headers->ctype && !is_array($structure[0]) && $headers->ctype != 'text/plain' + && strtolower($structure[0].'/'.$structure[1]) == 'text/plain') { + // we can handle single-part messages, by simple fix in structure (#1486898) + if (preg_match('/^(text|application)\/(.*)/', $headers->ctype, $m)) { + $structure[0] = $m[1]; + $structure[1] = $m[2]; + } + else + return false; } $struct = &$this->_structure_part($structure); @@ -1738,7 +1746,7 @@ * * @access private */ - function &_structure_part($part, $count=0, $parent='', $mime_headers=null, $raw_headers=null) + function &_structure_part($part, $count=0, $parent='', $mime_headers=null) { $struct = new rcube_message_part; $struct->mime_id = empty($parent) ? (string)$count : "$parent.$count"; @@ -1778,7 +1786,6 @@ if (!is_array($part[$i][0])) { $tmp_part_id = $struct->mime_id ? $struct->mime_id.'.'.($i+1) : $i+1; if (strtolower($part[$i][0]) == 'message' && strtolower($part[$i][1]) == 'rfc822') { - $raw_part_headers[] = $tmp_part_id; $mime_part_headers[] = $tmp_part_id; } else if (in_array('name', (array)$part[$i][2]) && (empty($part[$i][3]) || $part[$i][3]=='NIL')) { @@ -1794,11 +1801,6 @@ $mime_part_headers = $this->conn->fetchMIMEHeaders($this->mailbox, $this->_msg_id, $mime_part_headers); } - // we'll need a real content-type of message/rfc822 part - if ($raw_part_headers) { - $raw_part_headers = $this->conn->fetchMIMEHeaders($this->mailbox, - $this->_msg_id, $raw_part_headers, false); - } $struct->parts = array(); for ($i=0, $count=0; $i<count($part); $i++) { @@ -1806,7 +1808,7 @@ break; $tmp_part_id = $struct->mime_id ? $struct->mime_id.'.'.($i+1) : $i+1; $struct->parts[] = $this->_structure_part($part[$i], ++$count, $struct->mime_id, - $mime_part_headers[$tmp_part_id], $raw_part_headers[$tmp_part_id]); + $mime_part_headers[$tmp_part_id]); } return $struct; @@ -1898,24 +1900,24 @@ } $struct->headers = $this->_parse_headers($mime_headers) + $struct->headers; - // get real headers for message of type 'message/rfc822' + // get real content-type of message/rfc822 if ($struct->mimetype == 'message/rfc822') { - if (empty($raw_headers)) { - $raw_headers = $this->conn->fetchMIMEHeaders( - $this->mailbox, $this->_msg_id, (array)$struct->mime_id, false); - } - $struct->real_headers = $this->_parse_headers($raw_headers); - - // get real content-type of message/rfc822 - if (preg_match('/^([a-z0-9_\/-]+)/i', $struct->real_headers['content-type'], $matches)) { - $struct->real_mimetype = strtolower($matches[1]); + // single-part + if (!is_array($part[8][0])) + $struct->real_mimetype = strtolower($part[8][0] . '/' . $part[8][1]); + // multi-part + else { + for ($n=0; $n<count($part[8]); $n++) + if (!is_array($part[8][$n])) + break; + $struct->real_mimetype = 'multipart/' . strtolower($part[8][$n]); } } - } - if ($struct->ctype_primary == 'message') { - if (is_array($part[8]) && $di != 8 && empty($struct->parts)) - $struct->parts[] = $this->_structure_part($part[8], ++$count, $struct->mime_id); + if ($struct->ctype_primary == 'message' && empty($struct->parts)) { + if (is_array($part[8]) && $di != 8) + $struct->parts[] = $this->_structure_part($part[8], ++$count, $struct->mime_id); + } } // normalize filename property @@ -2237,11 +2239,8 @@ // make sure mailbox exists if ($this->mailbox_exists($mbox_name, true)) { - if ($is_file) { - $separator = rcmail::get_instance()->config->header_delimiter(); - $saved = $this->conn->appendFromFile($mailbox, $message, - $headers, $separator.$separator); - } + if ($is_file) + $saved = $this->conn->appendFromFile($mailbox, $message, $headers); else $saved = $this->conn->append($mailbox, $message); } @@ -3427,7 +3426,7 @@ $name = trim($val['name']); if (preg_match('/^[\'"]/', $name) && preg_match('/[\'"]$/', $name)) - $name = preg_replace(array('/^[\'"]/', '/[\'"]$/'), '', $name); + $name = trim($name, '\'"'); if ($name && $address && $name != $address) $string = sprintf('%s <%s>', preg_match("/$special_chars/", $name) ? '"'.addcslashes($name, '"').'"' : $name, $address); @@ -3459,7 +3458,7 @@ function decode_header($input, $remove_quotes=false) { $str = rcube_imap::decode_mime_string((string)$input, $this->default_charset); - if ($str{0}=='"' && $remove_quotes) + if ($str[0] == '"' && $remove_quotes) $str = str_replace('"', '', $str); return $str; -- Gitblit v1.9.1