Get the message structure.
public getStructure ( ) : Horde_Mime_Part | ||
return | Horde_Mime_Part | $structure The base MIME part of the message. |
/** * Constructor * * @param Horde_Imap_Client_Base $imap The imap client object. * @param Horde_Imap_Client_Mailbox $mbox The mailbox object. * @param Horde_Imap_Client_Data_Fetch $data The data returned from a FETCH * must contain at least uid, * structure and flags. */ public function __construct(Horde_Imap_Client_Base $imap, Horde_Imap_Client_Mailbox $mbox, Horde_Imap_Client_Data_Fetch $data) { $this->_imap = $imap; $this->_message = new Horde_ActiveSync_Mime($data->getStructure()); $this->_uid = $data->getUid(); $this->_flags = $data->getFlags(); $this->_mbox = $mbox; $this->_data = $data; $this->_envelope = $data->getEnvelope(); }
/** * Accessor * * @param string $property The property. * * @return mixed */ public function &__get($property) { switch ($property) { case 'envelope': $e = $this->_data->getEnvelope(); return $e; case 'flags': $f = $this->_data->getFlags(); return $f; case 'uid': $u = $this->_data->getUid(); return $u; case 'basePart': if (empty($this->_basePart)) { $this->_basePart = new Horde_ActiveSync_Mime($this->_data->getStructure()); } return $this->_basePart; } throw new InvalidArgumentException(sprintf('The property %s of Horde_ActiveSync_Imap_Message does not exist', $property)); }
/** * Process a message again to add body and attachment data. * * @param \Horde_Imap_Client_Data_Fetch $basemessagedata The structure and part of the message body * @param string|\Horde_Imap_Client_Ids $messageid The Hore message Uid * @return \stdClass The current value of the messagedata */ private function process_message_data_body(\Horde_Imap_Client_Data_Fetch $basemessagedata, $messageid) { global $CFG; // Get the current mailbox. $mailbox = $this->get_mailbox(); // We need the structure at various points below. $structure = $basemessagedata->getStructure(); // Now fetch the rest of the message content. $query = new \Horde_Imap_Client_Fetch_Query(); $query->fullText(); // Fetch all of the message parts too. $typemap = $structure->contentTypeMap(); foreach ($typemap as $part => $type) { // The body of the part - attempt to decode it on the server. $query->bodyPart($part, array('decode' => true, 'peek' => true)); $query->bodyPartSize($part); } $messagedata = $this->client->fetch($mailbox, $query, array('ids' => $messageid))->first(); // Store the data for this message. $contentplain = ''; $contenthtml = ''; $attachments = array('inline' => array(), 'attachment' => array()); $plainpartid = $structure->findBody('plain'); $htmlpartid = $structure->findBody('html'); foreach ($typemap as $part => $type) { // Get the message data from the body part, and combine it with the structure to give a fully-formed output. $stream = $messagedata->getBodyPart($part, true); $partdata = $structure->getPart($part); $partdata->setContents($stream, array('usestream' => true)); if ($part === $plainpartid) { $contentplain = $this->process_message_part_body($messagedata, $partdata, $part); } else { if ($part === $htmlpartid) { $contenthtml = $this->process_message_part_body($messagedata, $partdata, $part); } else { if ($filename = $partdata->getName($part)) { if ($attachment = $this->process_message_part_attachment($messagedata, $partdata, $part, $filename)) { // The disposition should be one of 'attachment', 'inline'. // If an empty string is provided, default to 'attachment'. $disposition = $partdata->getDisposition(); $disposition = $disposition == 'inline' ? 'inline' : 'attachment'; $attachments[$disposition][] = $attachment; } } } } // We don't handle any of the other MIME content at this stage. } // The message ID should always be in the first part. $this->currentmessagedata->plain = $contentplain; $this->currentmessagedata->html = $contenthtml; $this->currentmessagedata->attachments = $attachments; return $this->currentmessagedata; }
/** * @return array */ public function getFlags() { $flags = $this->fetch->getFlags(); return ['unseen' => !in_array(Horde_Imap_Client::FLAG_SEEN, $flags), 'flagged' => in_array(Horde_Imap_Client::FLAG_FLAGGED, $flags), 'answered' => in_array(Horde_Imap_Client::FLAG_ANSWERED, $flags), 'deleted' => in_array(Horde_Imap_Client::FLAG_DELETED, $flags), 'draft' => in_array(Horde_Imap_Client::FLAG_DRAFT, $flags), 'forwarded' => in_array(Horde_Imap_Client::FLAG_FORWARDED, $flags), 'hasAttachments' => $this->hasAttachments($this->fetch->getStructure())]; }