getPart() public method

Deprecation: Use array access instead.
public getPart ( $id )
Exemplo n.º 1
0
Arquivo: Mime.php Projeto: horde/horde
 /**
  * Determines if a MIME type is an attachment.
  * For our purposes, an attachment is any MIME part that can be
  * downloaded by itself (i.e. all the data needed to view the part is
  * contained within the download data).
  *
  * @param string $id         The MIME Id for the part we are checking.
  * @param string $mime_type  The MIME type.
  *
  * @return boolean  True if an attachment.
  * @todo Pass a single mime part as parameter.
  */
 public function isAttachment($id, $mime_type)
 {
     switch ($mime_type) {
         case 'text/plain':
             if (!($this->_base->findBody('plain') == $id)) {
                 return true;
             }
             return false;
         case 'text/html':
             if (!($this->_base->findBody('html') == $id)) {
                 return true;
             }
             return false;
         case 'application/pkcs7-signature':
         case 'application/x-pkcs7-signature':
             return false;
     }
     if ($this->_base->getPart($id)->getDisposition() == 'attachment') {
         return true;
     }
     list($ptype, ) = explode('/', $mime_type, 2);
     switch ($ptype) {
         case 'message':
             return in_array($mime_type, array('message/rfc822', 'message/disposition-notification'));
         case 'multipart':
             return false;
         default:
             return true;
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param Horde_Mime_Part $mime_part  A MIME part object. Must be of
  *                                    type multipart/related.
  */
 public function __construct(Horde_Mime_Part $mime_part)
 {
     if ($mime_part->getType() != 'multipart/related') {
         throw new InvalidArgumentException('MIME part must be of type multipart/related');
     }
     $ids = array_keys($mime_part->contentTypeMap());
     $related_id = $mime_part->getMimeId();
     $id = null;
     /* Build a list of parts -> CIDs. */
     foreach ($ids as $val) {
         if (strcmp($related_id, $val) !== 0 && ($cid = $mime_part->getPart($val)->getContentId())) {
             $this->_cids[$val] = $cid;
         }
     }
     /* Look at the 'start' parameter to determine which part to start
      * with. If no 'start' parameter, use the first part (RFC 2387
      * [3.1]). */
     $start = $mime_part->getContentTypeParameter('start');
     if (!empty($start)) {
         $id = $this->cidSearch($start);
     }
     if (empty($id)) {
         reset($ids);
         $id = next($ids);
     }
     $this->_start = $id;
 }
Exemplo n.º 3
0
 /**
  * Return the MIME part of the iCalendar attachment, if available.
  *
  * @return mixed  The mime part, if present, false otherwise.
  */
 public function hasiCalendar()
 {
     if (!$this->hasAttachments()) {
         return false;
     }
     foreach ($this->_base->contentTypeMap() as $id => $type) {
         if ($type == 'text/calendar') {
             return $this->_base->getPart($id);
         }
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Fetch a part of a MIME message.
  *
  * @param integer $id     The MIME index of the part requested.
  * @param array $options  Additional options:
  *   - length: (integer) If set, only download this many bytes of the
  *             bodypart from the server.
  *             DEFAULT: All data is retrieved.
  *   - nocontents: (boolean) If true, don't add the contents to the part
  *                 DEFAULT: Contents are added to the part
  *
  * @return Horde_Mime_Part  The raw MIME part asked for (reference).
  */
 public function getMIMEPart($id, $options = array())
 {
     $this->_buildMessage();
     $part = $this->_message->getPart($id);
     /* Ticket #9201: Treat 'ISO-8859-1' as 'windows-1252'. 1252 has some
      * characters (e.g. euro sign, back quote) not in 8859-1. There
      * shouldn't be any issue doing this since the additional code points
      * in 1252 don't map to anything in 8859-1. */
     if ($part && strcasecmp($part->getCharset(), 'ISO-8859-1') === 0) {
         $part->setCharset('windows-1252');
     }
     /* Don't download contents of entire body if ID == 0 (indicating the
      * body of the main multipart message).  I'm pretty sure we never
      * want to download the body of that part here. */
     if (!empty($id) && !is_null($part) && substr($id, -2) != '.0' && empty($options['nocontents']) && $this->_indices && !$part->getContents(array('stream' => true))) {
         $body = $this->getBodyPart($id, array('decode' => true, 'length' => empty($options['length']) ? null : $options['length'], 'stream' => true));
         $part->setContents($body->data, array('encoding' => $body->decode, 'usestream' => true));
     }
     return $part;
 }
Exemplo n.º 5
0
 /**
  * Build the HTML part of a SMARTREPLY or SMARTFORWARD
  *
  * @param string $html_id                The MIME part id of the html part of
  *                                       $base_part.
  * @param Horde_Mime_Part $mime_message  The MIME part of the email to be
  *                                       sent.
  * @param array $body_data @see Horde_ActiveSync_Imap_Message::getMessageBodyData()
  * @param Horde_Mime_Part $base_part     The base MIME part of the source
  *                                       message for a SMART request.
  *
  * @return string  The plaintext part of the email message that is being sent.
  */
 protected function _getHtmlPart($html_id, $mime_message, $body_data, $base_part)
 {
     if (!($id = $mime_message->findBody('html'))) {
         $smart_text = self::text2html(Horde_ActiveSync_Utils::ensureUtf8($mime_message->getPart($mime_message->findBody('plain'))->getContents(), $mime_message->getCharset()));
     } else {
         $smart_text = Horde_ActiveSync_Utils::ensureUtf8($mime_message->getPart($id)->getContents(), $mime_message->getCharset());
     }
     if ($this->_forward) {
         return $smart_text . $this->_forwardText($body_data, $base_part->getPart($html_id), true);
     }
     return $smart_text . $this->_replyText($body_data, $base_part->getPart($html_id), true);
 }
Exemplo n.º 6
0
 /**
  * Determine the object type based on a specific MIME part that carries a Kolab object.
  *
  * @param Horde_Mime_Part $structure A structural representation of the mime message.
  * @param string $id The MIME part carrying the Kolab object.
  *
  * @return string|boolean The object type or false if no matching object type was found.
  */
 public static function getObjectTypeFromMimePart(Horde_Mime_Part $structure, $id)
 {
     return self::getObjectTypeFromMimeType($structure->getPart($id)->getType());
 }