Message.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Mail
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * Zend_Mail_Part
  23. */
  24. #require_once 'Zend/Mail/Part.php';
  25. /**
  26. * Zend_Mail_Message_Interface
  27. */
  28. #require_once 'Zend/Mail/Message/Interface.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Mail
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Mail_Message extends Zend_Mail_Part implements Zend_Mail_Message_Interface
  36. {
  37. /**
  38. * flags for this message
  39. * @var array
  40. */
  41. protected $_flags = array();
  42. /**
  43. * Public constructor
  44. *
  45. * In addition to the parameters of Zend_Mail_Part::__construct() this constructor supports:
  46. * - file filename or file handle of a file with raw message content
  47. * - flags array with flags for message, keys are ignored, use constants defined in Zend_Mail_Storage
  48. *
  49. * @param string $rawMessage full message with or without headers
  50. * @throws Zend_Mail_Exception
  51. */
  52. public function __construct(array $params)
  53. {
  54. if (isset($params['file'])) {
  55. if (!is_resource($params['file'])) {
  56. $params['raw'] = @file_get_contents($params['file']);
  57. if ($params['raw'] === false) {
  58. /**
  59. * @see Zend_Mail_Exception
  60. */
  61. #require_once 'Zend/Mail/Exception.php';
  62. throw new Zend_Mail_Exception('could not open file');
  63. }
  64. } else {
  65. $params['raw'] = stream_get_contents($params['file']);
  66. }
  67. $params['raw'] = preg_replace("/(?<!\r)\n/", "\r\n", $params['raw']);
  68. }
  69. if (!empty($params['flags'])) {
  70. // set key and value to the same value for easy lookup
  71. $this->_flags = array_merge($this->_flags, array_combine($params['flags'],$params['flags']));
  72. }
  73. parent::__construct($params);
  74. }
  75. /**
  76. * return toplines as found after headers
  77. *
  78. * @return string toplines
  79. */
  80. public function getTopLines()
  81. {
  82. return $this->_topLines;
  83. }
  84. /**
  85. * check if flag is set
  86. *
  87. * @param mixed $flag a flag name, use constants defined in Zend_Mail_Storage
  88. * @return bool true if set, otherwise false
  89. */
  90. public function hasFlag($flag)
  91. {
  92. return isset($this->_flags[$flag]);
  93. }
  94. /**
  95. * get all set flags
  96. *
  97. * @return array array with flags, key and value are the same for easy lookup
  98. */
  99. public function getFlags()
  100. {
  101. return $this->_flags;
  102. }
  103. }