Ignore:
Timestamp:
Apr 16, 2011, 3:53:31 PM (13 years ago)
Author:
cljosse
Message:

[extensions] mail_supervisor fix bug in design

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Mail_supervisor/main.inc.php

    r10388 r10419  
    1616
    1717global $conf,$mails_options ;
    18 include_once (MAIL_SUPERV_PATH.'include/constants.php'); 
     18include_once (MAIL_SUPERV_PATH.'include/constants.php');
    1919include_once(MAIL_SUPERV_PATH.'mail_super.inc.php');
    2020
     
    2323
    2424$mails_options = mail_supervisor::Get_Options($mails_options,"mail_superv");
    25 /* EVENT_HANDLER_PRIORITY_NEUTRAL  */   
     25/* EVENT_HANDLER_PRIORITY_NEUTRAL  */
    2626//
    2727//
    2828include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' );
    29 include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); 
     29include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
    3030//===============loc_begin_index==============loc_after_page_header=============================================================
    3131add_event_handler('loc_begin_page_header',  array(&$mail_supervisor,'init')  );
     
    3535add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 10, 6);
    3636function clj_mail($result, $mailto, $subject, $content, $headers, $args) {
    37   global $conf, $user, $lang_info; 
     37  global $conf, $user, $lang_info;
    3838  global $conf_mail,$mails_options,$mails_donnees ;
    39   global  $template,$page ,$erreur_message,$infos_message, $lang; 
     39  global  $template,$page ,$erreur_message,$infos_message, $lang;
    4040  global $errors;
    4141  // lecture config table -------------
    42   include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
    43   load_language('plugin.lang', MAIL_SUPERV_PATH);
    44   if (isset($_POST["Submit"]) ) {
    45     if ($_POST["Submit"] != l10n('Sv_Envoyer') ) return true ;
    46   } 
    47   // remove_event_handler('send_mail', 'pwg_send_mail');     
    48         $message ="";
    49   if (!isset($infos_message))   {       $infos_message = "";    }
    50   if (!isset($erreur_message))  {       $erreur_message = '';   }         
    51    
     42  include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
     43  load_language('plugin.lang', MAIL_SUPERV_PATH);
     44   trigger_event('cl_begin_send_mail');
     45
     46 // remove_event_handler('send_mail', 'pwg_send_mail');
     47    $message ="";
     48  if (!isset($infos_message))   {   $infos_message = "";    }
     49  if (!isset($erreur_message))  {   $erreur_message = '';   }
     50
    5251  // $mails_options = explode("," , $conf['mail_superv']);
    5352  $envoie_ok=true ;
    5453  //======== verification si envoie de mail ou blocage connexion =====================
    5554
    56   if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' )    {
    57                 if (kill_list()) {
     55  if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' )    {
     56        if (kill_list()) {
    5857      $nb_destinataires=0; ;
    5958      $envoie_ok= false ;
    6059      $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ;
    61       $infos_message = l10n('Sv_mail_not_send')."<BR />"; 
     60      $infos_message = l10n('Sv_mail_not_send')."<BR />";
    6261      if ($mails_options['no_connect'] == 'on' ){
    63               if ($user['status'] == 'webmaster'){ 
    64               //---------- continuer si web master ----------
    65               }else{
    66                       if (!isset($_GET['admin'])) {
    67                                       die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!');
    68                                         }elseif   ($_GET['admin'] != 'piwigo')
    69                                                 {
    70                                       die('blacklist Hacking attempt!');
    71                       }             
    72               }                         
     62          if ($user['status'] == 'webmaster'){
     63          //---------- continuer si web master ----------
     64          }else{
     65              if (!isset($_GET['admin'])) {
     66                      die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!');
     67                        }elseif   ($_GET['admin'] != 'piwigo')
     68                            {
     69                      die('blacklist Hacking attempt!');
     70              }
     71          }
    7372      }
    74          return true;
    75                 }
    76         }
     73       trigger_event('cl_kill_send_mail', $ip);
     74         return true;
     75        }
     76    }
    7777  // lecture donnees       -------------
    78   $mails_donnees = mail_supervisor::Get_Datas(); 
    79   $nb_mails       =     $mails_donnees['nb_mails'] ;
    80   $next_day  =  $mails_donnees['date_mail'] ;   
    81   $reste =    $mails_donnees['reste'] ;         
    82         $rest_mail =    $mails_donnees['rest_mail'] ; 
    83         if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){
    84            $mails_donnees['nb_mails'] =0 ;
    85            $mails_donnees['date_mail'] = time();
    86         }       
    87         $rest_spam =    $mails_donnees['rest_spam'] ;
    88         if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){
    89            $mails_donnees['nb_spams'] =0 ;
    90            $mails_donnees['date_spam'] = time();
    91         }       
    92         $alerte =   ( $mails_donnees['reste'] >0 ) ? true : false ;     
    93         $alerte_mail =    ( $mails_donnees['nb_mails'] >   $mails_donnees['nb_mails_maxi']-1 ) ? true : false ;
    94         $alerte_spam =    ( $mails_donnees['nb_spams'] >   $mails_donnees['nb_spams_maxi']-1 ) ? true : false ;
    95 
    96   if ( ( !$alerte  && !$alerte_spam  && !$alerte_mail ) ) {             
    97     $nb_destinataires=0; 
     78  $mails_donnees = mail_supervisor::Get_Datas();
     79  $nb_mails   = $mails_donnees['nb_mails'] ;
     80  $next_day  =  $mails_donnees['date_mail'] ;
     81  $reste =    $mails_donnees['reste'] ;
     82    $rest_mail =    $mails_donnees['rest_mail'] ;
     83    if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){
     84       $mails_donnees['nb_mails'] =0 ;
     85       $mails_donnees['date_mail'] = time();
     86    }
     87    $rest_spam =    $mails_donnees['rest_spam'] ;
     88    if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){
     89       $mails_donnees['nb_spams'] =0 ;
     90       $mails_donnees['date_spam'] = time();
     91    }
     92    $alerte =   ( $mails_donnees['reste'] >0 ) ? true : false ;
     93    $alerte_mail =    ( $mails_donnees['nb_mails'] >   $mails_donnees['nb_mails_maxi']-1 ) ? true : false ;
     94    $alerte_spam =    ( $mails_donnees['nb_spams'] >   $mails_donnees['nb_spams_maxi']-1 ) ? true : false ;
     95
     96  if ( ( !$alerte  && !$alerte_spam  && !$alerte_mail ) ) {
     97    $nb_destinataires=0;
    9898  //====================================================
    99     $match_email = $conf_mail['email_webmaster'];     
     99    $match_email = $conf_mail['email_webmaster'];
     100
    100101    $new_args=array();
    101102    if( isset($args['Bcc']))
    102     foreach($args['Bcc'] as $key => $val){ 
    103       if (!preg_match('/'. $match_email.'/', $val)){ 
     103    foreach($args['Bcc'] as $key => $val){
     104      if (!preg_match('/'. $match_email.'/', $val)){
    104105          array_push($new_args, $val);
    105106      }else{
    106                 $mailto = $match_email;
     107            $mailto = $match_email;
    107108      }
    108109    }
     
    110111     //=======================================================================
    111112     $nb_destinataires=0;
    112     if ($mailto<>"" ) $nb_destinataires +=1;           
    113                 if (!empty($args['Cc']))  {     
    114         $nb_destinataires += count($args['Cc']); 
    115        
    116     } 
    117                 if (!empty($args['Bcc']))  {   
    118         $nb_destinataires += count($args['Bcc']);       
    119     } 
    120     if ($mailto == "" && $nb_destinataires==0 ) {
     113    if ($mailto<>"" ) $nb_destinataires +=1;
     114        if (!empty($args['Cc']))  {
     115        $nb_destinataires += count($args['Cc']);
     116
     117    }
     118        if (!empty($args['Bcc']))  {
     119        $nb_destinataires += count($args['Bcc']);
     120    }
     121    if ($mailto == "" && $nb_destinataires==0 ) {
    121122      $mailto = $conf_mail['email_webmaster'];
    122123      $nb_destinataires ++;
    123124    }
    124125
    125                 if ($mails_options['check_mailto'] == 'on') {
    126                         if ($mailto == "" && $nb_destinataires > 1 )    $mailto = $conf_mail['email_webmaster'];
    127                 }   
    128 
    129         $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ."<br />";
     126        if ($mails_options['check_mailto'] == 'on') {
     127            if ($mailto == "" && $nb_destinataires > 1 )    $mailto = $conf_mail['email_webmaster'];
     128        }
     129
     130    $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ."{". $lang_info['language_name'] ."}"."<br />";
    130131    //================= réecriture de l'entete ===============================
    131132    $match=array("<",">");
    132     $string=array("&lt;","&gt;") ;                     
    133     if ( $nb_destinataires  == 1 ) {   
    134       if ($mailto == "" ) {     
    135         if (!empty($args['Bcc'])){ 
     133    $string=array("&lt;","&gt;") ;
     134    if ( $nb_destinataires  == 1 ) {
     135      if ($mailto == "" ) {
     136        if (!empty($args['Bcc'])){
    136137          $mailto = get_strict_email_list(implode(',', $args['Bcc']));
    137138          $args['Bcc']=array();
    138         }else{   
     139        }else{
    139140          if (!empty($args['Cc']) ){  $mailto=get_strict_email_list(implode(',', $args['Cc']));
    140141           $args['Cc']=array();
     
    148149      $infos_message .="Destinataire:" .$mailto ;
    149150      //=============================================================================
    150        
     151
    151152    }else{
    152153          //=== plusieurs destinataires ===========
    153154      $cl_list_mail="";
    154       if ($mailto !="") $infos_message .="To: " . $mailto . " "."<br />" ;     
     155      if ($mailto !="") $infos_message .="To: " . $mailto . " "."<br />" ;
    155156      if (!empty($args['Cc'])) {
    156157        $ret= corrige_header('Cc',$headers,$args,$cl_list_mail,$mailto);
    157158        $headers = $ret->headers;
    158159        if($ret->list_mail!="") $infos_message .="Cc: " .  ( $ret->list_mail)."  <br />" ;
    159              
     160
    160161      }
    161       if (!empty($args['Bcc'])){ 
    162           $ret  = corrige_header('Bcc',$headers,$args,$cl_list_mail,$mailto); 
     162      if (!empty($args['Bcc'])){
     163          $ret  = corrige_header('Bcc',$headers,$args,$cl_list_mail,$mailto);
    163164          $headers = $ret->headers ;
    164165          if($ret->list_mail!="") $infos_message .="Bcc: " . ( $ret->list_mail) ."  <br />";
    165            
    166        }     
    167              $infos_message .=  " " ;
    168     }
    169      
    170      
     166
     167       }
     168         $infos_message .=  " " ;
     169    }
     170
     171
    171172            //=============================================================================
    172173            if ($mails_options['check_header_text']=='on')   {
    173               $texte = "This is a multi-part message in MIME format.\n";       
    174               $texte .= "-----=".$conf_mail['boundary_key']."\n"; 
    175               $texte .= "Ceci est un message est au format MIME.\n"; 
    176               $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; 
    177               $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
    178               $texte .= $mails_donnees['header_text']; // A voir texte brut...     
    179               $texte .= "\n\n";         
     174              $texte = "This is a multi-part message in MIME format.\n";
     175              $texte .= "-----=".$conf_mail['boundary_key']."\n";
     176              $texte .= "Ceci est un message est au format MIME.\n";
     177              $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n";
     178              $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n";
     179              $texte .= $mails_donnees['header_text']; // A voir texte brut...
     180              $texte .= "\n\n";
    180181              $content =$texte .$content ;
    181             }   
     182            }
    182183            // corrige erreur 'mail dropped, bare LF found'
    183           /*   if ( preg_match('/\n\./',$content)){ 
     184          /*   if ( preg_match('/\n\./',$content)){
    184185             $content=preg_replace('/\n\./', '/\n\.\./', $content);
    185186
     
    187188             }
    188189             $content = str_replace("\n.", "\n/./.", $content);
    189              $headers = str_replace("\n.", "\n..", $headers); 
     190             $headers = str_replace("\n.", "\n..", $headers);
    190191            $subject = str_replace("\n.", "\n..", $subject);
    191192             $mailto = str_replace("\n.", "\n..", $mailto);
    192193       */
    193              
    194             $ret=false; 
    195                 //======== Non mise en quarantaine ============= 
    196          
    197          
    198                     ob_start();
    199                       if ($nb_destinataires > 0) {   
    200 
    201             if( $envoie_ok)  $ret = mail($mailto, $subject,$content, $headers); 
    202            
     194
     195            $ret=false;
     196            //======== Non mise en quarantaine =============
     197
     198
     199            ob_start();
     200              if ($nb_destinataires > 0) {
     201
     202            if( $envoie_ok)  $ret = mail($mailto, $subject,$content, $headers);
     203
    203204          }else{
    204205            $message .= l10n('Sv_no_receiver_available');
     
    206207        $message .= ob_get_contents();
    207208        ob_end_clean();
    208         $mails_donnees['message']=$message;     
     209        $mails_donnees['message']=$message;
    209210        Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
    210211            } else {
    211                     //================== Est en quarantaine =======================     
    212                         $erreur_message .=      l10n('Sv_To_day_is')."<br />";
    213                             if ($alerte_spam ) {
    214                                 $type="Spams";                         
    215                                         $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
    216                                         $d2=$mails_donnees['nb_spams'];
    217                                         $d3= $mails_donnees['rest_spam'];
    218                                         $d4=time()+$d3 ;
    219                             } 
    220                             if ($alerte_mail) {
    221                     $type="Mails";                     
     212                //================== Est en quarantaine =======================
     213                $erreur_message .=  l10n('Sv_To_day_is')."<br />";
     214                if ($alerte_spam ) {
     215                        $type="Spams";
     216                        $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
     217                        $d2=$mails_donnees['nb_spams'];
     218                        $d3= $mails_donnees['rest_spam'];
     219                        $d4=time()+$d3 ;
     220                }
     221                if ($alerte_mail) {
     222                    $type="Mails";
    222223                    $d1=$mails_donnees['nb_mails']. '  \\  ' . $mails_donnees['nb_mails_maxi'];;
    223224                    $d2=$mails_donnees['date_mail'];
    224225                    $d3= $mails_donnees['rest_mail'];
    225226                    $d4=time()+$d3 ;
    226                             }
    227                             if ($alerte) {
    228                         $type="Spams(Quarantaine)";
    229                                     $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
    230                                     $d2=$mails_donnees['date_quarantaine'];
    231                                     $d3= $mails_donnees['reste'];
    232                                     $d4=time()+$d3 ;
    233                             }
     227                }
     228                if ($alerte) {
     229                $type="Spams(Quarantaine)";
     230                    $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
     231                    $d2=$mails_donnees['date_quarantaine'];
     232                    $d3= $mails_donnees['reste'];
     233                    $d4=time()+$d3 ;
     234                }
    234235            $d2=date(l10n('Sv_formatdate'),$d2);
    235236            $d3=int_to_heure($d3) ;
    236237            $d4=date(l10n('Sv_formatdate'),$d4);
    237238            if ($alerte_mail) {
    238                     $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
     239                $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
    239240            }else{
    240                         $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
    241             }
    242             $infos_message .= l10n('Sv_mail_not_send'); 
    243             }           
    244            $infos_message .= "<hr>";   
     241                $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
     242            }
     243            $infos_message .= l10n('Sv_mail_not_send');
     244            }
     245           $infos_message .= "<hr>";
    245246    mail_supervisor::sauve_donnees();
    246247    mail_supervisor::affiche_message();
    247248    return true ;
    248249}
    249 //===========================================================================================   
    250 function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto){                     
    251          global $conf, $user,  $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info;
     250//===========================================================================================
     251function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto){
     252     global $conf, $user,  $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info;
    252253     $match=array("<",">");
    253     $string=array("&lt;","&gt;") ;       
    254 //Warning: mail() has been disabled for security reasons 
    255        
    256         $est_un_spam =!(strpos(strtolower($message), 'spam') === false);
    257         $headers=str_replace( $match,$string, $headers);
    258        
    259         if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
    260                  ;                              // Bad recipient address syntax
    261                 $pos1 = strpos(strtolower($message), 'bad recipient address syntax');
    262                 if (  !($pos1 === false) ){
    263                         $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .';
    264                         $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />';
    265                         }       
    266        
    267         $erreur_message .= sprintf(l10n('Sv_debug_message'),
    268         ($ret==true)? "true" : "false",
    269         $message ,
    270         $mailto ,
    271         $headers ,
    272         $nb_destinataires );
    273        //=============== La fonction mail retourne une erreur =========================         
    274                                 }       
    275                                
    276         if ($est_un_spam == false)
    277                         {
    278                         if ($mails_donnees['nb_mails']==0) {    $mails_donnees['date_mail'] =  time();  }       
    279                         $mails_donnees['nb_mails'] += $nb_destinataires;
    280                         }
    281                         else
    282                         {
    283                                 $mails_donnees['nb_spams'] += $nb_destinataires;                       
    284                             //--- Detection de spam ------------------
    285                                 if ($mails_donnees['nb_spams']==0) {$mails_donnees['date_spam'] = time();       }
    286 
    287                                 $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false);
    288                                 if ( $trop_de_spam ) {
    289                                                 $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams'];
    290 
    291                                                 $mails_donnees['date_quarantaine']= time()  ;   
    292                                                 $mails_donnees['quarantaine']= true    ;       
    293                                                 $infos_message .= mail_supervisor::Memo_Var($mails_donnees);
    294                                         }
    295                         }
     254    $string=array("&lt;","&gt;") ;
     255//Warning: mail() has been disabled for security reasons
     256
     257    $est_un_spam =!(strpos(strtolower($message), 'spam') === false);
     258    $headers=str_replace( $match,$string, $headers);
     259
     260    if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
     261         ;              // Bad recipient address syntax
     262        $pos1 = strpos(strtolower($message), 'bad recipient address syntax');
     263        if (  !($pos1 === false) ){
     264            $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .';
     265            $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />';
     266            }
     267
     268    $erreur_message .= sprintf(l10n('Sv_debug_message'),
     269    ($ret==true)? "true" : "false",
     270    $message ,
     271    $mailto ,
     272    $headers ,
     273    $nb_destinataires );
     274       //=============== La fonction mail retourne une erreur =========================
     275                }
     276
     277        if ($est_un_spam == false)
     278            {
     279                if ($mails_donnees['nb_mails']==0) {    $mails_donnees['date_mail'] =  time();  }
     280                $mails_donnees['nb_mails'] += $nb_destinataires;
     281            }
     282            else
     283            {
     284                $mails_donnees['nb_spams'] += $nb_destinataires;
     285                //--- Detection de spam ------------------
     286                if ($mails_donnees['nb_spams']==0) {$mails_donnees['date_spam'] = time();   }
     287
     288                $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false);
     289                if ( $trop_de_spam ) {
     290                        $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams'];
     291
     292                        $mails_donnees['date_quarantaine']= time()  ;
     293                        $mails_donnees['quarantaine']= true    ;
     294                        $infos_message .= mail_supervisor::Memo_Var($mails_donnees);
     295                    }
     296            }
    296297 $ret=true;
    297  return $ret ; 
     298 return $ret ;
    298299}
    299300?>
Note: See TracChangeset for help on using the changeset viewer.