/user/plugins/email/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Attachment.php

https://gitlab.com/3dplex/3d-plex-main-site · PHP · 179 lines · 70 code · 16 blank · 93 comment · 3 complexity · 37137ef7f554b26a94a8fd14a986057d MD5 · raw file

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