function MailhandlerPhpImapRetrieve::test in Mailhandler 6.2
Same name and namespace in other branches
- 7.2 modules/mailhandler_php_imap/plugins/mailhandler/retrieve/MailhandlerPhpImapRetrieve.class.php \MailhandlerPhpImapRetrieve::test()
Test connection to a mailbox.
Parameters
object $mailbox: The mailbox to test.
Return value
array Test results.
Overrides MailhandlerRetrieve::test
File
- modules/
mailhandler_php_imap/ plugins/ mailhandler/ retrieve/ MailhandlerPhpImapRetrieve.class.php, line 54 - Definition of MailhandlerPhpImapRetrieve class.
Class
- MailhandlerPhpImapRetrieve
- Retrieve messages using PHP IMAP library.
Code
function test($mailbox) {
extract($mailbox->settings);
$ret = array();
$this->suppress_errors = TRUE;
$is_local = $type == 'local';
$folder_is_set = !empty($folder) && $folder != 'INBOX';
$connect_is_set = !empty($domain) && !empty($port) && !empty($name) && !empty($pass);
if ($is_local && $folder_is_set || !$is_local && $connect_is_set) {
if (!($result = $this
->open_mailbox($mailbox))) {
$errors = imap_errors();
foreach ($errors as $error) {
$ret[] = array(
'severity' => 'error',
'message' => t($error),
);
}
$ret[] = array(
'severity' => 'error',
'message' => t('Mailhandler could not access the mailbox using these settings'),
);
return $ret;
}
$ret[] = array(
'severity' => 'status',
'message' => t('Mailhandler was able to connect to the mailbox.'),
);
$box = $this
->mailbox_string($mailbox);
$box = ltrim($box, '/');
$status = imap_status($result, $box, SA_MESSAGES);
if ($status) {
$ret[] = array(
'severity' => 'status',
'message' => t('There are @messages messages in the mailbox folder.', array(
'@messages' => $status->messages,
)),
);
}
else {
$ret[] = array(
'severity' => 'warning',
'message' => t('Mailhandler could not open the mailbox.'),
);
}
$this
->close_mailbox($result, $mailbox);
}
return $ret;
}