1: <?php
2: /**
3: * Copyright 2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Determine the size of a mailbox.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Mbox_Size
24: {
25: /**
26: * Obtain the mailbox size
27: *
28: * @param IMP_Mailbox $mbox The mailbox to obtain the size of.
29: * @param boolean $formatted Whether to return a human readable value.
30: *
31: * @return mixed Either the size of the mailbox (in bytes) or a formatted
32: * string with this information.
33: */
34: public function getSize(IMP_Mailbox $mbox, $formatted = true)
35: {
36: $query = new Horde_Imap_Client_Fetch_Query();
37: $query->size();
38:
39: try {
40: $imp_imap = $mbox->imp_imap;
41: $res = $imp_imap->fetch($mbox, $query, array(
42: 'ids' => $imp_imap->getIdsOb(Horde_Imap_Client_Ids::ALL, true)
43: ));
44:
45: $size = 0;
46: foreach ($res as $v) {
47: $size += $v->getSize();
48: }
49:
50: return $formatted
51: ? sprintf(_("%.2fMB"), $size / (1024 * 1024))
52: : $size;
53: } catch (IMP_Imap_Exception $e) {
54: return 0;
55: }
56: }
57:
58: }
59: