/
mailchecker.php
186 lines (162 loc) · 7.37 KB
/
mailchecker.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
# Modified 12/15/2013 by Plugin Review Network
# ------------------------------------------------
# License and copyright:
# See license.txt for license information.
# ------------------------------------------------
include_once('config.php');
# MOD new tables include WP prefix
global $table_prefix;
$infrespsubscribers = $table_prefix.'InfResp_subscribers';
$infresppop3 = $table_prefix.'InfResp_POP3';
# Start checking the mail...
$query = "SELECT * FROM ".$infresppop3." WHERE username != 'username' AND password != 'password'";
$DB_POP3_Result = mysql_query($query) or die("Invalid query: " . mysql_error());
if (mysql_num_rows($DB_POP3_Result) > 0) {
while ($POP3_Result = mysql_fetch_assoc($DB_POP3_Result)) {
$DB_POP_ConfID = $POP3_Result['POP_ConfigID'];
$DB_Pop_Enabled = $POP3_Result['ThisPOP_Enabled'];
$DB_Confirm_Join = $POP3_Result['Confirm_Join'];
$DB_Attached_Responder = $POP3_Result['Attached_Responder'];
$DB_POP3_host = $POP3_Result['host'];
$DB_POP3_port = $POP3_Result['port'];
$DB_POP3_username = $POP3_Result['username'];
$DB_POP3_password = $POP3_Result['password'];
$DB_POP3_mailbox = $POP3_Result['mailbox'];
$DB_HTML_YN = $POP3_Result['HTML_YN'];
$DB_DeleteYN = $POP3_Result['Delete_After_Download'];
$DB_SpamHeader = $POP3_Result['Spam_Header'];
$DB_ConcatMid = $POP3_Result['Concat_Middle'];
$DB_Mail_Type = $POP3_Result['Mail_Type'];
if ($DB_Pop_Enabled == 1) {
$Responder_ID = $DB_Attached_Responder;
$conn = @imap_open("\{$DB_POP3_host:$DB_POP3_port/$DB_Mail_Type/notls}$DB_POP3_mailbox", $DB_POP3_username, $DB_POP3_password);
#or die("Couldn't connect to server: $DB_POP3_host <br>\n");
$headers = 0;
$headers = @imap_headers($conn);
# or die("Couldn't get email headers!");
if ($headers) {
$Num_Emails = sizeof($headers);
for($i = 1; $i <= $Num_Emails; $i++) {
$mailHeader = imap_headerinfo($conn, $i);
$mail_body = imap_fetchbody($conn, $i, 0);
$subject = MakeSafe($mailHeader->subject);
$date = MakeSafe($mailHeader->date);
$mail_body = MakeSafe($mail_body);
$from = $mailHeader->from;
foreach ($from as $id => $object) {
$fromname = $object->personal;
$fromaddress = $object->mailbox . "@" . $object->host;
$fromhost = $object->host;
}
$fromname = preg_replace("/\{.*\}/i", "", $fromname);
$fromname = preg_replace("/\(.*\)/i", "", $fromname);
$fromname = preg_replace("/\[.*\]/i", "", $fromname);
$fromname = preg_replace("/<.*>/i", "", $fromname);
$fromname = MakeSafe($fromname);
$Email_Address = MakeSafe($fromaddress);
$IsEmail = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$",$fromname);
if ($IsEmail == 1) {
$FirstName = $fromname;
$LastName = '';
}
else {
$Comma_List=explode(',',trim($fromname));
$Comma_MaxIndex = sizeof($Comma_List);
if ($Comma_MaxIndex > 1) {
$FirstName = '';
$LastName = $Comma_List[0];
for ($j=1; $j<=$Comma_MaxIndex-1; $j++) {
$FirstName .= ' ';
$FirstName .= $Comma_List[$j];
}
if ($DB_ConcatMid != 1) {
$Space_List = explode(' ',trim($FirstName));
$FirstName = $Space_List[0];
}
}
else {
$Space_List=explode(' ',trim($fromname));
$Space_MaxIndex = sizeof($Space_List);
$LastName = $Space_List[$Space_MaxIndex-1];
if ($DB_ConcatMid == 1) {
# --- Concats middle and first name ---
# print "$DB_ConcatMid - Bleh! <br>\n";
$FirstName = '';
for ($k=0; $k<=$Space_MaxIndex-2; $k++) {
$FirstName .= ' ';
$FirstName .= $Space_List[$k];
}
}
else {$FirstName = $Space_List[0];}
}
}
$FirstName = trim($FirstName);
$LastName = trim($LastName);
preg_match_all("/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/",$mail_body,$matches);
$Capped_IP = sizeof($matches[0]) - 1;
$MailCaptured_IPaddy = $matches[0][$Capped_IP];
$IPaddy = "$MailCaptured_IPaddy (Email guess)";
if ($DB_DeleteYN == 1) {imap_delete($conn, $i);}
$spam_filtered = 0;
if (!(isEmpty($DB_SpamHeader))) {
$pos = strpos($subject, $DB_SpamHeader);
if ($pos === false) {$spam_filtered = 0;}
else {$spam_filtered = 1;}
}
if ((!(UserIsSubscribed($Responder_ID,$Email_Address))) && (!(isInBlacklist($Email_Address))) && ($spam_filtered == 0) && (isEmail($Email_Address))) {
if ($DB_HTML_YN == 1) {$Set_HTML = 1;} else {$Set_HTML = 0;}
# Get responder info
# MOD for updated GetResponder function
if (!(ResponderExists($Responder_ID))) { admin_redirect(); }
$ResponderInfo = GetResponderInfo($Responder_ID);
// $DB_OptMethod = $ResponderInfo['OptinMethod'];
// if ($DB_OptMethod == "Double") {$DB_Confirm_Join = '1'}
// else {$DB_Confirm_Join = '0';}
# Setup the data
$DB_ResponderID = $Responder_ID;
$DB_SentMsgs = '';
$DB_EmailAddress = $Email_Address;
$DB_TimeJoined = time();
$DB_Real_TimeJoined = time();
$CanReceiveHTML = $Set_HTML;
$DB_LastActivity = time();
$DB_FirstName = $FirstName;
$DB_LastName = $LastName;
$DB_IPaddy = $IPaddy;
$DB_ReferralSource = "email join";
$DB_UniqueCode = generate_unique_code();
if ($DB_Confirm_Join == 1) {
# Add a non-confirmed row to the DB
$DB_Confirmed = "0";
$query = "INSERT INTO ".$infrespsubscribers." (ResponderID, SentMsgs, EmailAddress, TimeJoined, Real_TimeJoined, CanReceiveHTML, LastActivity, FirstName, LastName, IP_Addy, ReferralSource, UniqueCode, Confirmed)
VALUES('$DB_ResponderID','$DB_SentMsgs', '$DB_EmailAddress', '$DB_TimeJoined', '$DB_Real_TimeJoined', '$CanReceiveHTML', '$DB_LastActivity', '$DB_FirstName', '$DB_LastName', '$DB_IPaddy', '$DB_ReferralSource', '$DB_UniqueCode', '$DB_Confirmed')";
$DB_result = mysql_query($query) or die("Invalid query: " . mysql_error());
$DB_SubscriberID = mysql_insert_id();
# Send confirmation msg
SendMessageTemplate('templates/messages/subscribe.confirm.txt',$DB_EmailAddress,$ResponderInfo['FromEmail'],$DB_SubscriberID);
}
else {
# Add a confirmed row to the DB
$DB_Confirmed = "1";
$query = "INSERT INTO ".$infrespsubscribers." (ResponderID, SentMsgs, EmailAddress, TimeJoined, Real_TimeJoined, CanReceiveHTML, LastActivity, FirstName, LastName, IP_Addy, ReferralSource, UniqueCode, Confirmed)
VALUES('$DB_ResponderID','$DB_SentMsgs', '$DB_EmailAddress', '$DB_TimeJoined', '$DB_Real_TimeJoined', '$CanReceiveHTML', '$DB_LastActivity', '$DB_FirstName', '$DB_LastName', '$DB_IPaddy', '$DB_ReferralSource', '$DB_UniqueCode', '$DB_Confirmed')";
$DB_result = mysql_query($query) or die("Invalid query: " . mysql_error());
$DB_SubscriberID = mysql_insert_id();
# Send welcome and notification
SendMessageTemplate('templates/messages/subscribe.complete.txt',$DB_EmailAddress,$ResponderInfo['FromEmail'],$DB_SubscriberID);
if ($DB_NotifyOnSub == "1") {
SendMessageTemplate('templates/messages/new_subscriber.notify.txt',$ResponderInfo['FromEmail'],$ResponderInfo['FromEmail']);
}
}
}
}
@imap_expunge($conn);
@imap_close($conn);
}
}
}
}
# Should we disconnect from the DB?
if ($included != TRUE) {DB_disconnect();}
?>