Commit | Line | Data |
---|---|---|
a2f69042 RB |
1 | <?php |
2 | /*************************************************************************** | |
3 | * Copyright (C) 2003-2011 Polytechnique.org * | |
4 | * http://opensource.polytechnique.org/ * | |
5 | * * | |
6 | * This program is free software; you can redistribute it and/or modify * | |
7 | * it under the terms of the GNU General Public License as published by * | |
8 | * the Free Software Foundation; either version 2 of the License, or * | |
9 | * (at your option) any later version. * | |
10 | * * | |
11 | * This program is distributed in the hope that it will be useful, * | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 | * GNU General Public License for more details. * | |
15 | * * | |
16 | * You should have received a copy of the GNU General Public License * | |
17 | * along with this program; if not, write to the Free Software * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | // {{{ class MailingList | |
23 | ||
24 | class MailingList | |
25 | { | |
26 | public $address; // Fully qualified address of the list | |
27 | public $mbox; // mailbox for the list | |
28 | public $domain; // domain for the list | |
29 | protected $mmclient; // The XML-RPC client for Mailman requests | |
30 | ||
22c5024f | 31 | public function __construct($mbox, $domain, $user=null) |
a2f69042 RB |
32 | { |
33 | $this->mbox = $mbox; | |
34 | $this->domain = $domain; | |
35 | $this->address = "$mbox@$domain"; | |
36 | ||
22c5024f RB |
37 | if (is_null($user)) { |
38 | $user = S::user(); | |
a2f69042 | 39 | } |
22c5024f | 40 | $this->mmclient = new MMList($user, $this->domain); |
a2f69042 RB |
41 | } |
42 | ||
43 | /** Instantiate a MailingList from its address. | |
a2f69042 | 44 | */ |
22c5024f | 45 | public static function fromAddress($address, $user=null) |
a2f69042 RB |
46 | { |
47 | if (strstr($address, '@') !== false) { | |
48 | list($mbox, $domain) = explode('@', $address); | |
49 | } else { | |
50 | global $globals; | |
51 | $mbox = $address; | |
52 | $domain = $globals->mail->domain; | |
53 | } | |
22c5024f | 54 | return new MailingList($mbox, $domain, $user); |
a2f69042 RB |
55 | } |
56 | ||
57 | /** Retrieve the MailingList associated with a given promo. | |
a2f69042 | 58 | */ |
22c5024f | 59 | public static function promo($promo, $user=null) |
a2f69042 RB |
60 | { |
61 | global $globals; | |
62 | $mail_domain = $globals->mail->domain; | |
22c5024f | 63 | return new MailingList('promo', "$promo.$mail_domain", $user); |
a2f69042 RB |
64 | } |
65 | ||
be516d18 RB |
66 | const KIND_BOUNCE = 'bounces'; |
67 | const KIND_OWNER = 'owner'; | |
68 | public function getAddress($kind) | |
69 | { | |
70 | return $this->mbox . '-' . $kind . '@' . $this->domain; | |
71 | } | |
72 | ||
a2f69042 RB |
73 | /** Subscribe the current user to the list |
74 | */ | |
75 | public function subscribe() | |
76 | { | |
77 | return $this->mmclient->subscribe($this->mbox); | |
78 | } | |
79 | ||
be516d18 RB |
80 | /** Subscribe a batch of users to the list |
81 | */ | |
82 | public function subscribeBulk($members) | |
83 | { | |
84 | return $this->mmclient->mass_subscribe($this->mbox, $members); | |
85 | } | |
86 | ||
a2f69042 RB |
87 | /** Unsubscribe the current user from the list |
88 | */ | |
89 | public function unsubscribe() | |
90 | { | |
91 | return $this->mmclient->unsubscribe($this->mbox); | |
92 | } | |
93 | ||
be516d18 RB |
94 | /** Unsubscribe a batch of users from the list |
95 | */ | |
96 | public function unsubscribeBulk($members) | |
97 | { | |
98 | return $this->mmclient->mass_unsubscribe($this->mbox, $members); | |
99 | } | |
100 | ||
a2f69042 RB |
101 | /** Retrieve owners for the list. |
102 | * | |
103 | * TODO: document the return type | |
104 | */ | |
105 | public function getOwners() | |
106 | { | |
107 | return $this->mmclient->get_owners($this->mbox); | |
108 | } | |
109 | ||
be516d18 RB |
110 | /** Add an owner to the list |
111 | */ | |
112 | public function addOwner($email) | |
113 | { | |
114 | return $this->mmclient->add_owner($this->mbox, $email); | |
115 | } | |
116 | ||
117 | /** Remove an owner from the list | |
118 | */ | |
119 | public function removeOwner($email) | |
120 | { | |
121 | return $this->mmclient->del_owner($this->mbox, $email); | |
122 | } | |
123 | ||
a2f69042 RB |
124 | /** Retrieve members of the list. |
125 | * | |
126 | * TODO: document the return type | |
127 | */ | |
128 | public function getMembers() | |
129 | { | |
130 | return $this->mmclient->get_members($this->mbox); | |
131 | } | |
132 | ||
133 | /** Retrieve a subset of list members. | |
134 | * | |
135 | * TODO: document the return type | |
136 | */ | |
137 | public function getMembersLimit($page, $number_per_page) | |
138 | { | |
139 | return $this->mmclient->get_members_limit($this->mbox, $page, $number_per_page); | |
140 | } | |
141 | ||
be516d18 RB |
142 | /** Fetch pending list operations. |
143 | * | |
144 | * TODO: document the return type | |
145 | */ | |
146 | public function getPendingOps() | |
147 | { | |
148 | return $this->mmclient->get_pending_ops($this->mbox); | |
149 | } | |
150 | ||
7a708a96 | 151 | const REQ_ACCEPT = 1; |
be516d18 | 152 | const REQ_REJECT = 2; |
7a708a96 | 153 | const REQ_DISCARD = 3; |
be516d18 RB |
154 | const REQ_SUBSCRIBE = 4; |
155 | ||
156 | /** Handle a mailing list request | |
157 | */ | |
158 | public function handleRequest($kind, $value, $comment='') | |
159 | { | |
160 | return $this->mmclient->handle_request($this->mbox, $value, $kind, | |
161 | utf8_decode($comment)); | |
162 | } | |
163 | ||
164 | /** Retrieve the current status of a pending subscription request | |
165 | */ | |
166 | public function getPendingSubscription($email) | |
167 | { | |
168 | return $this->mmclient->get_pending_sub($this->mbox, $email); | |
169 | } | |
170 | ||
7a708a96 RB |
171 | /** Retrieve pending mails |
172 | */ | |
173 | public function getPendingMail($mid) | |
174 | { | |
175 | return $this->mmclient->get_pending_mail($this->mbox, $mid); | |
176 | } | |
177 | ||
a2f69042 RB |
178 | /** Create a list |
179 | */ | |
180 | public function create($description, $advertise, | |
181 | $moderation_level, $subscription_level, $owners, $members) | |
182 | { | |
183 | return $this->mmclient->create_list($this->mbox, utf8_decode($description), | |
184 | $advertise, $moderation_level, $subscription_level, | |
185 | $owners, $members); | |
186 | } | |
be516d18 RB |
187 | |
188 | /** Delete a list | |
189 | */ | |
190 | public function delete($remove_archives=false) | |
191 | { | |
192 | return $this->mmclient->delete_list($this->mbox, $remove_archives); | |
193 | } | |
194 | ||
195 | /** Set antispam level. | |
196 | */ | |
197 | public function setBogoLevel($level) | |
198 | { | |
199 | return $this->mmclient->set_bogo_level($this->mbox); | |
200 | } | |
201 | ||
202 | /** Get antispam level. | |
203 | * | |
204 | * @return int | |
205 | */ | |
206 | public function getBogoLevel() | |
207 | { | |
208 | $bogo = $this->mmclient->get_bogo_level($this->mbox); | |
209 | return $bogo; | |
210 | } | |
211 | ||
212 | /** Set public options. | |
213 | * | |
214 | * @param $options array | |
215 | */ | |
216 | public function setOwnerOptions($options) | |
217 | { | |
218 | return $this->mmclient->set_owner_options($this->mbox, $options); | |
219 | } | |
220 | ||
221 | /** Retrieve owner options | |
222 | * | |
223 | * @return array | |
224 | */ | |
225 | public function getOwnerOptions() | |
226 | { | |
227 | return $this->mmclient->get_owner_options($this->mbox); | |
228 | } | |
229 | ||
230 | /** Set admin options. | |
231 | * | |
232 | * @param $options array | |
233 | */ | |
234 | public function setAdminOptions($options) | |
235 | { | |
236 | return $this->mmclient->set_admin_options($this->mbox, $options); | |
237 | } | |
238 | ||
239 | /** Retrieve admin options | |
240 | * | |
241 | * @return array | |
242 | */ | |
243 | public function getAdminOptions() | |
244 | { | |
245 | return $this->mmclient->get_admin_options($this->mbox); | |
246 | } | |
247 | ||
248 | /** Check options, optionnally fixing them. | |
249 | */ | |
250 | public function checkOptions($fix=false) | |
251 | { | |
252 | return $this->mmclient->check_options($this->mbox, $fix); | |
253 | } | |
254 | ||
255 | /** Add an email to the list of whitelisted senders | |
256 | */ | |
257 | public function whitelistAdd($email) | |
258 | { | |
259 | return $this->mmclient->add_to_wl($this->mbox, $email); | |
260 | } | |
261 | ||
262 | /** Remove an email from the list of whitelisted senders | |
263 | */ | |
264 | public function whitelistRemove($email) | |
265 | { | |
266 | return $this->mmclient->del_from_wl($this->mbox, $email); | |
267 | } | |
a2f69042 RB |
268 | } |
269 | ||
270 | // }}} | |
271 | ||
272 | // vim:set et sw=4 sts=4 sws=4 enc=utf-8: | |
273 | ?> |