Пример #1
0
 /**
  * Fetch message body of a specific message from the server
  *
  * @param  int    Message UID
  * @param  string Part number
  * @param  object rcube_message_part Part object created by get_structure()
  * @param  mixed  True to print part, ressource to write part contents in
  * @param  resource File pointer to save the message part
  * @return string Message/part body if not printed
  */
 function &get_message_part($uid, $part = 1, $o_part = NULL, $print = NULL, $fp = NULL)
 {
     // get part encoding if not provided
     if (!is_object($o_part)) {
         $structure_str = iil_C_FetchStructureString($this->conn, $this->mailbox, $uid, true);
         $structure = iml_GetRawStructureArray($structure_str);
         // error or message not found
         if (empty($structure)) {
             return false;
         }
         $part_type = iml_GetPartTypeCode($structure, $part);
         $o_part = new rcube_message_part();
         $o_part->ctype_primary = $part_type == 0 ? 'text' : ($part_type == 2 ? 'message' : 'other');
         $o_part->encoding = strtolower(iml_GetPartEncodingString($structure, $part));
         $o_part->charset = iml_GetPartCharset($structure, $part);
     }
     // TODO: Add caching for message parts
     if (!$part) {
         $part = 'TEXT';
     }
     $body = iil_C_HandlePartBody($this->conn, $this->mailbox, $uid, true, $part, $o_part->encoding, $print, $fp);
     if ($fp || $print) {
         return true;
     }
     // convert charset (if text or message part)
     if ($o_part->ctype_primary == 'text' || $o_part->ctype_primary == 'message') {
         // assume default if no charset specified
         if (empty($o_part->charset) || strtolower($o_part->charset) == 'us-ascii') {
             $o_part->charset = $this->default_charset;
         }
         $body = rcube_charset_convert($body, $o_part->charset);
     }
     return $body;
 }
Пример #2
0
 /**
  * Fetch message body of a specific message from the server
  *
  * @param  int    Message UID
  * @param  string Part number
  * @param  object rcube_message_part Part object created by get_structure()
  * @param  mixed  True to print part, ressource to write part contents in
  * @param  resource File pointer to save the message part
  * @return string Message/part body if not printed
  */
 function &get_message_part($uid, $part = 1, $o_part = NULL, $print = NULL, $fp = NULL)
 {
     if (!($msg_id = $this->_uid2id($uid))) {
         return FALSE;
     }
     // get part encoding if not provided
     if (!is_object($o_part)) {
         $structure_str = iil_C_FetchStructureString($this->conn, $this->mailbox, $msg_id);
         $structure = iml_GetRawStructureArray($structure_str);
         $part_type = iml_GetPartTypeCode($structure, $part);
         $o_part = new rcube_message_part();
         $o_part->ctype_primary = $part_type == 0 ? 'text' : ($part_type == 2 ? 'message' : 'other');
         $o_part->encoding = strtolower(iml_GetPartEncodingString($structure, $part));
         $o_part->charset = iml_GetPartCharset($structure, $part);
     }
     // TODO: Add caching for message parts
     if (!$part) {
         $part = 'TEXT';
     }
     if ($print) {
         $mode = $o_part->encoding == 'base64' ? 3 : ($o_part->encoding == 'quoted-printable' ? 1 : 2);
         $body = iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, $mode);
         // we have to decode the part manually before printing
         if ($mode == 1) {
             echo $this->mime_decode($body, $o_part->encoding);
             $body = true;
         }
     } else {
         if ($fp && $o_part->encoding == 'base64') {
             return iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, 3, $fp);
         } else {
             $body = iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, 1);
         }
         // decode part body
         if ($o_part->encoding) {
             $body = $this->mime_decode($body, $o_part->encoding);
         }
         // convert charset (if text or message part)
         if ($o_part->ctype_primary == 'text' || $o_part->ctype_primary == 'message') {
             // assume default if no charset specified
             if (empty($o_part->charset)) {
                 $o_part->charset = $this->default_charset;
             }
             $body = rcube_charset_convert($body, $o_part->charset);
         }
         if ($fp) {
             fwrite($fp, $body);
             return true;
         }
     }
     return $body;
 }