Skip to content

Commit

Permalink
Merge 0bb1778 into ba247b8
Browse files Browse the repository at this point in the history
  • Loading branch information
Mowee committed Jan 26, 2015
2 parents ba247b8 + 0bb1778 commit 78a3e98
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/Fetch/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ class Server
*/
protected $service = 'imap';

/**
* Contains all of the IMAP errors that have occurred
*
* @var array
*/
protected $imapErrors = array();

/**
* This constructor takes the location and service thats trying to be connected to as its arguments.
*
Expand All @@ -135,6 +142,33 @@ public function __construct($serverPath, $port = 143, $service = 'imap')
$this->service = $service;
}

public function __destruct()
{
$this->setImapErrors();
}

/**
* Returns all of the IMAP errors that have occurred
*
* @return array
*/
public function getImapErrors()
{
if(empty($this->imapErrors)) {
$this->setImapErrors();
}

return $this->imapErrors;
}

/**
* Sets all the IMAP errors that have occurred
*/
public function setImapErrors()
{
$this->imapErrors = imap_errors();
}

/**
* This function sets the username and password used to connect to the server.
*
Expand Down Expand Up @@ -288,7 +322,7 @@ protected function setImapStream()
if (!imap_reopen($this->imapStream, $this->getServerString(), $this->options, 1))
throw new \RuntimeException(imap_last_error());
} else {
$imapStream = imap_open($this->getServerString(), $this->username, $this->password, $this->options, 1);
$imapStream = @imap_open($this->getServerString(), $this->username, $this->password, $this->options, 1);

if ($imapStream === false)
throw new \RuntimeException(imap_last_error());
Expand Down Expand Up @@ -455,4 +489,6 @@ public function listMailBoxes($pattern = '*')
{
return imap_list($this->getImapStream(), $this->getServerSpecification(), $pattern);
}


}

0 comments on commit 78a3e98

Please sign in to comment.