Compose the message, pulling together body, attachments etc
16546
def __compose(self):
		
		msg  = MIMEMultipart()
		msg['Subject'] = self.config['shutit.core.alerting.emailer.subject']
		msg['To']      = self.config['shutit.core.alerting.emailer.mailto']
		msg['From']    = self.config['shutit.core.alerting.emailer.mailfrom']
		# add the module's maintainer as a CC if configured
		if self.config['shutit.core.alerting.emailer.mailto_maintainer']:
			msg['Cc'] = self.config['shutit.core.alerting.emailer.maintainer']
		if self.config['shutit.core.alerting.emailer.signature'] != '':
			signature = '\n\n' + self.config['shutit.core.alerting.emailer.signature']
		else:
			signature = self.config['shutit.core.alerting.emailer.signature']
		body = MIMEText('\n'.join(self.lines) + signature)
		msg.attach(body)
		for attach in self.attaches:
			msg.attach(attach)
		return msg
389518
function () {

		// Message
		this.message = new TL.Message({}, this.options);
		this.message.addTo(this._el.container);

		// Create Layout
		this._el.content_container = TL.Dom.create("div", "tl-media-content-container", this._el.container);

		// Link
		if (this.data.link && this.data.link != "") {

			this._el.link = TL.Dom.create("a", "tl-media-link", this._el.content_container);
			this._el.link.href = this.data.link;
			if (this.data.link_target && this.data.link_target != "") {
				this._el.link.target = this.data.link_target;
			} else {
				this._el.link.target = "_blank";
			}

			this._el.content = TL.Dom.create("div", "tl-media-content", this._el.link);

		} else {
			this._el.content = TL.Dom.create("div", "tl-media-content", this._el.content_container);
		}


	}
1179203
def format_message
      message = Message.new

      message.id = @id
      message.text = @raw_data['text'] ||= ''
      media = @raw_data['media']
      message.type = media ? media['type'] : 'text'
      message.raw_from = @raw_data['from']['peer_id']
      message.from_type = @raw_data['from']['peer_type']
      message.raw_to = @raw_data['to']['peer_id']
      message.to_type = @raw_data['to']['peer_type']

      from = @client.contacts.find { |c| c.id == message.raw_from }
      to = @client.contacts.find { |c| c.id == message.raw_to }
      to = @client.chats.find { |c| c.id == message.raw_to } if to.nil?

      message.from = from
      message.to = to

      @message = message

      if @message.from.nil?
        user = @raw_data['from']
        user = TelegramContact.pick_or_new(@client, user)
        @client.contacts << user unless @client.contacts.include?(user)
        @message.from = user
      end

      if @message.to.nil?
        type = @raw_data['to']['peer_type']
        case type
        when 'chat', 'encr_chat'
          chat = TelegramChat.pick_or_new(@client, @raw_data['to'])
          @client.chats << chat unless @client.chats.include?(chat)
          if type == 'encr_chat' then
            @message.to = chat
          else
            @message.from = chat
          end
        when 'user'
          user = TelegramContact.pick_or_new(@client, @raw_data['to'])
          @client.contacts << user unless @client.contacts.include?(user)
          @message.to = user
        end
      end
    end
1303305
function(messageContent) {

                /**
                 * + Conversation                           {object}
                 *    - id                                  {long}
                 *    - joinDate                            {long}
                 *    - title                               {string}
                 *    - inviter                             {object : ParticipantVO}
                 *    - participants                        {list : ParticipantVO}
                 *    - time                                {long}
                 *    - lastMessage                         {string}
                 *    - lastParticipantName                 {string}
                 *    - group                               {boolean}
                 *    - partner                             {long}
                 *    - lastParticipantImage                {string}
                 *    - image                               {string}
                 *    - description                         {string}
                 *    - unreadCount                         {long}
                 *    - lastSeenMessageId                   {long}
                 *    - lastSeenMessageTime                 {long}
                 *    - lastSeenMessageNanos                {integer}
                 *    - lastMessageVO                       {object : ChatMessageVO}
                 *    - partnerLastSeenMessageId            {long}
                 *    - partnerLastSeenMessageTime          {long}
                 *    - partnerLastSeenMessageNanos         {integer}
                 *    - partnerLastDeliveredMessageId       {long}
                 *    - partnerLastDeliveredMessageTime     {long}
                 *    - partnerLastDeliveredMessageNanos    {integer}
                 *    - type                                {int}
                 *    - metadata                            {string}
                 *    - mute                                {boolean}
                 *    - participantCount                    {long}
                 *    - canEditInfo                         {boolean}
                 *    - canSpam                             {boolean}
                 *    - admin                               {boolean}
                 */

                var conversation = {
                    id: messageContent.id,
                    joinDate: messageContent.joinDate,
                    title: messageContent.title,
                    inviter: undefined,
                    participants: undefined,
                    time: messageContent.time,
                    lastMessage: messageContent.lastMessage,
                    lastParticipantName: messageContent.lastParticipantName,
                    group: messageContent.group,
                    partner: messageContent.partner,
                    lastParticipantImage: messageContent.lastParticipantImage,
                    image: messageContent.image,
                    description: messageContent.description,
                    unreadCount: messageContent.unreadCount,
                    lastSeenMessageId: messageContent.lastSeenMessageId,
                    lastSeenMessageTime: (messageContent.lastSeenMessageNanos)
                        ? (parseInt(parseInt(messageContent.lastSeenMessageTime) / 1000) * 1000000000) + parseInt(messageContent.lastSeenMessageNanos)
                        : (parseInt(messageContent.lastSeenMessageTime)),
                    lastMessageVO: undefined,
                    partnerLastSeenMessageId: messageContent.partnerLastSeenMessageId,
                    partnerLastSeenMessageTime: (messageContent.partnerLastSeenMessageNanos)
                        ? (parseInt(parseInt(messageContent.partnerLastSeenMessageTime) / 1000) * 1000000000) +
                                                parseInt(messageContent.partnerLastSeenMessageNanos)
                        : (parseInt(messageContent.partnerLastSeenMessageTime)),
                    partnerLastDeliveredMessageId: messageContent.partnerLastDeliveredMessageId,
                    partnerLastDeliveredMessageTime: (messageContent.partnerLastDeliveredMessageNanos)
                        ? (parseInt(parseInt(messageContent.partnerLastDeliveredMessageTime) / 1000) * 1000000000) +
                                                     parseInt(messageContent.partnerLastDeliveredMessageNanos)
                        : (parseInt(messageContent.partnerLastDeliveredMessageTime)),
                    type: messageContent.type,
                    metadata: messageContent.metadata,
                    mute: messageContent.mute,
                    participantCount: messageContent.participantCount,
                    canEditInfo: messageContent.canEditInfo,
                    canSpam: messageContent.canSpam,
                    admin: messageContent.admin
                };

                // Add inviter if exist
                if (messageContent.inviter) {
                    conversation.inviter = formatDataToMakeParticipant(messageContent.inviter, messageContent.id);
                }

                // Add participants list if exist
                if (messageContent.participants && Array.isArray(messageContent.participants)) {
                    conversation.participants = [];

                    for (var i = 0; i < messageContent.participants.length; i++) {
                        var participantData = formatDataToMakeParticipant(messageContent.participants[i], messageContent.id);
                        if (participantData) {
                            conversation.participants.push(participantData);
                        }
                    }
                }

                // Add lastMessageVO if exist
                if (messageContent.lastMessageVO) {
                    conversation.lastMessageVO = formatDataToMakeMessage(messageContent.id, messageContent.lastMessageVO);
                }

                return conversation;
            }
178286
def prepare_message(self, message_data, delivery_mode, priority=None,
            content_type=None, content_encoding=None):
        """"""
        properties = pika.BasicProperties(priority=priority,
                                          content_type=content_type,
                                          content_encoding=content_encoding,
                                          delivery_mode=delivery_mode)
        return message_data, properties
1005504
def compose(self, **kwargs):
        
        from psd_tools.api.composer import compose
        return compose(self, **kwargs)
545520
function buildMessageHTML(messageText, messageSenderId, messageDateSent, attachmentFileId, messageId) {
    var messageAttach;

    if (attachmentFileId) {
        messageAttach = '<img src="' + QB.content.privateUrl(attachmentFileId) + '" alt="attachment" class="attachments img-responsive" />';
    }

    var delivered = '<img class="icon-small" src="images/delivered.jpg" alt="" id="delivered_' + messageId + '">';
    var read = '<img class="icon-small" src="images/read.jpg" alt="" id="read_' + messageId + '">';

    var messageTextHtml = messageText;
    if (messageAttach) {
        messageTextHtml = messageAttach;
    }

    var messageHtml =
        '<div class="list-group-item" id="' + messageId + '">' +
        '<time datetime="' + messageDateSent + '" class="pull-right">' +
        jQuery.timeago(messageDateSent) +
        '</time>' +

        '<h4 class="list-group-item-heading">' + messageSenderId + '</h4>' +
        '<p class="list-group-item-text">' +
        messageTextHtml +
        '</p>' +
        delivered + read +
        '</div>';
    return messageHtml;
}
486742
def compose_message(orig_filename)
      orig_basename = File.basename(orig_filename)
      fixed_basename = orig_basename

      if config['leading_underscore']
        fixed_basename = '_' + fixed_basename unless fixed_basename.start_with?('_')
      else
        fixed_basename = fixed_basename.sub(/^_/, '')
      end

      if config['filename_extension']
        fixed_basename += '.scss' unless fixed_basename.end_with?('.scss')
      else
        fixed_basename = fixed_basename.sub(/\.scss$/, '')
      end

      fixed_filename = orig_filename.sub(/(.*)#{Regexp.quote(orig_basename)}/,
                                         "\\1#{fixed_basename}")
      "Imported partial `#{orig_filename}` should be written as `#{fixed_filename}`"
    end
993867
def send_mail(subject, message_plain, message_html, email_from, email_to,
              custom_headers={}, attachments=()):
    
    if not message_plain and not message_html:
        raise ValueError(_("Either message_plain or message_html should be not None"))

    if not message_plain:
        message_plain = html2text(message_html)

    message = {}

    message['subject'] = subject
    message['body'] = message_plain
    message['from_email'] = email_from
    message['to'] = email_to
    if attachments:
        message['attachments'] = attachments
    if custom_headers:
        message['headers'] = custom_headers

    msg = EmailMultiAlternatives(**message)
    if message_html:
        msg.attach_alternative(message_html, "text/html")
    msg.send()
