You are here

function mailhandler_node_process_mailbox in Mailhandler 7

Same name and namespace in other branches
  1. 6 mailhandler.module \mailhandler_node_process_mailbox()

Run message retrieval and node processing on a mailbox - is a wrapper around mailhandler_retrieve

Batch API smashes the stack, so this function is called twice when fetching messages via batch in order to return the results from the batch.

Parameters

$mailbox: Array of mailbox configuration

$mode: String ui or auto (ie cron) processing

$limit: Int maximum number of messages to retrieve

$messages: Array of retrieved messages

2 calls to mailhandler_node_process_mailbox()
mailhandler_cron in ./mailhandler.module
Implementation of hook_cron(). Process msgs from all enabled mailboxes.
mailhandler_mailhandler_batch_results in ./mailhandler.module
Implementation of hook_mailhandler_batch_results()
1 string reference to 'mailhandler_node_process_mailbox'
mailhandler_menu in ./mailhandler.module
Implementation of hook_menu().

File

./mailhandler.module, line 240

Code

function mailhandler_node_process_mailbox($mailbox = FALSE, $mode = FALSE, $limit = FALSE, $messages = array()) {
  if (empty($messages)) {
    if ($mode == 'ui') {
      mailhandler_retrieve($mailbox, $mode, $limit);
    }
    else {
      if ($messages = mailhandler_retrieve($mailbox, $mode, $limit)) {
        foreach ($messages as $message) {
          mailhandler_node_process_message($message['header'], $message['origbody'], $message['mailbox'], $message['mimeparts']);
        }
      }
    }
  }
  else {

    // See mailhandler_mailhandler_batch_results.  This hook is invoked
    // and mailhandler_process_mailbox is called a second time in order
    // to obtain the messages that were retrieved and continue processing.
    // This is necessary because we cannot obtain the results back from
    // batch processing directly.
    foreach ($messages as $message) {
      mailhandler_node_process_message($message['header'], $message['origbody'], $message['mailbox'], $message['mimeparts']);
    }
  }
}