source: extensions/Mail_supervisor/main.inc.php @ 4045

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

[mail_supervisor] Modification gestion reprise spam

File size: 9.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24/*
25Plugin Name: Mail supervisor
26Version: 1.1.1
27Description:  Mail supervisor surveille l'envoie des mails.
28Plugin URI: http://piwigo.org/ext/extension_view.php?eid=315
29Author: cljosse
30Author URI:http://cljosse.e3b.org
31*/
32
33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
34
35if (!defined('MAILl_SUPERV_DIR')) define('MAILl_SUPERV_DIR' , basename(dirname(__FILE__)));
36if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
37
38include_once (MAIL_SUPERV_PATH.'include/constants.php'); 
39include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); 
40
41/*
42EVENT_HANDLER_PRIORITY_NEUTRAL  */
43
44add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 1 , 6);
45
46function clj_mail($result, $mailto, $subject, $content, $headers, $args)
47{
48    global $conf, $user, $lang_info,  $conf_mail,$mails_options,$mails_données , $template,$page ,$erreur_message,$infos_message; 
49        // lecture config table -------------
50
51   
52        $mails_options = explode("," , $conf['mail_superv']);
53        $message ="";
54        if (!isset($infos_message))
55        {
56        $infos_message = "";
57        }
58if (!isset($erreur_message))
59        {
60        $erreur_message = '';
61        }
62        // lecture données       -------------
63    $mails_données = Get_Datas();
64
65       
66        $nb_mails         =     $mails_données['nb_mails'] ;
67        $next_day  =  $mails_données['date_mail'] ;
68       
69        $reste =    $mails_données['reste'] ;
70       
71       
72        $rest_mail =    $mails_données['rest_mail'] ;
73        if ($rest_mail <=0 || $mails_données['nb_mails'] ==0 ){
74           $mails_données['nb_mails'] =0 ;
75           $mails_données['date_mail'] = time();
76        }
77       
78        $rest_spam =    $mails_données['rest_spam'] ;
79        if ($rest_spam <=0 || $mails_données['nb_spams'] ==0 ){
80           $mails_données['nb_spams'] =0 ;
81           $mails_données['date_spam'] = time();
82        }
83       
84        $alerte =   ( $mails_données['reste'] >0 ) ? true : false ; 
85       
86        $alerte_mail =    ( $mails_données['nb_mails'] >   $mails_données['nb_mails_maxi']-1 ) ? true : false ;
87        $alerte_spam =    (  $mails_données['nb_spams'] >   $mails_données['nb_spams_maxi']-1 ) ? true : false ;
88       
89 
90 if ( ( !$alerte  && !$alerte_spam  && !$alerte_mail ) ) 
91        {
92                 
93  $nb_destinataires=0;
94                if ($mails_options[0] == 'on') {
95                        if ($mailto == "" )     $mailto = $conf_mail['email_webmaster'];
96                }   
97 if ($mailto<>"" )            $nb_destinataires +=1; 
98 if (!empty($args['Cc']))     $nb_destinataires += count($args['Cc']);
99 if (!empty($args['Bcc']))    $nb_destinataires += count($args['Bcc']);
100   //================= réécriture de l'entête ===============================
101if ( $nb_destinataires  == 1 )
102        {
103                if ($mailto == "" ) 
104                  {
105                 
106                          if (!empty($args['Cc']))  $mailto  = get_strict_email_list(implode(',', $args['Cc'])) ;
107                          if (!empty($args['Bcc'])) $mailto  = get_strict_email_list(implode(',', $args['Bcc'])) ;
108                         
109                                $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers);
110                                $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers);
111                  }
112        }else{
113
114   
115                if (!empty($args['Cc']))
116                        {
117                        if ($mails_options[1] == 'on') {  $headers= corrige_header('Cc',$headers);}
118                        }
119                if (!empty($args['Bcc']))
120                        {   
121                                if ($mails_options[1] == 'on') {  $headers      = corrige_header('Bcc',$headers);}
122                        }
123
124 
125     }
126
127if ($mails_options[2]=='on')   {
128
129        $texte = "This is a multi-part message in MIME format.\n"; 
130       
131        $texte .= "-----=".$conf_mail['boundary_key']."\n"; 
132        $texte .= "Ceci est un message est au format MIME.\n"; 
133        $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; 
134        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
135        $texte .= $mails_données['header_text']; // A voir texte brut...
136           
137                $texte .= "\n\n"; 
138       
139                $content =$texte .$content ;
140}
141 
142$ret=false;
143       
144            //======== Non mise en quarantaine =============
145                ob_start();
146                $ret = false;
147                 if ($nb_destinataires > 0) {
148                   $ret = mail($mailto, $subject, $content, $headers);
149 
150                        }else{
151                           $message .='Nombre de destinataires = 0';
152                        }
153                        $message .= ob_get_contents();
154            ob_end_clean();
155                        $mails_données['message']=$message;     
156                        Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
157               
158       
159       
160        } else {
161
162        //================== Est en quarantaine =======================
163                $erreur_message .=      l10n('To_day_is')."<br />";
164                        if ($alerte_spam ) { 
165                        $type="Spams";
166                               
167                                $d1=$mails_données['nb_spams'] . '  \\  ' . $mails_données['nb_spams_maxi'];
168                                $d2=$mails_données['nb_spams'];
169                                $d3= $mails_données['rest_spam'];
170                                $d4=time()+$d3 ;
171                        } 
172 
173                        if ($alerte_mail) {
174                        $type="Mails";
175                       
176                                $d1=$mails_données['nb_mails']. '  \\  ' . $mails_données['nb_mails_maxi'];;
177                                $d2=$mails_données['date_mail'];
178                                $d3= $mails_données['rest_mail'];
179                                $d4=time()+$d3 ;
180                               
181                               
182                        }
183                        if ($alerte) {
184                        $type="Spams(Quarantaine)";
185                                $d1=$mails_données['nb_spams'] . '  \\  ' . $mails_données['nb_spams_maxi'];
186                                $d2=$mails_données['date_quarantaine'];
187                                $d3= $mails_données['reste'];
188                                $d4=time()+$d3 ;
189                        } 
190
191
192$d2=date(l10n('formatdate'),$d2);
193$d3=int_to_heure($d3) ;
194$d4=date(l10n('formatdate'),$d4);
195
196        if ($alerte_mail) {
197              $erreur_message .='<br />'.sprintf(l10n('alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
198                }else{
199                           $erreur_message .='<br />'.sprintf(l10n('mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
200
201                }
202 $infos_message = l10n('mail_not_send');
203 
204 }                     
205 sauve_données();
206 return true ;
207}
208//===========================================================================================   
209function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto)
210{                       
211         global $conf, $user, $lang_info,  $conf_mail,$mails_options,$mails_données , $template,$page ,$infos_message,$erreur_message,$args; 
212    $match=array("<",">");
213    $string=array("&lt;","&gt;") ;       
214
215       
216        $est_un_spam =!(strpos(strtolower($message), 'spam') === false);
217        $headers=str_replace( $match,$string, $headers); 
218       
219        if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
220                 ;                              // Bad recipient address syntax
221                $pos1 = strpos(strtolower($message), 'bad recipient address syntax');
222                if (  !($pos1 === false) ){
223                        $erreur_message .='Détection de : Bad recipient address syntax .';
224                        $erreur_message .='Vérifiez les destinataires: (Bcc,Cc,To)<br />';
225                        }       
226       
227        $erreur_message .= sprintf(l10n('debug_message %s %s %s %s %s'),($ret==true)? "true" : "false",$message,$mailto,$headers,$nb_destinataires);
228       //=============== La fonction mail à retournéeune erreur =========================               
229
230                               
231                                }       
232                               
233        if ($est_un_spam == false) 
234                        {
235                        if ($mails_données['nb_mails']==0) {    $mails_données['date_mail'] =  time();  }       
236                        $mails_données['nb_mails'] += $nb_destinataires;
237                        }
238                        else
239                        {
240                                $mails_données['nb_spams'] += $nb_destinataires;                       
241                            //--- Détection de spam ------------------
242                                if ($mails_données['nb_spams']==0) {$mails_données['date_spam'] = time();       }
243
244                                $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false);
245                                if ( $trop_de_spam ) {
246                                                $mails_données['nb_spams_maxi']=$mails_données['nb_spams'];
247
248                                                $mails_données['date_quarantaine']= time()  ;   
249                                                $mails_données['quarantaine']= true    ;       
250                                                $infos_message .=memo_var($mails_données);
251                                        }
252
253                        }
254 
255
256 
257
258 
259 $ret=true;
260 return $ret ;
261 
262}
263
264//==========================================================================================
265function admin_menu($menu)
266{
267    array_push($menu, array('NAME' => 'Mail_Superv',
268      'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php')));
269    return $menu;
270}
271
272
273add_event_handler('get_admin_plugin_menu_links', 'admin_menu');
274//add_event_handler('loc_end_page_tail', 'affiche_message');
275add_event_handler('loc_after_page_header', 'affiche_message');
276
277?>
Note: See TracBrowser for help on using the repository browser.