[ 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/ -> mdaemon.php (source)

   1  <?php
   2  /**
   3   * Implementation of the Quota API for MDaemon servers.
   4   *
   5   * Parameters required:
   6   *   'app_location'  --  TODO
   7   *
   8   * $Horde: imp/lib/Quota/mdaemon.php,v 1.11.10.9 2007/01/02 13:55:02 jan Exp $
   9   *
  10   * Copyright 2002-2007 Mike Cochrane <mike@graftonhall.co.nz>
  11   *
  12   * See the enclosed file COPYING for license information (GPL). If you
  13   * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  14   *
  15   * @author  Mike Cochrane <mike@graftonhall.co.nz>
  16   * @since   IMP 4.0
  17   * @package IMP_Quota
  18   */
  19  class IMP_Quota_mdaemon extends IMP_Quota {
  20  
  21      /**
  22       * Get quota information (used/allocated), in bytes.
  23       *
  24       * @return mixed  An associative array.
  25       *                'limit' = Maximum quota allowed
  26       *                'usage' = Currently used portion of quota (in bytes)
  27       *                Returns PEAR_Error on failure.
  28       */
  29      function getQuota()
  30      {
  31          global $imp;
  32  
  33          $userDetails = $this->_getUserDetails($imp['user'], $imp['maildomain']);
  34  
  35          if ($userDetails !== false) {
  36              $userHome = trim(substr($userDetails, 105, 90));
  37              $total = intval(substr($userDetails, 229, 6)) * 1024;
  38  
  39              if ($total == 0) {
  40                  return array('usage' => 0, 'limit' => 0);
  41              }
  42  
  43              if (($taken = $this->_mailboxSize($userHome)) !== false) {
  44                  return array('usage' => $taken, 'limit' => $total);
  45              }
  46          }
  47  
  48          return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
  49      }
  50  
  51      /**
  52       * Get the size of a mailbox
  53       *
  54       * @access private
  55       *
  56       * @param string $path  The full path of the mailbox to fetch the quota
  57       *                     for including trailing backslash.
  58       *
  59       * @return mixed  The number of bytes in the mailbox (integer) or false
  60       *                (boolean) on error.
  61       */
  62      function _mailboxSize($path)
  63      {
  64          $contents = file_get_contents($path . '\imap.mrk');
  65  
  66          $pointer = 36;
  67          $size = 0;
  68          while ($pointer < strlen($contents)) {
  69              $details = unpack('a17Filename/a11Crap/VSize', substr($contents, $pointer, 36));
  70              $size += $details['Size'];
  71              $pointer += 36;
  72          }
  73  
  74          /* Recursivly check subfolders. */
  75          $d = dir($path);
  76          while (($entry = $d->read()) !== false) {
  77              if (($entry != '.') &&
  78                  ($entry != '..') &&
  79                  (substr($entry, -5, 5) == '.IMAP')) {
  80                  $size += $this->_mailboxSize($path . $entry . '\\');
  81              }
  82          }
  83          $d->close();
  84  
  85          return $size;
  86      }
  87  
  88      /**
  89       * Retrieve relevant line from userlist.dat.
  90       *
  91       * @param string $user   The username for which to retrieve detals.
  92       * @param string $realm  The realm (domain) for the user.
  93       *
  94       * @return mixed  Line from userlist.dat (string) or false (boolean).
  95       */
  96      function _getUserDetails($user, $realm)
  97      {
  98          $searchString = str_pad($realm, 45) . str_pad($user, 30);
  99  
 100          if (!($fp = fopen($this->_params['app_location'] . '/userlist.dat', 'rb'))) {
 101              return false;
 102          }
 103  
 104          while (!feof($fp)) {
 105              $line = fgets($fp, 4096);
 106              if (substr($line, 0, strlen($searchString)) == $searchString) {
 107                  fclose($fp);
 108                  return $line;
 109              }
 110          }
 111          fclose($fp);
 112  
 113          return false;
 114      }
 115  
 116  }


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