You are here

function mailhandler_test_mailbox in Mailhandler 7

Test connection to a mailbox, and output results as a message

1 call to mailhandler_test_mailbox()
mailhandler_add_edit_mailbox_validate in ./mailhandler.admin.inc
Verify that the Mailbox is valid, and save it to the database.

File

./mailhandler.admin.inc, line 302

Code

function mailhandler_test_mailbox(&$form_state) {
  module_load_include('inc', 'mailhandler', 'mailhandler.retrieve');
  $mailbox = $form_state['values'];
  $result = mailhandler_open_mailbox($mailbox);
  if ($result) {
    drupal_set_message('Mailhandler was able to connect to the mailbox.');
    imap_close($result);
  }
  else {
    if ($mailbox['domain']) {
      form_set_error('mailhandler', t('%c connection to %m failed.', array(
        '%c' => $mailbox['imap'] ? 'IMAP' : 'POP3',
        '%m' => $mailbox['mail'],
      )));
    }
    else {
      form_set_error('mailhandler', t('Mailhandler could not access local folder: %m', array(
        '%m' => $mailbox['mail'],
      )));
    }
  }
  return;
}