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

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

[mail_supervisor] debug warning messages.

File size: 8.7 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.0.2
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
33
34if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
35
36define('mail_superv_DIR' , basename(dirname(__FILE__)));
37define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
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        $infos_message="";
54        $message ="";
55        $erreur_messages="";
56
57        // lecture données       -------------
58    $mails_données = Get_Datas();
59
60       
61        $nb_mails         =     $mails_données['nb_mails'] ;
62        $next_day  =  $mails_données['date_mail'] ;
63       
64        $reste =    $mails_données['reste'] ;
65       
66       
67        $rest_mail =    $mails_données['rest_mail'] ;
68        if ($rest_mail <=0 || $mails_données['nb_mails'] ==0 ){
69           $mails_données['nb_mails'] =0 ;
70           $mails_données['date_mail'] = time();
71        }
72       
73        $rest_spam =    $mails_données['rest_spam'] ;
74        if ($rest_spam <=0 || $mails_données['nb_spams'] ==0 ){
75           $mails_données['nb_spams'] =0 ;
76           $mails_données['date_spam'] = time();
77        }
78       
79        $alerte =   ( $mails_données['reste'] >0 ) ? true : false ; 
80       
81        $alerte_mail =    ( $mails_données['nb_mails'] >   $mails_données['nb_mails_maxi'] ) ? true : false ;
82        $alerte_spam =    (  $mails_données['nb_spams'] >   $mails_données['nb_spams_maxi'] ) ? true : false ;
83       
84 
85 if ( ( !$alerte  && !$alerte_spam  && !$alerte_mail ) ) 
86        {
87                 
88  $nb_destinataires=0;
89 
90 if ($mailto<>"" )  $nb_destinataires +=1; 
91   //================= réécriture de l'entête ===============================
92
93if ($mails_options[0] == 'on') {
94        if ($mailto=="")        $mailto=$conf_mail['email_webmaster'];
95}
96                if (!empty($args['Cc']))
97                {$nb_destinataires += count($args['Cc']);
98                 if ($mails_options[1] == 'on') {  $headers= corrige_header('Cc:',$headers);}
99                }
100                if (!empty($args['Bcc']))
101                {  $nb_destinataires += count($args['Bcc']); 
102                   if ($mails_options[1] == 'on') {  $headers   = corrige_header('Bcc',$headers);}
103                }
104
105
106if ($mails_options[2]=='on')   {
107
108        $texte = "This is a multi-part message in MIME format.\n"; 
109       
110        $texte .= "-----=".$conf_mail['boundary_key']."\n"; 
111        $texte .= "Ceci est un message est au format MIME.\n"; 
112        $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; 
113        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
114        $texte .= $mails_données['header_text']; // A voir texte brut...
115           
116                $texte .= "\n\n"; 
117       
118                $content =$texte .$content ;
119}
120 
121$ret=false;
122
123         $infos_message .=$nb_destinataires;
124               
125                       
126            //======== Non mise en quarantaine =============
127                ob_start();
128                $ret = false;
129                 if ($nb_destinataires > 0) {
130                         $ret = mail($mailto, $subject, $content, $headers);
131 
132                        }else{
133                           $message .='Nombre de destinataires = 0';
134                        }
135                        $message .= ob_get_contents();
136            ob_end_clean();
137                        $mails_données['message']=$message;     
138                        Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
139               
140       
141       
142        } else {
143
144        //================== Est en quarantaine =======================
145                $erreur_message .=      l10n('To_day_is')."<br />";
146                        if ($alerte_spam ) { 
147                        $type="Spams";
148                                $d1=$mails_données['nb_spams'];
149                                $d2=$mails_données['date_spam'];
150                                $d3= $mails_données['rest_spam'];
151                                $d4=time()+$d3 ;
152                        } 
153 
154                        if ($alerte_mail) {
155                        $type="Mails";
156                       
157                                $d1=$mails_données['nb_mails'];
158                                $d2=$mails_données['date_mail'];
159                                $d3= $mails_données['rest_mail'];
160                                $d4=time()+$d3 ;
161                        }
162                        if ($alerte) {
163                        $type="Spams(Quarantaine)";
164                                $d1=$mails_données['nb_spams'];
165                                $d2=$mails_données['date_quarantaine'];
166                                $d3= $mails_données['reste'];
167                                $d4=time()+$d3 ;
168 } 
169
170
171$d2=date(l10n('formatdate'),$d2);
172$d3=int_to_heure($d3) ;
173$d4=date(l10n('formatdate'),$d4);
174
175                $erreur_message .='<br />'.sprintf(l10n('mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
176 }                     
177 sauve_données();
178 return true ;
179}
180//===========================================================================================   
181function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto)
182{                       
183         global $conf, $user, $lang_info,  $conf_mail,$mails_options,$mails_données , $template,$page ,$infos_message,$erreur_message,$args; 
184    $match=array("<",">");
185    $string=array("&lt;","&gt;") ;       
186
187       
188        $est_un_spam =!(strpos(strtolower($message), 'spam') === false);
189        $headers=str_replace( $match,$string, $headers); 
190       
191        if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
192                 ;                              // Bad recipient address syntax
193                $pos1 = strpos(strtolower($message), 'bad recipient address syntax');
194                if (  !($pos1 === false) ){
195                        $erreur_message .='Détection de : Bad recipient address syntax .';
196                        $erreur_message .='Vérifiez les destinataires: (Bcc,Cc,To)<br />';
197                        }       
198       
199        $erreur_message .= sprintf(l10n('debug_message %s %s %s %s %s'),($ret==true)? "true" : "false",$message,$mailto,$headers,$nb_destinataires);
200       //=============== La fonction mail à retournéeune erreur =========================               
201
202                               
203                                }       
204                               
205        if ($est_un_spam == false) 
206                        {
207                        if ($mails_données['nb_mails']==0) {    $mails_données['date_mail'] =  time();  }       
208                        $mails_données['nb_mails'] += $nb_destinataires;
209                        }
210                        else
211                        {
212                                $mails_données['nb_spams'] += $nb_destinataires;                       
213                            //--- Détection de spam ------------------
214                                if ($mails_données['nb_spams']==0) {$mails_données['date_spam'] = time();       }
215
216                                $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false);
217                                if ( $trop_de_spam ) {
218                                                $mails_données['nb_spams_maxi']=$mails_données['nb_spams'];
219                                                $quarantaine_periode="+".str_replace( $period_search, $period_match, $mails_données['quarantaine_periode']);
220                                                $next_day =  strtotime($quarantaine_periode);  // détection de 'Trop de spam
221                                                $mails_données['date_quarantaine']= time()  ;   
222                                                $mails_données['quarantaine']= true    ;       
223                                                $infos_message=memo_var($mails_données);
224                                        }
225
226                        }
227 
228
229 
230
231 
232 $ret=true;
233 return $ret ;
234 
235}
236
237//==========================================================================================
238function admin_menu($menu)
239{
240    array_push($menu, array('NAME' => 'Mail_Superv',
241      'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php')));
242    return $menu;
243}
244
245
246add_event_handler('get_admin_plugin_menu_links', 'admin_menu');
247//add_event_handler('loc_end_page_tail', 'affiche_message');
248add_event_handler('loc_after_page_header', 'affiche_message');
249
250?>
Note: See TracBrowser for help on using the repository browser.