Esempio n. 1
0
 public function __construct($options)
 {
     $params = $this->convertParams($options);
     $class = $params['protocol_class'];
     $this->protocol = new $class($params['host'], $params['port'], $params['ssl']);
     $this->protocol->login($params['user'], $params['password']);
     $class = $params['storage_class'];
     $this->storage = new $class($this->protocol);
 }
Esempio n. 2
0
 /**
  * create instance with parameters
  * Supported paramters are
  *   - user username
  *   - host hostname or ip address of IMAP server [optional, default = 'localhost']
  *   - password password for user 'username' [optional, default = '']
  *   - port port for IMAP server [optional, default = 110]
  *   - ssl 'SSL' or 'TLS' for secure sockets
  *   - folder select this folder [optional, default = 'INBOX']
  *
  * @param  array $params mail reader specific parameters
  * @throws \Zend\Mail\Storage\Exception
  * @throws \Zend\Mail\Protocol\Exception
  */
 public function __construct($params)
 {
     if (is_array($params)) {
         $params = (object) $params;
     }
     $this->_has['flags'] = true;
     if ($params instanceof Protocol\Imap) {
         $this->_protocol = $params;
         try {
             $this->selectFolder('INBOX');
         } catch (Exception $e) {
             throw new Exception\RuntimeException('cannot select INBOX, is this a valid transport?', 0, $e);
         }
         return;
     }
     if (!isset($params->user)) {
         throw new Exception\InvalidArgumentException('need at least user in params');
     }
     $host = isset($params->host) ? $params->host : 'localhost';
     $password = isset($params->password) ? $params->password : '';
     $port = isset($params->port) ? $params->port : null;
     $ssl = isset($params->ssl) ? $params->ssl : false;
     $this->_protocol = new Protocol\Imap();
     $this->_protocol->connect($host, $port, $ssl);
     if (!$this->_protocol->login($params->user, $password)) {
         throw new Exception\RuntimeException('cannot login, user or password wrong');
     }
     $this->selectFolder(isset($params->folder) ? $params->folder : 'INBOX');
 }
Esempio n. 3
0
 public function testStore()
 {
     $protocol = new Protocol\Imap($this->_params['host']);
     $protocol->login($this->_params['user'], $this->_params['password']);
     $protocol->select('INBOX');
     $this->assertTrue($protocol->store(array('\\Flagged'), 1));
     $this->assertTrue($protocol->store(array('\\Flagged'), 1, null, '-'));
     $this->assertTrue($protocol->store(array('\\Flagged'), 1, null, '+'));
     $result = $protocol->store(array('\\Flagged'), 1, null, '', false);
     $this->assertTrue(in_array('\\Flagged', $result[1]));
     $result = $protocol->store(array('\\Flagged'), 1, null, '-', false);
     $this->assertFalse(in_array('\\Flagged', $result[1]));
     $result = $protocol->store(array('\\Flagged'), 1, null, '+', false);
     $this->assertTrue(in_array('\\Flagged', $result[1]));
 }