Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Pop3.php
Go to the documentation of this file.
1 <?php
27 #require_once 'Zend/Mail/Storage/Abstract.php';
28 
32 #require_once 'Zend/Mail/Protocol/Pop3.php';
33 
37 #require_once 'Zend/Mail/Message.php';
38 
39 
48 {
53  protected $_protocol;
54 
55 
63  public function countMessages()
64  {
65  $this->_protocol->status($count, $null);
66  return (int)$count;
67  }
68 
76  public function getSize($id = 0)
77  {
78  $id = $id ? $id : null;
79  return $this->_protocol->getList($id);
80  }
81 
89  public function getMessage($id)
90  {
91  $bodyLines = 0;
92  $message = $this->_protocol->top($id, $bodyLines, true);
93 
94  return new $this->_messageClass(array('handler' => $this, 'id' => $id, 'headers' => $message,
95  'noToplines' => $bodyLines < 1));
96  }
97 
98  /*
99  * Get raw header of message or part
100  *
101  * @param int $id number of message
102  * @param null|array|string $part path to part or null for messsage header
103  * @param int $topLines include this many lines with header (after an empty line)
104  * @return string raw header
105  * @throws Zend_Mail_Protocol_Exception
106  * @throws Zend_Mail_Storage_Exception
107  */
108  public function getRawHeader($id, $part = null, $topLines = 0)
109  {
110  if ($part !== null) {
111  // TODO: implement
115  #require_once 'Zend/Mail/Storage/Exception.php';
116  throw new Zend_Mail_Storage_Exception('not implemented');
117  }
118 
119  return $this->_protocol->top($id, 0, true);
120  }
121 
122  /*
123  * Get raw content of message or part
124  *
125  * @param int $id number of message
126  * @param null|array|string $part path to part or null for messsage content
127  * @return string raw content
128  * @throws Zend_Mail_Protocol_Exception
129  * @throws Zend_Mail_Storage_Exception
130  */
131  public function getRawContent($id, $part = null)
132  {
133  if ($part !== null) {
134  // TODO: implement
138  #require_once 'Zend/Mail/Storage/Exception.php';
139  throw new Zend_Mail_Storage_Exception('not implemented');
140  }
141 
142  $content = $this->_protocol->retrieve($id);
143  // TODO: find a way to avoid decoding the headers
145  return $body;
146  }
147 
161  public function __construct($params)
162  {
163  if (is_array($params)) {
164  $params = (object)$params;
165  }
166 
167  $this->_has['fetchPart'] = false;
168  $this->_has['top'] = null;
169  $this->_has['uniqueid'] = null;
170 
171  if ($params instanceof Zend_Mail_Protocol_Pop3) {
172  $this->_protocol = $params;
173  return;
174  }
175 
176  if (!isset($params->user)) {
180  #require_once 'Zend/Mail/Storage/Exception.php';
181  throw new Zend_Mail_Storage_Exception('need at least user in params');
182  }
183 
184  $host = isset($params->host) ? $params->host : 'localhost';
185  $password = isset($params->password) ? $params->password : '';
186  $port = isset($params->port) ? $params->port : null;
187  $ssl = isset($params->ssl) ? $params->ssl : false;
188 
189  $this->_protocol = new Zend_Mail_Protocol_Pop3();
190  $this->_protocol->connect($host, $port, $ssl);
191  $this->_protocol->login($params->user, $password);
192  }
193 
200  public function close()
201  {
202  $this->_protocol->logout();
203  }
204 
211  public function noop()
212  {
213  return $this->_protocol->noop();
214  }
215 
225  public function removeMessage($id)
226  {
227  $this->_protocol->delete($id);
228  }
229 
239  public function getUniqueId($id = null)
240  {
241  if (!$this->hasUniqueid) {
242  if ($id) {
243  return $id;
244  }
245  $count = $this->countMessages();
246  if ($count < 1) {
247  return array();
248  }
249  $range = range(1, $count);
250  return array_combine($range, $range);
251  }
252 
253  return $this->_protocol->uniqueid($id);
254  }
255 
266  public function getNumberByUniqueId($id)
267  {
268  if (!$this->hasUniqueid) {
269  return $id;
270  }
271 
272  $ids = $this->getUniqueId();
273  foreach ($ids as $k => $v) {
274  if ($v == $id) {
275  return $k;
276  }
277  }
278 
282  #require_once 'Zend/Mail/Storage/Exception.php';
283  throw new Zend_Mail_Storage_Exception('unique id not found');
284  }
285 
295  public function __get($var)
296  {
297  $result = parent::__get($var);
298  if ($result !== null) {
299  return $result;
300  }
301 
302  if (strtolower($var) == 'hastop') {
303  if ($this->_protocol->hasTop === null) {
304  // need to make a real call, because not all server are honest in their capas
305  try {
306  $this->_protocol->top(1, 0, false);
307  } catch(Zend_Mail_Exception $e) {
308  // ignoring error
309  }
310  }
311  $this->_has['top'] = $this->_protocol->hasTop;
312  return $this->_protocol->hasTop;
313  }
314 
315  if (strtolower($var) == 'hasuniqueid') {
316  $id = null;
317  try {
318  $id = $this->_protocol->uniqueid(1);
319  } catch(Zend_Mail_Exception $e) {
320  // ignoring error
321  }
322  $this->_has['uniqueid'] = $id ? true : false;
323  return $this->_has['uniqueid'];
324  }
325 
326  return $result;
327  }
328 }
$id
Definition: fieldset.phtml:14
static splitMessage( $message, &$headers, &$body, $EOL=Zend_Mime::LINEEND)
Definition: Decode.php:123
$count
Definition: recent.phtml:13
$message
getNumberByUniqueId($id)
Definition: Pop3.php:266
getUniqueId($id=null)
Definition: Pop3.php:239
__construct($params)
Definition: Pop3.php:161
getRawHeader($id, $part=null, $topLines=0)
Definition: Pop3.php:108
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
getRawContent($id, $part=null)
Definition: Pop3.php:131