/* -----------------------------------------------------
Message as an associative array with external HTML template
-----------------------------------------------------
508883
public function sample2()
   {
      $data = array(
                  "NAME"       => 'Juliet & Romeo',
                  "EMAIL"      => 'some_email@example.com',
                  "MESSAGE"    => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Deserunt, ad labore iusto quibusdam totam. Repellendus, architecto quos temporibus dolores assumenda amet veritatis quisquam!',
                  "DATE"       => date('Y-m-d H:i:s'),
                  "SMALL_TEXT" => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.
                                    Sapiente, fugiat consequatur illo eaque ipsam expedita sint itaque quibusdam porro fugit quas quae placeat
                                    qui fuga sequi aspernatur nam quo quis.',
                  );

      $template_html = 'sample-2.html';

      $mail = new Mail();
      $mail->setMailBody($data, $template_html);
      $mail->sendMail('Test Sample 2 Assoc Array with an external template and plain-text file');
      exit('Message Sent!');
   }
805252
function(context, parent, args, container) {
		var name = args[0],
			template = args[1],
			node = document.createElement(name);
		template.toDOM(node, context, container);
		parent.appendChild(node);
	}
1287015
function (message, context) {
                message = this.messages[message] || message.toString();
                if (context) {
                    $.each(context, function (key, value) {
                        message = message.replace('{' + key + '}', value);
                    });
                }
                return message;
            }
1330409
def generate_message_crc_extra_array(outf, msgs):
    """"""

    crcs = []
    for msg in msgs:
        crcs.append("%u: %u" % (msg.id, msg.crc_extra))

    t.write(outf, """


/**
    Message CRSs extra for detection incompatible XML changes
*/
private let messageCrcsExtra: [UInt8: UInt8] = [${ARRAY_CONTENT}]
""", {'ARRAY_CONTENT' : ", ".join(crcs)})
976732
public static function setTemplate($data)
    {
        /***********************************
         * Message subject replace
         ************************************/

        //if (isset($data['message']))    $data['subject']    = str_replace("#message#", $data['message'], $data['subject']);      // Message coded ID, to track (comunik)
        if (isset($data['contactKey'])) $data['subject']    = str_replace("#contactKey#",   $data['contactKey'],                    $data['subject']);  // Contact coded ID, to track (comunik)
        if (isset($data['company']))    $data['subject']    = str_replace("#company#",      $data['company'],                       $data['subject']);  // Company name (comunik)
        if (isset($data['name']))       $data['subject']    = str_replace("#name#",         $data['name'],                          $data['subject']);  // Contact name (comunik)
        if (isset($data['surname']))    $data['subject']    = str_replace("#surname#",      $data['surname'],                       $data['subject']);  // Contact surname (comunik)
        if (isset($data['birthDate']))  $data['subject']    = str_replace("#birthDate#",    $data['birthDate'],                     $data['subject']);  // BirthDate (comunik)
        if (isset($data['email']))      $data['subject']    = str_replace("#email#",        $data['email'],                         $data['subject']);  // Contact email (comunik)
        $data['subject']                                    = str_replace("#date#",         date(config('pulsar.datePattern')),     $data['subject']);  // Current date

        /***********************************
         * Message html format replace
         ************************************/
        if(isset($data['html']))
            $data = self::replaceWildcard($data, 'html');

        /***********************************
         * Message text format replace
         ************************************/
        if(isset($data['text']))
            $data = self::replaceWildcard($data, 'text');

        return $data;
    }
610414
private void doMapPut(final Message<JsonObject> message) {
    final String name = message.body().getString("name");
    if (name == null) {
      message.reply(new JsonObject().putString("status", "error").putString("message", "No name specified."));
      return;
    }

    final Object key = message.body().getValue("key");
    if (key == null) {
      message.reply(new JsonObject().putString("status", "error").putString("message", "No key specified."));
      return;
    }

    final Object value = message.body().getValue("value");
    if (value == null) {
      message.reply(new JsonObject().putString("status", "error").putString("message", "No value specified."));
      return;
    }

    context.execute(new Action<Object>() {
      @Override
      public Object perform() {
        return data.getMap(formatKey(name)).put(key, value);
      }
    }, new Handler<AsyncResult<Object>>() {
      @Override
      public void handle(AsyncResult<Object> result) {
        if (result.failed()) {
          message.reply(new JsonObject().putString("status", "error").putString("message", result.cause().getMessage()));
        } else {
          message.reply(new JsonObject().putString("status", "ok").putValue("result", result.result()));
        }
      }
    });
  }
1074484
function _fnNameArray (context, iterable, filterContext) {
    var html = '',
        object, ref, length, key, i;

    length = iterable.length;
    for (i = 0; i < length; i++) {
      object = iterable[i];
      if (!object) {
        continue;
      }
      _body;
    }


    return html;
  }
119908
private function lazyParseStructure(): void
    {
        if (true === $this->structureParsed) {
            return;
        }
        $this->structureParsed = true;

        $this->lazyLoadStructure();

        $this->type = self::$typesMap[$this->structure->type] ?? self::TYPE_UNKNOWN;

        // In our context, \ENCOTHER is as useful as an uknown encoding
        $this->encoding = self::$encodingsMap[$this->structure->encoding] ?? self::ENCODING_UNKNOWN;
        $this->subtype  = $this->structure->subtype;

        if (isset($this->structure->bytes)) {
            $this->bytes = $this->structure->bytes;
        }
        if ($this->structure->ifdisposition) {
            $this->disposition = $this->structure->disposition;
        }
        if ($this->structure->ifdescription) {
            $this->description = $this->structure->description;
        }

        $this->parameters = new Parameters();
        if ($this->structure->ifparameters) {
            $this->parameters->add($this->structure->parameters);
        }

        if ($this->structure->ifdparameters) {
            $this->parameters->add($this->structure->dparameters);
        }

        // When the message is not multipart and the body is the attachment content
        // Prevents infinite recursion
        if (self::isAttachment($this->structure) && !$this instanceof Attachment) {
            $this->parts[] = new Attachment($this->resource, $this->getNumber(), '1', $this->structure);
        }

        if (isset($this->structure->parts)) {
            $parts = $this->structure->parts;
            // https://secure.php.net/manual/en/function.imap-fetchbody.php#89002
            if ($this instanceof Attachment && $this->isEmbeddedMessage() && 1 === \count($parts) && \TYPEMULTIPART === $parts[0]->type) {
                $parts = $parts[0]->parts;
            }
            foreach ($parts as $key => $partStructure) {
                $partNumber = (!$this instanceof Message) ? $this->partNumber . '.' : '';
                $partNumber .= (string) ($key + 1);

                $newPartClass = self::isAttachment($partStructure)
                    ? Attachment::class
                    : SimplePart::class
                ;

                $this->parts[] = new $newPartClass($this->resource, $this->getNumber(), $partNumber, $partStructure);
            }
        }
    }
685133
public function toMessage()
    {
        $message = clone $this;

        $altBody = $message->altBody();
        $attachments = $message->attachments();
        $inlines = $message->inlines();

        $root = $cursor = $message->stream();

        $body = $message->body();
        $bodyMime = $cursor->mime() ?: 'text/plain';
        $bodyCharset = $cursor->charset() ?: Mime::optimalCharset($body);

        if (count($attachments)) {
            $cursor->mime('multipart/mixed');
            $current = $cursor->add(new MixedPart());
            foreach ($attachments as $path => $attachment) {
                $cursor->add(fopen($path, 'r'), $attachment);
            }
            $cursor = $current;
        }

        if ($altBody || count($inlines)) {
            $cursor->mime('multipart/alternative');
        }

        if ($altBody) {
            $cursor->add($altBody, [
                'mime'     => 'text/plain',
                'charset'  => Mime::optimalCharset($altBody),
                'encoding' => Mime::optimalEncoding($altBody)
            ]);
        }

        if ($body) {
            $options = [
                'mime'     => $bodyMime,
                'charset'  => $bodyCharset,
                'encoding' => Mime::optimalEncoding($body)
            ];

            if ($inlines) {
                $current = $cursor->add(new MixedPart(['mime' => 'multipart/related']));
                $current->add($body, $options);
                foreach ($inlines as $path => $inline) {
                    $current->add(fopen($path, 'r'), $inline);
                }
            } else {
                $cursor->add($body, $options);
            }
        }

        $headers = $root->headers();
        $headers['Date'] = date('r');
        $headers['Message-ID'] = static::generateId($this->client());
        return $root->toMessage();
    }
764994
function Message_post(body,       // @arg Any - message body, instanceList[id]#inbox(,body,)
                      callback) { // @arg Function = null - callback(err:Error, buffer:Array):void
                                  // @desc post to message asynchronously.
//{@dev
    $valid($type(callback, "Function|omit"), Message_post, "callback");
//}@dev

    var taskCount = Object.keys(this._instanceList).length;
    var task = new global["Task"](taskCount, function(err, buffer) {
                            if (callback) {
                                callback(err, buffer);
                            }
                        }, { "name": "Message#post" });

    for (var id in this._instanceList) {
        var instance = this._instanceList[id];

        if (instance) {
            // call       Foo#inbox(task:Task, body:Any, id:String):void
            // call WebWorker#inbox(task:Task, body:Any, id:String):void
            instance[this._methodName].call(instance, task, body, id);
        }
    }
}
1282244
function(template, options){
			var payload = { data: {}, template_id: template };

			// Add root attributes to the payload root
			for(var attr in rootAttributes){
				if(!rootAttributes.hasOwnProperty(attr)){
					continue;
				}
				if(typeof options[attr] === 'undefined'){
					continue;
				}
				var key = rootAttributes[attr],
					val = options[attr];
				payload[key] = val;
				delete options[attr];
			}

			// Add any left over attribtues to the data object
			for(attr in options){
				if(!options.hasOwnProperty(attr)){
					continue;
				}
				payload.data[attr] = options[attr]
			}

			// Add to the list of emails
			this.mails.push(payload);
		}
1005891
public function forAjaxTemplate()
    {
        $view = SSViewer::create($this->getTemplates());

        $return = $view->dontRewriteHashlinks()->process($this);

        // Now that we're rendered, clear message
        $this->clearMessage();

        return $return;
    }
95292
function html(template) {
    var expressions = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        expressions[_i - 1] = arguments[_i];
    }
    var result = "";
    var i = 0;
    // resolve each expression and build the result string
    for (var _a = 0, template_1 = template; _a < template_1.length; _a++) {
        var part = template_1[_a];
        var expression = expressions[i++ - 1]; // this might be an array
        var resolvedExpression = resolveExpression(expression);
        result += "" + resolvedExpression + part;
    }
    // strip indentation and trim the result
    return strip_indent_1.default(result).trim();
}
1097961
function message_load($p)
    {
        $this->message = $p['object'];

        // handle attachments vcard attachments
        foreach ((array)$this->message->attachments as $attachment) {
            if ($this->is_vcard($attachment)) {
                $this->vcard_parts[] = $attachment->mime_id;
            }
        }
        // the same with message bodies
        foreach ((array)$this->message->parts as $part) {
            if ($this->is_vcard($part)) {
                $this->vcard_parts[]  = $part->mime_id;
                $this->vcard_bodies[] = $part->mime_id;
            }
        }

        if ($this->vcard_parts) {
            $this->add_texts('localization');
        }
    }
714766
function exportValue(&$submitValues, $assoc = false)
    {
        $value = null;
        foreach (array_keys($this->_elements) as $key) {
            $elementName = $this->_elements[$key]->getName();
            if ($this->_appendName) {
                if (is_null($elementName)) {
                    $this->_elements[$key]->setName($this->getName());
                } elseif ('' === $elementName) {
                    $this->_elements[$key]->setName($this->getName() . '[' . $key . ']');
                } else {
                    $this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']');
                }
            }
            $v = $this->_elements[$key]->exportValue($submitValues, $assoc);
            if ($this->_appendName) {
                $this->_elements[$key]->setName($elementName);
            }
            if (null !== $v) {
                // Make $value an array, we will use it like one
                if (null === $value) {
                    $value = array();
                }
                if ($assoc) {
                    // just like HTML_QuickForm::exportValues()
                    $value = HTML_QuickForm::arrayMerge($value, $v);
                } else {
                    // just like getValue(), but should work OK every time here
                    if (is_null($elementName)) {
                        $value = $v;
                    } elseif ('' === $elementName) {
                        $value[] = $v;
                    } else {
                        $value[$elementName] = $v;
                    }
                }
            }
        }
        // do not pass the value through _prepareValue, we took care of this already
        return $value;
    }
217339
function api($path, $post_data = array()) {
		// IE: "contact/view"
		$components = explode("/", $path);
		$component = $components[0];

		if (count($components) > 2) {
			// IE: "contact/tag/add?whatever"
			// shift off the first item (the component, IE: "contact").
			array_shift($components);
			// IE: convert to "tag_add?whatever"
			$method_str = implode("_", $components);
			$components = array($component, $method_str);
		}

		if (preg_match("/\?/", $components[1])) {
			// query params appended to method
			// IE: contact/edit?overwrite=0
			$method_arr = explode("?", $components[1]);
			$method = $method_arr[0];
			$params = $method_arr[1];
		}
		else {
			// just a method provided
			// IE: "contact/view
			if ( isset($components[1]) ) {
				$method = $components[1];
				$params = "";
			}
			else {
				return "Invalid method.";
			}
		}

		// adjustments
		if ($component == "list") {
			// reserved word
			$component = "list_";
		}
		elseif ($component == "branding") {
			$component = "design";
		}
		elseif ($component == "sync") {
			$component = "contact";
			$method = "sync";
		}
		elseif ($component == "singlesignon") {
			$component = "auth";
		}

		$class = ucwords($component); // IE: "contact" becomes "Contact"
		$class = "AC_" . $class;
		// IE: new Contact();

		$add_tracking = false;
		if ($class == "AC_Tracking") $add_tracking = true;
		if ($class == "AC_Tags") {
			$class = "AC_Tag";
		}

		$class = new $class($this->version, $this->url_base, $this->url, $this->api_key);

		$class->set_curl_timeout($this->get_curl_timeout());

		if ($add_tracking) {
			$class->track_email = $this->track_email;
			$class->track_actid = $this->track_actid;
			$class->track_key = $this->track_key;
		}

		if ($method == "list") {
			// reserved word
			$method = "list_";
		}

		$class->debug = $this->debug;

		$response = $class->$method($params, $post_data);
		return $response;
	}
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.'));
        }
    }