cvs: pear /Mail_Queue/Queue Body.php Container.php
| From: | Lorenzo Alberton | Date: | Wed, 01 Oct 2003 11:57:32 +0000 |
| Subject: | cvs: pear /Mail_Queue/Queue Body.php Container.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-13209@lists.php.net to get a copy of this message | ||
quipo Wed Oct 1 07:57:32 2003 EDT
Modified files:
/pear/Mail_Queue/Queue Body.php Container.php
Log:
- Error management has been rewritten. New error constants are used, so custom error mgmt is now
possible.
- Added a "pearErrorMode" option to specify what to do with Pear_Error (was:
PEAR_ERROR_PRINT by default)
- Added a "sequence" container option to specify the name of the sequence table.
- Moved Mail_Queue_Error class from Mail/Queue/Error.php to Mail/Queue.php.
Index: pear/Mail_Queue/Queue/Body.php diff -u pear/Mail_Queue/Queue/Body.php:1.2 pear/Mail_Queue/Queue/Body.php:1.3 --- pear/Mail_Queue/Queue/Body.php:1.2 Tue Feb 25 04:41:04 2003 +++ pear/Mail_Queue/Queue/Body.php Wed Oct 1 07:57:32 2003 @@ -1,329 +1,328 @@ -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | PHP Version 4 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2003 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Radek Maciaszek <chief@php.net> | -// +----------------------------------------------------------------------+ -// -// $Id: Body.php,v 1.2 2003/02/25 09:41:04 chief Exp $ - -/** -* Class contains mail data. -* -* @version $Revision: 1.2 $ -* @author Radek Maciaszek <chief@php.net> -*/ - -/** -* Mail_Queue_Body contains mail data -* -* @author Radek Maciaszek <wodzu@pomocprawna.info> -* @version $Revision: 1.2 $ -* @package Mail_Queue -* @access public -*/ -class Mail_Queue_Body { - - /** - * Ident - * - * @var integer - */ - var $id; - - /** - * Create time - * - * @var string - */ - var $create_time; - - /** - * Time to send mail - * - * @var string - */ - var $time_to_send; - - /** - * Time when mail was sent - * - * @var string - */ - var $sent_time = null; - - /** - * User id - who send mail - * MAILQUEUE_UNKNOWN - not login user (guest) - * MAILQUEUE_SYSTEM - mail send by system - * - * @var string - */ - var $id_user = MAILQUEUE_SYSTEM; - - /** - * use IP - * - * @var string - */ - var $ip; - - /** - * Sender email - * - * @var string - */ - var $sender; - - /** - * Reciepient email - * - * @var string - */ - var $recipient; - - /** - * Email headers (in RFC) - * - * @var string - */ - var $headers; - - /** - * Email body (in RFC) - could have attachments etc - * - * @var string - */ - var $body; - - /** - * How many times mail was sent - * - * @var integer - */ - var $try_sent = 0; - - /** - * Delete mail from database after success send - * - * @var bool - */ - var $delete_after_send = true; - - /** - * Mail_Queue_Body::Mail_Queue_Body() constructor - * - * @param integer $id Mail ident - * @param string $create_time Create time - * @param strine $time_to_send Time to send - * @param string $sent_time Sent time - * @param integer $id_user Sender user id (who sent mail) - * @param string $ip Sender user ip - * @param strine $sender Sender e-mail - * @param string $recipient Reciepient e-mail - * @param string $headers Mail headers (in RFC) - * @param string $body Mail body (in RFC) - * @param integer $try_sent How many times mail was sent - * - * @return void - * - * @access public - **/ - function Mail_Queue_Body( $id, $create_time, $time_to_send, $sent_time, $id_user, - $ip, $sender, $recipient, $headers, $body, - $delete_after_send = true, $try_sent = 0 ) - { - $this->id = $id; - $this->create_time = $create_time; - $this->time_to_send = $time_to_send; - $this->sent_time = $sent_time; - $this->id_user = $id_user; - $this->ip = $ip; - $this->sender = $sender; - $this->recipient = $recipient; - $this->headers = $headers; - $this->body = $body; - $this->delete_after_send = $delete_after_send; - $this->try_sent = $try_sent; - } - - /** - * Mail_Queue_Body::getId() - * - * @return integer Sender id - * @access public - **/ - function getId() - { - return $this->id; - } - - /** - * Return mail create time. - * - * Mail_Queue_Body::getCreateTime() - * - * @return string Mail create time - * @access public - **/ - function getCreateTime() - { - return $this->create_time; - } - - /** - * Return time to send mail. - * - * Mail_Queue_Body::getTimeToSend() - * - * @return string Time to send - * @access public - **/ - function getTimeToSend() - { - return $this->time_to_send; - } - - /** - * Return mail sent time (if sended) else false. - * - * Mail_Queue_Body::getSentTime() - * - * @return mixed String sent time or false if mail not was sent yet - * @access public - **/ - function getSentTime() - { - return empty($this->sent_time) ? false : $this->sent_time; - } - - /** - * Return sender id. - * - * Mail_Queue_Body::getIdUser() - * - * @return integer Sender id - * @access public - **/ - function getIdUser() - { - return $this->id_user; - } - - /** - * Return sender ip. - * - * Mail_Queue_Body::getIp() - * - * @return string IP - * @access public - **/ - function getIp() - { - return $this->ip; - } - - /** - * Return sender e-mail. - * - * Mail_Queue_Body::getSender() - * - * @return string E-mail - * @access public - **/ - function getSender() - { - return $this->sender; - } - - /** - * Return recipient e-mail. - * - * Mail_Queue_Body::getRecipient() - * - * @return string E-mail - * @access public - **/ - function getRecipient() - { - return $this->recipient; - } - - /** - * Return mail headers (in RFC) - * - * Mail_Queue_Body::getHeaders() - * - * @return string headers - * @access public - **/ - function getHeaders() - { - return $this->headers; - } - - /** - * Return mail body (in RFC) - * - * Mail_Queue_Body::getBody() - * - * @return string Body - * @access public - **/ - function getBody() - { - return $this->body; - } - - /** - * Return how many times mail was try to sent. - * - * Mail_Queue_Body::getTrySent() - * - * @return integer How many times mail was sent - * @access public - **/ - function getTrySent() - { - return $this->try_sent; - } - - /** - * Return true if mail must be delete after send from db. - * - * MailBody::isDeleteAfterSend() - * - * @return bool True if must be delete else false. - * @access public - **/ - function isDeleteAfterSend() - { - return $this->delete_after_send; - } - - /** - * Increase and return try_sent - * - * Mail_Queue_Body::try() - * - * @return integer How many times mail was sent - * @access public - **/ - function try() - { - return ++$this->try_sent; - } -} - +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP Version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Radek Maciaszek <chief@php.net> | +// +----------------------------------------------------------------------+ +// +// $Id: Body.php,v 1.3 2003/10/01 11:57:32 quipo Exp $ + +/** +* Class contains mail data. +* +* @version $Revision: 1.3 $ +* @author Radek Maciaszek <chief@php.net> +*/ + +/** +* Mail_Queue_Body contains mail data +* +* @author Radek Maciaszek <wodzu@pomocprawna.info> +* @version $Revision: 1.3 $ +* @package Mail_Queue +* @access public +*/ +class Mail_Queue_Body { + + /** + * Ident + * + * @var integer + */ + var $id; + + /** + * Create time + * + * @var string + */ + var $create_time; + + /** + * Time to send mail + * + * @var string + */ + var $time_to_send; + + /** + * Time when mail was sent + * + * @var string + */ + var $sent_time = null; + + /** + * User id - who send mail + * MAILQUEUE_UNKNOWN - not login user (guest) + * MAILQUEUE_SYSTEM - mail send by system + * + * @var string + */ + var $id_user = MAILQUEUE_SYSTEM; + + /** + * use IP + * + * @var string + */ + var $ip; + + /** + * Sender email + * + * @var string + */ + var $sender; + + /** + * Reciepient email + * + * @var string + */ + var $recipient; + + /** + * Email headers (in RFC) + * + * @var string + */ + var $headers; + + /** + * Email body (in RFC) - could have attachments etc + * + * @var string + */ + var $body; + + /** + * How many times mail was sent + * + * @var integer + */ + var $try_sent = 0; + + /** + * Delete mail from database after success send + * + * @var bool + */ + var $delete_after_send = true; + + /** + * Mail_Queue_Body::Mail_Queue_Body() constructor + * + * @param integer $id Mail ident + * @param string $create_time Create time + * @param strine $time_to_send Time to send + * @param string $sent_time Sent time + * @param integer $id_user Sender user id (who sent mail) + * @param string $ip Sender user ip + * @param strine $sender Sender e-mail + * @param string $recipient Reciepient e-mail + * @param string $headers Mail headers (in RFC) + * @param string $body Mail body (in RFC) + * @param integer $try_sent How many times mail was sent + * + * @return void + * + * @access public + **/ + function Mail_Queue_Body($id, $create_time, $time_to_send, $sent_time, $id_user, + $ip, $sender, $recipient, $headers, $body, + $delete_after_send=true, $try_sent=0) + { + $this->id = $id; + $this->create_time = $create_time; + $this->time_to_send = $time_to_send; + $this->sent_time = $sent_time; + $this->id_user = $id_user; + $this->ip = $ip; + $this->sender = $sender; + $this->recipient = $recipient; + $this->headers = $headers; + $this->body = $body; + $this->delete_after_send = $delete_after_send; + $this->try_sent = $try_sent; + } + + /** + * Mail_Queue_Body::getId() + * + * @return integer Sender id + * @access public + **/ + function getId() + { + return $this->id; + } + + /** + * Return mail create time. + * + * Mail_Queue_Body::getCreateTime() + * + * @return string Mail create time + * @access public + **/ + function getCreateTime() + { + return $this->create_time; + } + + /** + * Return time to send mail. + * + * Mail_Queue_Body::getTimeToSend() + * + * @return string Time to send + * @access public + **/ + function getTimeToSend() + { + return $this->time_to_send; + } + + /** + * Return mail sent time (if sended) else false. + * + * Mail_Queue_Body::getSentTime() + * + * @return mixed String sent time or false if mail not was sent yet + * @access public + **/ + function getSentTime() + { + return empty($this->sent_time) ? false : $this->sent_time; + } + + /** + * Return sender id. + * + * Mail_Queue_Body::getIdUser() + * + * @return integer Sender id + * @access public + **/ + function getIdUser() + { + return $this->id_user; + } + + /** + * Return sender ip. + * + * Mail_Queue_Body::getIp() + * + * @return string IP + * @access public + **/ + function getIp() + { + return $this->ip; + } + + /** + * Return sender e-mail. + * + * Mail_Queue_Body::getSender() + * + * @return string E-mail + * @access public + **/ + function getSender() + { + return $this->sender; + } + + /** + * Return recipient e-mail. + * + * Mail_Queue_Body::getRecipient() + * + * @return string E-mail + * @access public + **/ + function getRecipient() + { + return $this->recipient; + } + + /** + * Return mail headers (in RFC) + * + * Mail_Queue_Body::getHeaders() + * + * @return string headers + * @access public + **/ + function getHeaders() + { + return $this->headers; + } + + /** + * Return mail body (in RFC) + * + * Mail_Queue_Body::getBody() + * + * @return string Body + * @access public + **/ + function getBody() + { + return $this->body; + } + + /** + * Return how many times mail was try to sent. + * + * Mail_Queue_Body::getTrySent() + * + * @return integer How many times mail was sent + * @access public + **/ + function getTrySent() + { + return $this->try_sent; + } + + /** + * Return true if mail must be delete after send from db. + * + * MailBody::isDeleteAfterSend() + * + * @return bool True if must be delete else false. + * @access public + **/ + function isDeleteAfterSend() + { + return $this->delete_after_send; + } + + /** + * Increase and return try_sent + * + * Mail_Queue_Body::try() + * + * @return integer How many times mail was sent + * @access public + **/ + function try() + { + return ++$this->try_sent; + } +} ?> Index: pear/Mail_Queue/Queue/Container.php diff -u pear/Mail_Queue/Queue/Container.php:1.2 pear/Mail_Queue/Queue/Container.php:1.3 --- pear/Mail_Queue/Queue/Container.php:1.2 Tue Feb 25 04:41:04 2003 +++ pear/Mail_Queue/Queue/Container.php Wed Oct 1 07:57:32 2003 @@ -1,236 +1,275 @@ -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | PHP Version 4 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2003 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Radek Maciaszek <wodzu@tonet.pl> | -// +----------------------------------------------------------------------+ -// -// $Id: Container.php,v 1.2 2003/02/25 09:41:04 chief Exp $ - -/** -* Container base class for MTA queue. -* Define methods for all storage containers. -* -* @version $Revision: 1.2 $ -* @author Radek Maciaszek <chief@php.net> -*/ - -require_once "Mail/Queue/Error.php"; -require_once "Mail/Queue/Body.php"; - -/** -* Mail_Queue_Container - base class -* -* @author Radek Maciaszek <chief@php.net> -* @package Mail_Queue -* @access public -* @abstract -*/ -class Mail_Queue_Container { - - /** - * Array for mails in queue - * - * @var array - */ - var $queue_data = array(); - - /** - * Key for current mail in queue - * - * @var integer - * @access private - */ - var $_current_item = 0; - - /** - * Key for last mail in queue - * - * @var integer - * @access private - */ - var $_last_item = 0; - +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP Version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Radek Maciaszek <wodzu@tonet.pl> | +// +----------------------------------------------------------------------+ +// +// $Id: Container.php,v 1.3 2003/10/01 11:57:32 quipo Exp $ + +/** + * Container base class for MTA queue. + * Define methods for all storage containers. + * + * @version $Revision: 1.3 $ + * @author Radek Maciaszek <chief@php.net> + */ + +//require_once 'Mail/Queue/Error.php'; +require_once 'Mail/Queue/Body.php'; + +/** + * Mail_Queue_Container - base class + * + * @author Radek Maciaszek <chief@php.net> + * @package Mail_Queue + * @access public + * @abstract + */ +class Mail_Queue_Container +{ + // {{{ class vars + + /** + * Array for mails in queue + * + * @var array + */ + var $queue_data = array(); + + /** + * Key for current mail in queue + * + * @var integer + * @access private + */ + var $_current_item = 0; + + /** + * Key for last mail in queue + * + * @var integer + * @access private + */ + var $_last_item = 0; + + /** + * Variable to check if mails are loaded to queue + * @var boolean + * @access private + */ + var $_preloaded = false; + + /** + * Options + */ + var $limit; + var $offset; + var $try; + var $force_preload; + /** - * Variable to check if mails are loaded to queue - * @var boolean - * @access private - */ - var $_preloaded = false; - - /** - * Options - */ - var $limit; - var $offset; - var $try; - var $forse_preload; - - /** - * Get next mail from queue. When exclude first time preload all queue + * Pear error mode (see PEAR doc) * - * @return mixed MailBody object on success else Mail_Queue_Error - * @access public - */ - function get() - { - $this->_preload(); - if( !empty($this->queue_data) && !$this->isEmpty() ) { - if(!isset($this->queue_data[$this->_current_item])) { - return new Mail_Queue_Error('No item: '.$this->_current_item - . ' in queue!', __FILE__, __LINE__); - } - $object = $this->queue_data[$this->_current_item]; - unset($this->queue_data[$this->_current_item]); - $this->_current_item++; - return $object; - } else { - return false; - } - } - - /** - * Put new mail in queue. - * - * Mail_Queue_Container::put() - * - * @param string $time_to_send When mail have to be send - * @param integer $id_user Sender id - * @param string $ip Sender ip - * @param string $from Sender e-mail - * @param string $to Reciepient e-mail - * @param string $hdrs Mail headers (in RFC) - * @param string $body Mail body (in RFC) - * @return bool True on success - * @access public - **/ - function put($time_to_send, $id_user, $ip, $from, $to, $hdrs, $body, $delete_after_send) - { - $this->_last_item = count($this->queue_data); - $this->queue_data[$this->_last_item] = new Mail_Queue_Body( $id, date("d-m-y G:i:s"), - $time_to_send, null, $id_user, - $ip, $sender, $recipient, unserialize($headers), - unserialize($body), $delete_after_send, 0 ); - return true; - } - - /** - * Set common option - * - * Mail_Queue_Container::setOption() - * - * @param integer $limit Optional - Number of mails loaded to queue - * @param integer $offset Optional - You could also specify offset - * @param integer $try Optional - how many times should system try sent - * each mail - * @param boolean $force_preload Optional - FIXME - * @return void - * - * @access public - **/ - function setOption($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START, - $try = MAILQUEUE_TRY, $forse_preload = false) - { - $this->limit = $limit; - $this->offset = $offset; - $this->try = $try; - $this->forse_preload = $forse_preload; - } - - /** - * Check if queue is empty. - * - * @return boolean True if empty else false. - * @access public - */ - function isEmpty() - { - if($this->_current_item > $this->_last_item) - return true; - else - return false; - } - - /** - * Check how many times mail was sent. - * - * @param object MailBody - * @return mixed Integer or false if error. - * @access public - */ - function countSend( $mail ) - { - return false; - } - - /** - * Set mail as already sent. - * - * @param object MailBody object - * @return bool - * @access public - */ - function setAsSent( $mail ) - { - return false; - } - - /** - * Return mail by id $id (bypass mail_queue) - * - * @param integer $id Mail ID - * @return mixed Mail object or false on error. - * @access public - */ - function getMailById( $id ) - { - return false; - } - - /** - * Remove from queue mail with $id identifier. - * - * @param integer $id Mail ID - * @return bool True on success ale false. - * @access public - */ - function deleteMail( $id ) - { - return false; - } - - /** - * Preload mail to queue. - * - * @param integer $limit Optional - Number of mails loaded to queue - * @param integer $offset Optional - You could also specify offset - * @param boolean $force_preload Optional - FIXME - * - * @return mixed True on success else Mail_Queue_Error object. - * + * @var int $pearErrorMode * @access private */ - function _preload($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START, - $try = MAILQUEUE_TRY, $forse_preload = false) - { - if($this->_preloaded) return true; - - $this->_preloaded = true; - $this->_last_item = count($this->queue_data); - return true; - } - -} + var $pearErrorMode = PEAR_ERROR_RETURN; + // }}} + // {{{ get() + + /** + * Get next mail from queue. When exclude first time preload all queue + * + * @return mixed MailBody object on success else Mail_Queue_Error + * @access public + */ + function get() + { + $this->_preload(); + if(!empty($this->queue_data) && !$this->isEmpty()) { + if(!isset($this->queue_data[$this->_current_item])) { + return new Mail_Queue_Error(MAILQUEUE_ERROR_CANNOT_INITIALIZE, + $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, + 'No item: '.$this->_current_item.' in queue!'); + } + $object = $this->queue_data[$this->_current_item]; + unset($this->queue_data[$this->_current_item]); + $this->_current_item++; + return $object; + } else { + return false; + } + } + + // }}} + // {{{ put() + + /** + * Put new mail in queue. + * + * Mail_Queue_Container::put() + * + * @param string $time_to_send When mail have to be send + * @param integer $id_user Sender id + * @param string $ip Sender ip + * @param string $from Sender e-mail + * @param string $to Reciepient e-mail + * @param string $hdrs Mail headers (in RFC) + * @param string $body Mail body (in RFC) + * @return bool True on success + * @access public + **/ + function put($time_to_send, $id_user, $ip, $from, $to, $hdrs, $body, $delete_after_send) + { + $this->_last_item = count($this->queue_data); + $this->queue_data[$this->_last_item] = new Mail_Queue_Body($id, date("d-m-y G:i:s"), + $time_to_send, null, $id_user, + $ip, $sender, $recipient, unserialize($headers), + unserialize($body), $delete_after_send, 0); + return true; + } + + // }}} + // {{{ setOption() + + /** + * Set common option + * + * Mail_Queue_Container::setOption() + * + * @param integer $limit Optional - Number of mails loaded to queue + * @param integer $offset Optional - You could also specify offset + * @param integer $try Optional - how many times should system try sent + * each mail + * @param boolean $force_preload Optional - FIXME + * @return void + * + * @access public + **/ + function setOption($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START, + $try = MAILQUEUE_TRY, $force_preload = false) + { + $this->limit = $limit; + $this->offset = $offset; + $this->try = $try; + $this->force_preload = $force_preload; + } + + // }}} + // {{{ isEmpty() + + /** + * Check if queue is empty. + * + * @return boolean True if empty else false. + * @access public + */ + function isEmpty() + { + if($this->_current_item > $this->_last_item) { + return true; + } else { + return false; + } + } + + // }}} + // {{{ countSend() + + /** + * Check how many times mail was sent. + * + * @param object MailBody + * @return mixed Integer or false if error. + * @access public + */ + function countSend($mail) + { + return false; + } + + // }}} + // {{{ setAsSent() + + /** + * Set mail as already sent. + * + * @param object MailBody object + * @return bool + * @access public + */ + function setAsSent($mail) + { + return false; + } + + // }}} + // {{{ getMailById() + + /** + * Return mail by id $id (bypass mail_queue) + * + * @param integer $id Mail ID + * @return mixed Mail object or false on error. + * @access public + */ + function getMailById($id) + { + return false; + } + + // }}} + // {{{ deleteMail() + + /** + * Remove from queue mail with $id identifier. + * + * @param integer $id Mail ID + * @return bool True on success ale false. + * @access public + */ + function deleteMail($id) + { + return false; + } + + // }}} + // {{{ _preload() + + /** + * Preload mail to queue. + * + * @param integer $limit Optional - Number of mails loaded to queue + * @param integer $offset Optional - You could also specify offset + * @param boolean $force_preload Optional - FIXME + * + * @return mixed True on success else Mail_Queue_Error object. + * + * @access private + */ + function _preload($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START, + $try = MAILQUEUE_TRY, $forse_preload = false) + { + if($this->_preloaded) return true; + + $this->_preloaded = true; + $this->_last_item = count($this->queue_data); + return true; + } + + // }}} +} ?>
Index: pear/Mail_Queue/Queue/Body.php diff -u pear/Mail_Queue/Queue/Body.php:1.2 pear/Mail_Queue/Queue/Body.php:1.3 --- pear/Mail_Queue/Queue/Body.php:1.2 Tue Feb 25 04:41:04 2003 +++ pear/Mail_Queue/Queue/Body.php Wed Oct 1 07:57:32 2003 @@ -1,329 +1,328 @@ -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | PHP Version 4 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2003 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Radek Maciaszek <chief@php.net> | -// +----------------------------------------------------------------------+ -// -// $Id: Body.php,v 1.2 2003/02/25 09:41:04 chief Exp $ - -/** -* Class contains mail data. -* -* @version $Revision: 1.2 $ -* @author Radek Maciaszek <chief@php.net> -*/ - -/** -* Mail_Queue_Body contains mail data -* -* @author Radek Maciaszek <wodzu@pomocprawna.info> -* @version $Revision: 1.2 $ -* @package Mail_Queue -* @access public -*/ -class Mail_Queue_Body { - - /** - * Ident - * - * @var integer - */ - var $id; - - /** - * Create time - * - * @var string - */ - var $create_time; - - /** - * Time to send mail - * - * @var string - */ - var $time_to_send; - - /** - * Time when mail was sent - * - * @var string - */ - var $sent_time = null; - - /** - * User id - who send mail - * MAILQUEUE_UNKNOWN - not login user (guest) - * MAILQUEUE_SYSTEM - mail send by system - * - * @var string - */ - var $id_user = MAILQUEUE_SYSTEM; - - /** - * use IP - * - * @var string - */ - var $ip; - - /** - * Sender email - * - * @var string - */ - var $sender; - - /** - * Reciepient email - * - * @var string - */ - var $recipient; - - /** - * Email headers (in RFC) - * - * @var string - */ - var $headers; - - /** - * Email body (in RFC) - could have attachments etc - * - * @var string - */ - var $body; - - /** - * How many times mail was sent - * - * @var integer - */ - var $try_sent = 0; - - /** - * Delete mail from database after success send - * - * @var bool - */ - var $delete_after_send = true; - - /** - * Mail_Queue_Body::Mail_Queue_Body() constructor - * - * @param integer $id Mail ident - * @param string $create_time Create time - * @param strine $time_to_send Time to send - * @param string $sent_time Sent time - * @param integer $id_user Sender user id (who sent mail) - * @param string $ip Sender user ip - * @param strine $sender Sender e-mail - * @param string $recipient Reciepient e-mail - * @param string $headers Mail headers (in RFC) - * @param string $body Mail body (in RFC) - * @param integer $try_sent How many times mail was sent - * - * @return void - * - * @access public - **/ - function Mail_Queue_Body( $id, $create_time, $time_to_send, $sent_time, $id_user, - $ip, $sender, $recipient, $headers, $body, - $delete_after_send = true, $try_sent = 0 ) - { - $this->id = $id; - $this->create_time = $create_time; - $this->time_to_send = $time_to_send; - $this->sent_time = $sent_time; - $this->id_user = $id_user; - $this->ip = $ip; - $this->sender = $sender; - $this->recipient = $recipient; - $this->headers = $headers; - $this->body = $body; - $this->delete_after_send = $delete_after_send; - $this->try_sent = $try_sent; - } - - /** - * Mail_Queue_Body::getId() - * - * @return integer Sender id - * @access public - **/ - function getId() - { - return $this->id; - } - - /** - * Return mail create time. - * - * Mail_Queue_Body::getCreateTime() - * - * @return string Mail create time - * @access public - **/ - function getCreateTime() - { - return $this->create_time; - } - - /** - * Return time to send mail. - * - * Mail_Queue_Body::getTimeToSend() - * - * @return string Time to send - * @access public - **/ - function getTimeToSend() - { - return $this->time_to_send; - } - - /** - * Return mail sent time (if sended) else false. - * - * Mail_Queue_Body::getSentTime() - * - * @return mixed String sent time or false if mail not was sent yet - * @access public - **/ - function getSentTime() - { - return empty($this->sent_time) ? false : $this->sent_time; - } - - /** - * Return sender id. - * - * Mail_Queue_Body::getIdUser() - * - * @return integer Sender id - * @access public - **/ - function getIdUser() - { - return $this->id_user; - } - - /** - * Return sender ip. - * - * Mail_Queue_Body::getIp() - * - * @return string IP - * @access public - **/ - function getIp() - { - return $this->ip; - } - - /** - * Return sender e-mail. - * - * Mail_Queue_Body::getSender() - * - * @return string E-mail - * @access public - **/ - function getSender() - { - return $this->sender; - } - - /** - * Return recipient e-mail. - * - * Mail_Queue_Body::getRecipient() - * - * @return string E-mail - * @access public - **/ - function getRecipient() - { - return $this->recipient; - } - - /** - * Return mail headers (in RFC) - * - * Mail_Queue_Body::getHeaders() - * - * @return string headers - * @access public - **/ - function getHeaders() - { - return $this->headers; - } - - /** - * Return mail body (in RFC) - * - * Mail_Queue_Body::getBody() - * - * @return string Body - * @access public - **/ - function getBody() - { - return $this->body; - } - - /** - * Return how many times mail was try to sent. - * - * Mail_Queue_Body::getTrySent() - * - * @return integer How many times mail was sent - * @access public - **/ - function getTrySent() - { - return $this->try_sent; - } - - /** - * Return true if mail must be delete after send from db. - * - * MailBody::isDeleteAfterSend() - * - * @return bool True if must be delete else false. - * @access public - **/ - function isDeleteAfterSend() - { - return $this->delete_after_send; - } - - /** - * Increase and return try_sent - * - * Mail_Queue_Body::try() - * - * @return integer How many times mail was sent - * @access public - **/ - function try() - { - return ++$this->try_sent; - } -} - +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP Version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Radek Maciaszek <chief@php.net> | +// +----------------------------------------------------------------------+ +// +// $Id: Body.php,v 1.3 2003/10/01 11:57:32 quipo Exp $ + +/** +* Class contains mail data. +* +* @version $Revision: 1.3 $ +* @author Radek Maciaszek <chief@php.net> +*/ + +/** +* Mail_Queue_Body contains mail data +* +* @author Radek Maciaszek <wodzu@pomocprawna.info> +* @version $Revision: 1.3 $ +* @package Mail_Queue +* @access public +*/ +class Mail_Queue_Body { + + /** + * Ident + * + * @var integer + */ + var $id; + + /** + * Create time + * + * @var string + */ + var $create_time; + + /** + * Time to send mail + * + * @var string + */ + var $time_to_send; + + /** + * Time when mail was sent + * + * @var string + */ + var $sent_time = null; + + /** + * User id - who send mail + * MAILQUEUE_UNKNOWN - not login user (guest) + * MAILQUEUE_SYSTEM - mail send by system + * + * @var string + */ + var $id_user = MAILQUEUE_SYSTEM; + + /** + * use IP + * + * @var string + */ + var $ip; + + /** + * Sender email + * + * @var string + */ + var $sender; + + /** + * Reciepient email + * + * @var string + */ + var $recipient; + + /** + * Email headers (in RFC) + * + * @var string + */ + var $headers; + + /** + * Email body (in RFC) - could have attachments etc + * + * @var string + */ + var $body; + + /** + * How many times mail was sent + * + * @var integer + */ + var $try_sent = 0; + + /** + * Delete mail from database after success send + * + * @var bool + */ + var $delete_after_send = true; + + /** + * Mail_Queue_Body::Mail_Queue_Body() constructor + * + * @param integer $id Mail ident + * @param string $create_time Create time + * @param strine $time_to_send Time to send + * @param string $sent_time Sent time + * @param integer $id_user Sender user id (who sent mail) + * @param string $ip Sender user ip + * @param strine $sender Sender e-mail + * @param string $recipient Reciepient e-mail + * @param string $headers Mail headers (in RFC) + * @param string $body Mail body (in RFC) + * @param integer $try_sent How many times mail was sent + * + * @return void + * + * @access public + **/ + function Mail_Queue_Body($id, $create_time, $time_to_send, $sent_time, $id_user, + $ip, $sender, $recipient, $headers, $body, + $delete_after_send=true, $try_sent=0) + { + $this->id = $id; + $this->create_time = $create_time; + $this->time_to_send = $time_to_send; + $this->sent_time = $sent_time; + $this->id_user = $id_user; + $this->ip = $ip; + $this->sender = $sender; + $this->recipient = $recipient; + $this->headers = $headers; + $this->body = $body; + $this->delete_after_send = $delete_after_send; + $this->try_sent = $try_sent; + } + + /** + * Mail_Queue_Body::getId() + * + * @return integer Sender id + * @access public + **/ + function getId() + { + return $this->id; + } + + /** + * Return mail create time. + * + * Mail_Queue_Body::getCreateTime() + * + * @return string Mail create time + * @access public + **/ + function getCreateTime() + { + return $this->create_time; + } + + /** + * Return time to send mail. + * + * Mail_Queue_Body::getTimeToSend() + * + * @return string Time to send + * @access public + **/ + function getTimeToSend() + { + return $this->time_to_send; + } + + /** + * Return mail sent time (if sended) else false. + * + * Mail_Queue_Body::getSentTime() + * + * @return mixed String sent time or false if mail not was sent yet + * @access public + **/ + function getSentTime() + { + return empty($this->sent_time) ? false : $this->sent_time; + } + + /** + * Return sender id. + * + * Mail_Queue_Body::getIdUser() + * + * @return integer Sender id + * @access public + **/ + function getIdUser() + { + return $this->id_user; + } + + /** + * Return sender ip. + * + * Mail_Queue_Body::getIp() + * + * @return string IP + * @access public + **/ + function getIp() + { + return $this->ip; + } + + /** + * Return sender e-mail. + * + * Mail_Queue_Body::getSender() + * + * @return string E-mail + * @access public + **/ + function getSender() + { + return $this->sender; + } + + /** + * Return recipient e-mail. + * + * Mail_Queue_Body::getRecipient() + * + * @return string E-mail + * @access public + **/ + function getRecipient() + { + return $this->recipient; + } + + /** + * Return mail headers (in RFC) + * + * Mail_Queue_Body::getHeaders() + * + * @return string headers + * @access public + **/ + function getHeaders() + { + return $this->headers; + } + + /** + * Return mail body (in RFC) + * + * Mail_Queue_Body::getBody() + * + * @return string Body + * @access public + **/ + function getBody() + { + return $this->body; + } + + /** + * Return how many times mail was try to sent. + * + * Mail_Queue_Body::getTrySent() + * + * @return integer How many times mail was sent + * @access public + **/ + function getTrySent() + { + return $this->try_sent; + } + + /** + * Return true if mail must be delete after send from db. + * + * MailBody::isDeleteAfterSend() + * + * @return bool True if must be delete else false. + * @access public + **/ + function isDeleteAfterSend() + { + return $this->delete_after_send; + } + + /** + * Increase and return try_sent + * + * Mail_Queue_Body::try() + * + * @return integer How many times mail was sent + * @access public + **/ + function try() + { + return ++$this->try_sent; + } +} ?> Index: pear/Mail_Queue/Queue/Container.php diff -u pear/Mail_Queue/Queue/Container.php:1.2 pear/Mail_Queue/Queue/Container.php:1.3 --- pear/Mail_Queue/Queue/Container.php:1.2 Tue Feb 25 04:41:04 2003 +++ pear/Mail_Queue/Queue/Container.php Wed Oct 1 07:57:32 2003 @@ -1,236 +1,275 @@ -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | PHP Version 4 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2003 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Radek Maciaszek <wodzu@tonet.pl> | -// +----------------------------------------------------------------------+ -// -// $Id: Container.php,v 1.2 2003/02/25 09:41:04 chief Exp $ - -/** -* Container base class for MTA queue. -* Define methods for all storage containers. -* -* @version $Revision: 1.2 $ -* @author Radek Maciaszek <chief@php.net> -*/ - -require_once "Mail/Queue/Error.php"; -require_once "Mail/Queue/Body.php"; - -/** -* Mail_Queue_Container - base class -* -* @author Radek Maciaszek <chief@php.net> -* @package Mail_Queue -* @access public -* @abstract -*/ -class Mail_Queue_Container { - - /** - * Array for mails in queue - * - * @var array - */ - var $queue_data = array(); - - /** - * Key for current mail in queue - * - * @var integer - * @access private - */ - var $_current_item = 0; - - /** - * Key for last mail in queue - * - * @var integer - * @access private - */ - var $_last_item = 0; - +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP Version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Radek Maciaszek <wodzu@tonet.pl> | +// +----------------------------------------------------------------------+ +// +// $Id: Container.php,v 1.3 2003/10/01 11:57:32 quipo Exp $ + +/** + * Container base class for MTA queue. + * Define methods for all storage containers. + * + * @version $Revision: 1.3 $ + * @author Radek Maciaszek <chief@php.net> + */ + +//require_once 'Mail/Queue/Error.php'; +require_once 'Mail/Queue/Body.php'; + +/** + * Mail_Queue_Container - base class + * + * @author Radek Maciaszek <chief@php.net> + * @package Mail_Queue + * @access public + * @abstract + */ +class Mail_Queue_Container +{ + // {{{ class vars + + /** + * Array for mails in queue + * + * @var array + */ + var $queue_data = array(); + + /** + * Key for current mail in queue + * + * @var integer + * @access private + */ + var $_current_item = 0; + + /** + * Key for last mail in queue + * + * @var integer + * @access private + */ + var $_last_item = 0; + + /** + * Variable to check if mails are loaded to queue + * @var boolean + * @access private + */ + var $_preloaded = false; + + /** + * Options + */ + var $limit; + var $offset; + var $try; + var $force_preload; + /** - * Variable to check if mails are loaded to queue - * @var boolean - * @access private - */ - var $_preloaded = false; - - /** - * Options - */ - var $limit; - var $offset; - var $try; - var $forse_preload; - - /** - * Get next mail from queue. When exclude first time preload all queue + * Pear error mode (see PEAR doc) * - * @return mixed MailBody object on success else Mail_Queue_Error - * @access public - */ - function get() - { - $this->_preload(); - if( !empty($this->queue_data) && !$this->isEmpty() ) { - if(!isset($this->queue_data[$this->_current_item])) { - return new Mail_Queue_Error('No item: '.$this->_current_item - . ' in queue!', __FILE__, __LINE__); - } - $object = $this->queue_data[$this->_current_item]; - unset($this->queue_data[$this->_current_item]); - $this->_current_item++; - return $object; - } else { - return false; - } - } - - /** - * Put new mail in queue. - * - * Mail_Queue_Container::put() - * - * @param string $time_to_send When mail have to be send - * @param integer $id_user Sender id - * @param string $ip Sender ip - * @param string $from Sender e-mail - * @param string $to Reciepient e-mail - * @param string $hdrs Mail headers (in RFC) - * @param string $body Mail body (in RFC) - * @return bool True on success - * @access public - **/ - function put($time_to_send, $id_user, $ip, $from, $to, $hdrs, $body, $delete_after_send) - { - $this->_last_item = count($this->queue_data); - $this->queue_data[$this->_last_item] = new Mail_Queue_Body( $id, date("d-m-y G:i:s"), - $time_to_send, null, $id_user, - $ip, $sender, $recipient, unserialize($headers), - unserialize($body), $delete_after_send, 0 ); - return true; - } - - /** - * Set common option - * - * Mail_Queue_Container::setOption() - * - * @param integer $limit Optional - Number of mails loaded to queue - * @param integer $offset Optional - You could also specify offset - * @param integer $try Optional - how many times should system try sent - * each mail - * @param boolean $force_preload Optional - FIXME - * @return void - * - * @access public - **/ - function setOption($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START, - $try = MAILQUEUE_TRY, $forse_preload = false) - { - $this->limit = $limit; - $this->offset = $offset; - $this->try = $try; - $this->forse_preload = $forse_preload; - } - - /** - * Check if queue is empty. - * - * @return boolean True if empty else false. - * @access public - */ - function isEmpty() - { - if($this->_current_item > $this->_last_item) - return true; - else - return false; - } - - /** - * Check how many times mail was sent. - * - * @param object MailBody - * @return mixed Integer or false if error. - * @access public - */ - function countSend( $mail ) - { - return false; - } - - /** - * Set mail as already sent. - * - * @param object MailBody object - * @return bool - * @access public - */ - function setAsSent( $mail ) - { - return false; - } - - /** - * Return mail by id $id (bypass mail_queue) - * - * @param integer $id Mail ID - * @return mixed Mail object or false on error. - * @access public - */ - function getMailById( $id ) - { - return false; - } - - /** - * Remove from queue mail with $id identifier. - * - * @param integer $id Mail ID - * @return bool True on success ale false. - * @access public - */ - function deleteMail( $id ) - { - return false; - } - - /** - * Preload mail to queue. - * - * @param integer $limit Optional - Number of mails loaded to queue - * @param integer $offset Optional - You could also specify offset - * @param boolean $force_preload Optional - FIXME - * - * @return mixed True on success else Mail_Queue_Error object. - * + * @var int $pearErrorMode * @access private */ - function _preload($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START, - $try = MAILQUEUE_TRY, $forse_preload = false) - { - if($this->_preloaded) return true; - - $this->_preloaded = true; - $this->_last_item = count($this->queue_data); - return true; - } - -} + var $pearErrorMode = PEAR_ERROR_RETURN; + // }}} + // {{{ get() + + /** + * Get next mail from queue. When exclude first time preload all queue + * + * @return mixed MailBody object on success else Mail_Queue_Error + * @access public + */ + function get() + { + $this->_preload(); + if(!empty($this->queue_data) && !$this->isEmpty()) { + if(!isset($this->queue_data[$this->_current_item])) { + return new Mail_Queue_Error(MAILQUEUE_ERROR_CANNOT_INITIALIZE, + $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, + 'No item: '.$this->_current_item.' in queue!'); + } + $object = $this->queue_data[$this->_current_item]; + unset($this->queue_data[$this->_current_item]); + $this->_current_item++; + return $object; + } else { + return false; + } + } + + // }}} + // {{{ put() + + /** + * Put new mail in queue. + * + * Mail_Queue_Container::put() + * + * @param string $time_to_send When mail have to be send + * @param integer $id_user Sender id + * @param string $ip Sender ip + * @param string $from Sender e-mail + * @param string $to Reciepient e-mail + * @param string $hdrs Mail headers (in RFC) + * @param string $body Mail body (in RFC) + * @return bool True on success + * @access public + **/ + function put($time_to_send, $id_user, $ip, $from, $to, $hdrs, $body, $delete_after_send) + { + $this->_last_item = count($this->queue_data); + $this->queue_data[$this->_last_item] = new Mail_Queue_Body($id, date("d-m-y G:i:s"), + $time_to_send, null, $id_user, + $ip, $sender, $recipient, unserialize($headers), + unserialize($body), $delete_after_send, 0); + return true; + } + + // }}} + // {{{ setOption() + + /** + * Set common option + * + * Mail_Queue_Container::setOption() + * + * @param integer $limit Optional - Number of mails loaded to queue + * @param integer $offset Optional - You could also specify offset + * @param integer $try Optional - how many times should system try sent + * each mail + * @param boolean $force_preload Optional - FIXME + * @return void + * + * @access public + **/ + function setOption($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START, + $try = MAILQUEUE_TRY, $force_preload = false) + { + $this->limit = $limit; + $this->offset = $offset; + $this->try = $try; + $this->force_preload = $force_preload; + } + + // }}} + // {{{ isEmpty() + + /** + * Check if queue is empty. + * + * @return boolean True if empty else false. + * @access public + */ + function isEmpty() + { + if($this->_current_item > $this->_last_item) { + return true; + } else { + return false; + } + } + + // }}} + // {{{ countSend() + + /** + * Check how many times mail was sent. + * + * @param object MailBody + * @return mixed Integer or false if error. + * @access public + */ + function countSend($mail) + { + return false; + } + + // }}} + // {{{ setAsSent() + + /** + * Set mail as already sent. + * + * @param object MailBody object + * @return bool + * @access public + */ + function setAsSent($mail) + { + return false; + } + + // }}} + // {{{ getMailById() + + /** + * Return mail by id $id (bypass mail_queue) + * + * @param integer $id Mail ID + * @return mixed Mail object or false on error. + * @access public + */ + function getMailById($id) + { + return false; + } + + // }}} + // {{{ deleteMail() + + /** + * Remove from queue mail with $id identifier. + * + * @param integer $id Mail ID + * @return bool True on success ale false. + * @access public + */ + function deleteMail($id) + { + return false; + } + + // }}} + // {{{ _preload() + + /** + * Preload mail to queue. + * + * @param integer $limit Optional - Number of mails loaded to queue + * @param integer $offset Optional - You could also specify offset + * @param boolean $force_preload Optional - FIXME + * + * @return mixed True on success else Mail_Queue_Error object. + * + * @access private + */ + function _preload($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START, + $try = MAILQUEUE_TRY, $forse_preload = false) + { + if($this->_preloaded) return true; + + $this->_preloaded = true; + $this->_last_item = count($this->queue_data); + return true; + } + + // }}} +} ?>