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

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

[mail_supervisor] bug in traduction files (next)

File size: 9.8 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.5
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('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        $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
99                if (!empty($args['Bcc']))  { 
100                        $nb_destinataires += count($args['Bcc']); 
101                        } 
102                if (!empty($args['Cc']))  {   
103                        $nb_destinataires += count($args['Cc']); 
104                        }
105   //================= réécriture de l'entête ===============================
106if ( $nb_destinataires  == 1 )
107        {
108                if ($mailto == "" ) 
109                  {
110                          if (!empty($args['Cc']) and count($args['Cc']) > 0 )  $mailto  = get_strict_email_list(implode(',', $args['Cc'])) ;
111                          if (!empty($args['Bcc']) and count($args['Bcc']) > 0 ) $mailto  = get_strict_email_list(implode(',', $args['Bcc'])) ;
112                         
113                                $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers);
114                                $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers);
115                               
116                  }
117        }else{
118   
119                if (!empty($args['Cc']))
120                        {
121                         $headers= corrige_header('Cc',$headers);
122                                 
123                        }
124                if (!empty($args['Bcc']))
125                        {   
126                                   $headers     = corrige_header('Bcc',$headers); 
127                        }
128
129 
130     }
131
132if ($mails_options[2]=='on')   {
133
134        $texte = "This is a multi-part message in MIME format.\n"; 
135       
136        $texte .= "-----=".$conf_mail['boundary_key']."\n"; 
137        $texte .= "Ceci est un message est au format MIME.\n"; 
138        $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; 
139        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
140        $texte .= $mails_données['header_text']; // A voir texte brut...
141           
142                $texte .= "\n\n"; 
143       
144                $content =$texte .$content ;
145}
146 
147$ret=false;
148       
149            //======== Non mise en quarantaine =============
150                ob_start();
151                $ret = false;
152                 if ($nb_destinataires > 0) {
153                   $ret = mail($mailto, $subject, $content, $headers);
154/* <br />
155<b>Warning</b>:  mail() [<a href='function.mail'>function.mail</a>]: Trop de spam. Fonction mail() bloque.
156 in <b>/mnt/102/sdb/9/5/cl.josse/Galerie/plugins/mail_supervisor/main.inc.php</b> on line <b>132</b><br />
157*/
158                        }else{
159                           $message .='Nombre de destinataires = 0';
160                        }
161                        $message .= ob_get_contents();
162            ob_end_clean();
163                        $mails_données['message']=$message;     
164                        Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
165               
166       
167       
168        } else {
169
170        //================== Est en quarantaine =======================
171                $erreur_message .=      l10n('To_day_is')."<br />";
172                        if ($alerte_spam ) { 
173                        $type="Spams";
174                               
175                                $d1=$mails_données['nb_spams'] . '  \\  ' . $mails_données['nb_spams_maxi'];
176                                $d2=$mails_données['nb_spams'];
177                                $d3= $mails_données['rest_spam'];
178                                $d4=time()+$d3 ;
179                        } 
180 
181                        if ($alerte_mail) {
182                        $type="Mails";
183                       
184                                $d1=$mails_données['nb_mails']. '  \\  ' . $mails_données['nb_mails_maxi'];;
185                                $d2=$mails_données['date_mail'];
186                                $d3= $mails_données['rest_mail'];
187                                $d4=time()+$d3 ;
188                               
189                               
190                        }
191                        if ($alerte) {
192                        $type="Spams(Quarantaine)";
193                                $d1=$mails_données['nb_spams'] . '  \\  ' . $mails_données['nb_spams_maxi'];
194                                $d2=$mails_données['date_quarantaine'];
195                                $d3= $mails_données['reste'];
196                                $d4=time()+$d3 ;
197                        } 
198
199
200$d2=date(l10n('formatdate'),$d2);
201$d3=int_to_heure($d3) ;
202$d4=date(l10n('formatdate'),$d4);
203
204        if ($alerte_mail) {
205              $erreur_message .='<br />'.sprintf(l10n('alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
206                }else{
207                           $erreur_message .='<br />'.sprintf(l10n('mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
208
209                }
210 $infos_message = l10n('mail_not_send');
211 
212 }                     
213 sauve_données();
214 return true ;
215}
216//===========================================================================================   
217function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto)
218{                       
219         global $conf, $user, $lang_info,  $conf_mail,$mails_options,$mails_données , $template,$page ,$infos_message,$erreur_message,$args; 
220    $match=array("<",">");
221    $string=array("&lt;","&gt;") ;       
222
223       
224        $est_un_spam =!(strpos(strtolower($message), 'spam') === false);
225        $headers=str_replace( $match,$string, $headers); 
226       
227        if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
228                 ;                              // Bad recipient address syntax
229                $pos1 = strpos(strtolower($message), 'bad recipient address syntax');
230                if (  !($pos1 === false) ){
231                        $erreur_message .='Détection de : Bad recipient address syntax .';
232                        $erreur_message .='Vérifiez les destinataires: (Bcc,Cc,To)<br />';
233                        }       
234       
235        $erreur_message .= sprintf(l10n('debug_message %s %s %s %s %s'),($ret==true)? "true" : "false",$message,$mailto,$headers,$nb_destinataires);
236       //=============== La fonction mail à retournéeune erreur =========================               
237
238                               
239                                }       
240                               
241        if ($est_un_spam == false) 
242                        {
243                        if ($mails_données['nb_mails']==0) {    $mails_données['date_mail'] =  time();  }       
244                        $mails_données['nb_mails'] += $nb_destinataires;
245                        }
246                        else
247                        {
248                                $mails_données['nb_spams'] += $nb_destinataires;                       
249                            //--- Détection de spam ------------------
250                                if ($mails_données['nb_spams']==0) {$mails_données['date_spam'] = time();       }
251
252                                $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false);
253                                if ( $trop_de_spam ) {
254                                                $mails_données['nb_spams_maxi']=$mails_données['nb_spams'];
255
256                                                $mails_données['date_quarantaine']= time()  ;   
257                                                $mails_données['quarantaine']= true    ;       
258                                                $infos_message .=memo_var($mails_données);
259                                        }
260
261                        }
262 
263
264 
265
266 
267 $ret=true;
268 return $ret ;
269 
270}
271
272//==========================================================================================
273function admin_menu($menu)
274{
275    array_push($menu, array('NAME' => 'Mail_Superv',
276      'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php')));
277    return $menu;
278}
279
280
281add_event_handler('get_admin_plugin_menu_links', 'admin_menu');
282//add_event_handler('loc_end_page_tail', 'affiche_message');
283add_event_handler('loc_after_page_header', 'affiche_message');
284
285?>
Note: See TracBrowser for help on using the repository browser.