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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into ZF2-377
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-mabe committed Jul 17, 2012
5 parents 7bfa121 + 1914ec7 + 5ed923d + 0b38f0b + 47650bd commit ba228cf
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 44 deletions.
8 changes: 4 additions & 4 deletions src/Protocol/Imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Imap
* @param bool $ssl use ssl? 'SSL', 'TLS' or false
* @throws \Zend\Mail\Protocol\Exception\ExceptionInterface
*/
function __construct($host = '', $port = null, $ssl = false)
public function __construct($host = '', $port = null, $ssl = false)
{
if ($host) {
$this->connect($host, $port, $ssl);
Expand Down 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
5 changes: 4 additions & 1 deletion src/Storage/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Part implements RecursiveIterator, Part\PartInterface
* - headers headers as array (name => value) or string, if a content part is found it's used as toplines
* - noToplines ignore content found after headers in param 'headers'
* - content content as string
* - strict strictly parse raw content
*
* @param array $params full message with or without headers
* @throws Exception\InvalidArgumentException
Expand All @@ -97,9 +98,11 @@ public function __construct(array $params)
$this->_mail = $params['handler'];
$this->_messageNum = $params['id'];
}

$params['strict'] = isset($params['strict']) ? $params['strict'] : false;

if (isset($params['raw'])) {
Mime\Decode::splitMessage($params['raw'], $this->_headers, $this->_content);
Mime\Decode::splitMessage($params['raw'], $this->_headers, $this->_content, Mime\Mime::LINEEND, $params['strict']);
} elseif (isset($params['headers'])) {
if (is_array($params['headers'])) {
$this->_headers = new Headers();
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
20 changes: 10 additions & 10 deletions test/Storage/MaildirFolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function testLoadUnkownFolder()

public function testChangeFolder()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);

$mail->selectFolder('subfolder.test');
Expand All @@ -155,23 +155,23 @@ public function testUnknownFolder()

public function testGlobalName()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);

$this->assertEquals($mail->getFolders()->subfolder->__toString(), 'subfolder');
}

public function testLocalName()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);

$this->assertEquals($mail->getFolders()->subfolder->key(), 'test');
}

public function testIterator()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);
$iterator = new \RecursiveIteratorIterator($mail->getFolders(), \RecursiveIteratorIterator::SELF_FIRST);
// we search for this folder because we can't assume a order while iterating
Expand All @@ -194,7 +194,7 @@ public function testIterator()

public function testKeyLocalName()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);
$iterator = new \RecursiveIteratorIterator($mail->getFolders(), \RecursiveIteratorIterator::SELF_FIRST);
// we search for this folder because we can't assume a order while iterating
Expand All @@ -217,7 +217,7 @@ public function testKeyLocalName()

public function testInboxEquals()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);
$iterator = new \RecursiveIteratorIterator($mail->getFolders('INBOX.subfolder'), \RecursiveIteratorIterator::SELF_FIRST);
// we search for this folder because we can't assume a order while iterating
Expand Down Expand Up @@ -249,7 +249,7 @@ public function testSelectable()

public function testCount()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);

$count = $mail->countMessages();
Expand All @@ -262,7 +262,7 @@ public function testCount()

public function testSize()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);
$shouldSizes = array(1 => 397, 89, 694, 452, 497);

Expand All @@ -276,7 +276,7 @@ public function testSize()

public function testFetchHeader()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$mail = new Folder\Maildir($this->_params);

$subject = $mail->getMessage(1)->subject;
Expand All @@ -289,7 +289,7 @@ public function testFetchHeader()

public function testNotReadableFolder()
{
$this->markTestIncomplete("Fail");
$this->markTestIncomplete("Fail");
$stat = stat($this->_params['dirname'] . '.subfolder');
chmod($this->_params['dirname'] . '.subfolder', 0);
clearstatcache();
Expand Down
Loading

0 comments on commit ba228cf

Please sign in to comment.