Mailinglist
 All Data Structures Files Functions Variables Pages
MailinglistList.class.php
Go to the documentation of this file.
1 <?php
21 
37  return FALSE;
38  }
39 
47  if (!isset($msg->headers[$this->get_setting('generic_detect_header')])) return FALSE;
48  $header = $msg->headers[$this->get_setting('generic_detect_header')];
49  dpm($header, 'generic_list_match');
50  return TRUE;
51  }
52 
60  drupal_alter('mailinglist_message', $message, $this);
61  module_invoke_all('mailinglist_message', $message, $this);
62  }
63 
67  function schema(&$schema, $type) {
68  }
69 
73  function getMemberInfo($email) {
74  return FALSE;
75  }
76 
80  function getMemberPage($page) {
81  return array('next' => FALSE);
82  }
83 
85 
99  function getWebPage($url, $post="") {
100  $path = variable_get('file_private_path');
101  // If we don/t have a private path, get a public one, with defualts
102  if (empty($path)) {
104  $path = file_directory_temp();
105  } else {
106  // convert private path to abs.
107  $path = DRUPAL_ROOT . '/' . $path;
108  }
109 
110  $cookie = $path . "/mailinglist_cookie.inc";
111  $handle = curl_init($url);
112  curl_setopt($handle, CURLOPT_CRLF, TRUE);
113  curl_setopt($handle, CURLOPT_HEADER, TRUE); // Return header to program
114  curl_setopt($handle, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
115  curl_setopt($handle, CURLOPT_FOLLOWLOCATION, TRUE);
116  curl_setopt($handle, CURLOPT_COOKIEJAR, $cookie);
117  curl_setopt($handle, CURLOPT_COOKIEFILE, $cookie);
118  curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
119  if (!empty($post)) {
120  curl_setopt($handle, CURLOPT_POST, TRUE);
121  curl_setopt($handle, CURLOPT_POSTFIELDS, $post);
122  }
123  $page = curl_exec($handle);
124  $page = str_replace("\r\n", "\n", $page);
125  $headerbreak = strpos($page, "\n\n");
126  $headers = substr($page, 0, $headerbreak);
127  $body = substr($page, $headerbreak+2);
128 
129  // Fold continuation lines
130  $headers = str_replace(array("\n ", "\n\t"), " ", $headers);
131  $headers = explode("\n", $headers);
132  $head = array();
133  foreach ($headers as $header) {
134  $colon = strpos($header, ':');
135  if ($colon === FALSE) {
136  $head[] = $header;
137  }
138  else {
139  $sub = substr($header, 0, $colon);
140  $value = substr($header, $colon+1);
141  if (isset($head[$sub])) {
142  if (!is_array($head[$sub])) {
143  $head[$sub] = array($head[$sub]);
144  }
145  $head[$sub][] = trim($value);
146  }
147  else {
148  $head[$sub] = trim($value);
149  }
150  }
151  }
152  //@todo Process headers so body is in UTF-8
153  $page = array('header' => $head, 'body' => $body);
154  return $page;
155  }
156 
169  function edit_form(&$form, &$form_state) {
170  parent::edit_form($form, $form_state);
171 
172  /* Administrative Title for the list extry (builds default list_name); */
173  $form['info']['admin_title']['#description'] = t('Suggested, but not required, to be the email address of the maiinglist.');
174 
175  $form['basic']['settings']['to_address'] = array(
176  '#type' => 'textfield',
177  '#title' => t('To Address'),
178  '#default_value' => $this->get_setting('to_address'),
179  '#required' => TRUE,
180  '#description' => t('The Email address to send messages to the list'),
181  '#weight' => 10,
182  );
183 
184  $form['basic']['settings']['from_address'] = array(
185  '#type' => 'textfield',
186  '#title' => t('From Address'),
187  '#default_value' => $this->get_setting('from_address'),
188  '#required' => TRUE,
189  '#description' => t('The default From address the site should use to send Email to the list'),
190  '#weight' => 20,
191  );
192 
193  if (!isset($form['basic']['settings']['detect_method'])) {
194  // No Detectect method defined, so add default.
195  $form['basic']['settings']['detect_method'] = array(
196  '#type' => 'select',
197  '#title' => t('Message Detection'),
198  '#options' => array('rfc' => 'RFC-2369', 'generic' => 'Generic'),
199  '#default_value' => $this->get_setting('detect_method'),
200  '#description' => t('The method to use to detect messages from list'),
201  '#required' => TRUE,
202  '#weight' => 40,
203  );
204  }
205 
206  // Remember the method used to build the form.
207  $form['basic']['settings']['detect_method_menu'] = array(
208  '#type' => 'hidden',
209  '#value' => isset($form['basic']['settings']['detect_method']['#default_value']) ? $form['basic']['settings']['detect_method']['#default_value'] : $form['basic']['settings']['detect_method']['#value']
210  );
211 
212  if ($form['basic']['settings']['detect_method_menu']['#value'] == 'generic') {
213  $form['basic']['settings']['generic_detect_header'] = array(
214  '#type' => 'textfield',
215  '#title' => t('Header'),
216  '#default_value' => $this->get_setting('generic_detect_header'),
217  '#required' => TRUE,
218  '#description' => t('The Header to check to see if message comes from the list'),
219  '#weight' => 50,
220  );
221  $form['basic']['settings']['generic_detect_regex'] = array(
222  '#type' => 'textfield',
223  '#title' => t('Regex'),
224  '#default_value' => $this->get_setting('generic_detect_regex'),
225  '#required' => TRUE,
226  '#description' => t('Regex to test Header with'),
227  '#weight' => 60,
228  );
229  }
230  elseif ($form['basic']['settings']['detect_method']['#default_value'] == 'rfc') {
231  $form['basic']['settings']['list_id'] = array(
232  '#type' => 'textfield',
233  '#title' => t('List ID'),
234  '#default_value' => $this->get_setting('list_id'),
235  '#required' => TRUE,
236  '#description' => t('The value if the List-ID header to check for'),
237  '#weight' => 50,
238  );
239  }
240 
241  $form['operations'] = array(
242  '#tree' => FALSE,
243  '#weight' => 50,
244  'operations' => array(
245  '#type' => 'fieldset',
246  '#title' => 'Enabled Operations',
247  '#tree' => TRUE,
248  '#collapsible' => TRUE,
249  '#collapsed' => FALSE,
250  ),
251  );
253  foreach ($opers as $key => $oper) {
256  $form['operations']['operations'][$key] = array(
257  '#type' => 'checkbox',
258  '#title' => check_plain($oper->plugin['name']),
259  '#default_value' => isset($this->operations[$key]) && !empty($this->operations[$key]),
260  );
261  }
262  }
263 
269  function edit_form_validate(&$form, &$form_state) {
270  parent::edit_form_validate($form, $form_state);
271 
272  if (!valid_email_address($form_state['input']['settings']['to_address'])) {
273  form_set_error('to_address', 'To email address is not valid');
274  }
275  if (!valid_email_address($form_state['input']['settings']['from_address'])) {
276  form_set_error('from_address', 'From email address is not valid');
277  }
278  if ($form_state['input']['settings']['detect_method'] != $form_state['input']['settings']['detect_method_menu']) {
279  form_set_error('detect_method', 'Type Changed, Check Settings!');
280  }
281  }
283 }
Interface MailinglistMessageInterface.
genericListMatch(MailinglistMessageInterface $msg)
generic_list_match()
schema(&$schema, $type)
schema()
get_setting($name, $def=NULL)
get_settings()
edit_form_validate(&$form, &$form_state)
edit_form_validate()
Interface to a mailing list.
getWebPage($url, $post="")
getWebPage
checkMessage(MailinglistMessageInterface $msg)
Called on each message read from a mailbox to see if we want to process it.
mailinglist_operation_load_all()
mailinglist_operation_load_all()
Place for common code for classes used in export_ui classes.
edit_form(&$form, &$form_state)
Implements ctools_export_ui::edit_form(), cross linked via mailinglist_export_ui.class.php.
getMemberInfo($email)
getMemberInfo()
Retrieve messages from a Mailhandler Mailbox.
getMemberPage($page)
getMemberPage()
processMessage(MailinglistMessageInterface $message)
message_process()