Services/AzineTwigSwiftMailer.php
private function removeUnreferecedEmbededItemsFromMessage(\Swift_Message $message, $params, $htmlBody)
    {
        foreach ($params as $key => $value) {
            // remove unreferenced attachments from contentItems too.
            if ('contentItems' === $key) {
                foreach ($value as $contentItemParams) {
                    $message = $this->removeUnreferecedEmbededItemsFromMessage($message, $contentItemParams, $htmlBody);
                }
            } else {
                // check if the embeded items are referenced in the templates
                $isEmbededItem = is_string($value) && 1 == preg_match($this->encodedItemIdPattern, $value);

                if ($isEmbededItem && false === stripos($htmlBody, $value)) {
                    // remove unreferenced items
                    $children = array();

                    foreach ($message->getChildren() as $attachment) {
                        if ('cid:'.$attachment->getId() != $value) {
                            $children[] = $attachment;
                        }
                    }

                    $message->setChildren($children);
                }
            }
        }

        return $message;
    }
private function removeUnreferecedEmbededItemsFromMessage(\Swift_Message $message, $params, $htmlBody)
    {
        foreach ($params as $key => $value) {
            // remove unreferenced attachments from contentItems too.
            if ('contentItems' === $key) {
                foreach ($value as $contentItemParams) {
                    $message = $this->removeUnreferecedEmbededItemsFromMessage($message, $contentItemParams, $htmlBody);
                }
            } else {
                // check if the embeded items are referenced in the templates
                $isEmbededItem = is_string($value) && 1 == preg_match($this->encodedItemIdPattern, $value);

                if ($isEmbededItem && false === stripos($htmlBody, $value)) {
                    // remove unreferenced items
                    $children = array();

                    foreach ($message->getChildren() as $attachment) {
                        if ('cid:'.$attachment->getId() != $value) {
                            $children[] = $attachment;
                        }
                    }

                    $message->setChildren($children);
                }
            }
        }

        return $message;
    }
private function removeUnreferecedEmbededItemsFromMessage ( \ Swift_Message $ message , $ params , $ htmlBody ) { foreach ( $ params as $ key => $ value ) { // remove unreferenced attachments from contentItems too. if ( 'contentItems' === $ key ) { foreach ( $ value as $ contentItemParams ) { $ message = $ this -> removeUnreferecedEmbededItemsFromMessage ( $ message , $ contentItemParams , $ htmlBody ) ; } } else { // check if the embeded items are referenced in the templates $ isEmbededItem = is_string ( $ value ) && 1 == preg_match ( $ this -> encodedItemIdPattern , $ value ) ; if ( $ isEmbededItem && false === stripos ( $ htmlBody , $ value ) ) { // remove unreferenced items $ children = array ( ) ; foreach ( $ message -> getChildren ( ) as $ attachment ) { if ( 'cid:' . $ attachment -> getId ( ) != $ value ) { $ children [ ] = $ attachment ; } } $ message -> setChildren ( $ children ) ; } } } return $ message ; }
Remove all Embeded Attachments that are not referenced in the html-body from the message
to avoid using unneccary bandwidth.

@param \Swift_Message $message
@param array          $params   the parameters used to render the html
@param string         $htmlBody

@return \Swift_Message
Remove all Embeded Attachments that are not referenced in the html - body from the message to avoid using unneccary bandwidth .