Mailinglist
 All Data Structures Files Functions Variables Pages
MailinglistRetrieveUI.class.php
Go to the documentation of this file.
1 <?php
20  function hook_menu(&$items) {
21  parent::hook_menu($items);
22  if (isset($items['admin/config/system/mailinglist/mailbox'])) {
23  $items['admin/config/system/mailinglist/mailbox']['type'] = MENU_LOCAL_TASK;
24  }
25  }
26 
30  function edit_form(&$form, &$form_state) {
31 
32  // All Retrievers will need some settings for connection.
33  $form['connection']['#tree'] = FALSE;
34  $form['connection']['#weight'] = 20;
35  $form['connection']['settings']= array(
36  '#type' => 'fieldset',
37  '#title' => 'Mailbox connection settings',
38  '#tree' => TRUE,
39  '#collapsible' => TRUE,
40  '#collapsed' => FALSE,
41  );
42 
43  $form['extra']['#tree'] = FALSE;
44  $form['extra']['#weight'] = 90;
45  $form['extra']['settings']= array(
46  '#type' => 'fieldset',
47  '#title' => 'More settings',
48  '#tree' => TRUE,
49  '#collapsible' => TRUE,
50  '#collapsed' => TRUE,
51  );
52 
53  parent::edit_form($form, $form_state);
54 
55  // object_type selection is not dependant on type of object
56 
57  $retrieve_plugins = mailinglist_get_plugins('mailinglist', 'retrieve');
58  /* Type of Mail Box */
59  $form['info']['object_type'] = array(
60  '#type' => 'select',
61  '#title' => t('Mailbox Type'),
62  '#options' => _mailinglist_build_options($retrieve_plugins),
63  '#default_value' => isset($form_state['item']->object_type) ? $form_state['item']->object_type : NULL,
64  '#description' => t('Plug in to use to read mailbox'),
65  '#required' => TRUE,
66  );
67  }
68 
72  function list_header($form_state) {
73  if (isset($form_state['input']['test_result'])) {
74  return $form_state['input']['test_result'];
75  }
76  }
77 
81  function test_page($js, $input, $mailbox) {
82  $input['test_result'] = _mailinglist_mailbox_test_output($mailbox);
83  if (!$js) {
84  drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
85  }
86  else {
87  return $this->list_page($js, $input);
88  }
89  }
90 
96  function process_page($js, $input, $mailbox) {
97 // dpm($js);
98 // dpm($input);
99  dpm($mailbox, 'process_page');
100  $page['list'] = array(
101  '#theme' => 'table',
102  '#header' => array(
103  array('data' => 'Message', ),
104  array('data' => 'List'),
105  array('data' => 'Results', ),
106  array('data' => 'Subject', ),
107  ),
108  '#rows' => array(),
109  );
110 
111  drupal_set_title($this->get_page_title('process', $mailbox));
112 
113  // Check if we have a real mailbox object
114  if (method_exists($mailbox, 'get_message_list')) {
115  $lists = mailinglist_list_load_all();
116  $msg_list = $mailbox->get_message_list($mailbox->settings['limit']);
117  if (!$msg_list) {
118  // Avoid error message on error, maybe should log the error?
119  $msg_list = array();
120  }
121  foreach ($msg_list as $msg_idx => $msg_id) {
122  $msg = $mailbox->get_message($msg_id);
123  dpm($msg, $msg_id);
124  $handled = FALSE;
125  foreach ($lists as $list => $listobj) {
126  $handled = $listobj->processMessage($msg);
127  if ($handled) {
128  if ($mailbox->get_setting('delete_after_read', FALSE)) {
129  dpm('Purge', $msg_id);
130 // $mailbox -> purge_msg($msg_id);
131  }
132  break;
133  }
134  } // end of foreach ($lists), process handled code
135  if ($handled == FALSE) {
136  $list = "**None**";
137  $handled = "Unhandled";
138  }
139  if ($handled === TRUE) {
140  $handled = "Match";
141  }
142  $row = array($msg_id, $list, $handled, $msg->header('Subject'));
143  $msg_list[$msg_idx] = array($msg_id, $handled ? $list : 'Unhandled');
144  $page['list']['#rows'][$msg_idx] = $row;
145  }
146  $mailbox->close();
147  }
148  return $page;
149  }
151 }
Represents an email mailbox (IMAP, POP3, etc...).
_mailinglist_mailbox_test_output($mailbox)
_mailinglist_mailbox_test_output()
_mailinglist_build_options($source, $key_name= 'name')
Builds a Select control array from a menu form an array from a ctools_get_plugin. ...
list_header($form_state)
list_header()
test_page($js, $input, $mailbox)
Callback to test a mailbox connection.
mailinglist_get_plugins($module, $type)
Wrapper to load plugins.
process_page($js, $input, $mailbox)
process_page()
Place for common code for export_ui classes Forwards a lot of ctools_export_ui hooks to the exportabl...
edit_form(&$form, &$form_state)
Implements ctools_export_ui::edit_form().
hook_menu(&$items)
Implements ctools_export_ui::hook_form().
mailinglist_list_load_all($show_disabled=TRUE)
Load all mailinglists.