-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbounces.php
66 lines (55 loc) · 2.08 KB
/
bounces.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
<?php
//error_reporting(-1);
//ini_set('display_errors', 'On');
require_once('config.php');
require_once('db.php');
$url = $redmineBaseUrl . 'issues.json';
$url .= '?project_id=' . $projectId;
$url .= '&status_id=open';
$url .= '&limit=100'; // doesn't work
$url .= '&key=' . $redminapiKey;
$contents = file_get_contents($url);
if ($contents === false) {
exit;
}
$json = json_decode($contents);
$db = new db($dbLang, $dbName);
foreach($json->issues as $issue) {
if (strpos($issue->subject, 'Undelivered Mail Returned to Sender') !== false) {
preg_match("/[<<](\S+@\S+)[>>]/", $issue->description, $found);
$email = $found[1];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// todo: remove them form newsletter
//print_r($db->query("SELECT * FROM users WHERE email = '{$email}'"));
$db->query("DELETE FROM users WHERE email = '{$email}'");
// todo: mark as done
$url = $redmineBaseUrl . 'issues/' . $issue->id . '.json';
$payload = "{\"issue\":{\"status_id\":5,\"notes\":\"automatisiert erledigt.\"}}";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-length: " . strlen($payload),
"content-type: application/json",
"x-redmine-api-key: " . $redminapiKey
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
/*if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}*/
}
}
}