Overview

Packages

  • None
  • Vilma

Classes

  • Vilma
  • Vilma_Api
  • Vilma_Driver
  • Vilma_Driver_Qmailldap
  • Vilma_Driver_Sql
  • Vilma_Form_DeleteDomain
  • Vilma_Form_EditAlias
  • Vilma_Form_EditDomain
  • Vilma_Form_EditForward
  • Vilma_Form_EditUser
  • Vilma_MailboxDriver
  • Vilma_MailboxDriver_Hooks
  • Vilma_MailboxDriver_Imap
  • Vilma_MailboxDriver_Maildrop
  • Vilma_MailboxDriver_Null
  • Vilma_Test
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
 4:  *
 5:  * See the enclosed file LICENSE for license information (BSD). If you did not
 6:  * did not receive this file, see http://cvs.horde.org/co.php/vilma/LICENSE.
 7:  *
 8:  * @author  Jason M. Felice <jason.m.felice@gmail.com>
 9:  * @author  Jan Schneider <jan@horde.org>
10:  * @package Vilma
11:  */
12: class Vilma_MailboxDriver_Imap extends Vilma_MailboxDriver
13: {
14:     /**
15:      * An IMAP client.
16:      *
17:      * @var Horde_Imap_Client_Base
18:      */
19:     protected $_imap;
20: 
21:     /**
22:      * Constructor.
23:      *
24:      * @param array $params  Any parameters needed for this driver.
25:      */
26:     public function __construct(array $params = array())
27:     {
28:         parent::__construct($params);
29:         $params = array('username' => $this->_params['admin_user'],
30:                         'password' => $this->_params['admin_password'],
31:                         'hostspec' => $this->_params['hostspec'],
32:                         'port'     => $this->_params['port']);
33:         $this->_imap = Horde_Imap_Client::factory('Socket', $params);
34:     }
35: 
36:     /**
37:      * Creates a new mailbox.
38:      *
39:      * @param string $user    The name of the mailbox to create.
40:      * @param string $domain  The name of the domain in which to create the
41:      *                        mailbox.
42:      *
43:      * @throws Vilma_Exception
44:      */
45:     public function createMailbox($user, $domain)
46:     {
47:         try {
48:             $this->_imap->createMailbox($this->_params['userhierarchy'] . $user . '@' . $domain);
49:         } catch (Exception $e) {
50:             throw new Vilma_Exception($e);
51:         }
52:     }
53: 
54:     /**
55:      * Deletes an existing mailbox.
56:      *
57:      * @todo
58:      *
59:      * @param string $user    The name of the mailbox to delete.
60:      * @param string $domain  The name of the domain in which to delete the
61:      *                        mailbox.
62:      *
63:      * @throws Vilma_Exception
64:      */
65:     public function deleteMailbox($user, $domain)
66:     {
67:         try {
68:             $this->_imap->deleteMailbox($this->_params['userhierarchy'] . $user . '@' . $domain);
69:         } catch (Exception $e) {
70:             throw new Vilma_Exception($e);
71:         }
72:     }
73: 
74:     /**
75:      * Checks whether a mailbox exists and is set up properly.
76:      *
77:      * @param string $user    The name of the mailbox to check.
78:      * @param string $domain  The mailbox' domain.
79:      *
80:      * @return boolean  True if the mailbox exists.
81:      * @throws Vilma_Exception if the mailbox doesn't exist.
82:      */
83:     public function checkMailbox($user, $domain)
84:     {
85:         if (!$this->_imap->listMailboxes($this->_params['userhierarchy'] . $user . '@' . $domain)) {
86:             throw new Vilma_Exception(sprintf(_("Mailbox \"%s\" does not exist."), $user . '@' . $domain));
87:         }
88:         return true;
89:     }
90: }
91: 
API documentation generated by ApiGen