- $local_body = $part['body'];
- if (isset($local_header['content-disposition']) && preg_match("/attachment/", $local_header['content-disposition'])) {
- $this->_add_attachment($part);
- } else if (isset($local_header['content-type']) && preg_match("@text/([^;]+);@", $local_header['content-type'], $format)) {
- array_push($this->messages, $part);
+ $local_body = $part['body'];
+ if (!$this->_split_multipart($local_header, $local_body)) {
+ $is_text = isset($local_header['content-type']) && preg_match("@text/([^;]+);@", $local_header['content-type'])
+ && (!isset($local_header['content-disposition']) || !preg_match('@attachment@', $local_header['content-disposition']));
+
+ // alternative ==> multiple formats for messages
+ if ($type == 'alternative' && $is_text) {
+ array_push($this->messages, $part);
+
+ // !alternative ==> une body, others are attachments
+ } else if ($is_text) {
+ if (count($this->messages) == 0) {
+ $this->body = $local_body;
+ foreach (array_keys($local_header) as $key) {
+ $this->header[$key] = $local_header[$key];
+ }
+ array_push($this->messages, $part);
+ } else {
+ $this->_add_attachment($part);
+ }
+ } else {
+ $this->_add_attachment($part);
+ }