MDL-48334 tool_messageinbound: cleanup @package @category
[moodle.git] / admin / tool / messageinbound / classes / message / inbound / invalid_recipient_handler.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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.
13 //
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/>.
17 /**
18  * A Handler to re-process messages which previously failed sender
19  * verification.
20  *
21  * @package    tool_messageinbound
22  * @category   message
23  * @copyright  2014 Andrew Nicols
24  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25  */
27 namespace tool_messageinbound\message\inbound;
29 defined('MOODLE_INTERNAL') || die();
31 require_once($CFG->dirroot . '/repository/lib.php');
33 /**
34  * A Handler to re-process messages which previously failed sender
35  * verification.
36  *
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.
40  *
41  * @copyright  2014 Andrew Nicols
42  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43  */
44 class invalid_recipient_handler extends \core\message\inbound\handler {
46     /**
47      * Do not allow changes to the address validation setting.
48      */
49     public function allow_validateaddress_change() {
50         return false;
51     }
53     /**
54      * Return a description for the current handler.
55      *
56      * @return string
57      */
58     public function get_description() {
59         return get_string('invalid_recipient_handler', 'tool_messageinbound');
60     }
62     /**
63      * Return a name for the current handler.
64      * This appears in the admin pages as a human-readable name.
65      *
66      * @return string
67      */
68     public function get_name() {
69         return get_string('invalid_recipient_handler_name', 'tool_messageinbound');
70     }
72     /**
73      * Process a message received and validated by the Inbound Message processor.
74      *
75      * @param $messagedata The Inbound Message record
76      * @param $messagedata The message data packet.
77      * @return bool Whether the message was successfully processed.
78      */
79     public function process_message(\stdClass $record, \stdClass $data) {
80         global $DB;
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');
85         }
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);
93     }
95 }