[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/Mime/ -> Attachment.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of SwiftMailer.
   5   * (c) 2004-2009 Chris Corbyn
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * An attachment, in a multipart message.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
  17  {
  18      /** Recognized MIME types */
  19      private $_mimeTypes = array();
  20  
  21      /**
  22       * Create a new Attachment with $headers, $encoder and $cache.
  23       *
  24       * @param Swift_Mime_HeaderSet      $headers
  25       * @param Swift_Mime_ContentEncoder $encoder
  26       * @param Swift_KeyCache            $cache
  27       * @param Swift_Mime_Grammar        $grammar
  28       * @param array                     $mimeTypes optional
  29       */
  30      public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $mimeTypes = array())
  31      {
  32          parent::__construct($headers, $encoder, $cache, $grammar);
  33          $this->setDisposition('attachment');
  34          $this->setContentType('application/octet-stream');
  35          $this->_mimeTypes = $mimeTypes;
  36      }
  37  
  38      /**
  39       * Get the nesting level used for this attachment.
  40       *
  41       * Always returns {@link LEVEL_MIXED}.
  42       *
  43       * @return int
  44       */
  45      public function getNestingLevel()
  46      {
  47          return self::LEVEL_MIXED;
  48      }
  49  
  50      /**
  51       * Get the Content-Disposition of this attachment.
  52       *
  53       * By default attachments have a disposition of "attachment".
  54       *
  55       * @return string
  56       */
  57      public function getDisposition()
  58      {
  59          return $this->_getHeaderFieldModel('Content-Disposition');
  60      }
  61  
  62      /**
  63       * Set the Content-Disposition of this attachment.
  64       *
  65       * @param string $disposition
  66       *
  67       * @return Swift_Mime_Attachment
  68       */
  69      public function setDisposition($disposition)
  70      {
  71          if (!$this->_setHeaderFieldModel('Content-Disposition', $disposition)) {
  72              $this->getHeaders()->addParameterizedHeader(
  73                  'Content-Disposition', $disposition
  74                  );
  75          }
  76  
  77          return $this;
  78      }
  79  
  80      /**
  81       * Get the filename of this attachment when downloaded.
  82       *
  83       * @return string
  84       */
  85      public function getFilename()
  86      {
  87          return $this->_getHeaderParameter('Content-Disposition', 'filename');
  88      }
  89  
  90      /**
  91       * Set the filename of this attachment.
  92       *
  93       * @param string $filename
  94       *
  95       * @return Swift_Mime_Attachment
  96       */
  97      public function setFilename($filename)
  98      {
  99          $this->_setHeaderParameter('Content-Disposition', 'filename', $filename);
 100          $this->_setHeaderParameter('Content-Type', 'name', $filename);
 101  
 102          return $this;
 103      }
 104  
 105      /**
 106       * Get the file size of this attachment.
 107       *
 108       * @return int
 109       */
 110      public function getSize()
 111      {
 112          return $this->_getHeaderParameter('Content-Disposition', 'size');
 113      }
 114  
 115      /**
 116       * Set the file size of this attachment.
 117       *
 118       * @param int $size
 119       *
 120       * @return Swift_Mime_Attachment
 121       */
 122      public function setSize($size)
 123      {
 124          $this->_setHeaderParameter('Content-Disposition', 'size', $size);
 125  
 126          return $this;
 127      }
 128  
 129      /**
 130       * Set the file that this attachment is for.
 131       *
 132       * @param Swift_FileStream $file
 133       * @param string           $contentType optional
 134       *
 135       * @return Swift_Mime_Attachment
 136       */
 137      public function setFile(Swift_FileStream $file, $contentType = null)
 138      {
 139          $this->setFilename(basename($file->getPath()));
 140          $this->setBody($file, $contentType);
 141          if (!isset($contentType)) {
 142              $extension = strtolower(substr(
 143                  $file->getPath(), strrpos($file->getPath(), '.') + 1
 144                  ));
 145  
 146              if (array_key_exists($extension, $this->_mimeTypes)) {
 147                  $this->setContentType($this->_mimeTypes[$extension]);
 148              }
 149          }
 150  
 151          return $this;
 152      }
 153  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1