2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * A Handler to re-process messages which previously failed sender
21 * @package tool_messageinbound
23 * @copyright 2014 Andrew Nicols
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 namespace tool_messageinbound\message\inbound;
29 defined('MOODLE_INTERNAL') || die();
31 require_once($CFG->dirroot . '/repository/lib.php');
34 * A Handler to re-process messages which previously failed sender
37 * This may happen if the user did not use their registerd e-mail address,
38 * the verification hash used had expired, or if some erroneous content was
39 * introduced into the content hash.
41 * @copyright 2014 Andrew Nicols
42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44 class invalid_recipient_handler extends \core\message\inbound\handler {
47 * Do not allow changes to the address validation setting.
49 public function allow_validateaddress_change() {
54 * Return a description for the current handler.
58 public function get_description() {
59 return get_string('invalid_recipient_handler', 'tool_messageinbound');
63 * Return a name for the current handler.
64 * This appears in the admin pages as a human-readable name.
68 public function get_name() {
69 return get_string('invalid_recipient_handler_name', 'tool_messageinbound');
73 * Process a message received and validated by the Inbound Message processor.
75 * @param $messagedata The Inbound Message record
76 * @param $messagedata The message data packet.
77 * @return bool Whether the message was successfully processed.
79 public function process_message(\stdClass $record, \stdClass $data) {
82 if (!$maildata = $DB->get_record('messageinbound_messagelist', array('id' => $record->datavalue))) {
83 // The message requested couldn't be found. Failing here will alert the user that we failed.
84 throw new \core\message\inbound\processing_failed_exception('oldmessagenotfound', 'tool_messageinbound');
87 mtrace("=== Request to re-process message {$record->datavalue} from server.");
88 mtrace("=== Message-Id:\t{$maildata->messageid}");
89 mtrace("=== Recipient:\t{$maildata->address}");
91 $manager = new \tool_messageinbound\manager();
92 return $manager->process_existing_message($maildata);