Exemplo n.º 1
0
 /**
  * Replace strings in the message searching through all the allowed sub-parts.
  * @param Swift_Message_Mime The message (or part)
  * @param array The list of replacements
  * @param array The array to cache original values into where needed
  */
 protected function recursiveReplace(Swift_Message_Mime $mime, $replacements, &$store)
 {
     //Check headers
     if ($this->getPermittedInHeaders()) {
         foreach ($mime->headers->getList() as $name => $value) {
             if (is_string($value) && ($replaced = $this->replace($replacements, $value)) != $value) {
                 $mime->headers->set($name, $replaced);
                 $store["headers"][$name] = array();
                 $store["headers"][$name]["value"] = $value;
                 $store["headers"][$name]["attributes"] = array();
             }
             foreach ($mime->headers->listAttributes($name) as $att_name => $att_value) {
                 if (is_string($att_value) && ($att_replaced = $this->replace($replacements, $att_value)) != $att_value) {
                     if (!isset($store["headers"][$name])) {
                         $store["headers"][$name] = array("value" => false, "attributes" => array());
                     }
                     $mime->headers->setAttribute($name, $att_name, $att_replaced);
                     $store["headers"][$name]["attributes"][$att_name] = $att_value;
                 }
             }
         }
     }
     //Check body
     $body = $mime->getData();
     if ($this->isPermittedType($mime->getContentType()) && is_string($body) && ($replaced = $this->replace($replacements, $body)) != $body) {
         $mime->setData($replaced);
         $store["body"] = $body;
     }
     //Check sub-parts
     foreach ($mime->listChildren() as $id) {
         $store["children"][$id] = array("headers" => array(), "body" => false, "children" => array());
         $child = $mime->getChild($id);
         $this->recursiveReplace($child, $replacements, $store["children"][$id]);
     }
 }
 /**
  * Attach a mime part or an attachment of some sort
  * Any descendant of Swift_Message_Mime can be added safely (including other Swift_Message objects for mail forwarding!!)
  * @param Swift_Message_Mime The document to attach
  * @param string An identifier to use (one is returned otherwise)
  * @return string The identifier for the part
  */
 public function attach(Swift_Message_Mime $child, $id = null)
 {
     try {
         switch ($child->getLevel()) {
             case Swift_Message_Mime::LEVEL_ALTERNATIVE:
                 $sign = strtolower($child->getContentType()) == "text/plain" ? -1 : 1;
                 $id = $this->getReference("parent", "alternative")->addChild($child, $id, $sign);
                 $this->setReference("alternative", $id, $child);
                 break;
             case Swift_Message_Mime::LEVEL_RELATED:
                 $id = "cid:" . $child->getContentId();
                 $id = $this->getReference("parent", "related")->addChild($child, $id, 1);
                 $this->setReference("related", $id, $child);
                 break;
             case Swift_Message_Mime::LEVEL_MIXED:
             default:
                 $id = $this->getReference("parent", "mixed")->addChild($child, $id, 1);
                 $this->setReference("mixed", $id, $child);
                 break;
         }
         $this->postAttachFixStructure();
         $this->fixContentType();
         return $id;
     } catch (Swift_Message_MimeException $e) {
         throw new Swift_Message_MimeException("Something went wrong whilst trying to move some MIME parts during an attach(). " . "The MIME component threw an exception:<br />" . $e->getMessage());
     }
 }