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, $pass='')
34 $this->domain
= $domain;
35 $this->address
= "$mbox@$domain";
37 if ($user instanceof PlUser
) {
38 $this->mmclient
= new MMList($user, $this->domain
);
40 $this->mmclient
= new MMList($user, $pass, $this->domain
);
44 /** Instantiate a MailingList from its address.
46 * $user and $pass are connection parameters for MailMan.
48 public static function fromAddress($address, $user, $pass='')
50 if (strstr($address, '@') !== false
) {
51 list($mbox, $domain) = explode('@', $address);
55 $domain = $globals->mail
->domain
;
57 return new MailingList($mbox, $domain, $user, $pass);
60 /** Retrieve the MailingList associated with a given promo.
62 * $user and $pass are connection parameters for MailMan.
64 public static function promo($promo, $user, $pass='')
67 $mail_domain = $globals->mail
->domain
;
68 return new MailingList('promo', "$promo.$mail_domain", $user, $pass);
71 const KIND_BOUNCE
= 'bounces';
72 const KIND_OWNER
= 'owner';
73 public function getAddress($kind)
75 return $this->mbox
. '-' . $kind . '@' . $this->domain
;
78 /** Subscribe the current user to the list
80 public function subscribe()
82 return $this->mmclient
->subscribe($this->mbox
);
85 /** Subscribe a batch of users to the list
87 public function subscribeBulk($members)
89 return $this->mmclient
->mass_subscribe($this->mbox
, $members);
92 /** Unsubscribe the current user from the list
94 public function unsubscribe()
96 return $this->mmclient
->unsubscribe($this->mbox
);
99 /** Unsubscribe a batch of users from the list
101 public function unsubscribeBulk($members)
103 return $this->mmclient
->mass_unsubscribe($this->mbox
, $members);
106 /** Retrieve owners for the list.
108 * TODO: document the return type
110 public function getOwners()
112 return $this->mmclient
->get_owners($this->mbox
);
115 /** Add an owner to the list
117 public function addOwner($email)
119 return $this->mmclient
->add_owner($this->mbox
, $email);
122 /** Remove an owner from the list
124 public function removeOwner($email)
126 return $this->mmclient
->del_owner($this->mbox
, $email);
129 /** Retrieve members of the list.
131 * TODO: document the return type
133 public function getMembers()
135 return $this->mmclient
->get_members($this->mbox
);
138 /** Retrieve a subset of list members.
140 * TODO: document the return type
142 public function getMembersLimit($page, $number_per_page)
144 return $this->mmclient
->get_members_limit($this->mbox
, $page, $number_per_page);
147 /** Fetch pending list operations.
149 * TODO: document the return type
151 public function getPendingOps()
153 return $this->mmclient
->get_pending_ops($this->mbox
);
156 const REQ_REJECT
= 2;
157 const REQ_SUBSCRIBE
= 4;
159 /** Handle a mailing list request
161 public function handleRequest($kind, $value, $comment='')
163 return $this->mmclient
->handle_request($this->mbox
, $value, $kind,
164 utf8_decode($comment));
167 /** Retrieve the current status of a pending subscription request
169 public function getPendingSubscription($email)
171 return $this->mmclient
->get_pending_sub($this->mbox
, $email);
176 public function create($description, $advertise,
177 $moderation_level, $subscription_level, $owners, $members)
179 return $this->mmclient
->create_list($this->mbox
, utf8_decode($description),
180 $advertise, $moderation_level, $subscription_level,
186 public function delete($remove_archives=false
)
188 return $this->mmclient
->delete_list($this->mbox
, $remove_archives);
191 /** Set antispam level.
193 public function setBogoLevel($level)
195 return $this->mmclient
->set_bogo_level($this->mbox
);
198 /** Get antispam level.
202 public function getBogoLevel()
204 $bogo = $this->mmclient
->get_bogo_level($this->mbox
);
208 /** Set public options.
210 * @param $options array
212 public function setOwnerOptions($options)
214 return $this->mmclient
->set_owner_options($this->mbox
, $options);
217 /** Retrieve owner options
221 public function getOwnerOptions()
223 return $this->mmclient
->get_owner_options($this->mbox
);
226 /** Set admin options.
228 * @param $options array
230 public function setAdminOptions($options)
232 return $this->mmclient
->set_admin_options($this->mbox
, $options);
235 /** Retrieve admin options
239 public function getAdminOptions()
241 return $this->mmclient
->get_admin_options($this->mbox
);
244 /** Check options, optionnally fixing them.
246 public function checkOptions($fix=false
)
248 return $this->mmclient
->check_options($this->mbox
, $fix);
251 /** Add an email to the list of whitelisted senders
253 public function whitelistAdd($email)
255 return $this->mmclient
->add_to_wl($this->mbox
, $email);
258 /** Remove an email from the list of whitelisted senders
260 public function whitelistRemove($email)
262 return $this->mmclient
->del_from_wl($this->mbox
, $email);
268 // vim:set et sw=4 sts=4 sws=4 enc=utf-8: