1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * EGroupWare - EMailAdmin * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * Written by : Lars Kneschke [lkneschke@linux-at-work.de] * |
---|
6 | * ------------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \***************************************************************************/ |
---|
12 | |
---|
13 | include_once(PHPGW_SERVER_ROOT."/emailadmin/inc/class.defaultimap.inc.php"); |
---|
14 | |
---|
15 | class cyrusimap extends defaultimap |
---|
16 | { |
---|
17 | #function cyrusimap() |
---|
18 | #{ |
---|
19 | #} |
---|
20 | |
---|
21 | function addAccount($_hookValues) |
---|
22 | { |
---|
23 | #_debug_array($_hookValues); |
---|
24 | $username = $_hookValues['account_lid']; |
---|
25 | $userPassword = $_hookValues['new_passwd']; |
---|
26 | |
---|
27 | #_debug_array($this->profileData); |
---|
28 | $imapAdminUsername = $this->profileData['imapAdminUsername']; |
---|
29 | $imapAdminPW = $this->profileData['imapAdminPW']; |
---|
30 | |
---|
31 | $folderNames = array( |
---|
32 | "user.$username", |
---|
33 | "user.$username.Trash", |
---|
34 | "user.$username.Sent" |
---|
35 | ); |
---|
36 | |
---|
37 | // create the mailbox |
---|
38 | if($mbox = @imap_open ($this->getMailboxString(), $imapAdminUsername, $imapAdminPW)) |
---|
39 | { |
---|
40 | // create the users folders |
---|
41 | foreach($folderNames as $mailBoxName) |
---|
42 | { |
---|
43 | if(imap_createmailbox($mbox,imap_utf7_encode("{".$this->profileData['imapServer']."}$mailBoxName"))) |
---|
44 | { |
---|
45 | if(!imap_setacl($mbox, $mailBoxName, $username, "lrswipcd")) |
---|
46 | { |
---|
47 | # log error message |
---|
48 | } |
---|
49 | } |
---|
50 | } |
---|
51 | imap_close($mbox); |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | _debug_array(imap_errors()); |
---|
56 | return false; |
---|
57 | } |
---|
58 | |
---|
59 | // subscribe to the folders |
---|
60 | if($mbox = @imap_open($this->getMailboxString(), $username, $userPassword)) |
---|
61 | { |
---|
62 | imap_subscribe($mbox,$this->getMailboxString('INBOX')); |
---|
63 | imap_subscribe($mbox,$this->getMailboxString('INBOX.Sent')); |
---|
64 | imap_subscribe($mbox,$this->getMailboxString('INBOX.Trash')); |
---|
65 | imap_close($mbox); |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | # log error message |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | function deleteAccount($_hookValues) |
---|
74 | { |
---|
75 | $username = $_hookValues['account_lid']; |
---|
76 | |
---|
77 | $imapAdminUsername = $this->profileData['imapAdminUsername']; |
---|
78 | $imapAdminPW = $this->profileData['imapAdminPW']; |
---|
79 | |
---|
80 | if($mbox = @imap_open($this->getMailboxString(), $imapAdminUsername, $imapAdminPW)) |
---|
81 | { |
---|
82 | $mailBoxName = "user.$username"; |
---|
83 | // give the admin account the rights to delete this mailbox |
---|
84 | if(imap_setacl($mbox, $mailBoxName, $imapAdminUsername, "lrswipcda")) |
---|
85 | { |
---|
86 | if(imap_deletemailbox($mbox, |
---|
87 | imap_utf7_encode("{".$this->profileData['imapServer']."}$mailBoxName"))) |
---|
88 | { |
---|
89 | return true; |
---|
90 | } |
---|
91 | else |
---|
92 | { |
---|
93 | // not able to delete mailbox |
---|
94 | return false; |
---|
95 | } |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | // not able to set acl |
---|
100 | return false; |
---|
101 | } |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | // imap open failed |
---|
106 | return false; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | function updateAccount($_hookValues) |
---|
111 | { |
---|
112 | #_debug_array($_hookValues); |
---|
113 | $username = $_hookValues['account_lid']; |
---|
114 | if(isset($_hookValues['new_passwd'])) |
---|
115 | $userPassword = $_hookValues['new_passwd']; |
---|
116 | |
---|
117 | #_debug_array($this->profileData); |
---|
118 | $imapAdminUsername = $this->profileData['imapAdminUsername']; |
---|
119 | $imapAdminPW = $this->profileData['imapAdminPW']; |
---|
120 | |
---|
121 | $folderNames = array( |
---|
122 | "user.$username", |
---|
123 | "user.$username.Trash", |
---|
124 | "user.$username.Sent" |
---|
125 | ); |
---|
126 | |
---|
127 | // create the mailbox |
---|
128 | if($mbox = @imap_open ($this->getMailboxString(), $imapAdminUsername, $imapAdminPW)) |
---|
129 | { |
---|
130 | // create the users folders |
---|
131 | foreach($folderNames as $mailBoxName) |
---|
132 | { |
---|
133 | if(imap_createmailbox($mbox,imap_utf7_encode("{".$this->profileData['imapServer']."}$mailBoxName"))) |
---|
134 | { |
---|
135 | if(!imap_setacl($mbox, $mailBoxName, $username, "lrswipcd")) |
---|
136 | { |
---|
137 | # log error message |
---|
138 | } |
---|
139 | } |
---|
140 | } |
---|
141 | imap_close($mbox); |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | return false; |
---|
146 | } |
---|
147 | |
---|
148 | // we can only subscribe to the folders, if we have the users password |
---|
149 | if(isset($_hookValues['new_passwd'])) |
---|
150 | { |
---|
151 | if($mbox = @imap_open($this->getMailboxString(), $username, $userPassword)) |
---|
152 | { |
---|
153 | imap_subscribe($mbox,$this->getMailboxString('INBOX')); |
---|
154 | imap_subscribe($mbox,$this->getMailboxString('INBOX.Sent')); |
---|
155 | imap_subscribe($mbox,$this->getMailboxString('INBOX.Trash')); |
---|
156 | imap_close($mbox); |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | # log error message |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | ?> |
---|