Aleksander Machniak
2015-12-17 c82d09a052b929be2087a73d95be8657a33027b3
program/steps/mail/compose.inc
@@ -749,11 +749,9 @@
        if (!empty($MESSAGE->parts)) {
            // collect IDs of message/rfc822 parts
            if ($compose_mode == RCUBE_COMPOSE_EDIT || $compose_mode == RCUBE_COMPOSE_DRAFT) {
                foreach ($MESSAGE->attachments as $part) {
                    if ($part->mimetype == 'message/rfc822') {
                        $messages[] = $part->mime_id;
                    }
            foreach ($MESSAGE->mime_parts as $part) {
                if ($part->mimetype == 'message/rfc822') {
                    $messages[] = $part->mime_id;
                }
            }
@@ -763,7 +761,7 @@
                    continue;
                }
                // skip all content parts inside the message/rfc822 part in DRAFT/EDIT mode
                // skip all content parts inside the message/rfc822 part
                foreach ($messages as $mimeid) {
                    if (strpos($part->mime_id, $mimeid . '.') === 0) {
                        continue 2;
@@ -1180,6 +1178,10 @@
    $messages = array();
    foreach ((array)$message->mime_parts as $pid => $part) {
        if ($part->mimetype == 'message/rfc822') {
            $messages[] = $part->mime_id;
        }
        if ($part->disposition == 'attachment' || ($part->disposition == 'inline' && $bodyIsHtml) || $part->filename) {
            // skip parts that aren't valid attachments
            if ($part->ctype_primary == 'multipart' || $part->mimetype == 'application/ms-tnef') {
@@ -1196,23 +1198,10 @@
                continue;
            }
            // skip message/rfc822 attachments on forwards (#1489214)
            // Thunderbird when forwarding in inline mode displays such attachments
            // and skips any attachments from inside of such part, this however
            // skipped e.g. images used in HTML body or other attachments. So,
            // better to skip .eml attachments but not their content (included files).
            if ($part->mimetype == 'message/rfc822') {
                if ($compose_mode == RCUBE_COMPOSE_FORWARD) {
                    continue;
                }
                $messages[] = $part->mime_id;
            }
            else if ($compose_mode != RCUBE_COMPOSE_FORWARD) {
                // skip attachments included in message/rfc822 attachment (#1486487)
                foreach ($messages as $mimeid) {
                    if (strpos($part->mime_id, $mimeid . '.') === 0) {
                        continue 2;
                    }
            // skip attachments included in message/rfc822 attachment (#1486487, #1490607)
            foreach ($messages as $mimeid) {
                if (strpos($part->mime_id, $mimeid . '.') === 0) {
                    continue 2;
                }
            }
@@ -1244,9 +1233,22 @@
{
    global $RCMAIL, $COMPOSE;
    $cid_map = array();
    $cid_map  = array();
    $messages = array();
    foreach ((array)$message->mime_parts as $pid => $part) {
        if ($part->mimetype == 'message/rfc822') {
            $messages[] = $part->mime_id;
        }
        if (($part->content_id || $part->content_location) && $part->filename) {
            // skip attachments included in message/rfc822 attachment (#1486487, #1490607)
            foreach ($messages as $mimeid) {
                if (strpos($part->mime_id, $mimeid . '.') === 0) {
                    continue 2;
                }
            }
            if ($attachment = rcmail_save_attachment($message, $pid)) {
                $COMPOSE['attachments'][$attachment['id']] = $attachment;
                $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',