Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

Incoming Message address manager.

Copyright: 2014 Andrew Nicols <andrew@nicols.co.uk>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 485 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

address_manager:: (14 methods):
  set_handler()
  get_handler()
  set_data()
  set_data_key()
  fetch_data_key()
  generate_data_key()
  generate()
  is_correct_format()
  process()
  get_data()
  validate()
  process_envelope()
  handle_message()
  pack_int()


Class: address_manager  - X-Ref

Incoming Message address manager.

set_handler($classname)   X-Ref
Set the handler to use for the subsequent Inbound Message commands.

param: string $classname The name of the class for the handler.

get_handler()   X-Ref
Return the active handler.

return: \core\message\inbound\handler|null;

set_data($datavalue, $datakey = null)   X-Ref
Specify an integer data item value for this record.

param: int $datavalue The value of the data item.
param: string $datakey A hash to use for the datakey

set_data_key($datakey = null)   X-Ref
Specify a known data key for this data item.

If specified, the datakey must already exist in the messageinbound_datakeys
table, typically as a result of a previous Inbound Message setup.

This is intended as a performance optimisation when sending many
e-mails with different data to many users.

param: string $datakey A hash to use for the datakey

fetch_data_key()   X-Ref
Return the data key for the data item.

If no data key has been defined yet, this will call generate_data_key() to generate a new key on the fly.
return: string The secret key for this data item.

generate_data_key()   X-Ref
Generate a new secret key for the current data item and handler combination.

return: string The new generated secret key for this data item.

generate($userid, $userkey = null)   X-Ref
Generate an e-mail address for the Inbound Message handler, storing a private
key for the data object if one was not specified.

param: int $userid The ID of the user to generated an address for.
param: string $userkey The unique key for this user. If not specified this will be retrieved using
return: string|null The generated address, or null if an address could not be generated.

is_correct_format($address)   X-Ref
Determine whether the supplied address is of the correct format.

param: string $address The address to test
return: bool Whether the address matches the correct format

process($address)   X-Ref
Process an inbound address to obtain the data stored within it.

param: string $address The fully formed e-mail address to process.

get_data()   X-Ref
Retrieve the data parsed from the address.

return: \stdClass the parsed data.

validate($address)   X-Ref
Ensure that the parsed data is valid, and if the handler requires address validation, validate the sender against
the user record of identified user record.

param: string $address The fully formed e-mail address to process.
return: int The validation status.

process_envelope($recipient, $sender)   X-Ref
Process the message recipient, load the handler, and then validate
the sender with the associated data record.

param: string $recipient The recipient of the message
param: string $sender The sender of the message

handle_message(\stdClass $messagedata)   X-Ref
Process the message against the relevant handler.

param: \stdClass $messagedata The data for the current message being processed.
return: mixed The result of the handler's message processor. A truthy result suggests a successful send.

pack_int($int)   X-Ref
Pack an integer into a pair of 32-bit numbers.

param: int $int The integer to pack
return: string The encoded binary data