2 /***************************************************************************
3 * Copyright (C) 2003-2011 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 /** Subscribe a batch of users to the list
82 public function subscribeBulk($members)
84 return $this->mmclient
->mass_subscribe($this->mbox
, $members);
87 /** Unsubscribe the current user from the list
89 public function unsubscribe()
91 return $this->mmclient
->unsubscribe($this->mbox
);
94 /** Unsubscribe a batch of users from the list
96 public function unsubscribeBulk($members)
98 return $this->mmclient
->mass_unsubscribe($this->mbox
, $members);
101 /** Retrieve owners for the list.
103 * TODO: document the return type
105 public function getOwners()
107 return $this->mmclient
->get_owners($this->mbox
);
110 /** Add an owner to the list
112 public function addOwner($email)
114 return $this->mmclient
->add_owner($this->mbox
, $email);
117 /** Remove an owner from the list
119 public function removeOwner($email)
121 return $this->mmclient
->del_owner($this->mbox
, $email);
124 /** Retrieve members of the list.
126 * TODO: document the return type
128 public function getMembers()
130 return $this->mmclient
->get_members($this->mbox
);
133 /** Retrieve a subset of list members.
135 * TODO: document the return type
137 public function getMembersLimit($page, $number_per_page)
139 return $this->mmclient
->get_members_limit($this->mbox
, $page, $number_per_page);
142 /** Fetch pending list operations.
144 * TODO: document the return type
146 public function getPendingOps()
148 return $this->mmclient
->get_pending_ops($this->mbox
);
151 const REQ_REJECT
= 2;
152 const REQ_SUBSCRIBE
= 4;
154 /** Handle a mailing list request
156 public function handleRequest($kind, $value, $comment='')
158 return $this->mmclient
->handle_request($this->mbox
, $value, $kind,
159 utf8_decode($comment));
162 /** Retrieve the current status of a pending subscription request
164 public function getPendingSubscription($email)
166 return $this->mmclient
->get_pending_sub($this->mbox
, $email);
171 public function create($description, $advertise,
172 $moderation_level, $subscription_level, $owners, $members)
174 return $this->mmclient
->create_list($this->mbox
, utf8_decode($description),
175 $advertise, $moderation_level, $subscription_level,
181 public function delete($remove_archives=false
)
183 return $this->mmclient
->delete_list($this->mbox
, $remove_archives);
186 /** Set antispam level.
188 public function setBogoLevel($level)
190 return $this->mmclient
->set_bogo_level($this->mbox
);
193 /** Get antispam level.
197 public function getBogoLevel()
199 $bogo = $this->mmclient
->get_bogo_level($this->mbox
);
203 /** Set public options.
205 * @param $options array
207 public function setOwnerOptions($options)
209 return $this->mmclient
->set_owner_options($this->mbox
, $options);
212 /** Retrieve owner options
216 public function getOwnerOptions()
218 return $this->mmclient
->get_owner_options($this->mbox
);
221 /** Set admin options.
223 * @param $options array
225 public function setAdminOptions($options)
227 return $this->mmclient
->set_admin_options($this->mbox
, $options);
230 /** Retrieve admin options
234 public function getAdminOptions()
236 return $this->mmclient
->get_admin_options($this->mbox
);
239 /** Check options, optionnally fixing them.
241 public function checkOptions($fix=false
)
243 return $this->mmclient
->check_options($this->mbox
, $fix);
246 /** Add an email to the list of whitelisted senders
248 public function whitelistAdd($email)
250 return $this->mmclient
->add_to_wl($this->mbox
, $email);
253 /** Remove an email from the list of whitelisted senders
255 public function whitelistRemove($email)
257 return $this->mmclient
->del_from_wl($this->mbox
, $email);
263 // vim:set et sw=4 sts=4 sws=4 enc=utf-8: