Prepares the mail HTML/text content.
971056
protected function prepareContent()
    {
        $html = $this->getHtmlContent();

        if (class_exists("\\DOMDocument")) {
            $doc = new \DOMDocument();
            $doc->loadHTML($html);
        } else {
            throw new \RuntimeException("Required extension 'dom' seems to be missing.");
        }

        // Extract styles and remove style tags (optionally added again later).
        //
        // IMPORTANT: The style nodes need to be saved in an array first, or
        //            the replacement won't work correctly.
        $styleString = "";
        $styleNodes = [];
        foreach($doc->getElementsByTagName('style') as $styleNode) {
            $styleNodes[] = $styleNode;
        }
        foreach($styleNodes as $styleNode) {
            $skip = false;

            // Check if type is 'text/css' (defaults to it if not)
            $typeAttribute = $styleNode->attributes->getNamedItem("type");
            if ($typeAttribute !== null && (string)$typeAttribute->nodeValue !== "text/css") {
                $skip = true;
            }

            // Check media type is allowed (defaults to 'all')
            if ($skip === false) {
                $mediaAttribute = $styleNode->attributes->getNamedItem("media");
                if ($mediaAttribute !== null) {
                    $mediaAttribute = str_replace(" ", "", (string)$mediaAttribute->nodeValue);
                    $mediaTypes = explode(",", $mediaAttribute);
                    if (!in_array("all", $mediaTypes) && !in_array("screen", $mediaTypes)) {
                        $skip = true;
                    }
                }
            }

            // Add CSS if allowed
            if ($skip === false) {
                $styleString .= $styleNode->nodeValue . "\r\n";
            }

            $styleNode->parentNode->removeChild($styleNode);
        }

        // Prepare some variables
        $xpath = new \DOMXpath($doc);
        $reader = new CssString($styleString);
        $reader->setEnvironmentEncoding($this->getCharset());
        $rules = $reader->getStyleSheet()->getRules();

        // Set pseudo classes that can be set in a style attribute
        // and that are supported by the Symfony CssSelector (doesn't support CSS4 yet).
        $allowedPseudoClasses = [
            StyleSelector::PSEUDO_CLASS_FIRST_CHILD,
            StyleSelector::PSEUDO_CLASS_ROOT,
            StyleSelector::PSEUDO_CLASS_NTH_CHILD,
            StyleSelector::PSEUDO_CLASS_NTH_LAST_CHILD,
            StyleSelector::PSEUDO_CLASS_NTH_OF_TYPE,
            StyleSelector::PSEUDO_CLASS_NTH_LAST_OF_TYPE,
            StyleSelector::PSEUDO_CLASS_LAST_CHILD,
            StyleSelector::PSEUDO_CLASS_FIRST_OF_TYPE,
            StyleSelector::PSEUDO_CLASS_LAST_OF_TYPE,
            StyleSelector::PSEUDO_CLASS_ONLY_CHILD,
            StyleSelector::PSEUDO_CLASS_ONLY_OF_TYPE,
            StyleSelector::PSEUDO_CLASS_EMPTY,
            StyleSelector::PSEUDO_CLASS_NOT,
        ];

        // Extract all relevant style declarations
        $selectors = [];
        foreach ($this->getRelevantStyleRules($rules) as $styleRule) {
            foreach ($styleRule->getSelectors() as $selector) {
                // Check if the selector contains pseudo classes/elements that cannot
                // be mapped to elements
                $skip = false;
                foreach($selector->getPseudoClasses() as $pseudoClass) {
                    if (!in_array($pseudoClass, $allowedPseudoClasses)) {
                        $skip = true;
                        break;
                    }
                }
                if ($skip === false) {
                    $specificity = $selector->getSpecificity();
                    if (!isset($selectors[$specificity])) {
                        $selectors[$specificity] = [];
                    }
                    $selectorString = $selector->getValue();
                    if (!isset($selectors[$specificity][$selectorString])) {
                        $selectors[$specificity][$selectorString] = [];
                    }
                    foreach ($styleRule->getDeclarations() as $declaration) {
                        $selectors[$specificity][$selectorString][] = $declaration;
                    }
                }
            }
        }

        // Get all specificity values (to process the declarations in the correct order,
        // without sorting the array by key, which perhaps could result in a changed
        // order of selectors within the specificity).
        $specificityKeys = array_keys($selectors);
        sort($specificityKeys);

        // Temporary remove all existing style attributes, because they always have the highest priority
        // and are added again after all styles have been applied to the elements
        $elements = $xpath->query("descendant-or-self::*[@style]");
        /** @var \DOMElement $element */
        foreach ($elements as $element) {
            if ($element->attributes !== null) {
                $styleAttribute = $element->attributes->getNamedItem("style");

                $styleValue = "";
                if ($styleAttribute !== null) {
                    $styleValue = (string)$styleAttribute->nodeValue;
                }

                if ($styleValue !== "") {
                    $element->setAttribute('data-pre-mailer-original-style', $styleValue);
                    $element->removeAttribute('style');
                }
            }
        }

        // Process all style declarations in the correct order
        foreach ($specificityKeys as $specificityKey) {
            /** @var StyleDeclaration[] $declarations */
            foreach ($selectors[$specificityKey] as $selectorString => $declarations) {
                $xpathQuery = CssSelector::toXPath($selectorString);
                $elements = $xpath->query($xpathQuery);
                /** @var \DOMElement $element */
                foreach ($elements as $element) {
                    if ($element->attributes !== null) {
                        $styleAttribute = $element->attributes->getNamedItem("style");

                        $styleValue = "";
                        if ($styleAttribute !== null) {
                            $styleValue = (string)$styleAttribute->nodeValue;
                        }

                        $concat = ($styleValue === "") ? "" : ";";
                        foreach ($declarations as $declaration) {
                            $styleValue .= $concat . $declaration->getProperty() . ":" . $declaration->getValue();
                            $concat = ";";
                        }

                        $element->setAttribute('style', $styleValue);
                    }
                }
            }
        }

        // Add temporarily removed style attributes again, after all styles have been applied to the elements
        $elements = $xpath->query("descendant-or-self::*[@data-pre-mailer-original-style]");
        /** @var \DOMElement $element */
        foreach ($elements as $element) {
            if ($element->attributes !== null) {
                $styleAttribute = $element->attributes->getNamedItem("style");
                $styleValue = "";
                if ($styleAttribute !== null) {
                    $styleValue = (string)$styleAttribute->nodeValue;
                }

                $originalStyleAttribute = $element->attributes->getNamedItem("data-pre-mailer-original-style");
                $originalStyleValue = "";
                if ($originalStyleAttribute !== null) {
                    $originalStyleValue = (string)$originalStyleAttribute->nodeValue;
                }

                if ($styleValue !== "" || $originalStyleValue !== "") {
                    $styleValue = ($styleValue !== "" ? $styleValue . ";" : "") . $originalStyleValue;
                    $element->setAttribute('style', $styleValue);
                    $element->removeAttribute('data-pre-mailer-original-style');
                }
            }
        }

        // Optionally remove class attributes in HTML tags
        $optionHtmlClasses = $this->getOption(self::OPTION_HTML_CLASSES);
        if ($optionHtmlClasses === self::OPTION_HTML_CLASSES_REMOVE) {
            $nodesWithClass = [];
            foreach ($xpath->query('descendant-or-self::*[@class]') as $nodeWithClass) {
                $nodesWithClass[] = $nodeWithClass;
            }
            /** @var \DOMElement $nodeWithClass */
            foreach ($nodesWithClass as $nodeWithClass) {
                $nodeWithClass->removeAttribute('class');
            }
        }

        // Optionally remove HTML comments
        $optionHtmlComments = $this->getOption(self::OPTION_HTML_COMMENTS);
        if ($optionHtmlComments === self::OPTION_HTML_COMMENTS_REMOVE) {
            $commentNodes = [];
            foreach ($xpath->query('//comment()') as $comment) {
                $commentNodes[] = $comment;
            }
            foreach ($commentNodes as $commentNode) {
                $commentNode->parentNode->removeChild($commentNode);
            }
        }

        // Write XPath document back to DOM document
        $newDoc = $xpath->document;

        // Generate text version (before adding the styles again)
        $this->text = $this->prepareText($newDoc);

        // Optionally add styles tag to the HEAD or the BODY of the document
        $optionStyleTag = $this->getOption(self::OPTION_STYLE_TAG);
        if ($optionStyleTag === self::OPTION_STYLE_TAG_BODY || $optionStyleTag === self::OPTION_STYLE_TAG_HEAD) {
            $cssWriterClass = $this->getOption(self::OPTION_CSS_WRITER_CLASS);
            /** @var WriterAbstract $cssWriter */
            $cssWriter = new $cssWriterClass($reader->getStyleSheet());
            $styleNode = $newDoc->createElement("style");
            $styleNode->nodeValue = $cssWriter->getContent();

            if ($optionStyleTag === self::OPTION_STYLE_TAG_BODY) {
                /** @var \DOMNode $bodyNode */
                foreach($newDoc->getElementsByTagName('body') as $bodyNode) {
                    $bodyNode->insertBefore($styleNode, $bodyNode->firstChild);
                    break;
                }
            } elseif ($optionStyleTag === self::OPTION_STYLE_TAG_HEAD) {
                /** @var \DOMNode $headNode */
                foreach($newDoc->getElementsByTagName('head') as $headNode) {
                    $headNode->appendChild($styleNode);
                    break;
                }
            }
        }

        // Generate HTML version
        $this->html = $newDoc->saveHTML();
    }
802110
public function renderContentBegin()
    {
        echo CHtml::openTag('div', $this->htmlContentOptions);
        if (!empty($this->content)) {
            echo $this->content;
        }
    }
171739
def html_page(title="Page Title", body=""):
    """"""
    html = "<html>\n<head><title>%s</title></head>\n<body>\n" % (title)
    html += "<h1>%s</h1>\n" % (title)
    html += body
    html += "</body>\n</html>\n"
    return html
792695
def handle(self, *args, **options):
        """"""
        if options['clean']:
            clean()

        if options['local']:
            local()

        if options['remote']:
            results = remote()
            render = lambda t: render_to_string(t, results)
            if options['notify']:
                send_mail(
                    options['subject'],
                    render('summary.txt'),
                    options['from'],
                    [options['notify']],
                    html_message=render('summary.html'),
                    fail_silently=False,
                )
986091
protected function prepareMessageBody()
    {
        $attachments = $this->getSectionAttachments();
        if ($attachments) {
            $this->appendHeaderFields($this->contentInfoArray('multipart/mixed'));
            if (!empty($this->_text_plain) && !empty($this->_text_html)) {
                $this->_body = $this->boundaryDelimiterLine('multipart/mixed')
                            . $this->contentInfoString('multipart/alternative')
                            . $this->getSectionMultipartAlternative()
                            . $attachments
                ;
            } elseif (!empty($this->_text_plain)) {
                $this->_body = $this->boundaryDelimiterLine('multipart/mixed')
                            . $this->contentInfoString('text/plain')
                            . $this->getSectionTextPlain()
                            . $attachments
                ;
            } elseif (!empty($this->_text_html)) {
                $this->_body = $this->boundaryDelimiterLine('multipart/mixed')
                            . $this->contentInfoString('text/html')
                            . $this->getSectionTextHtml()
                            . $attachments
                ;
            } else {
                $this->_body = $attachments;
            }
            $this->_body .= $this->finalBoundaryDelimiterLine('multipart/mixed');
        } elseif (!empty($this->_text_plain) && !empty($this->_text_html)) {
            $this->appendHeaderFields($this->contentInfoArray('multipart/alternative'));
            $this->_body = $this->getSectionMultipartAlternative();
        } elseif (!empty($this->_text_plain)) {
            $this->appendHeaderFields($this->contentInfoArray('text/plain'));
            $this->_body = $this->getSectionTextPlain();
        } elseif (!empty($this->_text_html)) {
            $this->appendHeaderFields($this->contentInfoArray('text/html'));
            $this->_body = $this->getSectionTextHtml();
        } else {
            throw new EmailGatewayException(__('No attachments or body text was set. Can not send empty email.'));
        }
    }
1075648
def send_html_mail(subject, message, message_html, from_email, recipient_list,
                   priority=None, fail_silently=False, auth_user=None,
                   auth_password=None, headers={}):
    
    from django.utils.encoding import force_text
    from django.core.mail import EmailMultiAlternatives
    from mailer.models import make_message

    priority = get_priority(priority)

    # need to do this in case subject used lazy version of ugettext
    subject = force_text(subject)
    message = force_text(message)

    msg = make_message(subject=subject,
                       body=message,
                       from_email=from_email,
                       to=recipient_list,
                       priority=priority)
    email = msg.email
    email = EmailMultiAlternatives(
        email.subject,
        email.body,
        email.from_email,
        email.to,
        headers=headers
    )
    email.attach_alternative(message_html, "text/html")
    msg.email = email
    msg.save()
    return 1
1123053
def prepare_message(self, message_data, delivery_mode,
                        content_type, content_encoding, **kwargs):
        """"""
        return (message_data, content_type, content_encoding)
370310
function prepareTemplate(html) {

        var ESCAPE_STRING = /\s{2,}/g ,
            ESCAPE_CARRIAGE = /(\r)|(\n)|(\r\n)/g;

        return html.replace(ESCAPE_STRING, ' ').replace(ESCAPE_CARRIAGE, '');
    }
