mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 03:53:37 +00:00
More checks in the bounce cron job.
This commit is contained in:
@@ -25,32 +25,42 @@ class CronController extends Controller
|
|||||||
|
|
||||||
if (strlen(env('SENDGRID_USERNAME')) > 0 && strlen(env('SENDGRID_PASSWORD')) > 0) {
|
if (strlen(env('SENDGRID_USERNAME')) > 0 && strlen(env('SENDGRID_PASSWORD')) > 0) {
|
||||||
|
|
||||||
$URL = 'https://api.sendgrid.com/api/bounces.get.json';
|
$set = [
|
||||||
$parameters = [
|
'blocks' => 'https://api.sendgrid.com/api/blocks.get.json',
|
||||||
'api_user' => env('SENDGRID_USERNAME'),
|
'bounces' => 'https://api.sendgrid.com/api/bounces.get.json',
|
||||||
'api_key' => env('SENDGRID_PASSWORD'),
|
'invalids' => 'https://api.sendgrid.com/api/invalidemails.get.json',
|
||||||
'date' => 1,
|
|
||||||
'days' => 7
|
|
||||||
];
|
|
||||||
$fullURL = $URL . '?' . http_build_query($parameters);
|
|
||||||
$data = json_decode(file_get_contents($fullURL));
|
|
||||||
|
|
||||||
/*
|
];
|
||||||
* Loop the result, if any.
|
echo '<pre>';
|
||||||
*/
|
foreach ($set as $name => $URL) {
|
||||||
if (is_array($data)) {
|
|
||||||
echo 'Found ' . count($data) . ' entries in the SendGrid bounce list.' . "\n";
|
|
||||||
foreach ($data as $entry) {
|
$parameters = [
|
||||||
$address = $entry->email;
|
'api_user' => env('SENDGRID_USERNAME'),
|
||||||
$user = User::where('email', $address)->where('blocked', 0)->first();
|
'api_key' => env('SENDGRID_PASSWORD'),
|
||||||
if (!is_null($user)) {
|
'date' => 1,
|
||||||
echo 'Found a user: ' . $address . ', who is now blocked.' . "\n";
|
'days' => 7
|
||||||
$user->blocked = 1;
|
];
|
||||||
$user->blocked_code = 'bounced';
|
$fullURL = $URL . '?' . http_build_query($parameters);
|
||||||
$user->password = 'bounced';
|
$data = json_decode(file_get_contents($fullURL));
|
||||||
$user->save();
|
|
||||||
} else {
|
/*
|
||||||
echo 'Found no user: ' . $address . ', did nothing.' . "\n";
|
* Loop the result, if any.
|
||||||
|
*/
|
||||||
|
if (is_array($data)) {
|
||||||
|
echo 'Found ' . count($data) . ' entries in the SendGrid ' . $name . ' list.' . "\n";
|
||||||
|
foreach ($data as $entry) {
|
||||||
|
$address = $entry->email;
|
||||||
|
$user = User::where('email', $address)->where('blocked', 0)->first();
|
||||||
|
if (!is_null($user)) {
|
||||||
|
echo 'Found a user: ' . $address . ', who is now blocked.' . "\n";
|
||||||
|
$user->blocked = 1;
|
||||||
|
$user->blocked_code = 'bounced';
|
||||||
|
$user->password = 'bounced';
|
||||||
|
$user->save();
|
||||||
|
} else {
|
||||||
|
echo 'Found no user: ' . $address . ', did nothing.' . "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user