Mailinglist
 All Data Structures Files Functions Variables Pages
Mailman21List.class.php
Go to the documentation of this file.
1 <?php
11 
21  function edit_form(&$form, &$form_state) {
22  parent::edit_form($form, $form_state);
23  $form['basic']['settings']['admin_url'] = array(
24  '#type' => 'textfield',
25  '#title' => t('Mailman URL Base'),
26  '#default_value' => $this->get_setting('admin_url'),
27  '#required' => TRUE,
28  '#description' => t('Base URL of admin page (typically something like http://example.com/mailman )'),
29  '#weight' => 60,
30  );
31  $form['basic']['settings']['listname'] = array(
32  '#type' => 'textfield',
33  '#title' => t('List Name'),
34  '#default_value' => $this->get_setting('listname'),
35  '#required' => TRUE,
36  '#description' => t('Name of list as appears in URLs for the list'),
37  '#weight' => 60,
38  );
39  $form['basic']['settings']['admin_password'] = array(
40  '#type' => 'textfield',
41  '#title' => t('Admin Password'),
42  '#default_value' => _mailinglist_decode_password($this->get_setting('admin_password')),
43  '#required' => TRUE,
44  '#description' => t('Password to access List Interface'),
45  '#weight' => 60,
46  );
47  }
51  function edit_form_submit(&$form, &$form_state) {
52  dpm($form_state, 'Mailman21List::edit_form_submit');
53 
54  $form_state['values']['settings']['admin_password'] = _mailinglist_encode_password($form_state['values']['settings']['admin_password']);
55  }
57 
71  return parent::checkMessage($msg);
72  }
73 
81  return parent::processMessage($msg);
82  }
83 
94  function getMemberInfo($email) {
95  $listname = $this->get_setting('listname');
96  $url = $this->get_setting('admin_url') . '/options/' . $this->get_setting('listname') . '/' . str_replace('@', '--at--', $email);
97  $data = $this->getWebPage($url);
98  dpm($data, 'Get Info: ' . $email);
99  $body = $data['body'];
100  $pos = strpos($body, 'Your ' . $listname . ' Subscription Options');
101  if ($pos === FALSE) {
102  dpm(FALSE, 'Info');
103  return FALSE;
104  }
105  $info = array('Email' => $email);
106  $pos1 = strpos($body, 'name="fullname"');
107  $pos1 = strpos($body, 'value=', $pos1)+7;
108  $end = strpos($body, '"', $pos1);
109  $name = substr($body, $pos1, $end-$pos1);
110  $info['Name'] = $name;
111 
112  $pos = strpos($body, 'name="disablemail"', $pos);
113  $pos = strpos($body, 'CHECKED', $pos);
114  $no_mail = substr($body, $pos-3, 1);
115  //$info['NoMail'] = $no_mail;
116 
117  $pos = strpos($body, 'name="digest"', $pos);
118  $pos = strpos($body, 'CHECKED', $pos);
119  $digest = substr($body, $pos-3, 1);
120  //$info['Digest'] = $digest;
121 
122  $pos = strpos($body, 'name="mime"', $pos);
123  $pos = strpos($body, 'CHECKED', $pos);
124  $plain = substr($body, $pos-3, 1);
125  //$info['Plain'] = $plain;
126 
127  $info['Type'] = ($no_mail == '1' ? MAILINGLIST_SUB_NOMAIL :
128  ($digest == '0' ? MAILINGLIST_SUB_NORMAL :
130 
132  dpm($info, 'Info');
133  return $info;
134  }
135 
143  function SubscribeForm(&$form, &$form_state){
144  global $help;
145  $form['notice'] = array(
146  '#markup' => '<b>** Notice: Not Fully Implemented</b>',
147  '#weight' => -90);
148 
149  $form['email'] = array(
150  '#type' => 'textfield',
151  '#title' => t('EMail Address'),
152  '#default_value' => 'somebody@example.com',
153  '#required' => TRUE,
154  '#description' => t('This is the Email address which email from the list will be sent'),
155  '#weight' => 20,
156  );
157 
158  dpm($form, 'Subscribe Form');
159  }
160 
164  function UnsubscribeForm(&$form, &$form_state){
165  $form['notice'] = array(
166  '#markup' => '<b>** Notice: Not Fully Implemented</b>',
167  '#weight' => -90);
168 
169  $form['email'] = array(
170  '#type' => 'textfield',
171  '#title' => t('EMail Address'),
172  '#default_value' => 'somebody@example.com',
173  '#required' => TRUE,
174  '#description' => t('This is the Email address which email from the list will be sent'),
175  '#weight' => 20,
176  );
177 
178  dpm($form, 'Unsubscribe Form');
179  }
180 
184  function OptionsForm($form, $form_state){
185  $form['notice'] = array(
186  '#markup' => '<b>** Notice: Not Fully Implemented</b>',
187  '#weight' => -90);
188 
189  $form['email'] = array(
190  '#type' => 'textfield',
191  '#title' => t('EMail Address'),
192  '#default_value' => 'somebody@example.com',
193  '#required' => TRUE,
194  '#description' => t('This is the Email address which email from the list will be sent'),
195  '#weight' => 20,
196  );
197 
198  dpm($form, 'Options Form');
199  }
200 
222  function getMemberPage($page) {
223  if (!$page) {
224  $pagecode = '';
225  }
226  else {
227  $pagecode = '?letter=' . $page[0] . '&chunk=' . $page[1];
228  }
229  $url = $this->get_setting('admin_url') . '/admin/' . $this->get_setting('listname') . '/members' . $pagecode;
230  $data = $this->getWebPage($url);
231  dpm($data, 'Page Data');
232  $body = $data['body'];
233  $pos = strpos($body, 'Membership List');
234  $liststart = $pos;
235  if (!$page) {
236  // If starting, find where we start
238  $pos = strpos($body, 'letter=', $pos)+7;
239  $page[0] = substr($body, $pos, 1);
240  $page[1] = 0;
241  }
242  $next = $page;
244  $next[1] = $next[1]+1;
245  if (FALSE === strpos($body, 'chunk=' . $next[1], $pos)) {
246  // Don't find a listing for next chunk for this letter.
247  $next[1] = 0;
248  if($pos < 7) {
249  $this->log('Bad Pos1 ' . $pos . '\n' . html_specialchars($body), SELF::LOG_ERROR);
250  return array('next' => $next, 'page' => $page, 'members' => array());
251  }
252  $pos = strpos($body, 'letter=' . $next[0] . '"', $pos-7); // need to back up in case we found first letter
253  if($pos < 7) {
254  $this->log('Bad Pos2 ' . $pos . '\n' . html_specialchars($body), SELF::LOG_ERROR);
255  return array('next' => $next, 'page' => $page, 'members' => array());
256  }
257  $pos = strpos($body, 'letter=', $pos+7) + 7;
258  $letter = substr($body, $pos, 1);
259  if ($pos > 7 && $letter != $next[0]) {
260  $next[0] = $letter;
261  }
262  else {
263  $next = FALSE; // end of data.
264  }
265  }
266 
267  $members = array();
268  $pos = strpos($body, 'member address', $pos); // Advance to Header
269  $endpos = strpos($body, '</table>', $pos); // End of table
270  $pos = strpos($body, '<tr>', $pos);
271  while ($pos < $endpos) {
272  $pos1 = strpos($body, '</tr>', $pos);
273  $record = substr($body, $pos, $pos1-$pos+5);
274  $record = explode('<td>', $record);
275  // record [0] is <tr>
276  // record [1] is unsub.
277  // record [2] is email address, real name
278  $start = strpos($record[2], '>');
279  $end = strpos($record[2], '</a>');
280  $email = substr($record[2], $start+1, $end - $start-1);
281  $info['Email'] = $email;
282  $start = strpos($record[2], 'value=', $end) + 7;
283  $end = strpos($record[2], '"', $start);
284  $name = substr($record[2], $start, $end - $start);
285  $info['Name'] = $name;
286  // record[3] = Moderated.
287  $start = strpos($record[3], 'value=') + 7;
288  $end = strpos($record[3], '"', $start);
289  $mod = substr($record[3], $start, $end - $start);
290  $info['Moderated'] = $mod == "on";
291  // record[4] = Hide.
292  $start = strpos($record[4], 'value=') + 7;
293  $end = strpos($record[4], '"', $start);
294  $hide = substr($record[4], $start, $end - $start);
295  $info['Hide'] = $hide == "on";
296  // record[5] = NoMail.
297  $start = strpos($record[5], 'value=') + 7;
298  $end = strpos($record[5], '"', $start);
299  $no_mail = substr($record[5], $start, $end - $start);
300  if ($no_mail == 'on') {
301  $start = strpos($record[5], '[', $end)+1;
302  $info['NoMail'] = substr($record[5], $start, 1);
303  }
304  else {
305  $info['NoMail'] = FALSE;
306  }
307  // record[6] = Ack.
308  $start = strpos($record[6], 'value=') + 7;
309  $end = strpos($record[6], '"', $start);
310  $ack = substr($record[6], $start, $end - $start);
311  $info['Ack'] = $ack == "on";
312  // record[7] = MeToo.
313  $start = strpos($record[7], 'value=') + 7;
314  $end = strpos($record[7], '"', $start);
315  $metoo = substr($record[7], $start, $end - $start);
316  $info['MeToo'] = $metoo == 'on';
317  // record[8] = NoDups.
318  $start = strpos($record[8], 'value=') + 7;
319  $end = strpos($record[8], '"', $start);
320  $no_dups = substr($record[8], $start, $end - $start);
321  $info['NoDups'] = $no_dups == 'on';
322  // record[9] = digest.
323  $start = strpos($record[9], 'value=') + 7;
324  $end = strpos($record[9], '"', $start);
325  $digest = substr($record[9], $start, $end - $start);
326  // record[10] = Plain Digest.
327  $start = strpos($record[10], 'value=') + 7;
328  $end = strpos($record[10], '"', $start);
329  $plain = substr($record[10], $start, $end - $start);
330  $info['Type'] = ($no_mail == "on" ? MAILINGLIST_SUB_NOMAIL :
331  ($digest == 'off' ? MAILINGLIST_SUB_NORMAL :
333 
334  // record[11] = Language.
335  $end = strpos($record[11], 'Selected') - 2;
336  $string = substr($record[11], 0, $end);
337  $start = strrpos($string, '"') + 1;
338  $lang = substr($record[11], $start, $end - $start);
339  $info['Language'] = $lang;
340 
341  $members[$email] = $info;
342  // Find next entry
343  $pos = strpos($body, '<tr>', $pos1);
344  }
345  return array('next' => $next, 'page' => $page, 'members' => $members);
346  }
347 
357  function getWebPage($url, $post="") {
358  $page = parent::getWebPage($url, $post);
359  if (strpos($page['body'], 'name="admlogin"') ) {
360  $login_post = 'adminpw=' . _mailinglist_decode_password($this->get_setting('admin_password'));
361  $page = parent::getWebPage( $url, $login_post);
363  }
364  return $page;
365  }
366 }
Interface MailinglistMessageInterface.
getMemberInfo($email)
getMemberInfo()
_mailinglist_encode_password($pass)
_mailinglist_encode_password
const MAILINGLIST_SUB_MIME_DIGEST
get_setting($name, $def=NULL)
get_settings()
SubscribeForm(&$form, &$form_state)
Operation Forms.
Mailman 2.1.x List Personality Plugin.
log($str, $level=self::LOG_NOTICE, $parms=array())
log()
processMessage(MailinglistMessageInterface $msg)
processMessage()
OptionsForm($form, $form_state)
const MAILINGLIST_SUB_NOMAIL
const MAILINGLIST_SUB_DIGEST
edit_form_submit(&$form, &$form_state)
_mailinglist_decode_password($code)
_mailinglist_decode_password
getWebPage($url, $post="")
getWebPage
UnsubscribeForm(&$form, &$form_state)
getMemberPage($page)
getMemberPage
Retrieve messages from a Mailhandler Mailbox.
edit_form(&$form, &$form_state)
Implements ctools_export_ui::edit_form().
checkMessage(MailinglistMessageInterface $msg)
checkMessage()
const MAILINGLIST_SUB_NORMAL