319872
public function constructMultipartMessage()
    {

        $mixed_boundary = '__mixed_1S2U3R4E5B6E7R8T9';
        $alterative_boundary = '__alter_1S2U3R4E5B6E7R8T9';

        $this->attachments_in_HTML =0;

        if(strstr($this->body_HTML, "cid:")) {

            $this->attachments_in_HTML =1;
            $related_boundary = '__relate_1S2U3R4E5B6E7R8T9';
        }

        $this->_header_text = "From: ".$this->from.PHP_EOL;
        $this->_header_text .= "Reply-To: ".$this->from.PHP_EOL;
        $this->_header_text .= "Return-Path: ".$this->from.PHP_EOL;

        foreach($this->cc as $cc) {
            $this->_header_text .="Cc:".$cc.PHP_EOL;
        }

        foreach($this->bcc as $bcc) {
            $this->_header_text .="Bcc:".$bcc.PHP_EOL;
        }

        $this->_header_text .= "MIME-Version: 1.0".PHP_EOL;

        foreach($this->headers as $key=>$val) {
            $this->_header_text .= $key.":".$val.PHP_EOL;
        }

        $this->_header_text .= "Content-Type: multipart/mixed;".PHP_EOL;
        $this->_header_text .= ' boundary="'.$mixed_boundary.'"'.PHP_EOL.PHP_EOL;

        // Add a message for peoplewithout mime
        $message = "This message has an attachment in MIME format created with surebert mail.".PHP_EOL.PHP_EOL;

        //if there is body_HTML use it otherwise use just plain text
        if(!empty($this->body_HTML)) {

            $message .= "--".$mixed_boundary.PHP_EOL;

            if($this->attachments_in_HTML == 1) {
                $message .= "Content-Type: multipart/related;".PHP_EOL;
                $message .= ' boundary="'.$related_boundary.'"'.PHP_EOL.PHP_EOL;
                $message .= "--".$related_boundary.PHP_EOL;
            }

            $message .= "Content-Type: multipart/alternative;".PHP_EOL;
            $message .= ' boundary="'.$alterative_boundary.'"'.PHP_EOL.PHP_EOL;

            $message .= "--".$alterative_boundary.PHP_EOL;
            $message .= "Content-Type: text/plain; charset=".$this->charset."; format=flowed".PHP_EOL;
            $message .= "Content-Transfer-Encoding: ".$this->transfer_encoding.PHP_EOL;
            $message .= "Content-Disposition: inline".PHP_EOL.PHP_EOL;
            $message .= $this->body . PHP_EOL;

            $message .= "--".$alterative_boundary.PHP_EOL;
            $message .= "Content-Type: text/html; charset=".$this->charset.PHP_EOL;
            $message .= "Content-Transfer-Encoding: ".$this->transfer_encoding.PHP_EOL.PHP_EOL;
            $message .= $this->body_HTML . PHP_EOL;

            $message .="--".$alterative_boundary."--".PHP_EOL;

        } else {

            $message .= "--".$mixed_boundary.PHP_EOL;
            $message .= "Content-Type: text/plain; charset=".$this->charset."; format=flowed".PHP_EOL;
            $message .= "Content-Transfer-Encoding: ".$this->transfer_encoding.PHP_EOL;
            $message .= "Content-Disposition: inline".PHP_EOL.PHP_EOL;
            $message .= $this->body . PHP_EOL;
        }

        //add all attachments for this email
        foreach($this->attachments as &$attachment) {
            
        //if only filepath is set, grab name and contents from there
            if(isset($attachment->filepath)) {
                if(empty($attachment->name)) {
                    $attachment->name = basename($attachment->filepath);
                }

                if(empty($attachment->contents)) {
                    $attachment->contents = file_get_contents($attachment->filepath);
                }

                if(empty($attachment->mime_type)) {
                    $attachment->mime_type = \sb\Files::fileToMime($attachment->filepath);
                }

            }
            $ex = explode(".", $attachment->name);
            $attachment->extension = strtolower(array_pop($ex));

            //try and guess the mime type unless it is set
            if(empty($attachment->mime_type)) {
                $attachment->mime_type = \sb\Files::extensionToMime($attachment->extension);
            }

            if($attachment->encoding == 'base64' && !isset($attachment->_base64_encoded)){
                $attachment->_base64_encoded = true;
                $attachment->contents = chunk_split(base64_encode($attachment->contents));
            }

            // Add file attachment to the message

            if($this->attachments_in_HTML == 1) {
                $message .= "--".$related_boundary.PHP_EOL;
            } else {
                $message .= "--".$mixed_boundary.PHP_EOL;
            }

            if($attachment->mime_type == 'text/calendar'){
                $message .= "Content-class: urn:content-classes:calendarmessage;".PHP_EOL;
            }

            $message .= "Content-Type: ".$attachment->mime_type.";".PHP_EOL;
            $message .= " name=".$attachment->name.PHP_EOL;

            $message .= "Content-Transfer-Encoding: ".$attachment->encoding.PHP_EOL;
            $message .= "Content-ID: <".$attachment->name.">".PHP_EOL.PHP_EOL;

            $message .=  $attachment->contents.PHP_EOL;

        }

        //end related if using body_HTML
        if($this->attachments_in_HTML == 1) {
            $message .= "--".$related_boundary."--".PHP_EOL;
        }

        //end message
        $message .="--".$mixed_boundary."--".PHP_EOL;

        $this->body = $message;
        $raw = "";
        if($this->to){
            $raw .= "To: ".$this->to.PHP_EOL;
        }
        
        $raw .= "Subject: ".$this->subject.PHP_EOL;
        $raw .= $this->_header_text .$this->body;
        return $raw;
    }
94445
function completeProcess(messages) {
  var html = outputHTMLString(messages);
  var file = new Blob([html], {type: 'text/html'});
  var url = URL.createObjectURL(file);

  var a = document.getElementById('button');
  a.className = 'download';
  a.innerHTML = 'Download';
  a.href = url;
  a.download = "snap-it.html";
}
203833
public function assembleAttachmentBody()
    {
        $body = array();
        $body[] = "This is a multi-part message in MIME format.";
        $body[] = "--{$this->_uid}";
        $body[] = "Content-Type: text/html; charset=\"utf-8\"";
        $body[] = "Content-Transfer-Encoding: quoted-printable";
        $body[] = "";
        $body[] = quoted_printable_encode($this->_message);
        $body[] = "";
        $body[] = "--{$this->_uid}";

        foreach ($this->_attachments as $attachment) {
            $body[] = $this->getAttachmentMimeTemplate($attachment);
        }

        return implode(PHP_EOL, $body) . '--';
    }
1211494
def construct_message(self, email=None):
        
        # add subject, from and to
        self.multipart['Subject'] = self.subject
        self.multipart['From'] = self.config['EMAIL']
        self.multipart['Date'] = formatdate(localtime=True)
        if email is None and self.send_as_one:
            self.multipart['To'] = ", ".join(self.addresses)
        elif email is not None and self.send_as_one is False:
            self.multipart['To'] = email
        # add ccs
        if self.ccs is not None and self.ccs:
            self.multipart['Cc'] = ", ".join(self.ccs)
        # add html and text body
        html = MIMEText(self.html, 'html')
        alt_text = MIMEText(self.text, 'plain')
        self.multipart.attach(html)
        self.multipart.attach(alt_text)
        for file in self.files:
            self.multipart.attach(file)
756806
function () {
		if (connectionRequestID) {
			var data = {
				actions: []
			};
			if (status.actions.eChipSet) {
				data.actions.push(MESSENGER_CONST.ACTION.ECHIP_SET);
			}
			if (status.actions.eChipGet) {
				data.actions.push(MESSENGER_CONST.ACTION.ECHIP_GET);
			}
			composeMessage(connectionRequestID, MESSENGER_CONST.TYPE.RESPONSE, MESSENGER_CONST.ACTION.CONNECT, data);
		}
	}
273408
async def send_with_attachments(subject, message, filepaths, config):
    
    email_ = MIMEMultipart()
    email_.attach(MIMEText(message))
    email_["Subject"] = subject
    email_["From"] = get_attribute_from_config(config, EMAIL_SECTION_KEY, USER_KEY)
    email_["To"] = get_attribute_from_config(config, EMAIL_SECTION_KEY, RECEIVER_KEY)
    _attach_files(filepaths, email_)
    await _send_email(email_, config)
875602
public function createBody()
    {
        $this->envelope['date'] = '29.03.2017';
        $this->envelope['message_id'] = '81';

        $part1['type'] = TYPEMULTIPART;
        $part1['subtype'] = 'mixed';

        $part3['type'] = TYPETEXT;
        $part3['subtype'] = 'plain';
        $part3['description'] = 'description3';
        $part3['contents.data'] = "contents.data3\n\n\n\t";

        $body[1] = $part1;
        //$body[2] = $part2;
        $body[3] = $part3;

        $this->body = $body;
    }
1184609
public function compose(MessageInterface $message, $params = [])
    {
        $this->message = $message;

        if (is_array($this->viewName)) {
            if (isset($this->viewName['html'])) {
                $html = $this->render($this->viewName['html'], $params, $this->htmlLayout);
            }
            if (isset($this->viewName['text'])) {
                $text = $this->render($this->viewName['text'], $params, $this->textLayout);
            }
        } else {
            $html = $this->render($this->viewName, $params, $this->htmlLayout);
        }

        if (isset($html)) {
            $this->message->setHtmlBody($html);
        }
        if (isset($text)) {
            $this->message->setTextBody($text);
        } elseif (isset($html)) {
            if (preg_match('~<body[^>]*>(.*?)</body>~is', $html, $match)) {
                $html = $match[1];
            }
            // remove style and script
            $html = preg_replace('~<((style|script))[^>]*>(.*?)</\1>~is', '', $html);
            // strip all HTML tags and decode HTML entities
            $text = html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5);
            // improve whitespace
            $text = preg_replace("~^[ \t]+~m", '', trim($text));
            $text = preg_replace('~\R\R+~mu', "\n\n", $text);
            $this->message->setTextBody($text);
        }
    }