mailbox = $mailbox; $this->filter = $filter; parent::__construct(); } /** * Implementation of FeedsImportBatch::getRaw(); */ public function getRaw() { $mailbox = mailhandler_mailboxes_load($this->mailbox); module_load_include('inc', 'mailhandler', 'mailhandler.retrieve'); if ($result = mailhandler_open_mailbox($mailbox)) { if ($new = mailhandler_get_unread_messages($result)) { $messages = array(); $messages = mailhandler_retrieve($mailbox, $mailbox->limit, $mailbox->encoding, $this->filter); return array('messages' => $messages, 'mailbox' => $mailbox); } } else { drupal_set_message('Unable to connect to mailbox.'); } } } /** * Fetches data via HTTP. */ class MailhandlerFetcher extends FeedsFetcher { /** * Implementation of FeedsFetcher::fetch(). */ public function fetch(FeedsSource $source) { $source_config = $source->getConfigFor($this); return new MailhandlerImportBatch($source_config['mailbox'], $this->config['filter']); } /** * Source form. */ public function sourceForm($source_config) { $options = array(); $mailboxes = mailhandler_mailboxes_load(); foreach ($mailboxes as $key => $mailbox) { $options[$key] = $key; } $form = array(); // Load all the available mailboxes. $form['mailbox'] = array( '#type' => 'select', '#title' => t('Mailbox'), '#description' => t('Select a mailbox to use'), '#default_value' => isset($source_config['mailbox']) ? $source_config['mailbox'] : '', '#options' => $options, ); return $form; } /** * Override parent::configDefaults(). */ public function configDefaults() { return array( 'filter' => 'all', ); } /** * Config form. */ public function configForm(&$form_state) { $options = array(); $form = array(); $filters = mailhandler_get_plugins('mailhandler', 'filters'); foreach ($filters as $name => $filter) { $options[$name] = $filter['description']; } // Select message filter (to differentiate nodes/comments/etc) $form['filter'] = array( '#type' => 'select', '#title' => t('Message filter'), '#description' => t('Select which types of messages to import'), '#default_value' => $this->config['filter'], '#options' => $options, ); return $form; } }