Example #1
0
 /**
  * Fetch message body of a specific message from the server
  *
  * @param  int                $uid    Message UID
  * @param  string             $part   Part number
  * @param  rcube_message_part $o_part Part object created by get_structure()
  * @param  mixed              $print  True to print part, ressource to write part contents in
  * @param  resource           $fp     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 = $this->conn->fetchStructureString($this->mailbox, $uid, true);
         $structure = new rcube_mime_struct();
         // error or message not found
         if (!$structure->loadStructure($structure_str)) {
             return false;
         }
         $o_part = new rcube_message_part();
         $o_part->ctype_primary = strtolower($structure->getPartType($part));
         $o_part->encoding = strtolower($structure->getPartEncoding($part));
         $o_part->charset = $structure->getPartCharset($part);
     }
     // TODO: Add caching for message parts
     if (!$part) {
         $part = 'TEXT';
     }
     $body = $this->conn->handlePartBody($this->mailbox, $uid, true, $part, $o_part->encoding, $print, $fp);
     if ($fp || $print) {
         return true;
     }
     // convert charset (if text or message part) and part's charset is specified
     if ($body && $o_part->charset && preg_match('/^(text|message)$/', $o_part->ctype_primary)) {
         $body = rcube_charset_convert($body, $o_part->charset);
     }
     return $body;
 }