[ Index ]
 

Code source de IMP H3 (4.1.5)

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/lib/Quota/ -> logfile.php (source)

   1  <?php
   2  /**
   3   * Implementation of the Quota API for servers where IMAP Quota is not
   4   * supported, but it appears in the servers messages log for the IMAP
   5   * server.
   6   *
   7   * Requires the following parameter settings in imp/servers.php:
   8   * 'quota' => array(
   9   *     'driver' => 'logfile',
  10   *     'params' => array(
  11   *         'logfile' => '/path/to/log/file',
  12   *         'taillines' => 10,
  13   *         'FTPmail'   => 'FTP',
  14   *         'beginocc'  => 'usage = ',
  15   *         'midocc'    => ' of ',
  16   *         'endocc'    => ' bytes'
  17   *     )
  18   * );
  19   *
  20   * logfile    --  The path/to/filename of the log file to use.
  21   * taillines  --  The number of lines to look at in the tail of the logfile.
  22   * FTPmail    --  If you want to show what FTP space is available (IMAP folder)
  23   *                or what mail space is available (INBOX).
  24   *                Defines the search string to username:
  25   *                  FTPmail to identify the line with QUOTA info.
  26   * beginocc   --  String that designates the characters before the usage
  27   *                number.
  28   * midocc     --  String between usage and total storage space.
  29   * endocc     --  String after the storage number.
  30   *
  31   * $Horde: imp/lib/Quota/logfile.php,v 1.5.10.4 2005/10/18 12:13:36 jan Exp $
  32   *
  33   * See the enclosed file COPYING for license information (GPL). If you
  34   * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  35   *
  36   * @author  Tim Gorter <email@teletechnics.co.nz>
  37   * @since   IMP 4.0
  38   * @package IMP_Quota
  39   */
  40  class IMP_Quota_logfile extends IMP_Quota {
  41  
  42      /**
  43       * Constructor
  44       *
  45       * @param array $params  Hash containing connection parameters.
  46       */
  47      function IMP_Quota_logfile($params = array())
  48      {
  49          $this->_params = array(
  50              'logfile'   => '',
  51              'taillines' => 10,
  52              'FTPmail'   => 'FTP',
  53              'beginocc'  => 'usage = ',
  54              'midocc'    => ' of ',
  55              'endocc'    => ' bytes'
  56          );
  57  
  58          $this->_params = array_merge($this->_params, $params);
  59      }
  60  
  61      /**
  62       * Get quota information (used/allocated), in bytes.
  63       *
  64       * @return mixed  An associative array.
  65       *                'limit' = Maximum quota allowed
  66       *                'usage' = Currently used portion of quota (in bytes)
  67       *                Returns PEAR_Error on failure.
  68       */
  69      function getQuota()
  70      {
  71          global $imp;
  72  
  73          if (is_file($this->_params['logfile'])) {
  74              $full = file($this->_params['logfile']);
  75              for ( ; $this->_params['taillines'] > 0 ; $this->_params['taillines']--) {
  76                  $tail[] = $full[count($full)-$this->_params['taillines']];
  77              }
  78              $uname    = $imp['user'];
  79              $FTPmail  = $this->_params['FTPmail'];
  80              $virtline = preg_grep("[$uname: $FTPmail]", $tail);
  81              $virtline = (array_values($virtline));
  82              $usage    = substr("$virtline[0]", strpos("$virtline[0]", $this->_params['beginocc']) + strlen($this->_params['beginocc']),
  83                          strpos("$virtline[0]", $this->_params['midocc']));
  84              $storage  = substr("$virtline[0]", strpos("$virtline[0]", $this->_params['midocc']) + strlen($this->_params['midocc']),
  85                          strpos("$virtline[0]", $this->_params['endocc']));
  86              return array('usage' => $usage, 'limit' => $storage);
  87          }
  88          return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
  89      }
  90  
  91  }


Généré le : Thu Nov 29 12:30:07 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics