Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'weierophinney/feature/error-suppression…
Browse files Browse the repository at this point in the history
…-removal'
  • Loading branch information
akrabat committed Jul 13, 2012
4 parents 0b38f0b + 7bfa121 + 1914ec7 + 64cd04a commit 5ed923d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/Protocol/Imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function connect($host, $port = null, $ssl = false)
*/
protected function _nextLine()
{
$line = @fgets($this->_socket);
$line = fgets($this->_socket);
if ($line === false) {
throw new Exception\RuntimeException('cannot read - connection closed?');
}
Expand Down Expand Up @@ -309,7 +309,7 @@ public function sendRequest($command, $tokens = array(), &$tag = null)

foreach ($tokens as $token) {
if (is_array($token)) {
if (@fwrite($this->_socket, $line . ' ' . $token[0] . "\r\n") === false) {
if (fwrite($this->_socket, $line . ' ' . $token[0] . "\r\n") === false) {
throw new Exception\RuntimeException('cannot write - connection closed?');
}
if (!$this->_assumedNextLine('+ ')) {
Expand All @@ -321,7 +321,7 @@ public function sendRequest($command, $tokens = array(), &$tag = null)
}
}

if (@fwrite($this->_socket, $line . "\r\n") === false) {
if (fwrite($this->_socket, $line . "\r\n") === false) {
throw new Exception\RuntimeException('cannot write - connection closed?');
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/Storage/Folder/Maildir.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Zend\Mail\Storage;
use Zend\Mail\Storage\Exception;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -87,7 +88,9 @@ protected function _buildFolderTree()
$this->_rootFolder = new Storage\Folder('/', '/', false);
$this->_rootFolder->INBOX = new Storage\Folder('INBOX', 'INBOX', true);

$dh = @opendir($this->_rootdir);
ErrorHandler::start(E_WARNING);
$dh = opendir($this->_rootdir);
ErrorHandler::stop();
if (!$dh) {
throw new Exception\RuntimeException("can't read folders in maildir");
}
Expand Down Expand Up @@ -158,7 +161,9 @@ public function getFolders($rootFolder = null)
$subname = trim($rootFolder, $this->_delim);

while ($currentFolder) {
@list($entry, $subname) = @explode($this->_delim, $subname, 2);
ErrorHandler::start(E_NOTICE);
list($entry, $subname) = explode($this->_delim, $subname, 2);
ErrorHandler::stop();
$currentFolder = $currentFolder->$entry;
if (!$subname) {
break;
Expand Down
9 changes: 7 additions & 2 deletions src/Storage/Folder/Mbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Zend\Mail\Storage;
use Zend\Mail\Storage\Exception;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -90,7 +91,9 @@ protected function _buildFolderTree($currentDir, $parentFolder = null, $parentGl
$parentFolder = $this->_rootFolder;
}

$dh = @opendir($currentDir);
ErrorHandler::start(E_WARNING);
$dh = opendir($currentDir);
ErrorHandler::stop();
if (!$dh) {
throw new Exception\InvalidArgumentException("can't read dir $currentDir");
}
Expand Down Expand Up @@ -132,7 +135,9 @@ public function getFolders($rootFolder = null)
$currentFolder = $this->_rootFolder;
$subname = trim($rootFolder, DIRECTORY_SEPARATOR);
while ($currentFolder) {
@list($entry, $subname) = @explode(DIRECTORY_SEPARATOR, $subname, 2);
ErrorHandler::start(E_NOTICE);
list($entry, $subname) = explode(DIRECTORY_SEPARATOR, $subname, 2);
ErrorHandler::stop();
$currentFolder = $currentFolder->$entry;
if (!$subname) {
break;
Expand Down
20 changes: 15 additions & 5 deletions src/Storage/Maildir.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Zend\Mail\Storage;

use Zend\Mail;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -265,14 +266,18 @@ protected function _openMaildir($dirname)
$this->close();
}

$dh = @opendir($dirname . '/cur/');
ErrorHandler::start(E_WARNING);
$dh = opendir($dirname . '/cur/');
ErrorHandler::stop();
if (!$dh) {
throw new Exception\RuntimeException('cannot open maildir');
}
$this->_getMaildirFiles($dh, $dirname . '/cur/');
closedir($dh);

$dh = @opendir($dirname . '/new/');
ErrorHandler::start(E_WARNING);
$dh = opendir($dirname . '/new/');
ErrorHandler::stop();
if ($dh) {
$this->_getMaildirFiles($dh, $dirname . '/new/', array(Mail\Storage::FLAG_RECENT));
closedir($dh);
Expand All @@ -295,15 +300,20 @@ protected function _getMaildirFiles($dh, $dirname, $default_flags = array())
continue;
}

@list($uniq, $info) = explode(':', $entry, 2);
@list(,$size) = explode(',', $uniq, 2);
ErrorHandler::start(E_NOTICE);
list($uniq, $info) = explode(':', $entry, 2);
list(,$size) = explode(',', $uniq, 2);
ErrorHandler::stop();
if ($size && $size[0] == 'S' && $size[1] == '=') {
$size = substr($size, 2);
}
if (!ctype_digit($size)) {
$size = null;
}
@list($version, $flags) = explode(',', $info, 2);

ErrorHandler::start(E_NOTICE);
list($version, $flags) = explode(',', $info, 2);
ErrorHandler::stop();
if ($version != 2) {
$flags = '';
}
Expand Down
18 changes: 14 additions & 4 deletions src/Storage/Mbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Zend\Mail\Storage;

use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
* @package Zend_Mail
Expand Down Expand Up @@ -205,7 +207,9 @@ public function __construct($params)
protected function _isMboxFile($file, $fileIsString = true)
{
if ($fileIsString) {
$file = @fopen($file, 'r');
ErrorHandler::start(E_WARNING);
$file = fopen($file, 'r');
ErrorHandler::stop();
if (!$file) {
return false;
}
Expand All @@ -221,7 +225,9 @@ protected function _isMboxFile($file, $fileIsString = true)
}

if ($fileIsString) {
@fclose($file);
ErrorHandler::start(E_WARNING);
fclose($file);
ErrorHandler::stop();
}

return $result;
Expand All @@ -248,7 +254,9 @@ protected function _openMboxFile($filename)
$this->_filemtime = filemtime($this->_filename);

if (!$this->_isMboxFile($this->_fh, false)) {
@fclose($this->_fh);
ErrorHandler::start(E_WARNING);
fclose($this->_fh);
ErrorHandler::stop();
throw new Exception\InvalidArgumentException('file is not a valid mbox format');
}

Expand Down Expand Up @@ -281,7 +289,9 @@ protected function _openMboxFile($filename)
*/
public function close()
{
@fclose($this->_fh);
ErrorHandler::start(E_WARNING);
fclose($this->_fh);
ErrorHandler::stop();
$this->_positions = array();
}

Expand Down
20 changes: 16 additions & 4 deletions src/Storage/Writable/Maildir.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Zend\Mail\Storage;
use Zend\Mail\Storage\Exception as StorageException;
use Zend\Mail\Storage\Folder;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -472,7 +473,10 @@ public function appendMessage($message, $folder = null, $flags = null, $recent =
if (!link($temp_file['filename'], $new_filename)) {
$exception = new StorageException\RuntimeException('cannot link message file to final dir');
}
@unlink($temp_file['filename']);

ErrorHandler::start(E_WARNING);
unlink($temp_file['filename']);
ErrorHandler::stop();

if ($exception) {
throw $exception;
Expand Down Expand Up @@ -534,7 +538,10 @@ public function copyMessage($id, $folder)
} elseif (!link($temp_file['filename'], $new_file)) {
$exception = new StorageException\RuntimeException('cannot link message file to final dir');
}
@unlink($temp_file['filename']);

ErrorHandler::start(E_WARNING);
unlink($temp_file['filename']);
ErrorHandler::stop();

if ($exception) {
throw $exception;
Expand Down Expand Up @@ -600,7 +607,10 @@ public function moveMessage($id, $folder)
if (!rename($old_file, $new_file)) {
$exception = new StorageException\RuntimeException('cannot move message file');
}
@unlink($temp_file['filename']);

ErrorHandler::start(E_WARNING);
unlink($temp_file['filename']);
ErrorHandler::stop();

if ($exception) {
throw $exception;
Expand Down Expand Up @@ -691,7 +701,9 @@ public function setQuota($value)
public function getQuota($fromStorage = false)
{
if ($fromStorage) {
$fh = @fopen($this->_rootdir . 'maildirsize', 'r');
ErrorHandler::start(E_WARNING);
$fh = fopen($this->_rootdir . 'maildirsize', 'r');
ErrorHandler::stop();
if (!$fh) {
throw new StorageException\RuntimeException('cannot open maildirsize');
}
Expand Down

0 comments on commit 5ed923d

Please sign in to comment.