cvs: pear /Mail_Mbox mbox.php mbox_test.php package.xml
| From: | Roberto Bert� | Date: | Mon, 30 Dec 2002 16:22:53 +0000 |
| Subject: | cvs: pear /Mail_Mbox mbox.php mbox_test.php package.xml | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8000@lists.php.net to get a copy of this message | ||
darkelder Mon Dec 30 11:22:53 2002 EDT
Added files:
/pear/Mail_Mbox package.xml
Modified files:
/pear/Mail_Mbox mbox.php mbox_test.php
Log:
revision 0.1.3
Index: pear/Mail_Mbox/mbox.php diff -u pear/Mail_Mbox/mbox.php:1.2 pear/Mail_Mbox/mbox.php:1.3 --- pear/Mail_Mbox/mbox.php:1.2 Mon Dec 30 11:19:29 2002 +++ pear/Mail_Mbox/mbox.php Mon Dec 30 11:22:53 2002 @@ -16,86 +16,91 @@ // | Authors: Roberto Berto <darkelder.php.net> | // +----------------------------------------------------------------------+ // -// $Id: mbox.php,v 1.2 2002/12/30 16:19:29 darkelder Exp $ - -/** - * Mbox PHP class to Unix MBOX parsing and using - * - * AUTHOR - * Roberto Berto - darkelder@php.net - * http://opensource.under.com.br - * - * - * LICENSE (LGPL) - * Copyright (C) 2002-2003 Roberto Berto - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * Or at http://www.gnu.org/licenses/lgpl.txt - * - * - * METHODS: - * int resource mbox->open(string file) - * open a mbox and return a resource id - * - * bool mbox->close(resource) - * close a mbox resource id - * - * int mbox->size(resource) - * return mbox number of messages - * - * string mbox->get(int resource,messageNumber) - * return the message number of the resource - * - * bool mbox->update(int resource,int messageNumber,string message) - * update the message offset to message (need write permission) - * - * bool mbox->delete(int resource,int messageNumber) - * remove the message messageNumber (need write permission) - * - * bool mbox->insert(int resource,string message[,$offset = null]) - * add message to the end of the mbox. Offset == 0 message will be append at first message. If after == null will be the last one message. - * (need write permission) - * - * RELATED LINKS: - * - CPAN Perl Mail::Folder::Mbox Module (used as a start point to create this class) - * http://search.cpan.org/author/KJOHNSON/MailFolder-0.07/Mail/Folder/Mbox.pm - * - * - PHP Mime Decode PEAR Module (use it to parse headers and body) - * http://pear.php.net/package-info.php?pacid=21 - */ +// $Id: mbox.php,v 1.3 2002/12/30 16:22:53 darkelder Exp $ require_once "PEAR.php"; + /** + * Mbox PHP class to Unix MBOX parsing and using + * + * LICENSE (LGPL) + * Copyright (C) 2002-2003 Roberto Berto + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Or at http://www.gnu.org/licenses/lgpl.txt + * + * + * METHODS: + * int resource mbox->open(string file) + * open a mbox and return a resource id + * + * bool mbox->close(resource) + * close a mbox resource id + * + * int mbox->size(resource) + * return mbox number of messages + * + * string mbox->get(int resource, messageNumber) + * return the message number of the resource + * + * bool mbox->update(int resource, int messageNumber, string message) + * update the message offset to message (need write permission) + * + * bool mbox->remove(int resource, int messageNumber) + * remove the message messageNumber (need write permission) + * + * bool mbox->insert(int resource, string message[, $offset = null]) + * add message to the end of the mbox. Offset == 0 message will + * be append at first message. If after == null will be the last + * one message. (need write permission) + * + * RELATED LINKS: + * - CPAN Perl Mail::Folder::Mbox Module + * Used as a start point to create this class. + * http://search.cpan.org/author/KJOHNSON/MailFolder-0.07/Mail/Folder/Mbox.pm + * + * - PHP Mime Decode PEAR Module + * Use it to parse headers and body. + * http://pear.php.net/package-info.php?pacid=21 + * + * @author Roberto Berto <darkelder@php.net> + * @package Mail + * @access public + */ class Mail_Mbox extends PEAR { /** - * Resources data like file name, file resource, mbox number, and other cacheds things are stored here. - * Note that it isnt really a valid resource type. It is of int type. - * - * @var int - * @access private - */ + * Resources data like file name, file resource, mbox number, and other + * cacheds things are stored here. + * + * Note that it isnt really a valid resource type. It is of int type. + * + * @var int + * @access private + */ var $_resources; /** * Debug mode * * Set to true to turn on debug mode - * @var bool - * @access public + * + * @var bool + * @access public */ var $debug = false; + /** * Open a Mbox * @@ -104,9 +109,9 @@ * Also, this function will process the Mbox and create a cache * that tells each message start and end bytes. * - * @param int $file Mbox file to open - * @return mixed Resource ID on success else pear error class. - * @access public + * @param int $file Mbox file to open + * @return mixed ResourceID on success else pear error class + * @access public */ function open($file) { @@ -138,9 +143,9 @@ * * Close the Mbox file opened by open() * - * @param int $resourceId Mbox resouce id created by open - * @return mixed true on success else pear error class - * @access public + * @param int $resourceId Mbox resouce id created by open + * @return mixed true on success else pear error class + * @access public */ function close($resourceId) { @@ -161,8 +166,8 @@ * Get Mbox Number of Messages * * @param int $resourceId Mbox resouce id created by open - * @return int Number of messages on Mbox (starting on 1, 0 if no message exists) - * @access public + * @return int Number of messages on Mbox (starting on 1, 0 if no message exists) + * @access public */ function size($resourceId) { @@ -178,9 +183,10 @@ * * @param int $resourceId Mbox resouce id created by open * @param int $message The number of Message - * @return string Return the message else pear error class + * @return string Return the message else pear error class + * @access public */ - function get($resourceId,$message) + function get($resourceId, $message) { // checking if we have bytes locations for this message if (!is_array($this->_resources[$resourceId]["messages"][$message])) { @@ -193,17 +199,17 @@ // a debug feature to show the bytes locations if ($this->debug == true) { - printf("%08d=%08d<br>",$bytesStart,$bytesEnd); + printf("%08d=%08d<br />", $bytesStart, $bytesEnd); } // seek to start of message - if (@fseek($this->_resources[$resourceId]["fresource"],$bytesStart) == -1) { + if (@fseek($this->_resources[$resourceId]["fresource"], $bytesStart) == -1) { return PEAR::raiseError("Cannot read message bytes"); } if ($bytesEnd - $bytesStart > 0) { // reading and returning message (bytes to read = difference of bytes locations) - return fread($this->_resources[$resourceId]["fresource"],$bytesEnd - $bytesStart) . "\n"; + return fread($this->_resources[$resourceId]["fresource"], $bytesEnd - $bytesStart) . "\n"; } } @@ -215,10 +221,11 @@ * Note: messages start with 0. * * @param int $resourceId Mbox resouce id created by open - * @param int $message The number of Message to delete - * @return mixed Return true else pear error class + * @param int $message The number of Message to remove + * @return mixed Return true else pear error class + * @access public */ - function delete($resourceId,$message) + function remove($resourceId, $message) { // checking if we have bytes locations for this message if (!is_array($this->_resources[$resourceId]["messages"][$message])) { @@ -226,7 +233,7 @@ } // creating temp file - $ftempname = tempnam ("/tmp", rand(0,9)); + $ftempname = tempnam ("/tmp", rand(0, 9)); $ftemp = fopen($ftempname, "w"); if ($ftemp == false) { return PEAR::raiseError("Cannot create a temp file. Cannot handle this error."); @@ -240,9 +247,9 @@ continue; } - $messageThis = $this->get($resourceId,$x); + $messageThis = $this->get($resourceId, $x); if (is_string($messageThis)) { - fwrite($ftemp,$messageThis,strlen($messageThis)); + fwrite($ftemp, $messageThis, strlen($messageThis)); } } @@ -251,7 +258,7 @@ $this->close($resourceId); fclose($ftemp); - return $this->_move($resourceId,$ftempname,$filename); + return $this->_move($resourceId, $ftempname, $filename); } /** @@ -263,11 +270,11 @@ * * @param int $resourceId Mbox resouce id created by open * @param int $message The number of Message to updated - * @param string $content The new content of the Message + * @param string $content The new content of the Message * @return mixed Return true else pear error class - * + * @access public */ - function update($resourceId,$message,$content) + function update($resourceId, $message, $content) { // checking if we have bytes locations for this message if (!is_array($this->_resources[$resourceId]["messages"][$message])) { @@ -275,7 +282,7 @@ } // creating temp file - $ftempname = tempnam ("/tmp", rand(0,9)); + $ftempname = tempnam ("/tmp", rand(0, 9)); $ftemp = fopen($ftempname, "w"); if ($ftemp == false) { return PEAR::raiseError("Cannot create a temp file. Cannot handle this error."); @@ -288,11 +295,11 @@ if ($x == $message) { $messageThis = $content . "\n\n"; } else { - $messageThis = $this->get($resourceId,$x); + $messageThis = $this->get($resourceId, $x); } if (is_string($messageThis)) { - fwrite($ftemp,$messageThis,strlen($messageThis)); + fwrite($ftemp, $messageThis, strlen($messageThis)); } } @@ -301,15 +308,16 @@ $this->close($resourceId); fclose($ftemp); - return $this->_move($resourceId,$ftempname,$filename); + return $this->_move($resourceId, $ftempname, $filename); } /** * Insert a message * - * PEAR::Mail_Mbox will insert the message according its offset. 0 means before the - * actual message 0. 3 means before the message 3 (Remember: message 3 is the forth message). - * The default is put AFTER the last message. + * PEAR::Mail_Mbox will insert the message according its offset. + * 0 means before the actual message 0. 3 means before the message 3 + * (Remember: message 3 is the forth message). The default is put + * AFTER the last message. * * Note: PEAR::Mail_Mbox auto adds \n\n at end of the message * @@ -317,9 +325,9 @@ * @param string $content The content of the new Message * @param int offset Before the offset. Default: last message * @return mixed Return true else pear error class - * + * @access public */ - function insert($resourceId,$content,$offset = NULL) + function insert($resourceId, $content, $offset = NULL) { // checking if we have bytes locations for this message @@ -328,7 +336,7 @@ } // creating temp file - $ftempname = tempnam ("/tmp", rand(0,9)); + $ftempname = tempnam ("/tmp", rand(0, 9)); $ftemp = fopen($ftempname, "w"); if ($ftemp == false) { return PEAR::raiseError("Cannot create a temp file. Cannot handle this error."); @@ -339,22 +347,22 @@ $content .= "\n\n"; if ($messages == 0 && $offset !== NULL) { - fwrite($ftemp,$content,strlen($content)); + fwrite($ftemp, $content, strlen($content)); } else { for ($x = 0; $x < $messages; $x++) { if ($offset !== NULL && $x == $offset) { - fwrite($ftemp,$content,strlen($content)); + fwrite($ftemp, $content, strlen($content)); } - $messageThis = $this->get($resourceId,$x); + $messageThis = $this->get($resourceId, $x); if (is_string($messageThis)) { - fwrite($ftemp,$messageThis,strlen($messageThis)); + fwrite($ftemp, $messageThis, strlen($messageThis)); } } } if ($offset === NULL) { - fwrite($ftemp,$content,strlen($content)); + fwrite($ftemp, $content, strlen($content)); } // closing file @@ -362,7 +370,7 @@ $this->close($resourceId); fclose($ftemp); - return $this->_move($resourceId,$ftempname,$filename); + return $this->_move($resourceId, $ftempname, $filename); } @@ -372,12 +380,12 @@ * * Used internally to copy the content of the temp file to the mbox file * - * @parm int $resourceId Resource file - * @parm string $ftempname Source file - will be removed - * @param string $filename Output file - * @access private + * @parm int $resourceId Resource file + * @parm string $ftempname Source file - will be removed + * @param string $filename Output file + * @access private */ - function _move($resourceId,$ftempname,$filename) + function _move($resourceId, $ftempname, $filename) { // opening ftemp to read $ftemp = fopen($ftempname, "r"); @@ -387,15 +395,15 @@ } // copy from ftemp to fp - $fp = @fopen($filename,"w"); + $fp = @fopen($filename, "w"); if ($fp == false) { return PEAR::raiseError("Cannot write on mbox file."); } while (feof($ftemp) != true) { - $strings = fread($ftemp,4096); - if (!fwrite($fp,$strings,strlen($strings))) { + $strings = fread($ftemp, 4096); + if (!fwrite($fp, $strings, strlen($strings))) { return PEAR::raiseError("Cannot write to file."); } } @@ -419,8 +427,8 @@ * - Count the messages * - Get start bytes and end bytes of each messages * - * @param int $resourceId Mbox resouce id created by open - * @access private + * @param int $resourceId Mbox resouce id created by open + * @access private */ function _process($resourceId) { @@ -431,7 +439,7 @@ } // going to start - if (@fseek($this->_resources[$resourceId]["fresource"],0) == -1) { + if (@fseek($this->_resources[$resourceId]["fresource"], 0) == -1) { return PEAR::raiseError("Cannot read mbox"); } @@ -448,15 +456,15 @@ // each \n we will check things if ($c === "\n") { // checking if start with From - if (substr($lineThis,0,5) === "From ") { + if (substr($lineThis, 0, 5) === "From ") { // this line byte count is last line more 1 byte $bytesStart = $bytesEnd + 1; - // last line byte count is this line bytes minus this line lenght + // last line byte count is this line bytes minus this line length $bytesEnd = $bytes - strlen($lineThis); // we will check messages after they end if ($bytesStart != 1) { if ($this->debug == true) { - printf("#################### from byte %08d to byte %08d ################### <br>",$bytesStart,$bytesEnd); + printf("#################### from byte %08d to byte %08d ################### <br />", $bytesStart, $bytesEnd); } // setting new message points $messagesCount = $this->size($resourceId); @@ -479,7 +487,7 @@ // this line is blank now unset($lineThis); if ($this->debug == true) { - printf("%08d:%08d %s<br>",$lines,$bytes,$lineLast); + printf("%08d:%08d %s<br/>", $lines, $bytes, $lineLast); } } $bytes++; @@ -488,7 +496,7 @@ // this line byte count is last line more 1 byte $bytesStart = $bytesEnd + 1; - // last line byte count is this line bytes minus this line lenght + // last line byte count is this line bytes minus this line length $bytesEnd = $bytes - strlen($lineThis) - 2; // we will check messages after they end Index: pear/Mail_Mbox/mbox_test.php diff -u pear/Mail_Mbox/mbox_test.php:1.2 pear/Mail_Mbox/mbox_test.php:1.3 --- pear/Mail_Mbox/mbox_test.php:1.2 Mon Dec 30 11:19:29 2002 +++ pear/Mail_Mbox/mbox_test.php Mon Dec 30 11:22:53 2002 @@ -16,19 +16,19 @@ // | Authors: Roberto Berto <darkelder.php.net> | // +----------------------------------------------------------------------+ // -// $Id: mbox_test.php,v 1.2 2002/12/30 16:19:29 darkelder Exp $ +// $Id: mbox_test.php,v 1.3 2002/12/30 16:22:53 darkelder Exp $ // some random content $content = <<<EOF From Foo@example.com Fri Dec 27 14:31:10 2002 Return-Path: -Received: from [unix socket] by campos.terra.com.br (LMTP); Fri, 27 Dec +Received: from [unix socket] by campos.example.com (LMTP); Fri, 27 Dec 2002 14:31:10 -0200 (BRST) Date: Fri, 27 Dec 2002 14:31:21 -0500 Message-Id: <200212271931.gBRJVL012289@example.com> -Received: from pcp128525pcs.medfrd01.nj.comcast.net ( - pcp128525pcs.medfrd01.nj.comcast.net [68.45.42.4]) by - serjolen6com.siteprotect.net (v64.19) with ESMTP id +Received: from pcp128525pcs.foo.example.com ( + pcp128525pcs.example.com [99.99.99.99]) by/ + serjolen6com.example.com (v64.19) with ESMTP id MAILRELAYINZA98-3601058302; Fri, 08 Nov 2002 06:39:05 -0500 From: "Foo@example.com" To: fool@example.com @@ -40,7 +40,7 @@ // starting mbox require_once "mbox.php"; - $mbox =& new Mail_Mbox(); + $mbox = new Mail_Mbox(); // uncomment to see lots of things #$mbox->debug = true; @@ -54,7 +54,7 @@ // deleting a message (uncomment to test) - #$res1 = $mbox->delete($mid,0); + #$res1 = $mbox->remove($mid,0); if (PEAR::isError($res1)) { print $res1->getMessage(); @@ -88,12 +88,12 @@ printf("Message: %08d<pre>",$x); $thisMessage = $mbox->get($mid,$x); print $thisMessage; - print "<hr>"; + print "<hr />"; $decode = new Mail_mimeDecode($thisMessage, "\r\n"); $structure = $decode->decode(); print_r($structure); - print "</pre><hr><hr><hr>"; + print "</pre><hr /><hr /><hr />"; } Index: pear/Mail_Mbox/package.xml +++ pear/Mail_Mbox/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> <name>Mail_Mbox</name> <summary>Mbox PHP class to Unix MBOX parsing and using.</summary> <description>It can split messages inside a Mbox, return the number of messages, return, update or remove an specific message or add a message on the Mbox.</description> <maintainers> <maintainer> <user>darkelder</user> <name>Roberto Berto</name> <email>darkelder@php.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1.3</version> <date>2002-12-28</date> <license>PHP</license> <state>alpha</state> <notes>o First release</notes> <filelist> <file role="php" baseinstalldir="Mail" md5sum="cafaa4c67ced2395a3d241118c1d98d9" name="mbox.php"/> <file role="php" baseinstalldir="Mail" md5sum="7f709f7ade286eea34cb59a47af1dffa" name="mbox_test.php"/> </filelist> </release> <changelog> <release> <version>0.1.3</version> <date>2002-12-28</date> <state>alpha</state> <notes>o Changed Jon Parise stylistics things </notes> </release> </changelog> </package>
Index: pear/Mail_Mbox/mbox.php diff -u pear/Mail_Mbox/mbox.php:1.2 pear/Mail_Mbox/mbox.php:1.3 --- pear/Mail_Mbox/mbox.php:1.2 Mon Dec 30 11:19:29 2002 +++ pear/Mail_Mbox/mbox.php Mon Dec 30 11:22:53 2002 @@ -16,86 +16,91 @@ // | Authors: Roberto Berto <darkelder.php.net> | // +----------------------------------------------------------------------+ // -// $Id: mbox.php,v 1.2 2002/12/30 16:19:29 darkelder Exp $ - -/** - * Mbox PHP class to Unix MBOX parsing and using - * - * AUTHOR - * Roberto Berto - darkelder@php.net - * http://opensource.under.com.br - * - * - * LICENSE (LGPL) - * Copyright (C) 2002-2003 Roberto Berto - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * Or at http://www.gnu.org/licenses/lgpl.txt - * - * - * METHODS: - * int resource mbox->open(string file) - * open a mbox and return a resource id - * - * bool mbox->close(resource) - * close a mbox resource id - * - * int mbox->size(resource) - * return mbox number of messages - * - * string mbox->get(int resource,messageNumber) - * return the message number of the resource - * - * bool mbox->update(int resource,int messageNumber,string message) - * update the message offset to message (need write permission) - * - * bool mbox->delete(int resource,int messageNumber) - * remove the message messageNumber (need write permission) - * - * bool mbox->insert(int resource,string message[,$offset = null]) - * add message to the end of the mbox. Offset == 0 message will be append at first message. If after == null will be the last one message. - * (need write permission) - * - * RELATED LINKS: - * - CPAN Perl Mail::Folder::Mbox Module (used as a start point to create this class) - * http://search.cpan.org/author/KJOHNSON/MailFolder-0.07/Mail/Folder/Mbox.pm - * - * - PHP Mime Decode PEAR Module (use it to parse headers and body) - * http://pear.php.net/package-info.php?pacid=21 - */ +// $Id: mbox.php,v 1.3 2002/12/30 16:22:53 darkelder Exp $ require_once "PEAR.php"; + /** + * Mbox PHP class to Unix MBOX parsing and using + * + * LICENSE (LGPL) + * Copyright (C) 2002-2003 Roberto Berto + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Or at http://www.gnu.org/licenses/lgpl.txt + * + * + * METHODS: + * int resource mbox->open(string file) + * open a mbox and return a resource id + * + * bool mbox->close(resource) + * close a mbox resource id + * + * int mbox->size(resource) + * return mbox number of messages + * + * string mbox->get(int resource, messageNumber) + * return the message number of the resource + * + * bool mbox->update(int resource, int messageNumber, string message) + * update the message offset to message (need write permission) + * + * bool mbox->remove(int resource, int messageNumber) + * remove the message messageNumber (need write permission) + * + * bool mbox->insert(int resource, string message[, $offset = null]) + * add message to the end of the mbox. Offset == 0 message will + * be append at first message. If after == null will be the last + * one message. (need write permission) + * + * RELATED LINKS: + * - CPAN Perl Mail::Folder::Mbox Module + * Used as a start point to create this class. + * http://search.cpan.org/author/KJOHNSON/MailFolder-0.07/Mail/Folder/Mbox.pm + * + * - PHP Mime Decode PEAR Module + * Use it to parse headers and body. + * http://pear.php.net/package-info.php?pacid=21 + * + * @author Roberto Berto <darkelder@php.net> + * @package Mail + * @access public + */ class Mail_Mbox extends PEAR { /** - * Resources data like file name, file resource, mbox number, and other cacheds things are stored here. - * Note that it isnt really a valid resource type. It is of int type. - * - * @var int - * @access private - */ + * Resources data like file name, file resource, mbox number, and other + * cacheds things are stored here. + * + * Note that it isnt really a valid resource type. It is of int type. + * + * @var int + * @access private + */ var $_resources; /** * Debug mode * * Set to true to turn on debug mode - * @var bool - * @access public + * + * @var bool + * @access public */ var $debug = false; + /** * Open a Mbox * @@ -104,9 +109,9 @@ * Also, this function will process the Mbox and create a cache * that tells each message start and end bytes. * - * @param int $file Mbox file to open - * @return mixed Resource ID on success else pear error class. - * @access public + * @param int $file Mbox file to open + * @return mixed ResourceID on success else pear error class + * @access public */ function open($file) { @@ -138,9 +143,9 @@ * * Close the Mbox file opened by open() * - * @param int $resourceId Mbox resouce id created by open - * @return mixed true on success else pear error class - * @access public + * @param int $resourceId Mbox resouce id created by open + * @return mixed true on success else pear error class + * @access public */ function close($resourceId) { @@ -161,8 +166,8 @@ * Get Mbox Number of Messages * * @param int $resourceId Mbox resouce id created by open - * @return int Number of messages on Mbox (starting on 1, 0 if no message exists) - * @access public + * @return int Number of messages on Mbox (starting on 1, 0 if no message exists) + * @access public */ function size($resourceId) { @@ -178,9 +183,10 @@ * * @param int $resourceId Mbox resouce id created by open * @param int $message The number of Message - * @return string Return the message else pear error class + * @return string Return the message else pear error class + * @access public */ - function get($resourceId,$message) + function get($resourceId, $message) { // checking if we have bytes locations for this message if (!is_array($this->_resources[$resourceId]["messages"][$message])) { @@ -193,17 +199,17 @@ // a debug feature to show the bytes locations if ($this->debug == true) { - printf("%08d=%08d<br>",$bytesStart,$bytesEnd); + printf("%08d=%08d<br />", $bytesStart, $bytesEnd); } // seek to start of message - if (@fseek($this->_resources[$resourceId]["fresource"],$bytesStart) == -1) { + if (@fseek($this->_resources[$resourceId]["fresource"], $bytesStart) == -1) { return PEAR::raiseError("Cannot read message bytes"); } if ($bytesEnd - $bytesStart > 0) { // reading and returning message (bytes to read = difference of bytes locations) - return fread($this->_resources[$resourceId]["fresource"],$bytesEnd - $bytesStart) . "\n"; + return fread($this->_resources[$resourceId]["fresource"], $bytesEnd - $bytesStart) . "\n"; } } @@ -215,10 +221,11 @@ * Note: messages start with 0. * * @param int $resourceId Mbox resouce id created by open - * @param int $message The number of Message to delete - * @return mixed Return true else pear error class + * @param int $message The number of Message to remove + * @return mixed Return true else pear error class + * @access public */ - function delete($resourceId,$message) + function remove($resourceId, $message) { // checking if we have bytes locations for this message if (!is_array($this->_resources[$resourceId]["messages"][$message])) { @@ -226,7 +233,7 @@ } // creating temp file - $ftempname = tempnam ("/tmp", rand(0,9)); + $ftempname = tempnam ("/tmp", rand(0, 9)); $ftemp = fopen($ftempname, "w"); if ($ftemp == false) { return PEAR::raiseError("Cannot create a temp file. Cannot handle this error."); @@ -240,9 +247,9 @@ continue; } - $messageThis = $this->get($resourceId,$x); + $messageThis = $this->get($resourceId, $x); if (is_string($messageThis)) { - fwrite($ftemp,$messageThis,strlen($messageThis)); + fwrite($ftemp, $messageThis, strlen($messageThis)); } } @@ -251,7 +258,7 @@ $this->close($resourceId); fclose($ftemp); - return $this->_move($resourceId,$ftempname,$filename); + return $this->_move($resourceId, $ftempname, $filename); } /** @@ -263,11 +270,11 @@ * * @param int $resourceId Mbox resouce id created by open * @param int $message The number of Message to updated - * @param string $content The new content of the Message + * @param string $content The new content of the Message * @return mixed Return true else pear error class - * + * @access public */ - function update($resourceId,$message,$content) + function update($resourceId, $message, $content) { // checking if we have bytes locations for this message if (!is_array($this->_resources[$resourceId]["messages"][$message])) { @@ -275,7 +282,7 @@ } // creating temp file - $ftempname = tempnam ("/tmp", rand(0,9)); + $ftempname = tempnam ("/tmp", rand(0, 9)); $ftemp = fopen($ftempname, "w"); if ($ftemp == false) { return PEAR::raiseError("Cannot create a temp file. Cannot handle this error."); @@ -288,11 +295,11 @@ if ($x == $message) { $messageThis = $content . "\n\n"; } else { - $messageThis = $this->get($resourceId,$x); + $messageThis = $this->get($resourceId, $x); } if (is_string($messageThis)) { - fwrite($ftemp,$messageThis,strlen($messageThis)); + fwrite($ftemp, $messageThis, strlen($messageThis)); } } @@ -301,15 +308,16 @@ $this->close($resourceId); fclose($ftemp); - return $this->_move($resourceId,$ftempname,$filename); + return $this->_move($resourceId, $ftempname, $filename); } /** * Insert a message * - * PEAR::Mail_Mbox will insert the message according its offset. 0 means before the - * actual message 0. 3 means before the message 3 (Remember: message 3 is the forth message). - * The default is put AFTER the last message. + * PEAR::Mail_Mbox will insert the message according its offset. + * 0 means before the actual message 0. 3 means before the message 3 + * (Remember: message 3 is the forth message). The default is put + * AFTER the last message. * * Note: PEAR::Mail_Mbox auto adds \n\n at end of the message * @@ -317,9 +325,9 @@ * @param string $content The content of the new Message * @param int offset Before the offset. Default: last message * @return mixed Return true else pear error class - * + * @access public */ - function insert($resourceId,$content,$offset = NULL) + function insert($resourceId, $content, $offset = NULL) { // checking if we have bytes locations for this message @@ -328,7 +336,7 @@ } // creating temp file - $ftempname = tempnam ("/tmp", rand(0,9)); + $ftempname = tempnam ("/tmp", rand(0, 9)); $ftemp = fopen($ftempname, "w"); if ($ftemp == false) { return PEAR::raiseError("Cannot create a temp file. Cannot handle this error."); @@ -339,22 +347,22 @@ $content .= "\n\n"; if ($messages == 0 && $offset !== NULL) { - fwrite($ftemp,$content,strlen($content)); + fwrite($ftemp, $content, strlen($content)); } else { for ($x = 0; $x < $messages; $x++) { if ($offset !== NULL && $x == $offset) { - fwrite($ftemp,$content,strlen($content)); + fwrite($ftemp, $content, strlen($content)); } - $messageThis = $this->get($resourceId,$x); + $messageThis = $this->get($resourceId, $x); if (is_string($messageThis)) { - fwrite($ftemp,$messageThis,strlen($messageThis)); + fwrite($ftemp, $messageThis, strlen($messageThis)); } } } if ($offset === NULL) { - fwrite($ftemp,$content,strlen($content)); + fwrite($ftemp, $content, strlen($content)); } // closing file @@ -362,7 +370,7 @@ $this->close($resourceId); fclose($ftemp); - return $this->_move($resourceId,$ftempname,$filename); + return $this->_move($resourceId, $ftempname, $filename); } @@ -372,12 +380,12 @@ * * Used internally to copy the content of the temp file to the mbox file * - * @parm int $resourceId Resource file - * @parm string $ftempname Source file - will be removed - * @param string $filename Output file - * @access private + * @parm int $resourceId Resource file + * @parm string $ftempname Source file - will be removed + * @param string $filename Output file + * @access private */ - function _move($resourceId,$ftempname,$filename) + function _move($resourceId, $ftempname, $filename) { // opening ftemp to read $ftemp = fopen($ftempname, "r"); @@ -387,15 +395,15 @@ } // copy from ftemp to fp - $fp = @fopen($filename,"w"); + $fp = @fopen($filename, "w"); if ($fp == false) { return PEAR::raiseError("Cannot write on mbox file."); } while (feof($ftemp) != true) { - $strings = fread($ftemp,4096); - if (!fwrite($fp,$strings,strlen($strings))) { + $strings = fread($ftemp, 4096); + if (!fwrite($fp, $strings, strlen($strings))) { return PEAR::raiseError("Cannot write to file."); } } @@ -419,8 +427,8 @@ * - Count the messages * - Get start bytes and end bytes of each messages * - * @param int $resourceId Mbox resouce id created by open - * @access private + * @param int $resourceId Mbox resouce id created by open + * @access private */ function _process($resourceId) { @@ -431,7 +439,7 @@ } // going to start - if (@fseek($this->_resources[$resourceId]["fresource"],0) == -1) { + if (@fseek($this->_resources[$resourceId]["fresource"], 0) == -1) { return PEAR::raiseError("Cannot read mbox"); } @@ -448,15 +456,15 @@ // each \n we will check things if ($c === "\n") { // checking if start with From - if (substr($lineThis,0,5) === "From ") { + if (substr($lineThis, 0, 5) === "From ") { // this line byte count is last line more 1 byte $bytesStart = $bytesEnd + 1; - // last line byte count is this line bytes minus this line lenght + // last line byte count is this line bytes minus this line length $bytesEnd = $bytes - strlen($lineThis); // we will check messages after they end if ($bytesStart != 1) { if ($this->debug == true) { - printf("#################### from byte %08d to byte %08d ################### <br>",$bytesStart,$bytesEnd); + printf("#################### from byte %08d to byte %08d ################### <br />", $bytesStart, $bytesEnd); } // setting new message points $messagesCount = $this->size($resourceId); @@ -479,7 +487,7 @@ // this line is blank now unset($lineThis); if ($this->debug == true) { - printf("%08d:%08d %s<br>",$lines,$bytes,$lineLast); + printf("%08d:%08d %s<br/>", $lines, $bytes, $lineLast); } } $bytes++; @@ -488,7 +496,7 @@ // this line byte count is last line more 1 byte $bytesStart = $bytesEnd + 1; - // last line byte count is this line bytes minus this line lenght + // last line byte count is this line bytes minus this line length $bytesEnd = $bytes - strlen($lineThis) - 2; // we will check messages after they end Index: pear/Mail_Mbox/mbox_test.php diff -u pear/Mail_Mbox/mbox_test.php:1.2 pear/Mail_Mbox/mbox_test.php:1.3 --- pear/Mail_Mbox/mbox_test.php:1.2 Mon Dec 30 11:19:29 2002 +++ pear/Mail_Mbox/mbox_test.php Mon Dec 30 11:22:53 2002 @@ -16,19 +16,19 @@ // | Authors: Roberto Berto <darkelder.php.net> | // +----------------------------------------------------------------------+ // -// $Id: mbox_test.php,v 1.2 2002/12/30 16:19:29 darkelder Exp $ +// $Id: mbox_test.php,v 1.3 2002/12/30 16:22:53 darkelder Exp $ // some random content $content = <<<EOF From Foo@example.com Fri Dec 27 14:31:10 2002 Return-Path: -Received: from [unix socket] by campos.terra.com.br (LMTP); Fri, 27 Dec +Received: from [unix socket] by campos.example.com (LMTP); Fri, 27 Dec 2002 14:31:10 -0200 (BRST) Date: Fri, 27 Dec 2002 14:31:21 -0500 Message-Id: <200212271931.gBRJVL012289@example.com> -Received: from pcp128525pcs.medfrd01.nj.comcast.net ( - pcp128525pcs.medfrd01.nj.comcast.net [68.45.42.4]) by - serjolen6com.siteprotect.net (v64.19) with ESMTP id +Received: from pcp128525pcs.foo.example.com ( + pcp128525pcs.example.com [99.99.99.99]) by/ + serjolen6com.example.com (v64.19) with ESMTP id MAILRELAYINZA98-3601058302; Fri, 08 Nov 2002 06:39:05 -0500 From: "Foo@example.com" To: fool@example.com @@ -40,7 +40,7 @@ // starting mbox require_once "mbox.php"; - $mbox =& new Mail_Mbox(); + $mbox = new Mail_Mbox(); // uncomment to see lots of things #$mbox->debug = true; @@ -54,7 +54,7 @@ // deleting a message (uncomment to test) - #$res1 = $mbox->delete($mid,0); + #$res1 = $mbox->remove($mid,0); if (PEAR::isError($res1)) { print $res1->getMessage(); @@ -88,12 +88,12 @@ printf("Message: %08d<pre>",$x); $thisMessage = $mbox->get($mid,$x); print $thisMessage; - print "<hr>"; + print "<hr />"; $decode = new Mail_mimeDecode($thisMessage, "\r\n"); $structure = $decode->decode(); print_r($structure); - print "</pre><hr><hr><hr>"; + print "</pre><hr /><hr /><hr />"; } Index: pear/Mail_Mbox/package.xml +++ pear/Mail_Mbox/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> <name>Mail_Mbox</name> <summary>Mbox PHP class to Unix MBOX parsing and using.</summary> <description>It can split messages inside a Mbox, return the number of messages, return, update or remove an specific message or add a message on the Mbox.</description> <maintainers> <maintainer> <user>darkelder</user> <name>Roberto Berto</name> <email>darkelder@php.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1.3</version> <date>2002-12-28</date> <license>PHP</license> <state>alpha</state> <notes>o First release</notes> <filelist> <file role="php" baseinstalldir="Mail" md5sum="cafaa4c67ced2395a3d241118c1d98d9" name="mbox.php"/> <file role="php" baseinstalldir="Mail" md5sum="7f709f7ade286eea34cb59a47af1dffa" name="mbox_test.php"/> </filelist> </release> <changelog> <release> <version>0.1.3</version> <date>2002-12-28</date> <state>alpha</state> <notes>o Changed Jon Parise stylistics things </notes> </release> </changelog> </package>