609800
protected void appendXMLContent(StringBuffer msg) {

        // append header from xmlcontent
        msg.append(
            CmsMacroResolver.resolveMacros(m_mailContent.getStringValue(m_cms, "Header", m_locale), m_macroResolver));

        // append body
        msg.append("\n<br/><br/>\n");
        msg.append(generateHtmlMsg());
        msg.append("\n<br/><br/>\n");

        // append footer from xmlcontent
        msg.append(
            CmsMacroResolver.resolveMacros(m_mailContent.getStringValue(m_cms, "Footer", m_locale), m_macroResolver));
    }
310809
def html_part=(msg)
      # Assign the html part and set multipart/alternative if there's a text part.
      if msg
        msg = Mail::Part.new(:body => msg) unless msg.kind_of?(Mail::Message)

        @html_part = msg
        @html_part.content_type = 'text/html' unless @html_part.has_content_type?
        add_multipart_alternate_header if text_part
        add_part @html_part

      # If nil, delete the html part and back out of multipart/alternative.
      elsif @html_part
        parts.delete_if { |p| p.object_id == @html_part.object_id }
        @html_part = nil
        if text_part
          self.content_type = nil
          body.boundary = nil
        end
      end
    end
430056
private function prepareDisplay()
    {

        \OWeb\manage\Events::getInstance()->sendEvent('PrepareContent_Start@OWeb\manage\Template');

        //We save the content so that if there is an error we don't show half displayed codes
        ob_start();
        try {
            \OWeb\manage\Controller::getInstance()->display();
        } catch (\Exception $e) {
            \OWeb\manage\Events::getInstance()->sendEvent('PrepareContent_Fail@OWeb\manage\Template');
            ob_end_clean();
            ob_start();
            $ctr = \OWeb\manage\Controller::getInstance()->loadException($e);
            $ctr->addParams("exception", $e);
            \OWeb\manage\Controller::getInstance()->display();
        }

        \OWeb\manage\Events::getInstance()->sendEvent('PrepareContent_Succ@OWeb\manage\Template');

        $this->content = ob_get_contents();

        \OWeb\manage\Events::getInstance()->sendEvent('PrepareContent_End@OWeb\manage\Template');

        ob_end_clean();

        //$this->content_heads = \OWeb\manage\Headers::getInstance()->toString();
       // \OWeb\manage\Headers::getInstance()->reset();
    }
621925
@Deprecated
    public MailBuilder content(net.sargue.mailgun.content.MailContent content) { //NOSONAR
        return text(content.text()).html(content.html());
    }
1357190
public function prepareHtml($html)
    {
        // if it is a real html page, we have to convert it
        if (preg_match('/<body/isU', $html)) {
            $html = $this->getHtmlFromRealPage($html);
        }

        // replace some constants
        $html = str_replace('[[date_y]]', date('Y'), $html);
        $html = str_replace('[[date_m]]', date('m'), $html);
        $html = str_replace('[[date_d]]', date('d'), $html);

        $html = str_replace('[[date_h]]', date('H'), $html);
        $html = str_replace('[[date_i]]', date('i'), $html);
        $html = str_replace('[[date_s]]', date('s'), $html);

        return $html;
    }
578523
protected void respond(StaplerResponse rsp, String html) throws IOException, ServletException {
        rsp.setContentType("text/html;charset=UTF-8");
        rsp.getWriter().print(html);
    }
1351891
public void initHtmlParts() {

        if (m_htmlProps != null) {
            // html already initialized
            return;
        }
        try {
            m_htmlProps = new Properties();
            m_htmlProps.load(getClass().getClassLoader().getResourceAsStream(HTML_MESSAGE_FILE));
        } catch (Exception e) {
            e.printStackTrace();
            m_errors.add(e.toString());
        }
    }
709619
function initEmailForm() {
        var newsletterForm = document.getElementById('newsletter-form');
        var submitButton = document.getElementById('newsletter-submit');
        var formDetails = document.getElementById('newsletter-details');
        var emailField = document.querySelector('.mzp-js-email-field');
        var formExpanded = window.getComputedStyle(formDetails).display === 'none' ? false : true;

        function emailFormShowDetails() {
            if (!formExpanded) {
                formDetails.style.display = 'block';
                formExpanded = true;
            }
        }

        emailField.addEventListener('focus', function() {
            emailFormShowDetails();
        });

        submitButton.addEventListener('click', function(e) {
            if (!formExpanded) {
                e.preventDefault();
                emailFormShowDetails();
            }
        });

        newsletterForm.addEventListener('submit', function(e) {
            if (!formExpanded) {
                e.preventDefault();
                emailFormShowDetails();
            }
        });
    }
409401
def _prep_message(self):
        """"""
        self._header, self.header_auth = self._read_header()
        if self._header.content_type == ContentType.NO_FRAMING:
            self._prep_non_framed()
        self._message_prepped = True