public function MailhandlerPhpImapRetrieve::open_mailbox in Mailhandler 7.2
Same name and namespace in other branches
- 6.2 modules/mailhandler_php_imap/plugins/mailhandler/retrieve/MailhandlerPhpImapRetrieve.class.php \MailhandlerPhpImapRetrieve::open_mailbox()
Establish IMAP stream connection to specified mailbox.
Parameters
array $mailbox: Mailbox configuration.
Return value
resource|false IMAP stream.
3 calls to MailhandlerPhpImapRetrieve::open_mailbox()
- MailhandlerPhpImapRetrieve::purge_message in modules/
mailhandler_php_imap/ plugins/ mailhandler/ retrieve/ MailhandlerPhpImapRetrieve.class.php - Purge (mark as read or delete) a message.
- MailhandlerPhpImapRetrieve::retrieve in modules/
mailhandler_php_imap/ plugins/ mailhandler/ retrieve/ MailhandlerPhpImapRetrieve.class.php - Connect to mailbox and run message retrieval.
- MailhandlerPhpImapRetrieve::test in modules/
mailhandler_php_imap/ plugins/ mailhandler/ retrieve/ MailhandlerPhpImapRetrieve.class.php - Test connection to a mailbox.
File
- modules/
mailhandler_php_imap/ plugins/ mailhandler/ retrieve/ MailhandlerPhpImapRetrieve.class.php, line 122 - Definition of MailhandlerPhpImapRetrieve class.
Class
- MailhandlerPhpImapRetrieve
- Retrieve messages using PHP IMAP library.
Code
public function open_mailbox($mailbox) {
extract($mailbox->settings);
if (!function_exists('imap_open')) {
mailhandler_report('error', 'The PHP IMAP extension must be enabled in order to use Mailhandler.');
}
$box = $this
->mailbox_string($mailbox);
if ($type != 'local') {
$result = imap_open($box, $name, $pass, NULL, 1);
}
else {
// This is a local mbox.
// Change HOME to work around php_imap access restrictions.
$orig_home = getenv('HOME');
if (strpos($box, '/') === 0) {
$new_home = '/';
$box = ltrim($box, '/');
}
else {
// This is hackish, but better than using $_SERVER['DOCUMENT_ROOT']
$new_home = realpath(drupal_get_path('module', 'node') . '/../../');
}
if (!putenv("HOME={$new_home}")) {
mailhandler_error('error', 'Could not set home directory to %home.', array(
'%home' => $new_home,
));
}
$result = imap_open($box, '', '', NULL, 1);
// Restore HOME directory.
putenv("HOME={$orig_home}");
}
return $result;
}