PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / libs / Zend / Mail / Transport / Sendmail.php
matomo / app / libs / Zend / Mail / Transport Last commit date
Abstract.php 6 years ago Exception.php 6 years ago File.php 6 years ago Sendmail.php 6 years ago Smtp.php 6 years ago
Sendmail.php
221 lines
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 * @subpackage Transport
18 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Sendmail.php 23775 2011-03-01 17:25:24Z ralph $
21 */
22
23
24 /**
25 * @see Zend_Mail_Transport_Abstract
26 */
27 // require_once 'Zend/Mail/Transport/Abstract.php';
28
29
30 /**
31 * Class for sending eMails via the PHP internal mail() function
32 *
33 * @category Zend
34 * @package Zend_Mail
35 * @subpackage Transport
36 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license http://framework.zend.com/license/new-bsd New BSD License
38 */
39 class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract
40 {
41 /**
42 * Subject
43 * @var string
44 * @access public
45 */
46 public $subject = null;
47
48
49 /**
50 * Config options for sendmail parameters
51 *
52 * @var string
53 */
54 public $parameters;
55
56 /**
57 * EOL character string
58 * @var string
59 * @access public
60 */
61 public $EOL = PHP_EOL;
62
63 /**
64 * error information
65 * @var string
66 */
67 protected $_errstr;
68
69 /**
70 * Constructor.
71 *
72 * @param string|array|Zend_Config $parameters OPTIONAL (Default: null)
73 * @return void
74 */
75 public function __construct($parameters = null)
76 {
77 if ($parameters instanceof Zend_Config) {
78 $parameters = $parameters->toArray();
79 }
80
81 if (is_array($parameters)) {
82 $parameters = implode(' ', $parameters);
83 }
84
85 $this->parameters = $parameters;
86 }
87
88
89 /**
90 * Send mail using PHP native mail()
91 *
92 * @access public
93 * @return void
94 * @throws Zend_Mail_Transport_Exception if parameters is set
95 * but not a string
96 * @throws Zend_Mail_Transport_Exception on mail() failure
97 */
98 public function _sendMail()
99 {
100 if ($this->parameters === null) {
101 set_error_handler(array($this, '_handleMailErrors'));
102 $result = mail(
103 $this->recipients,
104 $this->_mail->getSubject(),
105 $this->body,
106 $this->header);
107 restore_error_handler();
108 } else {
109 if(!is_string($this->parameters)) {
110 /**
111 * @see Zend_Mail_Transport_Exception
112 *
113 * Exception is thrown here because
114 * $parameters is a public property
115 */
116 // require_once 'Zend/Mail/Transport/Exception.php';
117 throw new Zend_Mail_Transport_Exception(
118 'Parameters were set but are not a string'
119 );
120 }
121
122 set_error_handler(array($this, '_handleMailErrors'));
123 $result = mail(
124 $this->recipients,
125 $this->_mail->getSubject(),
126 $this->body,
127 $this->header,
128 $this->parameters);
129 restore_error_handler();
130 }
131
132 if ($this->_errstr !== null || !$result) {
133 /**
134 * @see Zend_Mail_Transport_Exception
135 */
136 // require_once 'Zend/Mail/Transport/Exception.php';
137 throw new Zend_Mail_Transport_Exception('Unable to send mail. ' . $this->_errstr);
138 }
139 }
140
141
142 /**
143 * Format and fix headers
144 *
145 * mail() uses its $to and $subject arguments to set the To: and Subject:
146 * headers, respectively. This method strips those out as a sanity check to
147 * prevent duplicate header entries.
148 *
149 * @access protected
150 * @param array $headers
151 * @return void
152 * @throws Zend_Mail_Transport_Exception
153 */
154 protected function _prepareHeaders($headers)
155 {
156 if (!$this->_mail) {
157 /**
158 * @see Zend_Mail_Transport_Exception
159 */
160 // require_once 'Zend/Mail/Transport/Exception.php';
161 throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
162 }
163
164 // mail() uses its $to parameter to set the To: header, and the $subject
165 // parameter to set the Subject: header. We need to strip them out.
166 if (0 === strpos(PHP_OS, 'WIN')) {
167 // If the current recipients list is empty, throw an error
168 if (empty($this->recipients)) {
169 /**
170 * @see Zend_Mail_Transport_Exception
171 */
172 // require_once 'Zend/Mail/Transport/Exception.php';
173 throw new Zend_Mail_Transport_Exception('Missing To addresses');
174 }
175 } else {
176 // All others, simply grab the recipients and unset the To: header
177 if (!isset($headers['To'])) {
178 /**
179 * @see Zend_Mail_Transport_Exception
180 */
181 // require_once 'Zend/Mail/Transport/Exception.php';
182 throw new Zend_Mail_Transport_Exception('Missing To header');
183 }
184
185 unset($headers['To']['append']);
186 $this->recipients = implode(',', $headers['To']);
187 }
188
189 // Remove recipient header
190 unset($headers['To']);
191
192 // Remove subject header, if present
193 if (isset($headers['Subject'])) {
194 unset($headers['Subject']);
195 }
196
197 // Prepare headers
198 parent::_prepareHeaders($headers);
199
200 // Fix issue with empty blank line ontop when using Sendmail Trnasport
201 $this->header = rtrim($this->header);
202 }
203
204 /**
205 * Temporary error handler for PHP native mail().
206 *
207 * @param int $errno
208 * @param string $errstr
209 * @param string $errfile
210 * @param string $errline
211 * @param array $errcontext
212 * @return true
213 */
214 public function _handleMailErrors($errno, $errstr, $errfile = null, $errline = null, array $errcontext = null)
215 {
216 $this->_errstr = $errstr;
217 return true;
218 }
219
220 }
221