svn: /pear/packages/Mail_Mbox/trunk/ Mail/Mbox.php package.xml tests/Mail_MboxTest.php

From: Date: Sun, 02 Aug 2009 15:27:02 +0000
Subject: svn: /pear/packages/Mail_Mbox/trunk/ Mail/Mbox.php package.xml tests/Mail_MboxTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-56838@lists.php.net to get a copy of this message
cweiske Sun, 02 Aug 2009 15:27:02 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=286671 Log: Implement request #16487: Insert on new box throws warning [cweiske] release 0.6.0 Bug: http://pear.php.net/bugs/16487 (unknown) Changed paths: _U pear/packages/Mail_Mbox/trunk/ U pear/packages/Mail_Mbox/trunk/Mail/Mbox.php U pear/packages/Mail_Mbox/trunk/package.xml U pear/packages/Mail_Mbox/trunk/tests/Mail_MboxTest.php Property changes on: pear/packages/Mail_Mbox/trunk ___________________________________________________________________ Added: svn:ignore + releases Modified: pear/packages/Mail_Mbox/trunk/Mail/Mbox.php =================================================================== --- pear/packages/Mail_Mbox/trunk/Mail/Mbox.php 2009-08-02 14:16:06 UTC (rev 286670) +++ pear/packages/Mail_Mbox/trunk/Mail/Mbox.php 2009-08-02 15:27:02 UTC (rev 286671) @@ -200,15 +200,22 @@ * @return boolean|PEAR_Error True if all went ok, PEAR_Error on failure * @access public */ - function open() + function open($create = false) { // check if file exists else return pear error if (!file_exists($this->_file)) { - return PEAR::raiseError( - 'Cannot open the mbox file "' - . $this->_file . '": file does not exist.', - MAIL_MBOX_ERROR_FILE_NOT_EXISTING - ); + if ($create) { + $ret = $this->_create(); + if (PEAR::isError($ret)) { + return $ret; + } + } else { + return PEAR::raiseError( + 'Cannot open the mbox file "' + . $this->_file . '": file does not exist.', + MAIL_MBOX_ERROR_FILE_NOT_EXISTING + ); + } } // opening the file @@ -228,6 +235,36 @@ } /** + * Creates the file + * + * @return boolean True if it was created, false if it already + * existed. PEAR_Error in case it could not + * be created. + * + * @access protected + */ + function _create() + { + if (file_exists($this->_file)) { + return false; + } + + //We should maybe try to check if the directory + // is writable here. But that's too much fuss for now. + touch($this->_file); + + if (file_exists($this->_file)) { + return true; + } + + //error + return PEAR::raiseError( + 'File could not be created', + MAIL_MBOX_ERROR_CANNOT_WRITE + ); + } + + /** * Re-opens the file and parses the messages again. * Used by other methods to be able to be able to prevent * re-opening the file. Modified: pear/packages/Mail_Mbox/trunk/package.xml =================================================================== --- pear/packages/Mail_Mbox/trunk/package.xml 2009-08-02 14:16:06 UTC (rev 286670) +++ pear/packages/Mail_Mbox/trunk/package.xml 2009-08-02 15:27:02 UTC (rev 286671) @@ -32,8 +32,8 @@ <date>2009-08-02</date> <version> - <release>0.5.2</release> - <api>0.5.1</api> + <release>0.6.0</release> + <api>0.6.0</api> </version> <stability> <release>beta</release> @@ -43,7 +43,7 @@ <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> - - Fix bug #15559: Inserting new message to a Mbox is not guaranteed to produce a valid Mbox [cweiske] + - Implement request #16487: Insert on new box throws warning [cweiske] </notes> <contents> @@ -81,6 +81,21 @@ <release> <version> + <release>0.6.0</release> + <api>0.6.0</api> + </version> + <stability> + <release>beta</release> + <api>beta</api> + </stability> + <date>2009-08-02</date> + <notes> + - Implement request #16487: Insert on new box throws warning [cweiske] + </notes> + </release> + + <release> + <version> <release>0.5.2</release> <api>0.5.1</api> </version> Modified: pear/packages/Mail_Mbox/trunk/tests/Mail_MboxTest.php =================================================================== --- pear/packages/Mail_Mbox/trunk/tests/Mail_MboxTest.php 2009-08-02 14:16:06 UTC (rev 286670) +++ pear/packages/Mail_Mbox/trunk/tests/Mail_MboxTest.php 2009-08-02 15:27:02 UTC (rev 286671) @@ -395,7 +395,29 @@ $this->assertFalse($this->mbox->getDebug()); } + public function testBug16487() + { + //file does not exist yet + $file = tempnam(sys_get_temp_dir(), 'mail_mbox'); + unlink($file); + $mbox = new Mail_Mbox($file); + //open without parameter does not create anything + $err = $mbox->open(); + $this->assertType('PEAR_Error', $err); + $this->assertEquals( + MAIL_MBOX_ERROR_FILE_NOT_EXISTING, $err->getCode() + ); + //with true as first parameter the file gets created + $err = $mbox->open(true); + $this->assertTrue($err); + $mbox->insert('From someone who loves you'); + $mbox->close(); + + $this->assertFileExists($file); + unlink($file); + } + protected function copy() { copy(Mail_MboxTest::$file, Mail_MboxTest::$filecopy);

« previous php.pear.cvs (#56838) next »