155275d3f1f60e84c37bc2edc5c3c1ef4ce808d7
2 /***************************************************************************
3 * Copyright (C) 2003-2013 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ class MailingList
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
31 public function __construct($mbox, $domain, $user=null
)
34 $this->domain
= $domain;
35 $this->address
= "$mbox@$domain";
40 $this->mmclient
= new MMList($user, $this->domain
);
43 /** Instantiate a MailingList from its address.
45 public static function fromAddress($address, $user=null
)
47 if (strstr($address, '@') !== false
) {
48 list($mbox, $domain) = explode('@', $address);
52 $domain = $globals->mail
->domain
;
54 return new MailingList($mbox, $domain, $user);
57 /** Retrieve the MailingList associated with a given promo.
59 public static function promo($promo, $user=null
)
62 $mail_domain = $globals->mail
->domain
;
63 return new MailingList('promo', "$promo.$mail_domain", $user);
66 const KIND_BOUNCE
= 'bounces';
67 const KIND_OWNER
= 'owner';
68 public function getAddress($kind)
70 return $this->mbox
. '-' . $kind . '@' . $this->domain
;
73 /** Subscribe the current user to the list
75 public function subscribe()
77 return $this->mmclient
->subscribe($this->mbox
);
80 public static function subscribeTo($mbox, $domain, $user=null
)
82 $mlist = new MailingList($mbox, $domain, $user);
83 return $mlist->subscribe();
86 public static function subscribePromo($promo, $user=null
)
88 $mlist = MailingList
::promo($promo, $user);
89 return $mlist->subscribe();
92 /** Subscribe a batch of users to the list
94 public function subscribeBulk($members)
96 return $this->mmclient
->mass_subscribe($this->mbox
, $members);
99 /** Unsubscribe the current user from the list
101 public function unsubscribe()
103 return $this->mmclient
->unsubscribe($this->mbox
);
106 /** Unsubscribe a batch of users from the list
108 public function unsubscribeBulk($members)
110 return $this->mmclient
->mass_unsubscribe($this->mbox
, $members);
113 /** Retrieve owners for the list.
115 * TODO: document the return type
117 public function getOwners()
119 return $this->mmclient
->get_owners($this->mbox
);
122 /** Add an owner to the list
124 public function addOwner($email)
126 return $this->mmclient
->add_owner($this->mbox
, $email);
129 /** Remove an owner from the list
131 public function removeOwner($email)
133 return $this->mmclient
->del_owner($this->mbox
, $email);
136 /** Retrieve members of the list.
138 * TODO: document the return type
140 public function getMembers()
142 return $this->mmclient
->get_members($this->mbox
);
145 /** Retrieve a subset of list members.
147 * TODO: document the return type
149 public function getMembersLimit($page, $number_per_page)
151 return $this->mmclient
->get_members_limit($this->mbox
, $page, $number_per_page);
154 /** Fetch pending list operations.
156 * TODO: document the return type
158 public function getPendingOps()
160 return $this->mmclient
->get_pending_ops($this->mbox
);
163 const REQ_ACCEPT
= 1;
164 const REQ_REJECT
= 2;
165 const REQ_DISCARD
= 3;
166 const REQ_SUBSCRIBE
= 4;
168 /** Handle a mailing list request
170 public function handleRequest($kind, $value, $comment='')
172 return $this->mmclient
->handle_request($this->mbox
, $value, $kind,
173 utf8_decode($comment));
176 /** Retrieve the current status of a pending subscription request
178 public function getPendingSubscription($email)
180 return $this->mmclient
->get_pending_sub($this->mbox
, $email);
183 /** Retrieve pending mails
185 public function getPendingMail($mid)
187 return $this->mmclient
->get_pending_mail($this->mbox
, $mid);
192 public static function create($mbox, $domain, $user, $description,
193 $advertise, $moderation_level, $subscription_level,
196 $mlist = new MailingList($mbox, $domain, $user);
197 return $mlist->mmclient
->create_list($mlist->mbox
, utf8_decode($description),
198 $advertise, $moderation_level, $subscription_level,
204 public function delete($remove_archives=false
)
206 return $this->mmclient
->delete_list($this->mbox
, $remove_archives);
209 /** Set antispam level.
211 public function setBogoLevel($level)
213 return $this->mmclient
->set_bogo_level($this->mbox
, $level);
216 /** Get antispam level.
220 public function getBogoLevel()
222 $bogo = $this->mmclient
->get_bogo_level($this->mbox
);
226 /** Set public options.
228 * @param $options array
230 public function setOwnerOptions($options)
232 return $this->mmclient
->set_owner_options($this->mbox
, $options);
235 /** Retrieve owner options
239 public function getOwnerOptions()
241 return $this->mmclient
->get_owner_options($this->mbox
);
244 /** Set admin options.
246 * @param $options array
248 public function setAdminOptions($options)
250 return $this->mmclient
->set_admin_options($this->mbox
, $options);
253 /** Retrieve admin options
257 public function getAdminOptions()
259 return $this->mmclient
->get_admin_options($this->mbox
);
262 /** Check options, optionnally fixing them.
264 public function checkOptions($fix=false
)
266 return $this->mmclient
->check_options($this->mbox
, $fix);
269 /** Add an email to the list of whitelisted senders
271 public function whitelistAdd($email)
273 return $this->mmclient
->add_to_wl($this->mbox
, $email);
276 /** Remove an email from the list of whitelisted senders
278 public function whitelistRemove($email)
280 return $this->mmclient
->del_from_wl($this->mbox
, $email);
286 // vim:set et sw=4 sts=4 sws=4 enc=utf-8: