TYPO3  7.6
Mime/Attachment.php
Go to the documentation of this file.
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 
17 {
19  private $_mimeTypes = array();
20 
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 
45  public function getNestingLevel()
46  {
47  return self::LEVEL_MIXED;
48  }
49 
57  public function getDisposition()
58  {
59  return $this->_getHeaderFieldModel('Content-Disposition');
60  }
61 
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 
85  public function getFilename()
86  {
87  return $this->_getHeaderParameter('Content-Disposition', 'filename');
88  }
89 
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 
110  public function getSize()
111  {
112  return $this->_getHeaderParameter('Content-Disposition', 'size');
113  }
114 
122  public function setSize($size)
123  {
124  $this->_setHeaderParameter('Content-Disposition', 'size', $size);
125 
126  return $this;
127  }
128 
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 }