Esempio n. 1
0
 /**
  * Constructor
  * @param mixed The input source.  Can be a file or a string
  * @param string The filename to use, optional
  * @param string The MIME type to use, optional
  * @param string The Content-ID to use, optional
  * @param string The encoding format to use, optional
  */
 public function __construct($data = null, $name = null, $type = "application/octet-stream", $cid = null, $encoding = "base64")
 {
     parent::__construct($data, $name, $type, $encoding, "inline");
     if ($cid === null) {
         $cid = self::generateFileName("swift-" . uniqid(time()) . ".");
         $cid = urlencode($cid) . "@" . (!empty($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : "swift");
     }
     $this->setContentId($cid);
     if ($name === null && !$data instanceof Swift_File) {
         $this->setFileName($cid);
     }
     $this->headers->set("Content-Description", null);
 }
Esempio n. 2
0
 /**
  * Constructor
  * @param mixed The input source.  Can be a file or a string
  * @param string The filename to use, optional
  * @param string The MIME type to use, optional
  * @param string The Content-ID to use, optional
  * @param string The encoding format to use, optional
  */
 function Swift_Message_EmbeddedFile($data = null, $name = null, $type = "application/octet-stream", $cid = null, $encoding = "base64")
 {
     $this->Swift_Message_Attachment($data, $name, $type, $encoding, "inline");
     if ($cid === null) {
         $cid = Swift_Message_Attachment::generateFileName("swift-" . uniqid(time()) . ".");
         $cid = urlencode($cid) . "@" . (!empty($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : "swift");
     }
     $this->setContentId($cid);
     if ($name === null && !is_a($data, "Swift_File")) {
         $this->setFileName($cid);
     }
     $this->headers->set("Content-Description", null);
 }
Esempio n. 3
0
 /**
  * $attachement is either a string (pathname), or a list of these options :
  * - path (*) is the real path on filesystem
  * - filename
  * - mime-type
  *
  * @param string|array $attachment
  * 
  * return Swift_Message_Attachment
  */
 protected static function getAttachment($attachment)
 {
     if (!is_array($attachment)) {
         $attachment = array('path' => $attachment);
     }
     if (!@$attachment['mime-type']) {
         $attachment['mime-type'] = mime_content_type($attachment['path']);
     }
     if (!@$attachment['filename']) {
         $attachment['filename'] = basename($attachment['path']);
     }
     $attach = new Swift_Message_Attachment(new Swift_File($attachment['path']));
     $attach->setContentType($attachment['mime-type']);
     $attach->setFileName($attachment['filename']);
     return $attach;
 }
 /**
  * The number of the file should go up by one each time.
  */
 public function testSequenceNumberIsAlwaysIncrementedInFileName()
 {
     $name = Swift_Message_Attachment::generateFileName();
     $id1 = (int) substr($name, -1);
     $name = Swift_Message_Attachment::generateFileName();
     $id2 = (int) substr($name, -1);
     $this->assertTrue($id2 > $id1);
     $name = Swift_Message_Attachment::generateFileName();
     $id3 = (int) substr($name, -1);
     $this->assertTrue($id3 > $id2);
 }
Esempio n. 5
0
 /**
  * Execute needed logic prior to building
  */
 function preBuild()
 {
     if ($this->getFileName() === null) {
         if (is_a($this->getData(), "Swift_File")) {
             $data =& $this->getData();
             $this->setFileName($data->getFileName());
         } else {
             $this->setFileName(Swift_Message_Attachment::generateFileName("file.att."));
         }
     }
 }