diff options
author | alecpl <alec@alec.pl> | 2011-10-26 11:35:00 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2011-10-26 11:35:00 +0000 |
commit | 8a6503a23c48470f4bc98a21bde61490e0836bda (patch) | |
tree | 0fa0eb3e525bfa264443d16b79dc441487cc95f3 | |
parent | 2db2ef3ec95f81a04acd5c143a39f0d8c06c4cae (diff) |
- Fix getting message part data from structure, fixes r5363
-rw-r--r-- | program/include/rcube_imap.php | 10 | ||||
-rw-r--r-- | program/include/rcube_imap_generic.php | 70 |
2 files changed, 41 insertions, 39 deletions
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index 834a63938..d2f954733 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2376,14 +2376,16 @@ class rcube_imap */ function &get_message_part($uid, $part=1, $o_part=NULL, $print=NULL, $fp=NULL, $skip_charset_conv=false) { - // get part encoding if not provided + // get part data if not provided if (!is_object($o_part)) { $structure = $this->conn->getStructure($this->mailbox, $uid, true); + $part_data = rcube_imap_generic::getStructurePartData($structure, $part); $o_part = new rcube_message_part; - $o_part->ctype_primary = strtolower(rcube_imap_generic::getStructurePartType($structure, $part)); - $o_part->encoding = strtolower(rcube_imap_generic::getStructurePartEncoding($structure, $part)); - $o_part->charset = rcube_imap_generic::getStructurePartCharset($structure, $part); + $o_part->ctype_primary = $part_data['type']; + $o_part->encoding = $part_data['encoding']; + $o_part->charset = $part_data['charset']; + $o_part->size = $part_data['size']; } if ($o_part && $o_part->size) { diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php index ecd2949d7..5c7a41c73 100644 --- a/program/include/rcube_imap_generic.php +++ b/program/include/rcube_imap_generic.php @@ -3176,47 +3176,48 @@ class rcube_imap_generic return false; } - static function getStructurePartType($structure, $part) + /** + * Returns data of a message part according to specified structure. + * + * @param array $structure Message structure (getStructure() result) + * @param string $part Message part identifier + * + * @return array Part data as hash array (type, encoding, charset, size) + */ + static function getStructurePartData($structure, $part) { $part_a = self::getStructurePartArray($structure, $part); - if (!empty($part_a)) { - if (is_array($part_a[0])) - return 'multipart'; - else if ($part_a[0]) - return $part_a[0]; - } + $data = array(); - return 'other'; - } + if (empty($part_a)) { + return $data; + } - static function getStructurePartEncoding($structure, $part) - { - $part_a = self::getStructurePartArray($structure, $part); - if ($part_a) { - if (!is_array($part_a[0])) - return $part_a[5]; - } + // content-type + if (is_array($part_a[0])) { + $data['type'] = 'multipart'; + } + else { + $data['type'] = strtolower($part_a[0]); - return ''; - } + // encoding + $data['encoding'] = strtolower($part_a[5]); - static function getStructurePartCharset($structure, $part) - { - $part_a = self::getStructurePartArray($structure, $part); - if ($part_a) { - if (is_array($part_a[0])) - return ''; - else { - if (is_array($part_a[2])) { - $name = ''; - while (list($key, $val) = each($part_a[2])) - if (strcasecmp($val, 'charset') == 0) - return $part_a[2][$key+1]; - } - } - } + // charset + if (is_array($part_a[2])) { + while (list($key, $val) = each($part_a[2])) { + if (strcasecmp($val, 'charset') == 0) { + $data['charset'] = $part_a[2][$key+1]; + break; + } + } + } + } - return ''; + // size + $data['size'] = intval($part_a[6]); + + return $data; } static function getStructurePartArray($a, $part) @@ -3249,7 +3250,6 @@ class rcube_imap_generic } } - /** * Creates next command identifier (tag) * |