1<?php
2/**
3 * Copyright 2013-2017 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 2013-2017 Horde LLC
10 * @license   http://www.horde.org/licenses/gpl GPL
11 * @package   IMP
12 */
13
14/**
15 * Extends base Indices object by incorporating base mailbox information.
16 *
17 * @author    Michael Slusarz <slusarz@horde.org>
18 * @category  Horde
19 * @copyright 2013-2017 Horde LLC
20 * @license   http://www.horde.org/licenses/gpl GPL
21 * @package   IMP
22 */
23class IMP_Indices_Mailbox extends IMP_Indices
24{
25    /**
26     * The BUIDs list.
27     *
28     * @var IMP_Indices
29     */
30    public $buids;
31
32    /**
33     * Base mailbox name.
34     *
35     * @var IMP_Mailbox
36     */
37    public $mailbox;
38
39    /**
40     * Constructor.
41     *
42     * @param mixed  Two possible inputs:
43     *   - 1 argument: Horde_Variables object. These GET/POST parameters are
44     *     reserved in IMP:
45     *     - buid: (string) BUID [Browser UID].
46     *     - mailbox: (string) Base64url encoded mailbox.
47     *     - muid: (string) MUID [Mailbox + UID].
48     *     - uid: (string) UID [Actual mail UID].
49     *   - 2 arguments: IMP_Mailbox object, IMP_Indices argument
50     */
51    public function __construct()
52    {
53        $args = func_get_args();
54
55        switch (func_num_args()) {
56        case 1:
57            if ($args[0] instanceof Horde_Variables) {
58                if (isset($args[0]->mailbox) && strlen($args[0]->mailbox)) {
59                    $this->mailbox = IMP_Mailbox::formFrom($args[0]->mailbox);
60
61                    if (isset($args[0]->buid)) {
62                        /* BUIDs are always integers. Do conversion here since
63                         * POP3 won't work otherwise. */
64                        $tmp = new Horde_Imap_Client_Ids($args[0]->buid);
65                        $this->buids = new IMP_Indices($this->mailbox, $tmp->ids);
66                        parent::__construct($this->mailbox->fromBuids($this->buids));
67                    } elseif (isset($args[0]->uid)) {
68                        parent::__construct($this->mailbox, $args[0]->uid);
69                    }
70                }
71
72                if (isset($args[0]->muid)) {
73                    parent::__construct($args[0]->muid);
74                }
75            }
76            break;
77
78        case 2:
79            if (($args[0] instanceof IMP_Mailbox) &&
80                ($args[1] instanceof IMP_Indices)) {
81                $this->mailbox = $args[0];
82                $this->buids = $args[0]->toBuids($args[1]);
83                parent::__construct($args[1]);
84            }
85            break;
86        }
87
88        if (!isset($this->buids)) {
89            $this->buids = new IMP_Indices($this->_indices);
90        }
91
92        if (!isset($this->mailbox)) {
93            $this->mailbox = IMP_Mailbox::get('INBOX');
94        }
95    }
96
97}
98