diff --git a/admin/tool/messageinbound/classes/manager.php b/admin/tool/messageinbound/classes/manager.php index 4fae00918c0..a0d1137276c 100644 --- a/admin/tool/messageinbound/classes/manager.php +++ b/admin/tool/messageinbound/classes/manager.php @@ -155,7 +155,7 @@ class manager { // Ensure that mailboxes exist. $this->ensure_mailboxes_exist(); // Select mailbox. - $this->client->select(mailbox: $mailbox); + $this->select_mailbox(mailbox: $mailbox); return true; } else { throw new \moodle_exception('imapconnectfailure', 'tool_messageinbound', '', null, 'Could not connect to IMAP server.'); @@ -331,9 +331,11 @@ class manager { */ public function tidy_old_messages(): bool { // Grab the new IMAP client. - if (!$this->get_imap_client(mailbox: $this->get_confirmation_folder())) { + if (!$this->get_imap_client()) { return false; } + // Switch to the confirmation folder. + $this->select_mailbox(mailbox: $this->get_confirmation_folder()); // Open the mailbox. mtrace("Searching for messages older than 24 hours in the '" . @@ -1332,6 +1334,17 @@ class manager { return $messagedata->sequence; } + /** + * Switch mailbox. + * + * @param string $mailbox The mailbox to switch to. + */ + protected function select_mailbox( + string $mailbox, + ): void { + $this->client->select(mailbox: $mailbox); + } + /** * We use Roundcube Framework to receive the emails. * This method will load the required dependencies.