Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  #!/usr/bin/php -f
   2  <?php
   3  
   4  //error_reporting(0);
   5  //ini_set('display_errors',0);
   6  require_once(__DIR__ . '/../config.php');
   7  $tmp = explode('@',$_ENV['RECIPIENT']);
   8  $address = $tmp[0];
   9  
  10  // BOUNCE EMAILS TO NOREPLY
  11  if ($_ENV['RECIPIENT'] == $CFG->noreplyaddress) {
  12      $user = new stdClass();
  13      $user->email = $_ENV['SENDER'];
  14  
  15      if (!validate_email($user->email)) {
  16          die();
  17      }
  18  
  19      $site = get_site();
  20      $subject = get_string('noreplybouncesubject','moodle',format_string($site->fullname));
  21      $body = get_string('noreplybouncemessage','moodle',format_string($site->fullname))."\n\n";
  22  
  23      $fd = fopen('php://stdin','r');
  24      if ($fd) {
  25          while(!feof($fd)) {
  26              $body .=  fgets($fd);
  27          }
  28          fclose($fd);
  29      }
  30  
  31      $user->id = 0; // to prevent anything annoying happening
  32  
  33      $from->firstname = null;
  34      $from->lastname = null;
  35      $from->email = '<>';
  36      $from->maildisplay = true;
  37  
  38      email_to_user($user,$from,$subject,$body);
  39      die ();
  40  }
  41  /// ALL OTHER PROCESSING
  42  // we need to split up the address
  43  $prefix = substr($address,0,4);
  44  $mod = substr($address,4,2);
  45  $modargs = substr($address,6,-16);
  46  $hash = substr($address,-16);
  47  
  48  if (substr(md5($prefix.$mod.$modargs.$CFG->siteidentifier),0,16) != $hash) {
  49      die("HASH DIDN'T MATCH!\n");
  50  }
  51  list(,$modid) = unpack('C',base64_decode($mod.'=='));
  52  
  53  if ($modid == '0') { // special
  54      $modname = 'moodle';
  55  }
  56  else {
  57      $modname = $DB->get_field("modules", "name", array("id"=>$modid));
  58      include_once('mod/'.$modname.'/lib.php');
  59  }
  60  $function = $modname.'_process_email';
  61  
  62  if (!function_exists($function)) {
  63      die();
  64  }
  65  $fd = fopen('php://stdin','r');
  66  if (!$fd) {
  67      exit();
  68  }
  69  
  70  while(!feof($fd)) {
  71      $body .= fgets($fd);
  72  }
  73  
  74  $function($modargs,$body);
  75  
  76  fclose($fd);
  77  
  78  
  79  
  80