Author: Derick Rethans Date: 2006-10-05 12:43:36 +0200 (Thu, 05 Oct 2006) New Revision: 3648
Log: - Fixed an issue with mbox files without an mbox header being present. Added: trunk/Mail/tests/transports/data/empty-no-header.mbox trunk/Mail/tests/transports/data/empty.mbox trunk/Mail/tests/transports/data/one-mail-no-header.mbox trunk/Mail/tests/transports/data/one-mail.mbox Modified: trunk/Mail/ChangeLog trunk/Mail/src/parser/interfaces/parser_set.php trunk/Mail/src/parser/parser.php trunk/Mail/src/transports/file/file_set.php trunk/Mail/src/transports/imap/imap_set.php trunk/Mail/src/transports/mbox/mbox_set.php trunk/Mail/src/transports/mbox/mbox_transport.php trunk/Mail/src/transports/pop3/pop3_set.php trunk/Mail/tests/parser/parser_test.php trunk/Mail/tests/parser/parts/multipart_mixed_test.php trunk/Mail/tests/transports/transport_mbox_test.php Modified: trunk/Mail/ChangeLog =================================================================== --- trunk/Mail/ChangeLog 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/ChangeLog 2006-10-05 10:43:36 UTC (rev 3648) @@ -35,6 +35,7 @@ anymore when the supplied parameter is an invalid message number. - Implemented support for character set and language for ezcContentDispositionHeader. +- Fixed an issue with mbox files without an mbox header being present. 1.1.2 - Monday 28 August 2006 Modified: trunk/Mail/src/parser/interfaces/parser_set.php =================================================================== --- trunk/Mail/src/parser/interfaces/parser_set.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/src/parser/interfaces/parser_set.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -34,5 +34,12 @@ * @return bool */ public function nextMail(); + + /** + * Returns whether mails are being available for parsing. + * + * @return bool + */ + public function hasData(); } ?> Modified: trunk/Mail/src/parser/parser.php =================================================================== --- trunk/Mail/src/parser/parser.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/src/parser/parser.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -56,6 +56,10 @@ public function parseMail( ezcMailParserSet $set, $class = "ezcMail" ) { $mail = array(); + if ( !$set->hasData() ) + { + return $mail; + } do { $this->partParser = new ezcMailRfc822Parser(); @@ -65,7 +69,7 @@ $this->partParser->parseBody( $data ); } $mail[] = $this->partParser->finish( $class ); - }while( $set->nextMail() ); + } while ( $set->nextMail() ); return $mail; } Modified: trunk/Mail/src/transports/file/file_set.php =================================================================== --- trunk/Mail/src/transports/file/file_set.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/src/transports/file/file_set.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -76,6 +76,16 @@ } /** + * Returns whether the file set contains files + * + * @return bool + */ + public function hasData() + { + return count( $this->files ); + } + + /** * Returns one line of data from the current mail in the set. * * Null is returned if there is no current mail in the set or Modified: trunk/Mail/src/transports/imap/imap_set.php =================================================================== --- trunk/Mail/src/transports/imap/imap_set.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/src/transports/imap/imap_set.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -245,5 +245,15 @@ $this->currentTag = $tagLetter . sprintf( "%04s", $tagNumber ); return $this->currentTag; } + + /** + * Returns whether the set has mails + * + * @return bool + */ + public function hasData() + { + return count( $this->messages ); + } } ?> Modified: trunk/Mail/src/transports/mbox/mbox_set.php =================================================================== --- trunk/Mail/src/transports/mbox/mbox_set.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/src/transports/mbox/mbox_set.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -103,6 +103,16 @@ } /** + * Returns whether the set contains mails + * + * @return bool + */ + public function hasData() + { + return $this->hasMoreMailData; + } + + /** * Moves the set to the next mail and returns true upon success. * * False is returned if there are no more mail in the set. Modified: trunk/Mail/src/transports/mbox/mbox_transport.php =================================================================== --- trunk/Mail/src/transports/mbox/mbox_transport.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/src/transports/mbox/mbox_transport.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -53,6 +53,29 @@ } /** + * Finds the position of the first message while skipping a possible header. + * + * Mbox files can contain a header which does not describe an email + * message. This method skips over this optional header by checking for a + * specific From MAILER-DAEMON header. + * + * @return int + */ + private function findFirstMessage() + { + $data = fgets( $this->fh ); + fseek( $this->fh, 0 ); + if ( substr( $data, 0, 18 ) === 'From MAILER-DAEMON' ) + { + return $this->findNextMessage(); + } + else + { + return 0; + } + } + + /** * Reads through the Mbox file and stops at the next message. * * Messages in Mbox files are separated with lines starting with "From " @@ -86,7 +109,7 @@ $messages = array(); fseek( $this->fh, 0 ); // Skip the first mail as this is the mbox header - $position = $this->findNextMessage(); + $position = $this->findFirstMessage(); if ( $position === false ) { return $messages; Modified: trunk/Mail/src/transports/pop3/pop3_set.php =================================================================== --- trunk/Mail/src/transports/pop3/pop3_set.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/src/transports/pop3/pop3_set.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -153,6 +153,15 @@ return false; } + /** + * Returns whether the set has mails + * + * @return bool + */ + public function hasData() + { + return count( $this->messages ); + } } ?> Modified: trunk/Mail/tests/parser/parser_test.php =================================================================== --- trunk/Mail/tests/parser/parser_test.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/tests/parser/parser_test.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -28,6 +28,11 @@ // } } + public function hasData() + { + return !feof( $this->fp ); + } + public function getNextLine() { if ( feof( $this->fp ) ) Modified: trunk/Mail/tests/parser/parts/multipart_mixed_test.php =================================================================== --- trunk/Mail/tests/parser/parts/multipart_mixed_test.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/tests/parser/parts/multipart_mixed_test.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -28,6 +28,11 @@ // } } + public function hasData() + { + return !feof( $this->fp ); + } + public function getNextLine() { if ( feof( $this->fp ) ) Added: trunk/Mail/tests/transports/data/empty-no-header.mbox =================================================================== Added: trunk/Mail/tests/transports/data/empty.mbox =================================================================== --- trunk/Mail/tests/transports/data/empty.mbox 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/tests/transports/data/empty.mbox 2006-10-05 10:43:36 UTC (rev 3648) @@ -0,0 +1,12 @@ +From MAILER-DAEMON Thu Oct 5 10:35:22 2006 +Date: 05 Oct 2006 10:35:22 +0200 +From: Mail System Internal Data <[EMAIL PROTECTED]> +Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA +X-IMAP: 1160037322 0000000000 +Status: RO + +This text is part of the internal format of your mail folder, and is not +a real message. It is created automatically by the mail system software. +If deleted, important folder data will be lost, and it will be re-created +with the data reset to initial values. + Added: trunk/Mail/tests/transports/data/one-mail-no-header.mbox =================================================================== --- trunk/Mail/tests/transports/data/one-mail-no-header.mbox 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/tests/transports/data/one-mail-no-header.mbox 2006-10-05 10:43:36 UTC (rev 3648) @@ -0,0 +1,66 @@ +From [EMAIL PROTECTED] Mon Oct 2 20:31:34 2006 +Return-Path: <[EMAIL PROTECTED]> +Received: from kossu.home.example.nl (localhost [127.0.0.1]) + by kossu.home.example.nl (8.13.7/8.13.7/Debian-2) with ESMTP id k92IVYTF014488 + for <[EMAIL PROTECTED]>; Mon, 2 Oct 2006 20:31:34 +0200 +X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) on host.example.nl +X-Spam-Level: +X-Spam-Status: No, score=0.0 required=8.0 tests=UNPARSEABLE_RELAY + autolearn=disabled version=3.1.4 +Received: from 127.0.0.1 [127.0.0.1] + by kossu.home.example.nl with POP3 (fetchmail-6.3.4) + for <[EMAIL PROTECTED]> (single-drop); Mon, 02 Oct 2006 20:31:34 +0200 (CEST) +Received: from localhost (localhost [127.0.0.1]) + by host.example.nl (8.13.7/8.12.11) with ESMTP id k92INSE6000130; + Mon, 2 Oct 2006 20:23:28 +0200 +X-Virus-Scanned: by amavisd-new at example.nl +Received: from host.example.nl (localhost [127.0.0.1]) + by host.example.nl (8.13.7/8.12.11) with ESMTP id k92IN0Ht016732; + Mon, 2 Oct 2006 20:23:00 +0200 +Received: with ECARTIS (v1.0.0; list xdebug-general); Mon, 02 Oct 2006 20:23:00 +0200 (CEST) +Received: from localhost (localhost [127.0.0.1]) + by host.example.nl (8.13.7/8.12.11) with ESMTP id k92IMxwc029854; + Mon, 2 Oct 2006 20:23:00 +0200 +Date: Mon, 2 Oct 2006 20:22:43 +0200 (CEST) +From: Derick Rethans <[EMAIL PROTECTED]> +X-X-Sender: [EMAIL PROTECTED] +To: Ethan Winn <[EMAIL PROTECTED]> +cc: [EMAIL PROTECTED] +Subject: [xdebug-general] Re: Vim foldexpr for text profile output +In-Reply-To: <[EMAIL PROTECTED]> +Message-ID: <[EMAIL PROTECTED]> +References: <[EMAIL PROTECTED]> + <[EMAIL PROTECTED]> +X-Face: "L'&[EMAIL PROTECTED]'XhNhLB]222([EMAIL PROTECTED]:GE[OO;"F5p>qtFBl|yVVA&D{A(g3[C}mG:199P+5C'v.M/[EMAIL PROTECTED]:Mv.[l6[uWl' +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-archive-position: 693 +X-ecartis-version: Ecartis v1.0.0 +Sender: [EMAIL PROTECTED] +Errors-to: [EMAIL PROTECTED] +X-original-sender: [EMAIL PROTECTED] +Precedence: bulk +X-list: xdebug-general +X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.12 (host.example.nl [127.0.0.1]); Mon, 02 Oct 2006 20:23:18 +0200 (CEST) +X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.96.0 +Status: R +X-Status: +X-Keywords: + +On Wed, 27 Sep 2006, Ethan Winn wrote: + +> Actually, I debugged a bit and this expression is really better: +> +> autocmd FileType xdebug set +> foldexpr=strlen(substitute(substitute(substitute(getline(v:lnum),'\\s>=>','->',\"g\"),'^.\\{21\\}\\(\\s\\+\\)\\?->.*$','\\1',''),'\\s\\s','\ +> ',\"g\")) + +Thanks! I added this as part of my trace file colorization script +(xt.vim) in the Xdebug repository with some small changes. + +regards, +Derick + +-- +Xdebug | http://example.org | [EMAIL PROTECTED] + Added: trunk/Mail/tests/transports/data/one-mail.mbox =================================================================== --- trunk/Mail/tests/transports/data/one-mail.mbox 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/tests/transports/data/one-mail.mbox 2006-10-05 10:43:36 UTC (rev 3648) @@ -0,0 +1,78 @@ +From MAILER-DAEMON Thu Oct 5 10:35:22 2006 +Date: 05 Oct 2006 10:35:22 +0200 +From: Mail System Internal Data <[EMAIL PROTECTED]> +Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA +X-IMAP: 1160037322 0000000000 +Status: RO + +This text is part of the internal format of your mail folder, and is not +a real message. It is created automatically by the mail system software. +If deleted, important folder data will be lost, and it will be re-created +with the data reset to initial values. + +From [EMAIL PROTECTED] Mon Oct 2 20:31:34 2006 +Return-Path: <[EMAIL PROTECTED]> +Received: from kossu.home.example.nl (localhost [127.0.0.1]) + by kossu.home.example.nl (8.13.7/8.13.7/Debian-2) with ESMTP id k92IVYTF014488 + for <[EMAIL PROTECTED]>; Mon, 2 Oct 2006 20:31:34 +0200 +X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) on host.example.nl +X-Spam-Level: +X-Spam-Status: No, score=0.0 required=8.0 tests=UNPARSEABLE_RELAY + autolearn=disabled version=3.1.4 +Received: from 127.0.0.1 [127.0.0.1] + by kossu.home.example.nl with POP3 (fetchmail-6.3.4) + for <[EMAIL PROTECTED]> (single-drop); Mon, 02 Oct 2006 20:31:34 +0200 (CEST) +Received: from localhost (localhost [127.0.0.1]) + by host.example.nl (8.13.7/8.12.11) with ESMTP id k92INSE6000130; + Mon, 2 Oct 2006 20:23:28 +0200 +X-Virus-Scanned: by amavisd-new at example.nl +Received: from host.example.nl (localhost [127.0.0.1]) + by host.example.nl (8.13.7/8.12.11) with ESMTP id k92IN0Ht016732; + Mon, 2 Oct 2006 20:23:00 +0200 +Received: with ECARTIS (v1.0.0; list xdebug-general); Mon, 02 Oct 2006 20:23:00 +0200 (CEST) +Received: from localhost (localhost [127.0.0.1]) + by host.example.nl (8.13.7/8.12.11) with ESMTP id k92IMxwc029854; + Mon, 2 Oct 2006 20:23:00 +0200 +Date: Mon, 2 Oct 2006 20:22:43 +0200 (CEST) +From: Derick Rethans <[EMAIL PROTECTED]> +X-X-Sender: [EMAIL PROTECTED] +To: Ethan Winn <[EMAIL PROTECTED]> +cc: [EMAIL PROTECTED] +Subject: [xdebug-general] Re: Vim foldexpr for text profile output +In-Reply-To: <[EMAIL PROTECTED]> +Message-ID: <[EMAIL PROTECTED]> +References: <[EMAIL PROTECTED]> + <[EMAIL PROTECTED]> +X-Face: "L'&[EMAIL PROTECTED]'XhNhLB]222([EMAIL PROTECTED]:GE[OO;"F5p>qtFBl|yVVA&D{A(g3[C}mG:199P+5C'v.M/[EMAIL PROTECTED]:Mv.[l6[uWl' +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-archive-position: 693 +X-ecartis-version: Ecartis v1.0.0 +Sender: [EMAIL PROTECTED] +Errors-to: [EMAIL PROTECTED] +X-original-sender: [EMAIL PROTECTED] +Precedence: bulk +X-list: xdebug-general +X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.12 (host.example.nl [127.0.0.1]); Mon, 02 Oct 2006 20:23:18 +0200 (CEST) +X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.96.0 +Status: R +X-Status: +X-Keywords: + +On Wed, 27 Sep 2006, Ethan Winn wrote: + +> Actually, I debugged a bit and this expression is really better: +> +> autocmd FileType xdebug set +> foldexpr=strlen(substitute(substitute(substitute(getline(v:lnum),'\\s>=>','->',\"g\"),'^.\\{21\\}\\(\\s\\+\\)\\?->.*$','\\1',''),'\\s\\s','\ +> ',\"g\")) + +Thanks! I added this as part of my trace file colorization script +(xt.vim) in the Xdebug repository with some small changes. + +regards, +Derick + +-- +Xdebug | http://example.org | [EMAIL PROTECTED] + Modified: trunk/Mail/tests/transports/transport_mbox_test.php =================================================================== --- trunk/Mail/tests/transports/transport_mbox_test.php 2006-10-05 08:07:44 UTC (rev 3647) +++ trunk/Mail/tests/transports/transport_mbox_test.php 2006-10-05 10:43:36 UTC (rev 3648) @@ -14,15 +14,44 @@ */ class ezcMailTransportMboxTest extends ezcTestCase { - public function testFetchMailFromBrokenMbox() + public function testFetchMailEmptyMbox() { - $mbox = new ezcMailMboxTransport( dirname( __FILE__ ) . "/../parser/data/various/test-filename-with-space" ); + $mbox = new ezcMailMboxTransport( dirname( __FILE__ ) . "/data/empty.mbox" ); $set = $mbox->fetchAll(); $parser = new ezcMailParser(); $mail = $parser->parseMail( $set ); $this->assertEquals( 0, count( $mail ) ); } + public function testFetchMailEmptyMboxNoHeader() + { + $mbox = new ezcMailMboxTransport( dirname( __FILE__ ) . "/data/empty-no-header.mbox" ); + $set = $mbox->fetchAll(); + $parser = new ezcMailParser(); + $mail = $parser->parseMail( $set ); + $this->assertEquals( 0, count( $mail ) ); + } + + public function testFetchMailMboxHeader() + { + $mbox = new ezcMailMboxTransport( dirname( __FILE__ ) . "/data/one-mail.mbox" ); + $set = $mbox->fetchAll(); + $parser = new ezcMailParser(); + $mail = $parser->parseMail( $set ); + $this->assertEquals( 1, count( $mail ) ); + $this->assertEquals( "[xdebug-general] Re: Vim foldexpr for text profile output", $mail[0]->subject ); + } + + public function testFetchMailMboxNoHeader() + { + $mbox = new ezcMailMboxTransport( dirname( __FILE__ ) . "/data/one-mail-no-header.mbox" ); + $set = $mbox->fetchAll(); + $parser = new ezcMailParser(); + $mail = $parser->parseMail( $set ); + $this->assertEquals( 1, count( $mail ) ); + $this->assertEquals( "[xdebug-general] Re: Vim foldexpr for text profile output", $mail[0]->subject ); + } + public function testFetchMailFromUnreadableMbox() { $tempDir = $this->createTempDir( 'ezcMailTransportMboxTest' ); @@ -159,8 +188,8 @@ $set = $mbox->fetchFromOffset( 0, 10 ); $parser = new ezcMailParser(); $mail = $parser->parseMail( $set ); - $this->assertEquals( 8, count( $mail ) ); - $this->assertEquals( "[svn-components] 3263 - docs/guidelines [eZComponents: Docs]", $mail[7]->subject ); + $this->assertEquals( 9, count( $mail ) ); + $this->assertEquals( "[svn-components] 3263 - docs/guidelines [eZComponents: Docs]", $mail[8]->subject ); } public function testfetchFromOffset5() @@ -169,8 +198,8 @@ $set = $mbox->fetchFromOffset( 0, 0 ); $parser = new ezcMailParser(); $mail = $parser->parseMail( $set ); - $this->assertEquals( 8, count( $mail ) ); - $this->assertEquals( "[svn-components] 3263 - docs/guidelines [eZComponents: Docs]", $mail[7]->subject ); + $this->assertEquals( 9, count( $mail ) ); + $this->assertEquals( "[svn-components] 3263 - docs/guidelines [eZComponents: Docs]", $mail[8]->subject ); } public function testBrokenFilePointer() -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components