forked from rbairwell/PHP-Bounce-Handler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmdlinetest.php
88 lines (81 loc) · 2.32 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Command line test utility
*
* PHP version 5
*
* @category Email
* @package BounceHandler
* @author Multiple <[email protected]>
* @license http://opensource.org/licenses/BSD-2-Clause BSD
* @link https://github.com/cfortune/PHP-Bounce-Handler/
*/
require_once'bounce_driver.class.php';
$total = array();
/**
* Check an email.
*
* @param string $email Contents of an email to check
*
* @return void
*/
function checkmail($email)
{
global $total;
$bh = new Bouncehandler();
$bounceinfo = $bh->get_the_facts($email);
// var_dump($bounceinfo);
// var_dump($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]);
while ($fn = readdir($dh)) {
if (substr($fn, 0, 1) !== '.') {
$email = file_get_contents($argv[$i] . '/' . $fn);
print $argv[$i] . "/$fn\n";
checkmail($email);
}
}
closedir($dh);
} 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);
}
/**
* Now show the results
*/
foreach ($total as $t => $v) {
printf("%-15s %6d\n", $t, $v);
}
}