You are here

function mailhandler_mailbox_stream_open in Mailhandler 6

Establish stream connection to specified mailbox.

Parameters

$mailbox: Array of mailbox configuration.

Return value

stream to work with other stream processing functions or FALSE.

Related topics

2 calls to mailhandler_mailbox_stream_open()
mailhandler_mailbox_test in ./mailhandler.module
Test the connection to a mailbox.
mailhandler_open_mailbox in ./mailhandler.retrieve.inc
(DEPRECATED) Establish IMAP stream connection to specified mailbox.

File

./mailhandler.module, line 497
Mailhandler module code.

Code

function mailhandler_mailbox_stream_open($mailbox) {

  // Build the mailbox string from mailbox settings.
  $proto = array(
    'pop',
    'imap',
  );

  // Build imap_open arguments.
  $box = array(
    'path' => $mailbox['domain'] ? '{' . $mailbox['domain'] . ':' . $mailbox['port'] . '/' . $proto[$mailbox['imap']] . $mailbox['extraimap'] . '}' . $mailbox['folder'] : $mailbox['folder'],
    'user' => $mailbox['domain'] ? $mailbox['name'] : '',
    'pass' => $mailbox['domain'] ? $mailbox['pass'] : '',
  );

  // Open stream (imap, pop or local folder).
  $result = imap_open($box['path'], $box['user'], $box['pass']);

  // Record a debug message to inform about no errors opening the stream.
  mailhandler_watchdog_record('Opening stream to %box: %result.', array(
    '%box' => $box['path'],
    '%result' => !imap_last_error(),
  ), WATCHDOG_DEBUG);

  // Provide a warning message when imap_open returns error.
  if (!$result) {

    // Record error from imap extension.
    mailhandler_watchdog_record('Error opening %box: %error.', array(
      '%box' => $box['path'],
      '%error' => imap_last_error(),
    ), WATCHDOG_WARNING);
  }
  return $result;
}