Exemplo n.º 1
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;
 }
 /**
  * Setting the filename should set the description first.
  */
 public function testSettingFileNameResetsDescription()
 {
     $attachment = new Swift_Message_Attachment("some string", "my_file.txt");
     $attachment->setDescription("another_file.txt");
     $this->assertEqual("another_file.txt", $attachment->getDescription());
     $attachment->setFileName("zip.button");
     $this->assertEqual("zip.button", $attachment->getDescription());
     $structure = $attachment->build()->readFull();
     $this->assertPattern("~Content-Type: application/octet-stream;\\s* name=(\"?)(zip\\.button)\\1\r\nContent-Transfer-Encoding: base64\r\n" . "Content-Description: \\2\r\nContent-Disposition: attachment;\\s* filename=(\"?)\\2\\3\r\n\r\n.*~s", $structure);
 }