00001 <?php
00027 require_once 'Zend/Mail/Storage/Abstract.php';
00028
00032 require_once 'Zend/Mail/Protocol/Pop3.php';
00033
00037 require_once 'Zend/Mail/Message.php';
00038
00039
00047 class Zend_Mail_Storage_Pop3 extends Zend_Mail_Storage_Abstract
00048 {
00053 protected $_protocol;
00054
00055
00063 public function countMessages()
00064 {
00065 $this->_protocol->status($count, $null);
00066 return (int)$count;
00067 }
00068
00076 public function getSize($id = 0)
00077 {
00078 $id = $id ? $id : null;
00079 return $this->_protocol->getList($id);
00080 }
00081
00089 public function getMessage($id)
00090 {
00091 $bodyLines = 0;
00092 $message = $this->_protocol->top($id, $bodyLines, true);
00093
00094 return new $this->_messageClass(array('handler' => $this, 'id' => $id, 'headers' => $message,
00095 'noToplines' => $bodyLines < 1));
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 public function getRawHeader($id, $part = null, $topLines = 0)
00109 {
00110 if ($part !== null) {
00111
00115 require_once 'Zend/Mail/Storage/Exception.php';
00116 throw new Zend_Mail_Storage_Exception('not implemented');
00117 }
00118
00119 return $this->_protocol->top($id, 0, true);
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 public function getRawContent($id, $part = null)
00132 {
00133 if ($part !== null) {
00134
00138 require_once 'Zend/Mail/Storage/Exception.php';
00139 throw new Zend_Mail_Storage_Exception('not implemented');
00140 }
00141
00142 $content = $this->_protocol->retrieve($id);
00143
00144 Zend_Mime_Decode::splitMessage($content, $null, $body);
00145 return $body;
00146 }
00147
00161 public function __construct($params)
00162 {
00163 if (is_array($params)) {
00164 $params = (object)$params;
00165 }
00166
00167 $this->_has['fetchPart'] = false;
00168 $this->_has['top'] = null;
00169 $this->_has['uniqueid'] = null;
00170
00171 if ($params instanceof Zend_Mail_Protocol_Pop3) {
00172 $this->_protocol = $params;
00173 return;
00174 }
00175
00176 if (!isset($params->user)) {
00180 require_once 'Zend/Mail/Storage/Exception.php';
00181 throw new Zend_Mail_Storage_Exception('need at least user in params');
00182 }
00183
00184 $host = isset($params->host) ? $params->host : 'localhost';
00185 $password = isset($params->password) ? $params->password : '';
00186 $port = isset($params->port) ? $params->port : null;
00187 $ssl = isset($params->ssl) ? $params->ssl : false;
00188
00189 $this->_protocol = new Zend_Mail_Protocol_Pop3();
00190 $this->_protocol->connect($host, $port, $ssl);
00191 $this->_protocol->login($params->user, $password);
00192 }
00193
00200 public function close()
00201 {
00202 $this->_protocol->logout();
00203 }
00204
00211 public function noop()
00212 {
00213 return $this->_protocol->noop();
00214 }
00215
00225 public function removeMessage($id)
00226 {
00227 $this->_protocol->delete($id);
00228 }
00229
00239 public function getUniqueId($id = null)
00240 {
00241 if (!$this->hasUniqueid) {
00242 if ($id) {
00243 return $id;
00244 }
00245 $count = $this->countMessages();
00246 if ($count < 1) {
00247 return array();
00248 }
00249 $range = range(1, $count);
00250 return array_combine($range, $range);
00251 }
00252
00253 return $this->_protocol->uniqueid($id);
00254 }
00255
00266 public function getNumberByUniqueId($id)
00267 {
00268 if (!$this->hasUniqueid) {
00269 return $id;
00270 }
00271
00272 $ids = $this->getUniqueId();
00273 foreach ($ids as $k => $v) {
00274 if ($v == $id) {
00275 return $k;
00276 }
00277 }
00278
00282 require_once 'Zend/Mail/Storage/Exception.php';
00283 throw new Zend_Mail_Storage_Exception('unique id not found');
00284 }
00285
00295 public function __get($var)
00296 {
00297 $result = parent::__get($var);
00298 if ($result !== null) {
00299 return $result;
00300 }
00301
00302 if (strtolower($var) == 'hastop') {
00303 if ($this->_protocol->hasTop === null) {
00304
00305 try {
00306 $this->_protocol->top(1, 0, false);
00307 } catch(Zend_Mail_Exception $e) {
00308
00309 }
00310 }
00311 $this->_has['top'] = $this->_protocol->hasTop;
00312 return $this->_protocol->hasTop;
00313 }
00314
00315 if (strtolower($var) == 'hasuniqueid') {
00316 $id = null;
00317 try {
00318 $id = $this->_protocol->uniqueid(1);
00319 } catch(Zend_Mail_Exception $e) {
00320
00321 }
00322 $this->_has['uniqueid'] = $id ? true : false;
00323 return $this->_has['uniqueid'];
00324 }
00325
00326 return $result;
00327 }
00328 }