1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* This is a sample callback function for PHPMailer-BMH (Bounce Mail Handler). |
4
|
|
|
* This callback function will echo the results of the BMH processing. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Callback (action) function |
9
|
|
|
* |
10
|
|
|
* @param int $msgnum the message number returned by Bounce Mail Handler |
11
|
|
|
* @param string $bounceType the bounce type: |
12
|
|
|
* 'antispam','autoreply','concurrent','content_reject','command_reject','internal_error','defer','delayed' |
13
|
|
|
* => |
14
|
|
|
* array('remove'=>0,'bounce_type'=>'temporary'),'dns_loop','dns_unknown','full','inactive','latin_only','other','oversize','outofoffice','unknown','unrecognized','user_reject','warning' |
15
|
|
|
* @param string $email the target email address |
16
|
|
|
* @param string $subject the subject, ignore now |
17
|
|
|
* @param string $xheader the XBounceHeader from the mail |
18
|
|
|
* @param boolean $remove remove status, 1 means removed, 0 means not removed |
19
|
|
|
* @param string|boolean $ruleNo Bounce Mail Handler detect rule no. |
20
|
|
|
* @param string|boolean $ruleCat Bounce Mail Handler detect rule category. |
21
|
|
|
* @param int $totalFetched total number of messages in the mailbox |
22
|
|
|
* @param string $body Bounce Mail Body |
23
|
|
|
* @param string $headerFull Bounce Mail Header |
24
|
|
|
* @param string $bodyFull Bounce Mail Body (full) |
25
|
|
|
* |
26
|
|
|
* @return boolean |
27
|
|
|
*/ |
28
|
|
|
function callbackAction($msgnum, $bounceType, $email, $subject, $xheader, $remove, $ruleNo = false, $ruleCat = false, $totalFetched = 0, $body = '', $headerFull = '', $bodyFull = '') |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$currentTime = date('Y-m-d H:i:s', time()); |
31
|
|
|
|
32
|
|
|
$displayData = prepData($email, $bounceType, $remove); |
33
|
|
|
$bounceType = $displayData['bounce_type']; |
34
|
|
|
$emailName = $displayData['emailName']; |
|
|
|
|
35
|
|
|
$emailAddy = $displayData['emailAddy']; |
|
|
|
|
36
|
|
|
$remove = $displayData['remove']; |
37
|
|
|
$removeraw = $displayData['removestat']; |
38
|
|
|
|
39
|
|
|
$msg = $msgnum . ',' . $currentTime . ',' . $ruleNo . ',' . $ruleCat . ',' . $bounceType . ',' . $removeraw . ',' . $email . ',' . $subject; |
40
|
|
|
|
41
|
|
|
$filename = 'logs/bouncelog_' . date('m') . date('Y') . '.csv'; |
42
|
|
|
if (!file_exists($filename)) { |
43
|
|
|
$tmsg = 'Msg#,Current Time,Rule Number,Rule Category,Bounce Type,Status,Email,Subject' . "\n" . $msg; |
44
|
|
|
} else { |
45
|
|
|
$fileContents = file_get_contents($filename); |
46
|
|
|
|
47
|
|
|
if (stripos($fileContents, "\n" . $msgnum . ',') !== false) { |
48
|
|
|
$doPutFile = false; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$tmsg = $msg; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$handle = fopen($filename, 'a'); |
55
|
|
|
if ($handle) { |
56
|
|
|
if (fwrite($handle, $tmsg . "\n") === false) { |
57
|
|
|
echo 'Cannot write message<br />'; |
58
|
|
|
} |
59
|
|
|
fclose($handle); |
60
|
|
|
} else { |
61
|
|
|
echo 'Cannot open file to append<br />'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
echo $msgnum . ': ' . $ruleNo . ' | ' . $ruleCat . ' | ' . $bounceType . ' | ' . $remove . ' | ' . $email . ' | ' . $subject . "<br />\n"; |
65
|
|
|
|
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Function to clean the data from the Callback Function for optimized display |
71
|
|
|
* |
72
|
|
|
* @param $email |
73
|
|
|
* @param $bounce_type |
74
|
|
|
* @param $remove |
75
|
|
|
* |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
function prepData($email, $bounce_type, $remove) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$data['bounce_type'] = trim($bounce_type); |
|
|
|
|
81
|
|
|
$data['email'] = ''; |
82
|
|
|
$data['emailName'] = ''; |
83
|
|
|
$data['emailAddy'] = ''; |
84
|
|
|
$data['remove'] = ''; |
85
|
|
|
if (strpos($email, '<') !== false) { |
86
|
|
|
$pos_start = strpos($email, '<'); |
87
|
|
|
$data['emailName'] = trim(substr($email, 0, $pos_start)); |
88
|
|
|
$data['emailAddy'] = substr($email, $pos_start + 1); |
89
|
|
|
$pos_end = strpos($data['emailAddy'], '>'); |
90
|
|
|
if ($pos_end) { |
91
|
|
|
$data['emailAddy'] = substr($data['emailAddy'], 0, $pos_end); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// replace the < and > able so they display on screen |
96
|
|
|
// replace the < and > able so they display on screen |
97
|
|
|
$email = str_replace(array('<', '>'), array('<', '>'), $email); |
98
|
|
|
|
99
|
|
|
// replace the "TO:<" with nothing |
100
|
|
|
$email = str_ireplace('TO:<', '', $email); |
101
|
|
|
|
102
|
|
|
$data['email'] = $email; |
103
|
|
|
|
104
|
|
|
// account for legitimate emails that have no bounce type |
105
|
|
|
if (trim($bounce_type) == '') { |
106
|
|
|
$data['bounce_type'] = 'none'; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// change the remove flag from true or 1 to textual representation |
110
|
|
|
if (stripos($remove, 'moved') !== false && stripos($remove, 'hard') !== false) { |
111
|
|
|
$data['removestat'] = 'moved (hard)'; |
112
|
|
|
$data['remove'] = '<span style="color:red;">' . 'moved (hard)' . '</span>'; |
113
|
|
|
} elseif (stripos($remove, 'moved') !== false && stripos($remove, 'soft') !== false) { |
114
|
|
|
$data['removestat'] = 'moved (soft)'; |
115
|
|
|
$data['remove'] = '<span style="color:gray;">' . 'moved (soft)' . '</span>'; |
116
|
|
|
} elseif ($remove == true || $remove == '1') { |
117
|
|
|
$data['removestat'] = 'deleted'; |
118
|
|
|
$data['remove'] = '<span style="color:red;">' . 'deleted' . '</span>'; |
119
|
|
|
} else { |
120
|
|
|
$data['removestat'] = 'not deleted'; |
121
|
|
|
$data['remove'] = '<span style="color:gray;">' . 'not deleted' . '</span>'; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $data; |
125
|
|
|
} |
126
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.