示例#1
0
 /**
  * Overrides setData() in MIME so that a filename can be set
  * @param mixed The data to set for the body
  * @param boolean If the stream is a file, should it's filename be used?
  * @throws Swift_FileException If the stream cannot be read
  */
 public function setData($data, $read_filename = true)
 {
     parent::setData($data);
     if ($read_filename && $data instanceof Swift_file) {
         $this->setFileName($data->getFileName());
     }
 }
示例#2
0
 /**
  * Overrides setData() in MIME so that a filename can be set
  * @param mixed The data to set for the body
  * @param boolean If the stream is a file, should it's filename be used?
  * @throws Swift_FileException If the stream cannot be read
  */
 function setData($data, $read_filename = true)
 {
     parent::setData($data);
     if ($read_filename && is_a($data, "Swift_file")) {
         $this->setFileName($data->getFileName());
     }
 }
示例#3
0
 /**
  * Constructor
  * @param mixed The data to use in the body
  * @param string Mime type
  * @param string The encoding format used
  * @param string The charset used
  */
 public function __construct($data = null, $type = "text/plain", $encoding = null, $charset = null)
 {
     parent::__construct();
     $this->setContentType($type);
     $this->setEncoding($encoding);
     $this->setCharset($charset);
     $this->setFlowed(false);
     if ($data !== null) {
         $this->setData($data);
         if ($charset === null) {
             Swift_ClassLoader::load("Swift_Message_Encoder");
             if (is_string($data) && Swift_Message_Encoder::instance()->isUTF8($data)) {
                 $this->setCharset("utf-8");
             } else {
                 $this->setCharset("iso-8859-1");
             }
             //The likely encoding
         }
     }
 }
示例#4
0
 /**
  * Put the original values back in the message after it was modified before sending.
  * @param Swift_Message_Mime The message (or part)
  * @param array The location of the stored values
  */
 protected function recursiveRestore(Swift_Message_Mime $mime, &$store)
 {
     //Restore headers
     foreach ($store["headers"] as $name => $array) {
         if ($array["value"] !== false) {
             $mime->headers->set($name, $array["value"]);
         }
         foreach ($array["attributes"] as $att_name => $att_value) {
             $mime->headers->setAttribute($name, $att_name, $att_value);
         }
     }
     //Restore body
     if ($store["body"] !== false) {
         $mime->setData($store["body"]);
     }
     //Restore children
     foreach ($store["children"] as $id => $child_store) {
         $child = $mime->getChild($id);
         $this->recursiveRestore($child, $child_store);
     }
 }
 /**
  * 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());
     }
 }
示例#6
0
 /**
  * Get the data in the format suitable for sending
  * @return Swift_Cache_OutputStream
  * @throws Swift_FileException If the file stream given cannot be read
  * @throws Swift_Message_MimeException If some required headers have been forcefully removed
  */
 function &buildData()
 {
     Swift_ClassLoader::load("Swift_Cache_JointOutputStream");
     $encoder =& $this->_encoder;
     if (!empty($this->children)) {
         if ($this->boundary === null) {
             $this->boundary = Swift_Message_Mime::generateBoundary();
         }
         $this->headers->setAttribute("Content-Type", "boundary", $this->boundary);
         $this->cache->clear("append");
         foreach ($this->children as $id => $part) {
             $this->cache->write("append", $this->LE . "--" . $this->boundary . $this->LE);
             $part_stream = $this->children[$id]->build();
             while (false !== ($bytes = $part_stream->read())) {
                 $this->cache->write("append", $bytes);
             }
         }
         $this->cache->write("append", $this->LE . "--" . $this->boundary . "--" . $this->LE);
     }
     $i = array();
     $joint_os = new Swift_Cache_JointOutputStream($i);
     //Try using a cached version to save some cycles (at the expense of memory)
     if ($this->cache->has("body")) {
         $body =& $this->cache->getOutputStream("body");
         $joint_os->addStream($body);
         $append =& $this->cache->getOutputStream("append");
         $joint_os->addStream($append);
         return $joint_os;
     }
     $data =& $this->getData();
     $is_file = is_a($this->getData(), "Swift_File");
     switch ($this->getEncoding()) {
         case "quoted-printable":
             if ($is_file) {
                 $qp_os = $encoder->QPEncodeFile($this->getData(), 76, $this->LE);
                 while (false !== ($bytes = $qp_os->read())) {
                     $this->cache->write("body", $bytes);
                 }
             } else {
                 $this->cache->write("body", $encoder->QPEncode($this->getData(), 76, 0, false, $this->LE));
             }
             break;
         case "base64":
             if ($is_file) {
                 $b64_os = $encoder->base64EncodeFile($this->getData(), 76, $this->LE);
                 while (false !== ($bytes = $b64_os->read())) {
                     $this->cache->write("body", $bytes);
                 }
             } else {
                 $this->cache->write("body", $encoder->base64Encode($this->getData(), 76, 0, false, $this->LE));
             }
             break;
         case "binary":
             if ($is_file) {
                 $data = $this->getData();
                 while (false !== ($bytes = $data->read(8192))) {
                     $this->cache->write("body", $bytes);
                 }
             } else {
                 $this->cache->write("body", $this->getData());
             }
             break;
         case "7bit":
             if ($is_file) {
                 $os = $encoder->encode7BitFile($this->getData(), $this->wrap, $this->LE);
                 while (false !== ($bytes = $os->read())) {
                     $this->cache->write("body", $bytes);
                 }
             } else {
                 $this->cache->write("body", $encoder->encode7Bit($this->getData(), $this->wrap, $this->LE));
             }
             break;
         case "8bit":
         default:
             if ($is_file) {
                 $os = $encoder->encode8BitFile($this->getData(), $this->wrap, $this->LE);
                 while (false !== ($bytes = $os->read())) {
                     $this->cache->write("body", $bytes);
                 }
             } else {
                 $this->cache->write("body", $encoder->encode8Bit($this->getData(), $this->wrap, $this->LE));
             }
             break;
     }
     $body =& $this->cache->getOutputStream("body");
     $joint_os->addStream($body);
     $append =& $this->cache->getOutputStream("append");
     $joint_os->addStream($append);
     return $joint_os;
 }