[imp] display mailbox size and total

LOUVOIS Prebagarane louvois at linguist.jussieu.fr
Mon Apr 5 03:29:15 PDT 2004


Hello,

If you want to display wu-imap user's mailbox folders size and their total, 
i 've writted and tested a small script successfully without using the 
"imp_show_quota".

My configuration:
( horde 2.2.5, imp 3.2.3 )

what do you have to do ?

1) add the "bab.php" in horde/imp/bab.php

---------------------------- file bab.php starting 
----------------------------------
<?php
/*
  * $Horde: imp/prefs.php,v 2.146.2.23 2003/04/14 16:28:45 chuck Exp $
  *
  * Copyright 1999-2003 Charles J. Hagenbuch <chuck at horde.org>
  * Copyright 1999-2003 Jon Parise <jon at horde.org>
  *
  * See the enclosed file COPYING for license information (GPL).  If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  */


/* I used prefs.php file as an example for headers and footers.
   script will display users mailbox folder's size.
   some parts of the scripts come from www.php.net
   I am sure there are lot of thing to change or to remove !!
   --- louvois at linguist.jussieu.fr --- */


define('IMP_BASE', dirname(__FILE__));
require_once IMP_BASE . '/lib/base.php';
require IMP_BASE . '/config/servers.php';
require IMP_BASE . '/config/prefs.php';


IMP::checkAuthentication(OP_HALFOPEN);

/* See if we have a preferences group set. */
$group = Horde::getFormData('group');

$title = _("User Options");
$js_onLoad = null;
require IMP_TEMPLATES . '/common-header.inc';
require IMP_BASE . '/menu.php';
require IMP_BASE . '/status.php';


function display_size($valeur)
{
$temp = 0;
if($valeur >= 1048576)
         {
         $temp = round($valeur/1048576,2);
         $temp = $temp . " MEGA BYTES";
         }
elseif ( $valeur >= 1024)
         {
         $temp = round($valeur/1024,2);
         $temp = $temp . " KILO BYTES";
         }
else
         {
         $temp = $valeur;
         $temp = $temp . " BYTES";
         }
$retour = "<td><font color=yellow >".$temp."</font></td>";

return $retour ;
}
//fin function display_size


function display_folders_size()
{
global $imp, $prefs, $conf;
$list = imap_getmailboxes($imp['stream'], "{mailhost.linguist.jussieu.fr}", 
"%");
$TOTAL = 0.0 ;
echo "<table border=0>";
if (is_array($list))
  {
    reset($list);
    while (list($key, $val) = each($list))
         {
         echo "<tr><td>";
         $inter1 = imap_utf7_decode($val->name);
         echo "<font color=yellow >$inter1</font>";
         echo "</td>";
         $stream = @imap_open($val->name, $imp['user'], 
Secret::read(Secret::getKey('imp'), $imp['pass']));
         $get_info = imap_mailboxmsginfo($stream);
         $mailbox_size = $get_info->Size;
         $TOTAL = $TOTAL +  $get_info->Size;

         $affiche_boite = display_size($mailbox_size);
         echo " $affiche_boite ";

         } //while

         $affiche_total = display_size($TOTAL);
         echo "<tr><td><font color=white size=+1>TOTAL</font></td>" . 
$affiche_total . "</tr>";
         echo "</table>";
  } else
  {
   echo "imap_getmailboxes failed: " . imap_last_error() . "\n";
   }
}
// fin function


display_folders_size();

// BAB

$registry->shutdown();
require IMP_TEMPLATES . '/common-footer.inc';

imap_errors();

// BAB
-----------------------------------  End of file "bab.php" 
-------------------------------------------------------



2) add this part  at the end of the file horde/imp/conf/menu.php

------- BEGINNING -------------------------------
$_menu = array();
/* Add your custom entries below this line. */
$_menu[] = array(
        'url' =>        '/imp/bab.php',
        'text' =>       'Taille de vos dossiers',
         'icon' =>       'folders.gif',
         'icon_path' =>  '/imp/graphics/',
        'onclick' =>    ''
    );
------- ENDING -------------------------------


THAT IS ALL





-- 
Cordialement,

LOUVOIS Prébagarane
Ingénieur Systèmes
UFR Linguistique
Université Paris-VII
louvois at linguist.jussieu.fr




More information about the imp mailing list