home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / Container.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  7.3 KB  |  277 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Radek Maciaszek <wodzu@tonet.pl>                            |
  17. // |          Lorenzo Alberton <l dot alberton at quipo dot it>           |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Container.php,v 1.5 2004/02/29 09:15:24 quipo Exp $
  21.  
  22. /**
  23.  * File Container.php
  24.  *
  25.  * @package Mail_Queue
  26.  */
  27. require_once 'Mail/Queue/Body.php';
  28.  
  29. /**
  30.  * Mail_Queue_Container - base class for MTA queue.
  31.  * Define methods for all storage containers.
  32.  *
  33.  * @version  $Revision: 1.5 $
  34.  * @author   Radek Maciaszek <chief@php.net>
  35.  * @author   Lorenzo Alberton <l dot alberton at quipo dot it>
  36.  * @package  Mail_Queue
  37.  * @access   public
  38.  * @abstract
  39.  */
  40. class Mail_Queue_Container
  41. {
  42.     // {{{ class vars
  43.  
  44.     /**
  45.      * Array for mails in queue
  46.      *
  47.      * @var array
  48.      */
  49.     var $queue_data = array();
  50.  
  51.     /**
  52.      * Key for current mail in queue
  53.      *
  54.      * @var integer
  55.      * @access private
  56.      */
  57.     var $_current_item = 0;
  58.  
  59.     /**
  60.      * Key for last mail in queue
  61.      *
  62.      * @var integer
  63.      * @access private
  64.      */
  65.     var $_last_item = 0;
  66.  
  67.     /**
  68.      * Options
  69.      */
  70.     var $limit;
  71.     var $offset;
  72.     var $try;
  73.     var $force_preload;
  74.     var $buffer_size = 10; //number of mails in the queue
  75.  
  76.     /**
  77.      * Pear error mode (see PEAR doc)
  78.      *
  79.      * @var int $pearErrorMode
  80.      * @access private
  81.      */
  82.     var $pearErrorMode = PEAR_ERROR_RETURN;
  83.  
  84.     // }}}
  85.     // {{{ get()
  86.  
  87.     /**
  88.      * Get next mail from queue. When exclude first time preload all queue
  89.      *
  90.      * @return mixed  MailBody object on success else Mail_Queue_Error
  91.      * @access    public
  92.      */
  93.     function get()
  94.     {
  95.         if (Mail_Queue::isError($err = $this->preload())) {
  96.             return $err;
  97.         }
  98.         if (empty($this->queue_data)) {
  99.             return false;
  100.         }
  101.         if (!isset($this->queue_data[$this->_current_item])) {
  102.             //unlikely...
  103.             return new Mail_Queue_Error(MAILQUEUE_ERROR_CANNOT_INITIALIZE,
  104.                 $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__,
  105.                 'No item: '.$this->_current_item.' in queue!');
  106.         }
  107.  
  108.         $object = $this->queue_data[$this->_current_item];
  109.         unset($this->queue_data[$this->_current_item]);
  110.         $this->_current_item++;
  111.         return $object;
  112.     }
  113.  
  114.     // }}}
  115.     // {{{ put()
  116.  
  117.     /**
  118.      * Put new mail in queue.
  119.      *
  120.      * Mail_Queue_Container::put()
  121.      *
  122.      * @param string $time_to_send  When mail have to be send
  123.      * @param integer $id_user  Sender id
  124.      * @param string $ip  Sender ip
  125.      * @param string $from  Sender e-mail
  126.      * @param string $to  Reciepient e-mail
  127.      * @param string $hdrs  Mail headers (in RFC)
  128.      * @param string $body  Mail body (in RFC)
  129.      * @return bool True on success
  130.      * @access public
  131.      **/
  132. /*
  133.     function put($time_to_send, $id_user, $ip, $from, $to, $hdrs, $body, $delete_after_send)
  134.     {
  135.         $this->_last_item = count($this->queue_data);
  136.         $this->queue_data[$this->_last_item] = new Mail_Queue_Body($id, date("d-m-y G:i:s"),
  137.                     $time_to_send, null, $id_user,
  138.                     $ip, $sender, $recipient, unserialize($headers),
  139.                     unserialize($body), $delete_after_send, 0);
  140.         return true;
  141.     }
  142. */
  143.     // }}}
  144.     // {{{ setOption()
  145.  
  146.     /**
  147.      * Set common option
  148.      *
  149.      * Mail_Queue_Container::setOption()
  150.      *
  151.      * @param integer  $limit  Optional - Number of mails loaded to queue
  152.      * @param integer  $offset Optional - You could also specify offset
  153.      * @param integer  $try  Optional - how many times should system try sent
  154.      *                       each mail
  155.      * @param boolean  $force_preload  Optional - FIXME
  156.      * @return void
  157.      *
  158.      * @access public
  159.      **/
  160.     function setOption($limit = MAILQUEUE_ALL, $offset = MAILQUEUE_START,
  161.                         $try = MAILQUEUE_TRY, $force_preload = false)
  162.     {
  163.         $this->limit = $limit;
  164.         $this->offset = $offset;
  165.         $this->try = $try;
  166.         $this->force_preload = $force_preload;
  167.     }
  168.  
  169.     // }}}
  170.     // {{{ countSend()
  171.  
  172.     /**
  173.      * Check how many times mail was sent.
  174.      *
  175.      * @param object   MailBody
  176.      * @return mixed  Integer or false if error.
  177.      * @access public
  178.      */
  179.     function countSend($mail)
  180.     {
  181.         return false;
  182.     }
  183.  
  184.     // }}}
  185.     // {{{ setAsSent()
  186.  
  187.     /**
  188.      * Set mail as already sent.
  189.      *
  190.      * @param object MailBody object
  191.      * @return bool
  192.      * @access public
  193.      */
  194.     function setAsSent($mail)
  195.     {
  196.         return false;
  197.     }
  198.  
  199.     // }}}
  200.     // {{{ getMailById()
  201.  
  202.     /**
  203.      * Return mail by id $id (bypass mail_queue)
  204.      *
  205.      * @param integer $id  Mail ID
  206.      * @return mixed  Mail object or false on error.
  207.      * @access public
  208.      */
  209.     function getMailById($id)
  210.     {
  211.         return false;
  212.     }
  213.  
  214.     // }}}
  215.     // {{{ deleteMail()
  216.  
  217.     /**
  218.      * Remove from queue mail with $id identifier.
  219.      *
  220.      * @param integer $id  Mail ID
  221.      * @return bool  True on success ale false.
  222.      * @access public
  223.      */
  224.     function deleteMail($id)
  225.     {
  226.         return false;
  227.     }
  228.  
  229.     // }}}
  230.     // {{{ preload()
  231.  
  232.     /**
  233.      * Preload mail to queue.
  234.      * The buffer size can be set in the options.
  235.      *
  236.      * @return mixed  True on success else Mail_Queue_Error object.
  237.      * @access private
  238.      */
  239.     function preload()
  240.     {
  241.         //remember buffer offset
  242.         static $from = 0;
  243.  
  244.         if (!empty($this->queue_data)) {
  245.             return true;
  246.         }
  247.  
  248.         $bkp = array(
  249.             'offset' => $this->offset,
  250.             'limit'  => $this->limit
  251.         );
  252.  
  253.         //set buffer size and offset
  254.         $this->offset = $from;
  255.         $this->limit = $this->buffer_size;
  256.  
  257.         if (Mail_Queue::isError($err = $this->_preload())) {
  258.             return $err;
  259.         }
  260.  
  261.         //restore options
  262.         $this->offset = $bkp['offset'];
  263.         $this->limit  = $bkp['limit'];
  264.  
  265.         //set buffer pointers
  266.         $this->_current_item = 0;
  267.         $this->_last_item = count($this->queue_data)-1;
  268.  
  269.         //update buffer offset
  270.         $from += count($this->queue_data);
  271.  
  272.         return true;
  273.     }
  274.  
  275.     // }}}
  276. }
  277. ?>