source: extensions/free_mail/main.inc.php @ 3981

Last change on this file since 3981 was 3981, checked in by cljosse, 15 years ago

correctness of management groups

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