source: moodle/trunk/fuentes/admin/tool/messageinbound/classes/message/inbound/invalid_recipient_handler.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 3.2 KB
Line 
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/>.
16
17/**
18 * A Handler to re-process messages which previously failed sender
19 * verification.
20 *
21 * @package    task_messageinbound
22 * @copyright  2014 Andrew Nicols
23 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26namespace tool_messageinbound\message\inbound;
27
28defined('MOODLE_INTERNAL') || die();
29
30require_once($CFG->dirroot . '/repository/lib.php');
31
32/**
33 * A Handler to re-process messages which previously failed sender
34 * verification.
35 *
36 * This may happen if the user did not use their registerd e-mail address,
37 * the verification hash used had expired, or if some erroneous content was
38 * introduced into the content hash.
39 *
40 * @package    task
41 * @copyright  2014 Andrew Nicols
42 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 */
44class invalid_recipient_handler extends \core\message\inbound\handler {
45
46    /**
47     * Do not allow changes to the address validation setting.
48     */
49    public function allow_validateaddress_change() {
50        return false;
51    }
52
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    }
61
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    }
71
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;
81
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        }
86
87        mtrace("=== Request to re-process message {$record->datavalue} from server.");
88        mtrace("=== Message-Id:\t{$maildata->messageid}");
89        mtrace("=== Recipient:\t{$maildata->address}");
90
91        $manager = new \tool_messageinbound\manager();
92        return $manager->process_existing_message($maildata);
93    }
94
95}
Note: See TracBrowser for help on using the repository browser.