Sorted hard coded string.
[moodle-linuxchix.git] / admin / process_email.php
blob66d5f855536f1a1118f0f9fa5794d4cad9b008f2
1 #!/usr/bin/php -f
2 <?
3 define('FULLME','cron'); // prevent warnings
4 //error_reporting(0);
5 //ini_set('display_errors',0);
6 require_once(dirname(dirname(__FILE__)).'/config.php');
7 $tmp = explode('@',$_ENV['RECIPIENT']);
8 $address = $tmp[0];
10 // BOUNCE EMAILS TO NOREPLY
11 if ($_ENV['RECIPIENT'] == $CFG->noreplyaddress) {
12 $user->email = $_ENV['SENDER'];
14 if (!validate_email($user->email)) {
15 die();
18 $site = get_site();
19 $subject = get_string('noreplybouncesubject','moodle',$site->fullname);
20 $body = get_string('noreplybouncemessage','moodle',$site->fullname)."\n\n";
22 $fd = fopen('php://stdin','r');
23 if ($fd) {
24 while(!feof($fd)) {
25 $body .= fgets($fd);
27 fclose($fd);
30 $user->id = 0; // to prevent anything annoying happening
32 $from->firstname = null;
33 $from->lastname = null;
34 $from->email = '<>';
35 $from->maildisplay = true;
37 email_to_user($user,$from,$subject,$body);
38 die ();
40 /// ALL OTHER PROCESSING
41 // we need to split up the address
42 $prefix = substr($address,0,4);
43 $mod = substr($address,4,2);
44 $modargs = substr($address,6,-16);
45 $hash = substr($address,-16);
47 if (substr(md5($prefix.$mod.$modargs.$CFG->siteidentifier),0,16) != $hash) {
48 die("HASH DIDN'T MATCH!\n");
50 list(,$modid) = unpack('C',base64_decode($mod.'=='));
52 if ($modid == '0') { // special
53 $modname = 'moodle';
55 else {
56 $modname = get_field("modules","name","id",$modid);
57 require_once('mod/'.$modname.'/lib.php');
59 $function = $modname.'_process_email';
61 if (!function_exists($function)) {
62 die();
64 $fd = fopen('php://stdin','r');
65 if (!$fd) {
66 exit();
69 while(!feof($fd)) {
70 $body .= fgets($fd);
73 $function($modargs,$body);
75 fclose($handle);