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

Last change on this file since 4180 was 4180, checked in by cljosse, 14 years ago

[mail_supervisor] update design for firefox

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