Navigation Menu

Skip to content

Commit

Permalink
MDL-51894 inboundmessage: Ensure that all mailboxes exist
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Oct 26, 2015
1 parent 9382ac3 commit fd424b9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions admin/tool/messageinbound/classes/manager.php
Expand Up @@ -102,6 +102,10 @@ protected function get_imap_client() {
try {
$this->client->login();
mtrace("Connection established.");

// Ensure that mailboxes exist.
$this->ensure_mailboxes_exist();

return true;

} catch (\Horde_Imap_Client_Exception $e) {
Expand Down Expand Up @@ -741,6 +745,27 @@ private function message_has_flag($messageid, $flag) {
return in_array($flag, $flags);
}

/**
* Ensure that all mailboxes exist.
*/
private function ensure_mailboxes_exist() {
$requiredmailboxes = array(
self::MAILBOX,
self::CONFIRMATIONFOLDER,
);

$existingmailboxes = $this->client->listMailboxes($requiredmailboxes);
foreach ($requiredmailboxes as $mailbox) {
if (isset($existingmailboxes[$mailbox])) {
// This mailbox was found.
continue;
}

mtrace("Unable to find the '{$mailbox}' mailbox - creating it.");
$this->client->createMailbox($mailbox);
}
}

/**
* Attempt to determine whether this message is a bulk message (e.g. automated reply).
*
Expand Down

0 comments on commit fd424b9

Please sign in to comment.