| | |
| | | |
| | | |
| | | /** |
| | | * Determine if the message contains a HTML part |
| | | * Determine if the message contains a HTML part. This must to be |
| | | * a real part not an attachment (or its part) |
| | | * This must to be |
| | | * a real part not an attachment (or its part) |
| | | * |
| | | * @param bool $recursive Enables checking in all levels of the structure |
| | | * @param bool $enriched Enables checking for text/enriched parts too |
| | | * @param bool $enriched Enables checking for text/enriched parts too |
| | | * |
| | | * @return bool True if a HTML is available, False if not |
| | | */ |
| | | function has_html_part($recursive = true, $enriched = false) |
| | | function has_html_part($enriched = false) |
| | | { |
| | | // check all message parts |
| | | foreach ($this->parts as $part) { |
| | | foreach ($this->mime_parts as $part) { |
| | | if ($part->mimetype == 'text/html' || ($enriched && $part->mimetype == 'text/enriched')) { |
| | | // Level check, we'll skip e.g. HTML attachments |
| | | if (!$recursive) { |
| | | $level = explode('.', $part->mime_id); |
| | | // Skip if part is an attachment, don't use is_attachment() here |
| | | if ($part->filename) { |
| | | continue; |
| | | } |
| | | |
| | | // Skip if level too deep or part has a file name |
| | | if (count($level) > 2 || $part->filename) { |
| | | continue; |
| | | $level = explode('.', $part->mime_id); |
| | | |
| | | // Check if the part belongs to higher-level's alternative/related |
| | | while (array_pop($level) !== null) { |
| | | if (!count($level)) { |
| | | return true; |
| | | } |
| | | |
| | | // HTML part can be on the lower level, if not... |
| | | if (count($level) > 1) { |
| | | array_pop($level); |
| | | $parent = $this->mime_parts[join('.', $level)]; |
| | | // ... parent isn't multipart/alternative or related |
| | | if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') { |
| | | continue; |
| | | } |
| | | $parent = $this->mime_parts[join('.', $level)]; |
| | | if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') { |
| | | continue 2; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | if ($part->size) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Determine if the message contains a text/plain part. This must to be |
| | | * a real part not an attachment (or its part) |
| | | * |
| | | * @return bool True if a plain text part is available, False if not |
| | | */ |
| | | function has_text_part() |
| | | { |
| | | // check all message parts |
| | | foreach ($this->mime_parts as $part) { |
| | | if ($part->mimetype == 'text/plain') { |
| | | // Skip if part is an attachment, don't use is_attachment() here |
| | | if ($part->filename) { |
| | | continue; |
| | | } |
| | | |
| | | $level = explode('.', $part->mime_id); |
| | | |
| | | // Check if the part belongs to higher-level's alternative/related |
| | | while (array_pop($level) !== null) { |
| | | if (!count($level)) { |
| | | return true; |
| | | } |
| | | |
| | | $parent = $this->mime_parts[join('.', $level)]; |
| | | if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') { |
| | | continue 2; |
| | | } |
| | | } |
| | | |
| | | if ($part->size) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | foreach ($this->inline_parts as $inline_object) { |
| | | $part_url = $this->get_part_url($inline_object->mime_id, true); |
| | | if ($inline_object->content_id) |
| | | if (isset($inline_object->content_id)) |
| | | $a_replaces['cid:'.$inline_object->content_id] = $part_url; |
| | | if ($inline_object->content_location) { |
| | | $a_replaces[$inline_object->content_location] = $part_url; |