source: subversion/branches/devel-vnext/plugins/macbay_pop3/lib/macbay_pop3.class.php @ 699

Last change on this file since 699 was 699, checked in by till, 6 years ago

# bugfixes
+ debugging

File size: 3.8 KB
Line 
1<?php
2/**
3 * macbay_filter
4 *
5 * @final
6 * @author Till Klampaeckel <till@php.net>
7 * @uses   Zend_XmlRpc_Client
8 */
9final class macbay_pop3
10{
11    protected $client;
12    protected $params;
13
14    /**
15     * __construct
16     *
17     * @access public
18     * @param  Zend_XmlRpc_Client $rpc_client
19     * @param  array $params
20     */
21    public function __construct(Zend_XmlRpc_Client $rpc_client, $params)
22    {
23        $this->client = $rpc_client;
24        $this->params = $params;
25    }
26
27    /**
28     * getRpop
29     *
30     * Queries the XMLRPC service for the user's RPOP accounts. Returns an array
31     * with index rpop (the accounts), and maxRpop - the maximum number of RPOPs
32     * this user is allowed to have (CGPro configuration item).
33     *
34     * Also translates the numerical entries from the response to an associative
35     * array for easier handling in the template.
36     *
37     * @access public
38     * @return array
39     * @uses   macbay_pop3::$client
40     * @uses   macbay_pop3::$params
41     * @uses   macbay_pop3::handleError()
42     */
43    public function getRpop()
44    {
45        try {
46            $data = $this->client->call('cli.getRpop', $this->params);
47            if (empty($data['rpop']) || !is_array($data['rpop'])) {
48                $data['rpop'] = array();
49                return $data;
50            }
51            $keep = array();
52            foreach($data['rpop'] AS $rpop_id=>$rpop_data) {
53                $keep[$rpop_id] = array(
54                        'servername' => $rpop_data[2],
55                        'username'   => $rpop_data[3],
56                        'password'   => $rpop_data[4],
57                        'interval'   => (intval($rpop_data[5])/60),
58                        'leave'      => (($rpop_data[6] == 'Leave')?1:0),
59                        'status'     => $rpop_data[9]
60                );
61            }
62            $data['rpop'] = $keep;
63            return $data;
64        }
65        catch (Exception $e) {
66            // var_dump($e);
67            return self::handleError($e);
68        }
69    }
70
71    /**
72     * saveRpop
73     *
74     * Adds an RPOP account, or saves changes to an existing one. The difference
75     * is key=id in rpop array.
76     *
77     * Saving is not yet implemented, we only add.
78     *
79     * @param  array $rpop
80     * @return mixed
81     * @uses   macbay_pop3::handleError()
82     */
83    public function saveRpop($rpop)
84    {
85        if (!is_array($rpop)) {
86            return false;
87        }
88        try {
89            $params = $this->params;
90            array_push($params, $rpop);
91            $status = $this->client->call('cli.saveRpop', $params);
92            return $status;
93        }
94        catch(Exception $e) {
95            return self::handleError($e);
96        }
97    }
98
99    /**
100     * deleteRpop
101     *
102     * Deletes an RPOP account based on the internal ID-hash (non CGPro).
103     *
104     * @param  string $id
105     * @return boolean
106     * @uses   macbay_pop3::$client
107     * @uses   macbay_pop3::$params
108     * @uses   macbay_pop3::handleError()
109     */
110    public function deleteRpop($id)
111    {
112        try {
113            $params = $this->params;
114            array_push($params, $id);
115            return $this->client->call('cli.deleteRpop', $params);
116        }
117        catch (Exception $e) {
118            return self::handleError($e);
119        }
120    }
121
122    /**
123     * handleError
124     *
125     * Bridges the exception to RC's build in error handler.
126     *
127     * @access static
128     * @param  Exception $e
129     * @param  int $line
130     * @uses   rc_bugs::raise_error()
131     * @return void
132     */
133    static function handleError($e, $line)
134    {
135        rc_bugs::raise_error(
136            array(
137                'code' => $e->getCode(),
138                'type' => 'xmlrpc',
139                'message' => $e->getMessage(),
140                'file'    => __FILE__,
141                'line'    => $line
142            ),
143            TRUE
144        );
145        return false;
146    }
147}
Note: See TracBrowser for help on using the repository browser.