Skip to content

Commit

Permalink
MDL-53315 inboundmessage: Add support for IMAP Namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Mar 20, 2016
1 parent fed66ad commit d4274a5
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions admin/tool/messageinbound/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class manager {
*/
const MESSAGE_DELETED = '\deleted';

/**
* @var \string IMAP folder namespace.
*/
protected $imapnamespace = null;

/**
* @var \Horde_Imap_Client_Socket A reference to the IMAP client.
*/
Expand Down Expand Up @@ -126,6 +131,25 @@ protected function close_connection() {
$this->client = null;
}

/**
* Get the confirmation folder imap name
*
* @return string
*/
protected function get_confirmation_folder() {

if ($this->imapnamespace === null) {
if ($this->client->queryCapability('NAMESPACE')) {
$namespaces = $this->client->getNamespaces(array(), array('ob_return' => true));
$this->imapnamespace = $namespaces->getNamespace('INBOX');
} else {
$this->imapnamespace = '';
}
}

return $this->imapnamespace . self::CONFIRMATIONFOLDER;
}

/**
* Get the current mailbox information.
*
Expand Down Expand Up @@ -198,13 +222,13 @@ public function process_existing_message(\stdClass $maildata) {
// When dealing with Inbound Message messages, we mark them as flagged and seen. Restrict the search to those criterion.
$search->flag(self::MESSAGE_SEEN, true);
$search->flag(self::MESSAGE_FLAGGED, true);
mtrace("Searching for a Seen, Flagged message in the folder '" . self::CONFIRMATIONFOLDER . "'");
mtrace("Searching for a Seen, Flagged message in the folder '" . $this->get_confirmation_folder() . "'");

// Match the message ID.
$search->headerText('message-id', $maildata->messageid);
$search->headerText('to', $maildata->address);

$results = $this->client->search(self::CONFIRMATIONFOLDER, $search);
$results = $this->client->search($this->get_confirmation_folder(), $search);

// Build the base query.
$query = new \Horde_Imap_Client_Fetch_Query();
Expand All @@ -213,7 +237,7 @@ public function process_existing_message(\stdClass $maildata) {


// Fetch the first message from the client.
$messages = $this->client->fetch(self::CONFIRMATIONFOLDER, $query, array('ids' => $results['match']));
$messages = $this->client->fetch($this->get_confirmation_folder(), $query, array('ids' => $results['match']));
$this->addressmanager = new \core\message\inbound\address_manager();
if ($message = $messages->first()) {
mtrace("--> Found the message. Passing back to the pickup system.");
Expand Down Expand Up @@ -248,8 +272,8 @@ public function tidy_old_messages() {

// Open the mailbox.
mtrace("Searching for messages older than 24 hours in the '" .
self::CONFIRMATIONFOLDER . "' folder.");
$this->client->openMailbox(self::CONFIRMATIONFOLDER);
$this->get_confirmation_folder() . "' folder.");
$this->client->openMailbox($this->get_confirmation_folder());

$mailbox = $this->get_mailbox();

Expand Down Expand Up @@ -746,9 +770,10 @@ private function message_has_flag($messageid, $flag) {
* Ensure that all mailboxes exist.
*/
private function ensure_mailboxes_exist() {

$requiredmailboxes = array(
self::MAILBOX,
self::CONFIRMATIONFOLDER,
$this->get_confirmation_folder(),
);

$existingmailboxes = $this->client->listMailboxes($requiredmailboxes);
Expand Down Expand Up @@ -866,7 +891,7 @@ private function handle_verification_failure(
}

// Move the message into a new mailbox.
$this->client->copy(self::MAILBOX, self::CONFIRMATIONFOLDER, array(
$this->client->copy(self::MAILBOX, $this->get_confirmation_folder(), array(
'create' => true,
'ids' => $messageids,
'move' => true,
Expand Down

0 comments on commit d4274a5

Please sign in to comment.