Skip to content

Commit 718e65e

Browse files
committed
updated the code to fix a blank email problem
1 parent 7b610d6 commit 718e65e

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

src/ImapAbuseCheck.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ public function __construct($imap_server, $username, $password, $db, $delete_att
8181
}
8282
$this->mb_db = new Db(ZONEMTA_MYSQL_DB, ZONEMTA_MYSQL_USERNAME, ZONEMTA_MYSQL_PASSWORD, ZONEMTA_MYSQL_HOST);
8383
$this->mb_ips = explode("\n", trim(`grep address /home/sites/zone-mta/config/pools.js |cut -d\" -f4`));
84-
$this->mongo_client= new \MongoDB\Client('mongodb://'.ZONEMTA_USERNAME.':'.rawurlencode(ZONEMTA_PASSWORD).'@'.ZONEMTA_HOST.':27017/');
85-
$this->mongo_users = $this->mongo_client->selectDatabase('zone-mta')->selectCollection('users');
86-
$result = $this->mongo_users->find();
87-
foreach ($result as $user)
88-
$this->mb_users[] = $user->username;
84+
try {
85+
$this->mongo_client= new \MongoDB\Client('mongodb://'.ZONEMTA_USERNAME.':'.rawurlencode(ZONEMTA_PASSWORD).'@'.ZONEMTA_HOST.':27017/');
86+
$this->mongo_users = $this->mongo_client->selectDatabase('zone-mta')->selectCollection('users');
87+
$result = $this->mongo_users->find();
88+
foreach ($result as $user)
89+
$this->mb_users[] = $user->username;
90+
} catch (\Exception $e) {
91+
myadmin_log('myadmin', 'error', 'MongoDB '.ZONEMTA_HOST.' down: '.$e->getMessage(), __LINE__, __FILE__);
92+
}
8993
$this->connect();
9094
function_requirements('get_server_from_ip');
9195
}
@@ -270,8 +274,8 @@ public function process($type = 'spam', $limit = false)
270274
}
271275
if (in_array($ip, $this->mb_ips)) {
272276
if (preg_match_all('/Authenticated sender: (?P<user>[^\)]*)\)/ms', $this->plainmsg, $matches) ||
273-
preg_match_all('/smtp.auth=(?P<user>\S*)\s/ms', $this->plainmsg, $matches)) {
274-
foreach ($matches['user'] as $user) {
277+
preg_match_all('/smtp.auth=(?P<user>\S*)\s/ms', $this->plainmsg, $matches)) {
278+
foreach ($matches['user'] as $user) {
275279
if (in_array($user, $this->mb_users)) {
276280
$mbUser = $db->real_escape($user);
277281
$db->query("select * from mail where mail_username='{$mbUser}'");
@@ -285,22 +289,22 @@ public function process($type = 'spam', $limit = false)
285289
];
286290
}
287291
}
288-
}
289-
}
290-
if (preg_match_all('/^ by (\S+|\S+ \(\S+\)) with (LMP|SMTP|ESMTP|ESMTPA|ESMTPS|ESMTPSA|HTTP) id (\S+)\.(\d{3})\s*$/mU', $this->plainmsg, $matches)) {
291-
$ids = $matches[3];
292-
foreach ($ids as $id) {
293-
$id = $this->mb_db->real_escape($id);
294-
$this->mb_db->query("select * from mail_messagestore where id='{$id}'");
295-
if ($this->mb_db->num_rows() > 0) {
292+
}
293+
}
294+
if (preg_match_all('/^ by (\S+|\S+ \(\S+\)) with (LMP|SMTP|ESMTP|ESMTPA|ESMTPS|ESMTPSA|HTTP) id (\S+)\.(\d{3})\s*$/mU', $this->plainmsg, $matches)) {
295+
$ids = $matches[3];
296+
foreach ($ids as $id) {
297+
$id = $this->mb_db->real_escape($id);
298+
$this->mb_db->query("select * from mail_messagestore where id='{$id}'");
299+
if ($this->mb_db->num_rows() > 0) {
296300
$mbId = $id;
297-
}
301+
}
298302
}
299-
}
303+
}
300304
}
301305
if (mb_substr($ip, 0, 10) == '66.45.228.' || (isset($server_data['email']) && $server_data['email'] != '')) {
302306
// if ($this->abused >= 5) exit;
303-
$email = (null === $server_data['email_abuse'] ? $server_data['email'] : $server_data['email_abuse']);
307+
$email = (!isset($server_data['email_abuse']) || is_null($server_data['email_abuse']) || trim($server_data['email_abuse']) == '' ? $server_data['email'] : $server_data['email_abuse']);
304308
$subject = 'InterServer Abuse Report for '.$ip;
305309
if (mb_substr($ip, 0, 10) == '66.45.228.') {
306310
echo "{$this->imap_folder} Overwriting IP $ip Contact $email => abuse@interserver.net".PHP_EOL;

0 commit comments

Comments
 (0)