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

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

[mail_supervisor] update design black list

File size: 9.9 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.2.4
27Description:  Mail supervisor surveille l'envoie des mails.
28Plugin URI: http://piwigo.org/ext/extension_view.php?eid=315
29Author: cljosse
30Author URI:http://cl.josse.free.fr
31*/
32
33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
34
35if (!defined('MAIL_SUPERV_DIR')) define('MAIL_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, $lang; 
49        // lecture config table -------------
50 load_language('plugin.lang', MAIL_SUPERV_PATH);
51   
52   
53        $mails_options = explode("," , $conf['mail_superv']);
54       
55        if ($mails_options[3]=='on')
56        {
57                if (kill_list())
58                 {
59                    $erreur_message .= l10n('is_a_spam') ;
60                        return true;
61                 }
62        }
63       
64        $message ="";
65        if (!isset($infos_message))
66        {
67        $infos_message = "";
68        }
69if (!isset($erreur_message))
70        {
71        $erreur_message = '';
72        }
73        // lecture données       -------------
74    $mails_données = Get_Datas();
75
76       
77        $nb_mails         =     $mails_données['nb_mails'] ;
78        $next_day  =  $mails_données['date_mail'] ;
79       
80        $reste =    $mails_données['reste'] ;
81       
82       
83        $rest_mail =    $mails_données['rest_mail'] ;
84        if ($rest_mail <=0 || $mails_données['nb_mails'] ==0 ){
85           $mails_données['nb_mails'] =0 ;
86           $mails_données['date_mail'] = time();
87        }
88       
89        $rest_spam =    $mails_données['rest_spam'] ;
90        if ($rest_spam <=0 || $mails_données['nb_spams'] ==0 ){
91           $mails_données['nb_spams'] =0 ;
92           $mails_données['date_spam'] = time();
93        }
94       
95        $alerte =   ( $mails_données['reste'] >0 ) ? true : false ; 
96       
97        $alerte_mail =    ( $mails_données['nb_mails'] >   $mails_données['nb_mails_maxi']-1 ) ? true : false ;
98        $alerte_spam =    (  $mails_données['nb_spams'] >   $mails_données['nb_spams_maxi']-1 ) ? true : false ;
99       
100 
101 if ( ( !$alerte  && !$alerte_spam  && !$alerte_mail ) ) 
102        {
103                 
104  $nb_destinataires=0;
105                if ($mails_options[0] == 'on') {
106                        if ($mailto == "" )     $mailto = $conf_mail['email_webmaster'];
107                }   
108 if ($mailto<>"" )            $nb_destinataires +=1; 
109
110                if (!empty($args['Bcc']))  { 
111                        $nb_destinataires += count($args['Bcc']); 
112                        } 
113                if (!empty($args['Cc']))  {   
114                        $nb_destinataires += count($args['Cc']); 
115                        }
116   //================= réécriture de l'entête ===============================
117if ( $nb_destinataires  == 1 )
118        {
119                if ($mailto == "" ) 
120                  {
121                          if (!empty($args['Cc']) and count($args['Cc']) > 0 )  $mailto  = get_strict_email_list(implode(',', $args['Cc'])) ;
122                          if (!empty($args['Bcc']) and count($args['Bcc']) > 0 ) $mailto  = get_strict_email_list(implode(',', $args['Bcc'])) ;
123                         
124                                $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers);
125                                $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers);
126                               
127                  }
128        }else{
129   
130 
131     }
132
133//=============================================================================         
134if (!empty($args['Cc']))
135                        {
136                         $headers= corrige_header('Cc',$headers,$args);
137                        }
138                if (!empty($args['Bcc']))
139                        {   
140                                   $headers     = corrige_header('Bcc',$headers,$args); 
141                        }
142//=============================================================================                 
143if ($mails_options[2]=='on')   {
144
145        $texte = "This is a multi-part message in MIME format.\n"; 
146       
147        $texte .= "-----=".$conf_mail['boundary_key']."\n"; 
148        $texte .= "Ceci est un message est au format MIME.\n"; 
149        $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; 
150        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
151        $texte .= $mails_données['header_text']; // A voir texte brut...
152           
153                $texte .= "\n\n"; 
154       
155                $content =$texte .$content ;
156}
157 
158$ret=false;
159       
160            //======== Non mise en quarantaine =============
161                ob_start();
162                $ret = false;
163                 if ($nb_destinataires > 0) {
164                   $ret = mail($mailto, $subject, $content, $headers);
165
166                        }else{
167                           $message .= l10n('no_receiver_available');
168                        }
169                        $message .= ob_get_contents();
170            ob_end_clean();
171                        $mails_données['message']=$message;     
172                        Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
173               
174       
175       
176        } else {
177
178        //================== Est en quarantaine =======================
179                $erreur_message .=      l10n('To_day_is')."<br />";
180                        if ($alerte_spam ) { 
181                        $type="Spams";
182                               
183                                $d1=$mails_données['nb_spams'] . '  \\  ' . $mails_données['nb_spams_maxi'];
184                                $d2=$mails_données['nb_spams'];
185                                $d3= $mails_données['rest_spam'];
186                                $d4=time()+$d3 ;
187                        } 
188 
189                        if ($alerte_mail) {
190                        $type="Mails";
191                       
192                                $d1=$mails_données['nb_mails']. '  \\  ' . $mails_données['nb_mails_maxi'];;
193                                $d2=$mails_données['date_mail'];
194                                $d3= $mails_données['rest_mail'];
195                                $d4=time()+$d3 ;
196                               
197                               
198                        }
199                        if ($alerte) {
200                        $type="Spams(Quarantaine)";
201                                $d1=$mails_données['nb_spams'] . '  \\  ' . $mails_données['nb_spams_maxi'];
202                                $d2=$mails_données['date_quarantaine'];
203                                $d3= $mails_données['reste'];
204                                $d4=time()+$d3 ;
205                        } 
206
207
208$d2=date(l10n('formatdate'),$d2);
209$d3=int_to_heure($d3) ;
210$d4=date(l10n('formatdate'),$d4);
211
212        if ($alerte_mail) {
213              $erreur_message .='<br />'.sprintf(l10n('alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
214                }else{
215                           $erreur_message .='<br />'.sprintf(l10n('mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
216
217                }
218 $infos_message = l10n('mail_not_send');
219 
220 }                     
221 sauve_données();
222 return true ;
223}
224//===========================================================================================   
225function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto)
226{                       
227         global $conf, $user,  $conf_mail,$mails_options,$mails_données , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; 
228
229         
230         
231    $match=array("<",">");
232    $string=array("&lt;","&gt;") ;       
233
234//Warning: mail() has been disabled for security reasons
235       
236        $est_un_spam =!(strpos(strtolower($message), 'spam') === false);
237        $headers=str_replace( $match,$string, $headers); 
238       
239        if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
240                 ;                              // Bad recipient address syntax
241                $pos1 = strpos(strtolower($message), 'bad recipient address syntax');
242                if (  !($pos1 === false) ){
243                        $erreur_message .= l10n('detection_de').' : Bad recipient address syntax .';
244                        $erreur_message .= l10n('verifiez_les_destinataires').' (Bcc,Cc,To)<br />';
245                        }       
246       
247        $erreur_message .= sprintf(l10n('debug_message %s %s %s %s %s'),($ret==true)? "true" : "false",$message,$mailto,$headers,$nb_destinataires);
248       //=============== La fonction mail à retournéeune erreur =========================               
249
250                               
251                                }       
252                               
253        if ($est_un_spam == false) 
254                        {
255                        if ($mails_données['nb_mails']==0) {    $mails_données['date_mail'] =  time();  }       
256                        $mails_données['nb_mails'] += $nb_destinataires;
257                        }
258                        else
259                        {
260                                $mails_données['nb_spams'] += $nb_destinataires;                       
261                            //--- Détection de spam ------------------
262                                if ($mails_données['nb_spams']==0) {$mails_données['date_spam'] = time();       }
263
264                                $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false);
265                                if ( $trop_de_spam ) {
266                                                $mails_données['nb_spams_maxi']=$mails_données['nb_spams'];
267
268                                                $mails_données['date_quarantaine']= time()  ;   
269                                                $mails_données['quarantaine']= true    ;       
270                                                $infos_message .=memo_var($mails_données);
271                                        }
272
273                        }
274 
275 
276
277 
278 $ret=true;
279 return $ret ;
280 
281}
282
283//==========================================================================================
284function admin_menu($menu)
285{
286    array_push($menu, array('NAME' => 'Mail_Superv',
287      'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php')));
288    return $menu;
289}
290
291
292add_event_handler('get_admin_plugin_menu_links', 'admin_menu');
293
294add_event_handler('loc_after_page_header', 'affiche_message');
295?>
Note: See TracBrowser for help on using the repository browser.