File: process_email.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (79 lines) | stat: -rwxr-xr-x 1,843 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/php -f
<?php // $Id: process_email.php,v 1.4 2006/03/07 21:46:33 skodak Exp $
define('FULLME','cron'); // prevent warnings
//error_reporting(0);
//ini_set('display_errors',0);
require_once(dirname(dirname(__FILE__)).'/config.php');
$tmp = explode('@',$_ENV['RECIPIENT']);
$address = $tmp[0];

// BOUNCE EMAILS TO NOREPLY
if ($_ENV['RECIPIENT'] == $CFG->noreplyaddress) {
    $user->email = $_ENV['SENDER'];

    if (!validate_email($user->email)) {
        die();
    }
    
    $site = get_site();
    $subject = get_string('noreplybouncesubject','moodle',$site->fullname);
    $body = get_string('noreplybouncemessage','moodle',$site->fullname)."\n\n";
    
    $fd = fopen('php://stdin','r');
    if ($fd) {
        while(!feof($fd)) {
            $body .=  fgets($fd);
        }
        fclose($fd);
    }
    
    $user->id = 0; // to prevent anything annoying happening
    
    $from->firstname = null;
    $from->lastname = null;
    $from->email = '<>';
    $from->maildisplay = true;
    
    email_to_user($user,$from,$subject,$body);
    die ();
}
/// ALL OTHER PROCESSING
// we need to split up the address
$prefix = substr($address,0,4);
$mod = substr($address,4,2);
$modargs = substr($address,6,-16);
$hash = substr($address,-16);

if (substr(md5($prefix.$mod.$modargs.$CFG->siteidentifier),0,16) != $hash) {
    die("HASH DIDN'T MATCH!\n");
}
list(,$modid) = unpack('C',base64_decode($mod.'=='));

if ($modid == '0') { // special
    $modname = 'moodle';
}
else {
    $modname = get_field("modules","name","id",$modid);
    require_once('mod/'.$modname.'/lib.php');
}
$function = $modname.'_process_email';

if (!function_exists($function)) {
    die(); 
}
$fd = fopen('php://stdin','r');
if (!$fd) {
    exit();
}

while(!feof($fd)) {
    $body .= fgets($fd);
}

$function($modargs,$body); 

fclose($handle);



?>