-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcron.php
More file actions
145 lines (125 loc) · 5.25 KB
/
cron.php
File metadata and controls
145 lines (125 loc) · 5.25 KB
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
<?php
//load rc config file
include('/opt/roundcubemail/config/config.inc.php');
//load config file
include('config.inc.php');
//read all users prefs
preg_match('|([a-z]+)://([^:]*)(:(.*))?@([A-Za-z0-9\.-]*)(/([0-9a-zA-Z_/\.]*))|',
$config['db_dsnw'],$matches);
$dsnArray=array(
$matches[1].':host='.$matches[5].';dbname='.$matches[7],
$matches[2],
$matches[4]
);
$dsn = $dsnArray[0];
$username = $dsnArray[1];
$password = $dsnArray[2];
try {
$conn = new PDO($dsn, $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$requete = $conn->query("SELECT * FROM users;");
foreach($requete->fetchAll() as $personne){
$preferences = unserialize($personne['preferences']);
if (substr($personne['username'],-9) != ".disabled"){
if (isset($preferences['frequency']) && isset($preferences['maxlength'])){
$tabPrefs[$personne['username']] = array("frequency" => $preferences['frequency'], "maxlength" => $preferences['maxlength']);
}else{
$tabPrefs[$personne['username']] = array("frequency" => $config['default_frequency'], "maxlength" => $config['default_maxlength']);
}
}
}
//Read today's date
$monthDay = date('d');
$weekDay = date('l');
if ($weekDay == $config['day_of_weekly_report'])
$weekly = true;
else
$weekly = false;
if ($monthDay == $config['day_of_monthly_report'])
$monthly = true;
else
$monthly = false;
//parse junkdirs and send report
$listeMail = array();
$dir = $config['dir'];
$domaineDirectory = scandir($dir);
$sortedJunkDirectory = array();
$temp = 0;
foreach ($domaineDirectory as $domaine)
{
if ($domaine != '.' && $domaine != '..' && is_dir("$dir/$domaine")){
$userDirectory = scandir("$dir/$domaine");
foreach ($userDirectory as $user)
{
array_splice($listeMail,0);
if ($user != '.' && $user != '..' && is_dir("$dir/$domaine/$user")){
$adresseMail = "$user@$domaine";
if (isset($tabPrefs["$adresseMail"]) && $temp<50){
$preferencesUser = $tabPrefs["$adresseMail"];
$frequency = $preferencesUser["frequency"];
$maxlength = $preferencesUser["maxlength"];
if ($frequency!="never" && file_exists("$dir/$domaine/$user/Maildir/.Junk/cur")&&(($frequency == "weekly" && $weekly)||($frequency=="monthly" && $monthly)||($frequency=="daily"))){
$junkDirectory = scandir("$dir/$domaine/$user/Maildir/.Junk/cur");
array_splice($sortedJunkDirectory,0);
foreach ($junkDirectory as $junk){
$date = filemtime("$dir/$domaine/$user/Maildir/.Junk/cur/$junk");
$sortedJunkDirectory["$date"] = $junk;
}
ksort($sortedJunkDirectory);
$nbMails=1;
$uidFile = file("$dir/$domaine/$user/Maildir/.Junk/dovecot-uidlist");
foreach ($sortedJunkDirectory as $junk)
{
if ($junk != '.' && $junk != '..' && $nbMails<=$maxlength){
$file = file("$dir/$domaine/$user/Maildir/.Junk/cur/$junk");
//Get sender
$sender = substr(preg_grep("/^From:/",$file)[array_keys(preg_grep("/^From:/",$file))[0]],6);
//Get date
if (explode(",",explode(":",preg_grep("/^Date:/",$file)[array_keys(preg_grep("/^Date:/",$file))[0]])[1])){
if (substr(explode(",",explode(":",preg_grep("/^Date:/",$file)[array_keys(preg_grep("/^Date:/",$file))[0]])[1])[1],0,-3))
$date = substr(explode(",",explode(":",preg_grep("/^Date:/",$file)[array_keys(preg_grep("/^Date:/",$file))[0]])[1])[1],0,-3);
else
$date = substr(explode(",",explode(":",preg_grep("/^Date:/",$file)[array_keys(preg_grep("/^Date:/",$file))[0]])[1])[0],0,-3);
}else{
$date = substr(explode(":",preg_grep("/^Date:/",$file)[array_keys(preg_grep("/^Date:/",$file))[0]])[1],0,12);
}
//Get junk_subject
if (preg_grep("/^Subject:/",$file))
$junk_subject = substr(preg_grep("/^Subject:/",$file)[array_keys(preg_grep("/^Subject: /",$file))[0]],9);
else
$junk_subject = $config['no_subject'];
//Get mail uid
$formattedJunk = explode(":","$junk")[0];
$uid = explode(" ",preg_grep("/$formattedJunk/",$uidFile)[array_keys(preg_grep("/$formattedJunk/",$uidFile))[0]])[0];
$mail["sender"]=$sender;
$mail["date"]=$date;
$mail["subject"]=$junk_subject;
$mail["uid"]=$uid;
array_push($listeMail,$mail);
$nbMails++;
}
}
}
if (!empty($listeMail)){
$temp++;
$adresseMail = "test@akiway.com";
$subject = $config['subject'];
$message = '<html><body>';
$message .= '<table style="border:1px solid; border-collapse:collapse"><tr><th>Objet</th><th style="border:1px solid">Envoyé par</th><th>Date</th><th style="border:1px solid">UID</th></tr>';
foreach ($listeMail as $mail){
$message .= '<tr style="border:1px solid"><td>'.$mail["subject"].'</td><td style="border:1px solid">'.$mail["sender"].'</td><td>'.$mail["date"].'</td><td style="border:1px solid"><a href="https://mail3.ircf.fr/?_task=mail&_uid='.$mail["uid"].'&_action=plugin.junk_report.not_junk">Rétablir</a></td></tr>';
}
$message .= '</table></body></html>';
mail($adresseMail,$subject,$message,implode("\r\n", $header));
}
}
}
}
}
}
echo "$temp";