Beispiel #1
0
 /**
  * This function returns the data of the attachment. Combined with getMimeType() it can be used to directly output
  * data to a browser.
  *
  * @return string
  */
 public function getData()
 {
     if (!isset($this->data)) {
         $message_body = isset($this->part_id) ? $this->imap->fetchBody($this->imap_stream, $this->message_id, $this->part_id, FT_UID) : $this->imap->body($this->imap_stream, $this->message_id, FT_UID);
         $message_body = Message::decode($message_body, $this->encoding);
         $this->data = $message_body;
     }
     return $this->data;
 }
Beispiel #2
0
 /**
  * This function takes in a structure and identifier and processes that part of the message. If that portion of the
  * message has its own subparts, those are recursively processed using this function.
  *
  * @param \stdClass $structure
  * @param string $part_identifier
  *
  * @todoa process attachments.
  */
 protected function processStructure($structure, $part_identifier = null)
 {
     $parameters = self::getParametersFromStructure($structure);
     if (isset($parameters['name']) || isset($parameters['filename'])) {
         $attachment = new Attachment($this, $structure, $part_identifier);
         $this->attachments[] = $attachment;
     } elseif ($structure->type == 0 || $structure->type == 1) {
         $message_body = isset($part_identifier) ? $this->imap->fetchBody($this->imap_stream, $this->uid, $part_identifier, FT_UID) : $this->imap->body($this->imap_stream, $this->uid, FT_UID);
         $message_body = self::decode($message_body, $structure->encoding);
         if (!empty($parameters['charset']) && $parameters['charset'] !== $this->charset) {
             $message_body = iconv($parameters['charset'], $this->charset, $message_body);
         }
         if (strtolower($structure->subtype) == 'plain' || $structure->type == 1) {
             if (isset($this->plaintext_message)) {
                 $this->plaintext_message .= PHP_EOL . PHP_EOL;
             } else {
                 $this->plaintext_message = '';
             }
             $this->plaintext_message .= trim($message_body);
         } else {
             if (isset($this->html_message)) {
                 $this->html_message .= '<br><br>';
             } else {
                 $this->html_message = '';
             }
             $this->html_message .= $message_body;
         }
     }
     if (isset($structure->parts)) {
         // multipart: iterate through each part
         foreach ($structure->parts as $partIndex => $part) {
             $partId = $partIndex + 1;
             if (isset($part_identifier)) {
                 $partId = $part_identifier . '.' . $partId;
             }
             $this->processStructure($part, $partId);
         }
     }
 }