You are here

public function MailhandlerParser::parse in Mailhandler 6.2

Same name and namespace in other branches
  1. 7.2 plugins/feeds/plugins/MailhandlerParser.class.php \MailhandlerParser::parse()

Implementation of FeedsParser::parse().

Overrides FeedsParser::parse

File

plugins/feeds/plugins/MailhandlerParser.class.php, line 78
MailhandlerParser class.

Class

MailhandlerParser
Parses an IMAP stream.

Code

public function parse(FeedsImportBatch $batch, FeedsSource $source) {
  $fetched = $batch
    ->getRaw();
  $mailbox = $fetched['mailbox'];
  $messages = $fetched['messages'];
  if (!empty($messages)) {
    foreach ($messages as $mid => &$message) {
      $this
        ->authenticate($message, $mailbox);
      if ($class = mailhandler_plugin_load_class('mailhandler', $mailbox->settings['retrieve'], 'retrieve', 'handler')) {
        $class
          ->purge_message($mailbox, $message);
      }
      if ($message['authenticated_uid'] == 0) {

        // User was not authenticated
        module_invoke_all('mailhandler_auth', 'auth_failed', $message);
        $source_config = $source
          ->getConfigFor($this);
        if ($source_config['auth_required']) {
          mailhandler_report('warning', 'User could not be authenticated. Please check your Mailhandler authentication plugin settings.');
          unset($messages[$mid]);
          continue;
        }
      }
      $this
        ->commands($message, $source);
    }
    $batch
      ->setItems($messages);
  }
  else {
    if (isset($fetched['new'])) {
      mailhandler_report('info', 'No new messages.');
    }
  }
}