1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Free Mail |
---|
4 | Version: 1.0.5 |
---|
5 | Description: Plugin modifie l entete des mails en cas de SPAM |
---|
6 | Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=309 |
---|
7 | Author: cljosse |
---|
8 | Author URI:http://cljosse.e3b.org |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | define('Free_Mail_DIR' , basename(dirname(__FILE__))); |
---|
13 | define('Free_Mail_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
14 | include_once (Free_Mail_PATH.'include/constants.php'); |
---|
15 | |
---|
16 | /* |
---|
17 | add_event_handler('send_mail_headers','clj_send_mail_headers' ) ; |
---|
18 | function clj_send_mail_headers($headers) |
---|
19 | { |
---|
20 | echo '<pre>'; |
---|
21 | print_r($headers) ; |
---|
22 | echo '</pre>' ; |
---|
23 | } |
---|
24 | |
---|
25 | add_event_handler('send_mail_to', 'clj_send_mail_to'); |
---|
26 | function clj_send_mail_to($mailto) |
---|
27 | { |
---|
28 | echo '<pre>'; |
---|
29 | //print_r($mailto) ; |
---|
30 | echo '</pre>' ; |
---|
31 | } |
---|
32 | |
---|
33 | add_event_handler('send_mail_content', 'clj_send_mail_content'); |
---|
34 | function clj_send_mail_content($content) |
---|
35 | { |
---|
36 | echo '<pre>'; |
---|
37 | //print_r($content) ; |
---|
38 | echo '</pre>' ; |
---|
39 | } |
---|
40 | |
---|
41 | */ |
---|
42 | // trigger_event('send_mail_to', get_strict_email_list($to)), |
---|
43 | // add_event_handler('send_mail_to', 'clj_send_mail_to'); |
---|
44 | /*function clj_send_mail_to($mailto) |
---|
45 | { |
---|
46 | |
---|
47 | $to=get_strict_email_list($mailto); |
---|
48 | echo '<pre>'; |
---|
49 | print_r($mailto) ; |
---|
50 | print_r( $to); |
---|
51 | echo '</pre>' ; |
---|
52 | |
---|
53 | |
---|
54 | } |
---|
55 | EVENT_HANDLER_PRIORITY_NEUTRAL */ |
---|
56 | |
---|
57 | add_event_handler('send_mail', 'clj_send_mail',1 , 6); |
---|
58 | |
---|
59 | function clj_send_mail($result, $mailto, $subject, $content, $headers, $args) |
---|
60 | { |
---|
61 | global $conf, $user, $lang_info, $conf_mail; |
---|
62 | |
---|
63 | $infos=Get_données(); |
---|
64 | |
---|
65 | $nbenv = $infos->nbenv ; |
---|
66 | $next_day = $infos->next_day ; |
---|
67 | $reste = $infos->reste ; |
---|
68 | $quarantaine = $infos->quarantaine ; |
---|
69 | $admins = $infos->admins ; |
---|
70 | |
---|
71 | $ret="Attente de déblocage SPAMS " ; |
---|
72 | |
---|
73 | |
---|
74 | //================= réécriture de l'entête =============================== |
---|
75 | |
---|
76 | if (!isset( $mailto)){ echo 'erreur maito absent'; exit(); } |
---|
77 | if (empty( $mailto)) { |
---|
78 | /* |
---|
79 | echo '<pre> |
---|
80 | ------------------------------------------------------------------- |
---|
81 | CONF_MAIL |
---|
82 | '; |
---|
83 | print_r($conf_mail) ; |
---|
84 | echo '<pre> |
---|
85 | ------------------------------------------------------------------- |
---|
86 | ARGS |
---|
87 | '; |
---|
88 | print_r($args) ; |
---|
89 | echo '</pre>' ; |
---|
90 | */ |
---|
91 | |
---|
92 | //$mailto=$conf_mail['email_webmaster']; |
---|
93 | //$mailto=""; |
---|
94 | |
---|
95 | $headers = 'From: '.$args['from']."\n"; |
---|
96 | $headers.= 'Reply-To: '.$args['from']."\n"; |
---|
97 | |
---|
98 | if (!empty($args['Cc'])) |
---|
99 | { |
---|
100 | // $headers.= 'Cc: '.implode(',', $args['Cc'])." \n"; |
---|
101 | $headers.= 'Cc: '.implode(',', $admins)." \n"; |
---|
102 | } |
---|
103 | if (!empty($args['Bcc'])) |
---|
104 | { |
---|
105 | // $headers.= 'Bcc: '.implode(',', $args['Bcc'])." \n"; |
---|
106 | $headers.= 'Bcc: '.implode(',', $admins)." \n"; |
---|
107 | } |
---|
108 | $headers.= 'Content-Type: multipart/alternative;'."\n"; |
---|
109 | $headers.= ' boundary="---='.$conf_mail['boundary_key'].'";'."\n"; |
---|
110 | $headers.= ' reply-type=original'."\n"; |
---|
111 | $headers.= 'MIME-Version: 1.0'."\n"; |
---|
112 | $headers.= 'X-Mailer: Piwigo Mailer'."\n"; |
---|
113 | /* |
---|
114 | echo '<pre> |
---|
115 | ------------------------------------------------------------------- |
---|
116 | headers |
---|
117 | '; |
---|
118 | print_r($headers) ; |
---|
119 | echo '</pre>' ; |
---|
120 | */ |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | $ret=false; |
---|
125 | if ( $reste <=0 ) { |
---|
126 | ob_start(); |
---|
127 | $ret = mail($mailto, $subject, $content, $headers); |
---|
128 | $message = ob_get_contents()."\n"; |
---|
129 | |
---|
130 | |
---|
131 | //ob_flush(); |
---|
132 | ob_end_clean(); |
---|
133 | //Trop de spam |
---|
134 | $pos = strpos($message, 'spam'); |
---|
135 | $query = ' |
---|
136 | UPDATE '.FREE_MAIL_TABLE.' |
---|
137 | SET message="'. $message.'. " |
---|
138 | ;'; |
---|
139 | pwg_query($query); |
---|
140 | |
---|
141 | if ($pos === false) { |
---|
142 | if ($nbenv==0) { |
---|
143 | $dateenv=time(); |
---|
144 | $query = ' |
---|
145 | UPDATE '.FREE_MAIL_TABLE.' |
---|
146 | SET dateenv="'. $dateenv.'" |
---|
147 | ;'; |
---|
148 | pwg_query($query); |
---|
149 | } |
---|
150 | $next_day = time() + (0); //20 secondes |
---|
151 | $query = ' |
---|
152 | UPDATE '.FREE_MAIL_TABLE.' |
---|
153 | SET date_check="'. $next_day .'" |
---|
154 | ;'; |
---|
155 | pwg_query($query); |
---|
156 | |
---|
157 | $nbenv += 1; |
---|
158 | $query = ' |
---|
159 | UPDATE '.FREE_MAIL_TABLE.' |
---|
160 | SET nbenv="'. $nbenv.'" |
---|
161 | ;'; |
---|
162 | pwg_query($query); |
---|
163 | |
---|
164 | |
---|
165 | if ($ret) { |
---|
166 | |
---|
167 | return $ret; |
---|
168 | |
---|
169 | } |
---|
170 | echo '<pre>'; |
---|
171 | echo ' |
---|
172 | ---- La fonction mail à retournée [false] ------ |
---|
173 | '; |
---|
174 | |
---|
175 | |
---|
176 | echo 'mailto: '.$mailto.' |
---|
177 | '; |
---|
178 | echo ' |
---|
179 | -------- MESSAGE ----------------- |
---|
180 | '; |
---|
181 | print_r($message) ; |
---|
182 | echo ' |
---|
183 | --------HEADERS ----------------- |
---|
184 | '; |
---|
185 | print_r($headers) ; |
---|
186 | echo ' |
---|
187 | --------CONTENT ----------------- |
---|
188 | '; |
---|
189 | print_r($content) ; |
---|
190 | echo '</pre>' ; |
---|
191 | exit(); |
---|
192 | |
---|
193 | } else { |
---|
194 | echo $message; |
---|
195 | $ret=false; |
---|
196 | } |
---|
197 | //================================================================== |
---|
198 | |
---|
199 | if ($ret) { |
---|
200 | return $ret; |
---|
201 | }else{ |
---|
202 | $next_day = time() + (2 * 24 * 60 * 60); |
---|
203 | echo "Attention defaut d'envoie de mails " .$ret. "\n" ; |
---|
204 | $query = ' |
---|
205 | UPDATE '.FREE_MAIL_TABLE.' |
---|
206 | SET date_check="'. $next_day.'" |
---|
207 | ;'; |
---|
208 | pwg_query($query); |
---|
209 | $reste=($next_day-time()) /3600 ; |
---|
210 | exit(); |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | }else{ |
---|
216 | |
---|
217 | /* echo '<pre>'; |
---|
218 | print_r ($headers); |
---|
219 | print_r($content ); |
---|
220 | echo '</pre>'; |
---|
221 | */ |
---|
222 | |
---|
223 | |
---|
224 | if ($reste >= 1) { |
---|
225 | echo '<pre>'; |
---|
226 | print "Attention il ya eu un défaut d'envoie de mails encore |
---|
227 | ". (int ) $reste . "H |
---|
228 | avant le déblocage." ; |
---|
229 | } |
---|
230 | else{echo '<pre>'; |
---|
231 | print "Il faut attendre au minimun 20 sec avent un deuxième envoie encore avant le déblocage." ; |
---|
232 | } |
---|
233 | |
---|
234 | echo '</pre>'; |
---|
235 | echo ' |
---|
236 | <a href="admin.php">RETOUR </a> |
---|
237 | '; |
---|
238 | |
---|
239 | echo "Dernier message :".$message. " reçu."; |
---|
240 | |
---|
241 | exit(); |
---|
242 | |
---|
243 | echo 'ARGS: '; |
---|
244 | print_r($args) ; |
---|
245 | echo ' |
---|
246 | ---------------------------------------------------- |
---|
247 | MAIL TO: |
---|
248 | ' ; |
---|
249 | print_r($mailto) ; |
---|
250 | |
---|
251 | echo ' |
---|
252 | ---------------------------------------------------- |
---|
253 | HEADER |
---|
254 | ' ; |
---|
255 | print_r($headers) ; |
---|
256 | echo ' |
---|
257 | ---------------------------------------------------- |
---|
258 | content |
---|
259 | ' ; |
---|
260 | |
---|
261 | print_r($content) ; |
---|
262 | echo '</pre>' ; |
---|
263 | |
---|
264 | |
---|
265 | } |
---|
266 | |
---|
267 | |
---|
268 | } |
---|
269 | |
---|
270 | //================================================================================= |
---|
271 | function Get_colonne_de($table) |
---|
272 | { |
---|
273 | $columns_of = array(); |
---|
274 | $query = 'DESC '.$table.';'; |
---|
275 | $result = mysql_query($query); |
---|
276 | $columns_of[$table] = array(); |
---|
277 | while ($row = mysql_fetch_row($result)) |
---|
278 | { |
---|
279 | array_push($columns_of[$table], $row[0]); |
---|
280 | } |
---|
281 | return $columns_of; |
---|
282 | } |
---|
283 | |
---|
284 | function Get_données() |
---|
285 | { |
---|
286 | global $conf, $user; |
---|
287 | |
---|
288 | $nb = Get_colonne_de(FREE_MAIL_TABLE); |
---|
289 | $table=$nb[FREE_MAIL_TABLE]; |
---|
290 | //================================================================================ |
---|
291 | if (!in_array( "nbenv",$table)) { |
---|
292 | $query = "ALTER TABLE `".FREE_MAIL_TABLE."` ADD `nbenv` smallint(5) NOT NULL default '0' "; |
---|
293 | pwg_query($query); } |
---|
294 | if (!in_array( "dateenv",$table)) { |
---|
295 | $query = "ALTER TABLE `".FREE_MAIL_TABLE."` ADD `dateenv` INT NOT NULL default '0' "; |
---|
296 | pwg_query($query); } |
---|
297 | if (!in_array( "quarantaine",$table)) { |
---|
298 | $query = "ALTER TABLE `".FREE_MAIL_TABLE."` ADD `quarantaine` bool NOT NULL "; |
---|
299 | pwg_query($query); } |
---|
300 | if (!in_array( "message",$table)) { |
---|
301 | $query = "ALTER TABLE `".FREE_MAIL_TABLE."` ADD `message` TEXT "; |
---|
302 | pwg_query($query); } |
---|
303 | $query = " |
---|
304 | SELECT COUNT(*) |
---|
305 | FROM ".FREE_MAIL_TABLE." |
---|
306 | ;"; |
---|
307 | //============================================================================== |
---|
308 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
309 | if ($count == 0) |
---|
310 | { |
---|
311 | $next_day = time() ; |
---|
312 | $date_check=''; |
---|
313 | $q = ' |
---|
314 | INSERT INTO '.FREE_MAIL_TABLE.' (id,nbenv, date_check,dateenv, quarantaine,message) |
---|
315 | VALUES (1,0,"'. $next_day.'","'. $next_day.'" ,false,".") |
---|
316 | ;'; |
---|
317 | pwg_query($q); |
---|
318 | } |
---|
319 | |
---|
320 | |
---|
321 | $query = " |
---|
322 | SELECT * |
---|
323 | FROM ".FREE_MAIL_TABLE." |
---|
324 | ;"; |
---|
325 | $data = mysql_fetch_array(pwg_query($query)); |
---|
326 | // limite 2000 par semaine. |
---|
327 | |
---|
328 | $infos->nbenv = $data['nbenv']; |
---|
329 | $infos->next_day = $data['date_check']; |
---|
330 | |
---|
331 | $infos->reste =(float) ( $data['date_check'] - time())/3600 ; |
---|
332 | |
---|
333 | $infos->quarantaine = $data['quarantaine']; |
---|
334 | $infos->message = $data['message']; |
---|
335 | //============================================================ |
---|
336 | |
---|
337 | $admins = array(); |
---|
338 | |
---|
339 | $query = ' |
---|
340 | select |
---|
341 | U.'.$conf['user_fields']['username'].' as username, |
---|
342 | U.'.$conf['user_fields']['email'].' as mail_address |
---|
343 | from |
---|
344 | '.USERS_TABLE.' as U, |
---|
345 | '.USER_INFOS_TABLE.' as I |
---|
346 | where |
---|
347 | I.user_id = U.'.$conf['user_fields']['id'].' and |
---|
348 | I.status in (\'webmaster\', \'admin\') and |
---|
349 | I.adviser = \'false\' and |
---|
350 | '.$conf['user_fields']['email'].' is not null and |
---|
351 | I.user_id <> '.$user['id'].' |
---|
352 | order by |
---|
353 | username |
---|
354 | '; |
---|
355 | |
---|
356 | $datas = pwg_query($query); |
---|
357 | if (!empty($datas)) |
---|
358 | { |
---|
359 | while ($admin = mysql_fetch_array($datas)) |
---|
360 | { |
---|
361 | if (!empty($admin['mail_address'])) |
---|
362 | { |
---|
363 | // array_push($admins, format_email($admin['username'], $admin['mail_address'])); |
---|
364 | $temp= $admin['mail_address'] ; |
---|
365 | array_push($admins,$temp); |
---|
366 | } |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | if (count($admins) > 0) |
---|
371 | { |
---|
372 | |
---|
373 | } |
---|
374 | $infos->admins = $admins ; |
---|
375 | return $infos; |
---|
376 | //======================================================================== |
---|
377 | echo '<pre>'; |
---|
378 | echo FREE_MAIL_TABLE; |
---|
379 | echo ' |
---|
380 | ----------- ADMINS ---------------------------------------- |
---|
381 | '; |
---|
382 | print_r ($admins); |
---|
383 | echo ' |
---|
384 | ------------------------------------------------------------------- |
---|
385 | '; |
---|
386 | print_r ($infos); |
---|
387 | echo '</pre>'; |
---|
388 | |
---|
389 | |
---|
390 | |
---|
391 | |
---|
392 | } |
---|
393 | |
---|
394 | ?> |
---|