forked from cfortune/PHP-Bounce-Handler
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmdlinetest.php
72 lines (64 loc) · 1.99 KB
/
cmdlinetest.php
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
<?php
require_once('bounce_driver.class.php');
$total = array();
function checkmail($email) {
global $total;
$bh = new Bouncehandler();
$bounceinfo = $bh->get_the_facts($email);
# var_export($bounceinfo);
# var_export($bh);
print " TYPE ". @$bh->type. "\n";
if ($bh->type == 'bounce') {
print " ACTION ". $bounceinfo[0]['action']. "\n";
print " STATUS ". $bounceinfo[0]['status']. "\n";
print " RECIPIENT ". $bounceinfo[0]['recipient']. "\n";
}
if ($bh->type == 'fbl') {
print " ENV FROM ". @$bh->fbl_hash['Original-mail-from']. "\n";
print " AGENT ". @$bh->fbl_hash['User-agent']. "\n";
print " IP ". @$bh->fbl_hash['Source-ip']. "\n";
}
if ($bh->type == 'autoresponse') {
print " AUTO ". $bounceinfo[0]['autoresponse']. "\n";
}
if ($bh->type)
@$total[$bh->type]++;
else
@$total['unknown']++;
print "\n";
}
if (defined('STDIN')) {
if (count($argv) > 1) {
for ($i = 1; $i < count($argv); $i++) {
if (is_dir($argv[$i])) {
$dh = opendir($argv[$i]);
$fns = array();
while ($fn = readdir($dh))
if ($fn[0] !== '.' && !is_dir($argv[1]. '/'. $fn))
$fns[] = $argv[1]. '/'. $fn;
closedir($dh);
foreach (sort($fns) as $fn) {
$email = file_get_contents($fn);
print "$fn\n";
checkmail($email);
}
}
else {
$email = file_get_contents($argv[$i]);
print $argv[$i]."\n";
checkmail($email);
}
}
}
else {
$handle = fopen("php://stdin","r");
$email = stream_get_contents($handle);
fclose($handle);
checkmail($email);
}
# and the results
foreach ($total as $t => $v) {
printf("%-15s %6d\n", $t, $v);
}
}
?>