-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
148 lines (124 loc) · 4.85 KB
/
function.php
File metadata and controls
148 lines (124 loc) · 4.85 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
146
147
148
<?php
/*
* Takes the result of the sql query on the basis of roundcube and returns associating for each user its frequency and maxlength.
* If these two values are not defined they are defined by the default value in the config file.
*/
function setPreferencesArray($requete,$config){
foreach ($requete->fetchAll() as $personne){
$personne["preferences"] = preg_replace_callback('!s:(\d+):"(.*?)";!s',
function($m){
$len = strlen($m[2]);
$result = "s:$len:\"{$m[2]}\";";
return $result;
},$personne["preferences"]);
$preferences = unserialize($personne['preferences']);
if (substr($personne['username'],-9) != ".disabled"){
if (isset($preferences['frequency']) && isset($preferences['maxlength'])){
$tab[$personne['username']] = array("frequency" => $preferences['frequency'], "maxlength" => $preferences['maxlength']);
}else{
$tab[$personne['username']] = array("frequency" => $config['default_frequency'], "maxlength" => $config['default_maxlength']);
}
}
}
return $tab;
}
/*
* Formats a dsn of the form mysql://user:pass@hostname/databasename and returns an array(dsn, user, pass) to use PDO.
*/
function formatDSN($dsn){
preg_match('|([a-z]+)://([^:]*)(:(.*))?@([A-Za-z0-9\.-]*)(/([0-9a-zA-Z_/\.]*))|',
$dsn,$matches);
$dsnArray=array(
$matches[1].':host='.$matches[5].';dbname='.$matches[7],
$matches[2],
$matches[4]
);
return $dsnArray;
}
/*
* Match tabPrefs with the list of users retrieved in ispconfig.
* Return an array associating these users with their frequency, their maxlength and their email.
*/
function matchPrefstoEmail($requete_ispc,$tab,$config){
$tabPrefs = array();
foreach($requete_ispc->fetchAll() as $personne){
if (isset($tab[$personne['email']])){
$tabPrefs[$personne['email']] = array("frequency" => $tab[$personne['email']]['frequency'],
"maxlength" => $tab[$personne['email']]['maxlength'],
"maildir" => $personne['maildir']);
}
}
return $tabPrefs;
}
/*
* Get the sender of a mail from his stored file given in parameters.
* Return the sender mail adress
*/
function getSender($file){
$fromLine = preg_grep("/^From:/",$file)[array_keys(preg_grep("/^From:/",$file))[0]];
if (strpos($fromLine,"<")) {
return $sender = substr($fromLine, strpos($fromLine, "<") + 1, strpos($fromLine, ">") - strpos($fromLine, "<") - 1);
} else {
return $sender = substr($fromLine, 6);
}
}
/*
* Get the date of a mail from his stored file given in parameters.
* Return the date translated in French
*/
function getMailDate($file){
if (explode(",",explode(":",preg_grep("/^Date:/",$file)[array_keys(preg_grep("/^Date:/",$file))[0]])[1])){
if (@explode(",",explode(":",preg_grep("/^Date:/",$file)[array_keys(preg_grep("/^Date:/",$file))[0]])[1])[1])
$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);
}
$arrayDate = explode(" ",$date);
$arraySize = count($arrayDate);
$day = $arrayDate[$arraySize-3];
$month = $arrayDate[$arraySize-2];
$year = $arrayDate[$arraySize-1];
$monthTab["Jan"] = "Janvier";
$monthTab["Feb"] = "Fevrier";
$monthTab["Mar"] = "Mars";
$monthTab["Apr"] = "Avril";
$monthTab["May"] = "Mai";
$monthTab["Jun"] = "Juin";
$monthTab["Jul"] = "Juillet";
$monthTab["Aug"] = "Aout";
$monthTab["Sep"] = "Septembre";
$monthTab["Oct"] = "Octobre";
$monthTab["Nov"] = "Novembre";
$monthTab["Dec"] = "Decembre";
$formattedDate = $day." ".$monthTab[$month]." ".$year;
return $formattedDate;
}
/*
* Get the spam-score of a mail from his stored file given in parameters.
* Return the spam-score
*/
function getSpamScore($file){
return substr(preg_grep("/^X-Spam-Score:/",$file)[array_keys(preg_grep("/^X-Spam-Score:/",$file))[0]],14);
}
/*
* Get the uid of a mail from the dovecot-uid file
* Get in parameters the uid-file as array and the name of the mail file
*/
function getUID($uidFile, $junk){
$formattedJunk = explode(":",substr(strrchr("$junk","/"),1))[0];
return explode(" ",preg_grep("/$formattedJunk/",$uidFile)[array_keys(preg_grep("/$formattedJunk/",$uidFile))[0]])[0];
}
/*
* Get the subject of a mail from his stored file given in parameters.
* Return the spam-score or the default value set in the config.
*/
function getSubject($file, $config){
if (preg_grep("/^Subject:/",$file) && !empty(array_keys(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'];
}
return $junk_subject;
}