/**
  * Implementation of FeedsParser::parse().
  */
 public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result)
 {
     $fetched = $fetcher_result->getRaw();
     $mailbox = $fetched['mailbox'];
     $result = new FeedsParserResult();
     if (!empty($fetched['messages'])) {
         foreach ($fetched['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_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.');
                     continue;
                 }
             }
             $this->commands($message, $source);
             $result->items[] = $message;
         }
     }
     return $result;
 }
 /**
  * Implements ctools_export_ui::edit_form_validate().
  */
 function edit_form_validate(&$form, &$form_state)
 {
     parent::edit_form_validate($form, $form_state);
     // If POP3 mailbox is chosen, messages should be deleted after processing.
     // Do not set an actual error because this is helpful for testing purposes.
     if ($form_state['values']['settings']['type'] == 'pop3' && $form_state['values']['settings']['delete_after_read'] == 0) {
         mailhandler_report('warning', 'Unless you check off "Delete messages after they are processed" when using a POP3 mailbox, old emails will be re-imported each time the mailbox is processed. You can partially prevent this by mapping Message ID to a unique target in the processor configuration - see INSTALL.txt or advanced help for more information');
     }
     // Dummy library is only for testing.
     if ($form_state['values']['settings']['retrieve'] == 'MailhandlerRetrieveDummy') {
         mailhandler_report('warning', 'Because you selected the dummy retrieval library, Mailhandler will not import any messages. Please select another retrieval library, such as the PHP IMAP library.');
     }
 }
 /**
  * Capture and report IMAP errors.
  */
 function report_errors()
 {
     if (!$this->suppress_errors) {
         $errors = imap_errors();
         if ($errors) {
             list(, $caller) = debug_backtrace(false);
             $function = $caller['function'];
             foreach ($errors as $error) {
                 mailhandler_report('error', 'IMAP error in %function: %error', array('%function' => $function, '%error' => $error));
             }
         }
     }
 }
 /**
  * Capture and report IMAP errors.
  */
 public function report_errors($mailbox)
 {
     // Need to be able to suppress errors when we are testing from an AJAX call.
     // Otherwise we get nasty AJAX dialogs.
     if (!$this->suppress_errors) {
         $errors = imap_errors();
         if ($errors) {
             list(, $caller) = debug_backtrace(FALSE);
             $function = $caller['function'];
             foreach ($errors as $error) {
                 if ($error == "SECURITY PROBLEM: insecure server advertised AUTH=PLAIN" && $mailbox->settings['insecure']) {
                     continue;
                 }
                 mailhandler_report('error', 'IMAP error in %function: %error', array('%function' => $function, '%error' => $error));
             }
         }
     }
 }