Changeset 11835


Ignore:
Timestamp:
Jul 26, 2011, 12:42:48 PM (13 years ago)
Author:
cljosse
Message:

[extensions] mail_supervisor cleaning of the programs

Location:
extensions/Mail_supervisor
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • extensions/Mail_supervisor/admin/mail_superv_admin.php

    r11807 r11835  
    182182      $mails_options['check_mailto'] = isset($_POST['check_mailto']) ? $_POST['check_mailto'] : 'off' ;
    183183      $mails_options['check_header_carbon'] = isset($_POST['check_header_carbon']) ? $_POST['check_header_carbon'] : 'off' ;
    184       $mails_options['check_header_text'] = isset($_POST['check_header_text']) ? $_POST['check_header_text'] : 'off' ;
     184      $mails_options['check_send_webmaster'] = isset($_POST['check_send_webmaster']) ? $_POST['check_send_webmaster'] : 'off' ;
    185185      $mails_options['no_ipaddress'] = isset($_POST['no_ipaddress']) ? $_POST['no_ipaddress'] : 'off' ;
    186186
     
    203203      $infos_message  =  l10n('Sv_save_config') . " : " . l10n('Sv_Datas') . "<br />" ;
    204204      $erreur_message = "";
    205       $mails_donnees = mail_supervisor::Get_Datas() ;
     205     
    206206    }
    207207 }
     
    217217                        'check_mailto' => ($mails_options['check_mailto'] == 'on') ? 'checked="checked"' : '' ,
    218218                        'check_header_carbons' => ($mails_options['check_header_carbon'] == 'on') ? 'checked="checked"' : '' ,
    219                         'check_header_text' => ($mails_options['check_header_text'] == 'on') ? 'checked="checked"' : '' ,
     219                        'check_send_webmaster' => ($mails_options['check_send_webmaster'] == 'on') ? 'checked="checked"' : '' ,
    220220                        'no_ipaddress' => ($mails_options['no_ipaddress'] == 'on') ? 'checked="checked"' : '' ,
    221221
     
    492492                        'set_auto' => ($mails_options['set_auto'] == 'on') ? 'checked="checked"' : '' ,
    493493                        'set_id' => ($mails_options['set_id'] == 'on') ? 'checked="checked"' : '' ,
     494
    494495                        'IP' =>  $ip ,
    495496                        'PAYS' =>  $pays  ,
  • extensions/Mail_supervisor/admin/mail_superv_admin.tpl

    r11807 r11835  
    1818<td><input type="checkbox" name="check_header_carbon" value="on" {$check_header_carbons} />&nbsp;{'Sv_check_header_carbon'|translate}</td>
    1919 <td><input type="checkbox" name="no_ipaddress" value="on" {$no_ipaddress} />&nbsp;{'Sv_no_ipaddress'|translate}</td>
    20   { if  $PHPWG_VERSION <= '2.0.4' }
    21 <td><input type="checkbox" name="check_header_text" value="off" {$check_header_text} />&nbsp;
    22 {'Sv_check_header_text'|translate}</td>
    23 <td><input type="text" name="header_text"  value={$header_text} /></td>
     20 
     21<td><input type="checkbox" name="check_send_webmaster" value="off" {$check_send_webmaster} />&nbsp;
     22{'Sv_check_send_webmaster'|translate}</td>
     23 { if  $PHPWG_VERSION <= '2.0.4' }
     24 <td><input type="text" name="header_text"  value={$header_text} /></td>
    2425    {/if}
    2526</tr>
  • extensions/Mail_supervisor/admin/mail_superv_help.tpl

    r10419 r11835  
    5555 <li>{'Sv_hlp_2_2'|translate}</li>
    5656</ul>
    57   <li><span  class="throw">{'Sv_check_header_text'|translate}</span> </li>
     57  <li><span  class="throw">{'Sv_check_send_webmaster'|translate}</span> </li>
    5858  <ul>
    5959 <li>{'Sv_hlp_2_3'|translate}</li>
  • extensions/Mail_supervisor/include/fonctions.php

    r11811 r11835  
    3131global $lang ;
    3232global $template ;
     33
    3334//===============================================
    3435function corrige_header($Carbonne,$headers,$args,$cl_list_mail,$mailto="")  {
  • extensions/Mail_supervisor/language/en_UK/help/plugin.lang.php

    r9397 r11835  
    1919$lang['Sv_Options']='Options';
    2020
    21 $lang['Sv_hlp_2_1']='Send a copy of the mail to the Webmaster.';
     21$lang['Sv_hlp_2_1']='Send a copy of the mail to the Webmaster if Maito is empty.';
    2222$lang['Sv_hlp_2_2']='Change Cc addressees structure if default \'bad syntax\''; //Didn't understand this one :-/
    23 $lang['Sv_hlp_2_3']='If Piwigo version is lower than 2.0.5, add a text block in mail header. ';
     23$lang['Sv_hlp_2_3']='Send a copy of the mail to the Webmaster. ';
    2424
    2525//========================================================================================================
  • extensions/Mail_supervisor/language/en_UK/plugin.lang.php

    r11807 r11835  
    6565$lang['Sv_check_mailto'] = 'If the "To" field in the mail heading is empty, send a copy to the Webmaster.';
    6666$lang['Sv_check_header_carbon'] = 'Change the Bcc, Cc in the header';
    67 $lang['Sv_check_header_text'] = 'Format text.';
     67$lang['Sv_check_send_webmaster'] = 'Alway send a copy to the Webmaster.';
    6868
    6969$lang['Sv_admin'] = 'Exclude administrator from mailings.';
  • extensions/Mail_supervisor/language/fr_FR/help/plugin.lang.php

    r10419 r11835  
    1919$lang['Sv_Options']='Options';
    2020
    21 $lang['Sv_hlp_2_1']='Envoie une copie du mail au Webmaster..';
     21$lang['Sv_hlp_2_1']='Envoie une copie du mail au Webmaster, si le champs mailto est vide..';
    2222$lang['Sv_hlp_2_2']='Modifie la structure des destnataires en copie carbonne si defaut \'bad syntax\'';
    23 $lang['Sv_hlp_2_3']='Si la version piwigo est inferieur à 2.0.5, rajoute un bloc texte dans l\' entête de mail. ';
     23$lang['Sv_hlp_2_3']='Envoie une copie du mail au Webmaster. ';
    2424
    2525//========================================================================================================
  • extensions/Mail_supervisor/language/fr_FR/plugin.lang.php

    r11807 r11835  
    6666$lang['Sv_save_config'] = 'Données sauvegardées';
    6767$lang['Sv_syntax_error'] = 'Erreur de syntaxe. ';
    68 $lang['Sv_check_mailto'] = 'Si le champ "To" dans l\'entête est vide, envoyer une copie vers le WebMaster.';
     68$lang['Sv_check_mailto'] = 'Si le champ "To" dans l\'entête est vide, envoyer une copie à l\'administrateur du site.';
    6969$lang['Sv_check_header_carbon'] = 'Modifier le code  Bcc , Ccc   dans le header';
    70 $lang['Sv_check_header_text'] = 'Envoie en format texte.';
     70$lang['Sv_check_send_webmaster'] = 'Toujours envoyer une copie à l\'administrateur du site.';
    7171
    7272$lang['Sv_admin'] = 'Exclure l\'administrateur des envoies.';
     
    110110                            ' Le        %s <br />' ;
    111111
    112     $ms_f1='La fonction mail à retourné';
    113     $ms_f2='MESSAGE erreur             ';
    114     $ms_f3='mailto                     ';
    115     $ms_f4='SUJET                   ';
    116     $ms_f5='HEADERS                 ';
    117     $ms_f6='CONTENU                  ';
    118     $ms_f7='Nombre de destinataires   ';
     112    $ms_f1='La fonction mail à retourné ';
     113    $ms_f2='MESSAGE erreur ';
     114    $ms_f3='mailto ';
     115    $ms_f4='SUJET ';
     116    $ms_f5='HEADERS ';
     117    $ms_f6='CONTENU ';
     118    $ms_f7='Nombre de destinataires ';
    119119
    120120$lang['Sv_debug_message']=  '<div style="border: 1px solid red; color: green;">
  • extensions/Mail_supervisor/mail_send.inc.php

    r11808 r11835  
    33class clj {
    44static public function send_mail($result, $mailto, $subject, $content, $headers, $args) {
    5 
    6 $ret =clj_send_mail($result, $mailto, $subject, $content, $headers, $args);
    7 
    8 if($ret=="") return true ;
    9 return true ;
    10 
    11 //
    12 return false; // envoie
    13 return true ; // pas d'envoie
     5global $conf, $conf_mail, $lang_info, $page;
     6  global  $user;
     7  global $mails_options,$mails_donnees ;
     8  global  $template,$erreur_message,$infos_message;
     9  global $errors;
     10  $result=true;
     11
     12  include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
     13  load_language('plugin.lang', MAIL_SUPERV_PATH);
     14
     15    $infos= clj::pwg_mail($mailto,$args) ;   
     16    $mailto=$infos->mailto;
     17    $subject=$infos->subject;
     18    $content=$infos->content;
     19    $headers=$infos->headers;
     20    $result=$infos->result;
     21    $args=$infos->args;
     22    $nb_destinataires=$infos->nb_destinataires;
     23
     24$ret =clj_send_mail($result, $mailto, $subject, $content, $headers, $args,$nb_destinataires);
     25return  $ret;
     26
     27//================================
     28// Photographie
     29//================================
     30    $ret="false"; 
     31     $message ="";
     32
     33      ob_start();
     34      $ret = mail($mailto, $subject,$content, $headers); 
     35      $message = ob_get_contents();
     36      ob_end_clean();   
     37      Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content);
     38
     39 
     40     return  $ret;
     41 return true ;
     42
     43
     44//===========================
     45//return false; // envoie
     46//return true ; // pas d'envoie
     47//===========================
    1448}
    1549/************************************
     
    6397 * @return boolean (Ok or not)
    6498 * pour mise au point .
     99 * http://www.faqs.org/rfcs/rfc2822.html
    65100 */
    66 function cl_pwg_mail($to, $args = array()){
     101function pwg_mail($to, $args = array()){
    67102  global $conf, $conf_mail, $lang_info, $page;
     103  global $mails_options ;
     104     remove_event_handler('send_mail', 'pwg_send_mail');
     105
    68106  if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) {
    69     return true;
    70   }
     107    $retour->mailto= "";
     108    $retour->subject= "";
     109    $retour->content= "";
     110    $retour->headers=  "";
     111    $retour->args= $args ;     
     112    $retour->nb_destinataires=0  ;
     113    $retour->$result=true  ;
     114    return $retour ;     
     115  }
     116
    71117  if (!isset($conf_mail))  {
    72118    $conf_mail = get_mail_configuration();
    73119  }
     120  $args['email_format']="text/html";
     121
    74122  if (empty($args['email_format'])) {
    75123    $args['email_format'] = $conf_mail['default_email_format'];
     
    88136  $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
    89137  // Ascii convertion
    90   $cvt_subject = encode_mime_header($cvt_subject);
     138  $cvt_subject = encode_mime_header($cvt_subject); 
    91139
    92140  if (!isset($args['content']))  {
     
    96144  if (empty($args['content_format']))  {
    97145    $args['content_format'] = 'text/plain';
    98   }
    99 
    100   if ($conf_mail['send_bcc_mail_webmaster'])  {
    101     $args['Bcc'][] = $conf_mail['formated_email_webmaster'];
    102   }
     146  } 
     147
     148  if ($conf_mail['send_bcc_mail_webmaster'] || $mails_options['check_send_webmaster']=="on")  {
     149    $args['Bcc'][] = $conf_mail['formated_email_webmaster'];   
     150 }
     151    $webmaster = $conf_mail['formated_email_webmaster'];   
     152//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     153    $Cc="";$Bcc="";
     154   if (empty($mailto)) $mailto="";
     155 $nb_destinataires=0;
     156if( isset($args['Bcc'])){
     157  $nb_destinataires=count($args['Bcc']);
     158  $Bcc=  implode(',', $args['Bcc']) ;
     159}
     160if( isset($args['Cc'])){
     161  $nb_destinataires +=count($args['Cc']);
     162  $Cc= implode(',', $args['Cc']) ;
     163}
     164if(!empty($to)) $nb_destinataires +=count(explode(",",$to));
     165
     166
     167if($nb_destinataires==1 && empty($to)){
     168    if (isset($args['Bcc']) && count($args['Bcc'])==1) $to = array_pop($args['Bcc']);
     169    if (isset($args['Cc']) && count($args['Cc'])==1){ $to = array_pop($args['Cc']);
     170  }
     171}
     172$mailto=$to ;
     173//=============================================
     174// Test Si Mailto vide
     175//=============================================
     176if ($mails_options['check_mailto'] == 'on' && empty($mailto) ) {
     177    //=== suppression webmaster adresse dans les copies .
     178    $match_email = $webmaster;
     179    $new_args=array();
     180    if( isset($args['Bcc']))
     181      foreach($args['Bcc'] as $key => $val){
     182        if (!preg_match('/'. $conf_mail['email_webmaster'] .'/', $val)){
     183            array_push($new_args, $val);
     184        }
     185      }
     186    $args['Bcc']=$new_args;
     187    //=======================================================================
     188    $new_args=array();
     189    if( isset($args['Cc']))
     190      foreach($args['Cc'] as $key => $val){
     191        if (!preg_match('/'. $conf_mail['email_webmaster'] .'/', $val)){
     192            array_push($new_args, $val);
     193        }
     194      }
     195    $args['Cc']=$new_args;
     196    $nb_destinataires =count($args['Bcc'])+count($args['Cc']) ;
     197    //=======================================================================   
     198    $mailto = $webmaster;
     199    $nb_destinataires++;
     200}
     201  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     202
    103203
    104204  if (empty($args['theme']))  {
    105205    $args['theme'] = get_default_theme();
    106206  }
    107 
    108   $headers = 'From: '.$args['from']."\n";
    109   $headers.= 'Reply-To: '.$args['from']."\n";
    110 
    111   if (!empty($args['Cc']))  {
    112     $headers.= 'Cc: '.implode(',', $args['Cc'])."\n";
    113   }
    114 
    115   if (!empty($args['Bcc']))  {
    116     $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";
    117   }
    118 
    119   $headers.= 'Content-Type: multipart/alternative;'."\n";
    120   $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'."\n";
    121   $headers.= '  reply-type=original'."\n";
    122   $headers.= 'MIME-Version: 1.0'."\n";
    123   $headers.= 'X-Mailer: Piwigo Mailer'."\n";
    124 
    125   // List on content-type
     207  //============================================
     208  // TEST EOL
     209  //
     210  //===========================================
     211  //    Note:
     212  // Si le message n'est pas reçu, essayez d'utiliser uniquement un caractère LF (\n).
     213  // Quelques agents de transfert de mail Unix de mauvaise qualité remplacent le caractère LF
     214  // par le caractère CRLF automatiquement
     215  //(ce qui revient à doubler le caractère CR si le caractère CRLF est utilisé).
     216  // Ceci doit être un dernier recours car cela ne correspond pas à la » RFC 2822.
     217      //======================================================
     218      // drop LF barre 
     219      //======================================================
     220      $Eol="\n";
     221      $pattern="/free.fr|club/";
     222       if(  preg_match($pattern, $mailto) ||  preg_match($pattern, $Cc) ||  preg_match($pattern, $Bcc)){
     223         $Eol="\r\n";
     224       }
     225//====================================================
     226// Headers
     227//====================================================
     228  $headers = 'From: '.$args['from'].$Eol;
     229  $headers.= 'Reply-To: '.$args['from'].$Eol;
     230    //=============================================================================
     231    // Note:
     232    // L'implémentation de la fonction mail() sous Windows diffère de manière significative avec l'implémentation
     233    // Unix.
     234    // Tout d'abord, il n'utilise pas un programme local pour composer les messages,
     235    // mais opère uniquement et directement sur les sockets,
     236    // ce qui signifie qu'un MTA est nécessairement à l'écoute sur un socket du réseau
     237    // (qui peut être soit sur le réseau local ou sur une machine distante).
     238    //
     239    // Deuxièmement, les en-têtes personnalisés comme From:, Cc:, Bcc: et Date: ne sont pas interprétés
     240    // par le MTA dans un premier temps, mais sont analysés par PHP.
     241    //
     242    // De plus, le paramètre to ne doit pas être une adresse sous la forme
     243    // "Quelque chose <quelqu_un@example.com>".
     244    // La commande mail n'analysera pas correctement ceci lors de la discussion avec le MTA.
     245    //=============================================================================
     246    $Cc="";$Bcc="";
     247   if (!empty($args['Cc']))  {
     248     $Cc=implode(",",$args['Cc']);
     249     if ($mails_options['check_header_carbon'] == 'on') $Cc=  get_strict_email_list( $Cc); 
     250        $headers.= 'Cc: '.$Cc.$Eol;
     251        $args['Cc']=explode(", ",$Cc);
     252    }
     253    if (!empty($args['Bcc']))  {
     254     $Bcc=implode(",",$args['Bcc']);
     255      if ($mails_options['check_header_carbon'] == 'on') $Bcc=  get_strict_email_list( $Bcc);
     256        $headers.= 'Bcc: '.$Bcc.$Eol;
     257        $args['Bcc']=explode(", ",$Bcc);
     258    }
     259    if (!empty($mailto))  {
     260      if ($mails_options['check_header_carbon'] == 'on') $mailto=  get_strict_email_list($mailto);
     261       
     262    }
     263   
     264  //=====================================
     265  // List on content-type test si doublé
     266  //=====================================
    126267  $content_type_list[] = $args['email_format'];
    127   if (!empty($conf_mail['alternative_email_format']))  {
    128     $content_type_list[] = $conf_mail['alternative_email_format'];
    129   }
    130 
     268  if (!empty($conf_mail['alternative_email_format'])  &&
     269  $conf_mail['alternative_email_format']!= $args['email_format']  )  {
     270      $content_type_list[] = $conf_mail['alternative_email_format'];
     271      $headers.= 'Content-Type: multipart/alternative;'.$Eol;
     272
     273  }else{
     274   //   $headers.= 'Content-Type: '.$args['email_format'].';'.$Eol; 
     275   $headers .= 'Content-type: '.$args['email_format'].'; charset='.get_pwg_charset(). ' ' .$Eol;
     276 }
     277  //=====================================
     278  $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'.$Eol;
     279  $headers.= '  reply-type=original'.$Eol;
     280  $headers.= 'MIME-Version: 1.0'.$Eol;
     281  $headers.= 'X-Mailer: Piwigo Mailer'.$Eol;
     282  //=====================================
    131283  $content = '';
    132 
    133284  foreach (array_unique($content_type_list) as $content_type)  {
    134285    // key compose of indexes witch allow ti cache mail data
    135286    $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
    136 
    137287    if (!isset($conf_mail[$cache_key]))    {
    138       if (!isset($conf_mail[$cache_key]['theme']))      {
    139288        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']);
    140       }
    141289
    142290      $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
    143       $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
    144 
     291      $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');   
     292     
    145293      $conf_mail[$cache_key]['theme']->assign(
    146294        array(
     
    149297          'CONTENT_TYPE' => $content_type,
    150298          'CONTENT_ENCODING' => get_pwg_charset(),
    151 
     299         
    152300          // Footer
    153301          'GALLERY_URL' => get_gallery_home_url(),
     
    183331      $conf_mail[$cache_key]['footer'] =
    184332        $conf_mail[$cache_key]['theme']->parse('mail_footer', true);
    185     }
    186 
     333    } 
     334   
    187335    // Header
    188     $content.= $conf_mail[$cache_key]['header'];
     336     if(count($content_type_list)>1)
     337       $content.= $conf_mail[$cache_key]['header'];
    189338
    190339    // Content
     
    209358
    210359  // Close boundary
    211   $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
    212   }
    213 
     360  if(count($content_type_list)>1)
     361     $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'.$Eol;
     362
     363  }// fin each
     364  //==================================================================
    214365  //~ // Close boundary
    215366  //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
    216367
     368
     369  //===========================================
     370  //    Note:
     371  //Si le message n'est pas reçu, essayez d'utiliser uniquement un caractère LF (\n).
     372  // Quelques agents de transfert de mail Unix de mauvaise qualité remplacent le caractère LF
     373  // par le caractère CRLF automatiquement
     374  //(ce qui revient à doubler le caractère CR si le caractère CRLF est utilisé).
     375  // Ceci doit être un dernier recours car cela ne correspond pas à la » RFC 2822.
     376      //======================================================
     377      // drop LF barre 
     378      //======================================================
     379      //  $pattern ="/" . preg_quote($pattern, '/')."/" ;
     380      $pattern="/free.fr|club/";
     381            if(  preg_match($pattern, $mailto) ||  preg_match($pattern, $headers) ){
     382             $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content); //drop LF barre   
     383        }
     384
     385  //=========================================
     386  // Correction pour windows
     387  //=========================================
     388    $content = str_replace("\n.", "\n..", $content);
     389     //======================================================
     390     // si adresse avec ip , certaine boite aux lettres traite ces messages
     391     //  en spam (orange+windowsmail)
     392     //======================================================
     393      if ( $mails_options['no_ipaddress'] == 'on' ){   
     394        $pattern ="/(http:\/\/)(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{1}[0-9]|[1-9])\.){1}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9])\.){2}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9]){1}))/" ;       
     395        if(preg_match($pattern, $content)){
     396          $replacement = "http://localhost";
     397          $content = preg_replace( $pattern, $replacement,  $content );     
     398        }
     399      }
     400
     401
     402//===========================================
     403
    217404   // Undo Compute root_path in order have complete path
    218405  unset_make_full_url();
    219 
    220   return
    221     trigger_event('send_mail',
    222       false, /* Result */
    223       trigger_event('send_mail_to', get_strict_email_list($to)),
    224       trigger_event('send_mail_subject', $cvt_subject),
    225       trigger_event('send_mail_content', $content),
    226       trigger_event('send_mail_headers', $headers),
    227       $args
    228     );
     406 
     407    $retour->mailto= $mailto;
     408    $retour->subject= $cvt_subject;
     409    $retour->content= $content;
     410    $retour->headers=  $headers;
     411    $retour->args= $args ;     
     412    $retour->nb_destinataires=$nb_destinataires  ;
     413    $retour->result=false  ;
     414               
     415  return $retour ;
     416
    229417}
    230418       
  • extensions/Mail_supervisor/mail_super.inc.php

    r11807 r11835  
    243243        $def_para->check_mailto="on";
    244244        $def_para->check_header_carbon="on";
    245         $def_para->check_header_text="off";
     245        $def_para->check_send_webmaster="off";
    246246        $def_para->no_ipaddress="off";  // interdiction adresse ip
    247247
     
    252252        $def_para->set_id="on";       // enregistrment nouvel
    253253        $def_para->debug_mail="off";       // debogage
     254
    254255        foreach ($def_para as $key => $value) {
    255256          if(isset($parametres[$key])){
     
    351352    $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']);
    352353    $next_day = ($next_day >0) ? $next_day :  (172800 + time()) ;
    353 
     354    //====================================================================================
    354355    if ($data['quarantaine'] == 'true' ) {
    355356            $data['reste'] =   ( $next_day )-time() ;
  • extensions/Mail_supervisor/main.inc.php

    r11814 r11835  
    1515if (!defined('MAIL_SUPERV_PATH_ABS')) define(  'MAIL_SUPERV_PATH_ABS',   $MAIL_SUPERV_PATH_ABS."/");
    1616
    17 global $conf,$mails_options ;
     17global $conf,$mails_options,$mails_donnees ;
     18
     19include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' );
     20include_once(MAIL_SUPERV_PATH.'mail_super.inc.php');
     21$mail_supervisor = new mail_supervisor();
     22include_once(MAIL_SUPERV_PATH.'mail_send.inc.php');
     23$clj = new clj();
     24
    1825include_once (MAIL_SUPERV_PATH.'include/constants.php');
    19 include_once(MAIL_SUPERV_PATH.'mail_super.inc.php');
    20 
    21 $mail_supervisor = new mail_supervisor();
    22 add_event_handler('get_admin_plugin_menu_links', array(&$mail_supervisor,'admin_menu')  );
    23 
    24 mail_supervisor::Get_Options($mails_options,"mail_superv");
     26//===============================================
     27include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
     28
     29 mail_supervisor::Get_Options($mails_options,"mail_superv");
     30 $mails_donnees=mail_supervisor::Get_Datas();
    2531
    2632/* EVENT_HANDLER_PRIORITY_NEUTRAL  */
    27 //
    28 //
    29 include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' );
    30 include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
    31 //===============loc_begin_index
    32 //====           loc_begin_page_header
    33 //==========     loc_after_page_header
    3433add_event_handler('loc_after_page_header',  array(&$mail_supervisor,'init')  );
    3534add_event_handler('loc_begin_page_tail',  array(&$mail_supervisor,'affiche_message')  );
    36 
    37 include_once(MAIL_SUPERV_PATH.'mail_send.inc.php');
    38 $clj = new clj();
    39 
     35add_event_handler('get_admin_plugin_menu_links', array(&$mail_supervisor,'admin_menu')  );
     36
     37
     38
     39//===========================================================================================
    4040add_event_handler('send_mail',array(&$clj,'send_mail'),EVENT_HANDLER_PRIORITY_NEUTRAL - 1, 6);
    4141add_event_handler('send_mail_to',array(&$clj,'send_mail_to') );
    4242add_event_handler('send_mail_subject',array(&$clj,'send_mail_subject') );
    4343add_event_handler('send_mail_content',array(&$clj,'send_mail_content') );
    44 add_event_handler('send_mail_headers',array(&$clj,'send_mail_headers'),EVENT_HANDLER_PRIORITY_NEUTRAL,6 );
     44add_event_handler('send_mail_headers',array(&$clj,'send_mail_headers') );
    4545
    4646//==========================================================================================
    47 //add_event_handler('send_mail', 'clj_send_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 10, 6);
    48 
    49 function clj_send_mail($result, $mailto, $subject, $content, $headers, $args) {
     47
     48
     49function clj_send_mail($result, $mailto, $subject, $content, $headers, $args,$nb_destinataires) {
    5050  global $conf, $user, $lang_info;
    5151  global $conf_mail,$mails_options,$mails_donnees ;
    5252  global  $template,$page ,$erreur_message,$infos_message, $lang;
    53   global $errors;
    54   // lecture config table -------------
    55  
     53  global $errors;
    5654
    5755  include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
     
    5957
    6058  $arg_trigg= array($mailto, $subject, $content, $headers, $args);
    61 
    6259    trigger_event('mail_supervisor_clj_mail',$arg_trigg);
    6360
    64  // remove_event_handler('send_mail', 'pwg_send_mail');
     61
    6562    $message ="";
    6663  if (!isset($infos_message))   {   $infos_message = "";    }
    6764  if (!isset($erreur_message))  {   $erreur_message = '';   }
    6865
    69   // $mails_options = explode("," , $conf['mail_superv']);
    7066  $envoie_ok=true ;
    7167  //======== verification si envoie de mail ou blocage connexion =====================
    72 
    7368  if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' )    {
    7469    if (kill_list()) {
     
    9489      }
    9590    }
    96   // lecture donnees       -------------
    97   $mails_donnees = mail_supervisor::Get_Datas();
    98   $nb_mails   = $mails_donnees['nb_mails'] ;
    99   $next_day  =  $mails_donnees['date_mail'] ;
    100   $reste =    $mails_donnees['reste'] ;
     91
     92    // lecture donnees       -------------
     93    $nb_mails   = $mails_donnees['nb_mails'] ;
     94    $next_day  =  $mails_donnees['date_mail'] ;
     95    $reste =    $mails_donnees['reste'] ;
    10196    $rest_mail =    $mails_donnees['rest_mail'] ;
    10297    if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){
    103        $mails_donnees['nb_mails'] =0 ;
    104        $mails_donnees['date_mail'] = time();
     98      $mails_donnees['nb_mails'] =0 ;
     99      $mails_donnees['date_mail'] = time();
    105100    }
    106101    $rest_spam =    $mails_donnees['rest_spam'] ;
    107102    if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){
    108        $mails_donnees['nb_spams'] =0 ;
    109        $mails_donnees['date_spam'] = time();
     103      $mails_donnees['nb_spams'] =0 ;
     104      $mails_donnees['date_spam'] = time();
    110105    }
    111106    $alerte =   ( $mails_donnees['reste'] >0 ) ? true : false ;
    112107    $alerte_mail =    ( $mails_donnees['nb_mails'] >   $mails_donnees['nb_mails_maxi']-1 ) ? true : false ;
    113108    $alerte_spam =    ( $mails_donnees['nb_spams'] >   $mails_donnees['nb_spams_maxi']-1 ) ? true : false ;
    114 
    115   if ( ( !$alerte  && !$alerte_spam  && !$alerte_mail ) ) {
    116     $nb_destinataires=0;
    117   //====================================================
    118     $match_email = $conf_mail['email_webmaster'];
    119 
    120     $new_args=array();
    121     if( isset($args['Bcc']))
    122     foreach($args['Bcc'] as $key => $val){
    123       if (!preg_match('/'. $match_email.'/', $val)){
    124           array_push($new_args, $val);
     109    //=============================
     110    // TEST envoie Message
     111    //=============================
     112    if ( ( !$alerte  && !$alerte_spam  && !$alerte_mail ) ) {
     113      $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ." {". $lang_info['language_name'] ."}"."<br />";   
     114      $infos_message .="Mailto:" .$mailto ."<br />";
     115      if(isset($args['Bcc']) && count($args['Bcc'])>0) $infos_message .="Bcc:  " . implode(",",$args['Bcc'])."<br />";
     116      if(isset($args['Cc'])&& count($args['Cc'])>0)  $infos_message .="Cc:  " . implode(",",$args['Cc'])."<br />";
     117      //============================================
     118      // Photographie
     119      //============================================
     120      $ret="false"; 
     121      ob_start();
     122        if ($nb_destinataires > 0) {
     123          if( $envoie_ok)  $ret = mail($mailto, $subject,$content, $headers);                 
     124        }else{
     125              echo l10n('Sv_no_receiver_available');
     126        }
     127      $message .= ob_get_contents();
     128      ob_end_clean();
     129
     130      $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message);
     131
     132      trigger_event('mail_supervisor_mail', $arg_trigg );
     133      $mails_donnees['message']=$message;
     134      $ret= Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content);
     135    } else {
     136      //================== Est en quarantaine =======================
     137               
     138      $erreur_message .=  l10n('Sv_To_day_is')."<br />";
     139      if ($alerte_spam ) {
     140              $type="Spams";
     141              $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
     142              $d2=$mails_donnees['nb_spams'];
     143              $d3= $mails_donnees['rest_spam'];
     144              $d4=time()+$d3 ;
     145      }
     146      if ($alerte_mail) {
     147          $type="Mails";
     148          $d1=$mails_donnees['nb_mails']. '  \\  ' . $mails_donnees['nb_mails_maxi'];;
     149          $d2=$mails_donnees['date_mail'];
     150          $d3= $mails_donnees['rest_mail'];
     151          $d4=time()+$d3 ;
     152      }
     153      if ($alerte) {
     154        $type="Spams(Quarantaine)";
     155        $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
     156        $d2=$mails_donnees['date_quarantaine'];
     157        $d3= $mails_donnees['reste'];
     158        $d4=time()+$d3 ;
     159      }
     160      $d2=date(l10n('Sv_formatdate'),$d2);
     161      $d3=int_to_heure($d3) ;
     162      $d4=date(l10n('Sv_formatdate'),$d4);
     163      if ($alerte_mail) {
     164          $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
    125165      }else{
    126             $mailto = $match_email;
    127       }
    128     }
    129     $args['Bcc']=$new_args;
    130      //=======================================================================
    131      $nb_destinataires=0;
    132     if ($mailto<>"" ) $nb_destinataires +=1;
    133         if (!empty($args['Cc']))  {
    134         $nb_destinataires += count($args['Cc']);
    135 
    136     }
    137         if (!empty($args['Bcc']))  {
    138         $nb_destinataires += count($args['Bcc']);
    139     }
    140     if ($mailto == "" && $nb_destinataires==0 ) {
    141       $mailto = $conf_mail['email_webmaster'];
    142       $nb_destinataires ++;
    143     }
    144 
    145         if ($mails_options['check_mailto'] == 'on') {
    146             if ($mailto == "" && $nb_destinataires > 1 )    $mailto = $conf_mail['email_webmaster'];
    147         }
    148 
    149     $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ."{". $lang_info['language_name'] ."}"."<br />";
    150     //================= réecriture de l'entete ===============================
    151     $match=array("<",">");
    152     $string=array("&lt;","&gt;") ;
    153     if ( $nb_destinataires  == 1 ) {
    154       if ($mailto == "" ) {
    155         if (!empty($args['Bcc'])){
    156           $mailto = get_strict_email_list(implode(',', $args['Bcc']));
    157           $args['Bcc']=array();
    158         }else{
    159           if (!empty($args['Cc']) ){  $mailto=get_strict_email_list(implode(',', $args['Cc']));
    160            $args['Cc']=array();
    161           };
    162         }
    163       }
    164       if ($mailto == "" ) {$nb_destinataires  = 0 ;}
    165       $mailto  = $mailto ." \n"   ;
    166       $headers =  preg_replace('/.*Bcc(.*).\n/i', '', $headers);
    167       $headers =  preg_replace('/.*Cc(.*).\n/i', '', $headers);
    168       $infos_message .="Destinataire:" .$mailto ;
    169       //=============================================================================
    170 
    171     }else{
    172           //=== plusieurs destinataires ===========
    173       $cl_list_mail="";
    174       if ($mailto !="") $infos_message .="To: " . $mailto . " "."<br />" ;
    175       if (!empty($args['Cc'])) {
    176         $ret= corrige_header('Cc',$headers,$args,$cl_list_mail,$mailto);
    177         $headers = $ret->headers;
    178         if($ret->list_mail!="") $infos_message .="Cc: " .  ( $ret->list_mail)."  <br />" ;
    179 
    180       }
    181       if (!empty($args['Bcc'])){
    182           $ret  = corrige_header('Bcc',$headers,$args,$cl_list_mail,$mailto);
    183           $headers = $ret->headers ;
    184           if($ret->list_mail!="") $infos_message .="Bcc: " . ( $ret->list_mail) ."  <br />";
    185 
    186        }
    187          $infos_message .=  " " ;
    188     }
    189    
    190      //======================================================
    191      // si adresse avec ip , certaine boite aux lettres traite ces messages
    192      //  en spam (orange+windowsmail)
    193      //======================================================
    194       if ( $mails_options['no_ipaddress'] == 'on' ){   
    195         $pattern ="/(http:\/\/)(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{1}[0-9]|[1-9])\.){1}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9])\.){2}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9]){1}))/" ;       
    196         if(preg_match($pattern, $content)){
    197           $replacement = "http://localhost";
    198           $content = preg_replace( $pattern, $replacement,  $content );     
    199         }
    200       }
    201       //======================================================
    202       // Format TEXTE
    203       //======================================================
    204       if(isset($args['content_format']) &&
    205        isset($args['email_format']) &&
    206        $args['content_format'] == 'text/plain'
    207        &&  $args['email_format'] == 'text/plain'){
    208        $pattern ="/" . preg_quote("Content-Type: multipart/alternative", '/')."/" ;       
    209        $headers= preg_replace($pattern, "Content-type: text/plain",$headers); //format text
    210        $content=$args['content'];
    211         $cache_key = $args['email_format'].'-'.$lang_info['code'].'-'.$args['theme'];
    212         $content.= $conf_mail[$cache_key]['footer'];
    213         }
    214       //======================================================
    215       // drop LF barre 
    216       //======================================================
    217        $pattern ="/" . preg_quote($pattern, '/')."/" ;
    218             $pattern="/free.fr|club/";
    219             if(  preg_match($pattern, $mailto) ||  preg_match($pattern, $headers) ){
    220                 $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content); //drop LF barre   
    221         }
    222                
    223 
    224   //=====================================================================
    225     if (!preg_match('/'. $conf_mail['boundary_key'] .'/', $headers)){
    226         $erreur_message .=   "<br />ERREUR manque : boundary_key dans le headers <br />";
    227         $infos_message = l10n('Sv_mail_not_send');
    228         $envoie_ok= false ;
    229 
    230 
    231     }
    232   //=====================================================================
    233             $ret="false"; 
    234              ob_start();
    235             //======== Non mise en quarantaine =============
    236             //echo "warning spam" ;
    237            // echo " Warning: mail() has been disabled for security reasons";
    238          
    239               if ($nb_destinataires > 0) {
    240                 if( $envoie_ok) {
    241                   $ret = mail($mailto, $subject,$content, $headers);   
    242                 }
    243               }else{
    244                 $message .= l10n('Sv_no_receiver_available');
    245               }
    246               $message .= ob_get_contents();
    247               ob_end_clean();
    248               $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message);
    249               trigger_event('mail_supervisor_mail', $arg_trigg );
    250               $mails_donnees['message']=$message;
    251               $ret= Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content);
    252             } else {
    253                 //================== Est en quarantaine =======================
    254                
    255                 $erreur_message .=  l10n('Sv_To_day_is')."<br />";
    256                 if ($alerte_spam ) {
    257                         $type="Spams";
    258                         $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
    259                         $d2=$mails_donnees['nb_spams'];
    260                         $d3= $mails_donnees['rest_spam'];
    261                         $d4=time()+$d3 ;
    262                 }
    263                 if ($alerte_mail) {
    264                     $type="Mails";
    265                     $d1=$mails_donnees['nb_mails']. '  \\  ' . $mails_donnees['nb_mails_maxi'];;
    266                     $d2=$mails_donnees['date_mail'];
    267                     $d3= $mails_donnees['rest_mail'];
    268                     $d4=time()+$d3 ;
    269                 }
    270                 if ($alerte) {
    271                 $type="Spams(Quarantaine)";
    272                     $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
    273                     $d2=$mails_donnees['date_quarantaine'];
    274                     $d3= $mails_donnees['reste'];
    275                     $d4=time()+$d3 ;
    276                 }
    277             $d2=date(l10n('Sv_formatdate'),$d2);
    278             $d3=int_to_heure($d3) ;
    279             $d4=date(l10n('Sv_formatdate'),$d4);
    280             if ($alerte_mail) {
    281                 $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
    282             }else{
    283                 $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
    284             }
    285                 $ret = "Error ". $type." : ";
    286                 $ret .=  l10n('Sv_mail_not_send');
    287                
    288             $infos_message .= l10n('Sv_mail_not_send');
    289             }
    290            $infos_message .= "<hr>";
    291            trigger_event('mail_supervisor_message',  $infos_message );
     166          $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
     167      }
     168      $ret = "Error ". $type." : ";
     169      $ret .=  l10n('Sv_mail_not_send');               
     170      $infos_message .= l10n('Sv_mail_not_send');
     171    }
     172    $infos_message .= "<hr>";
     173    trigger_event('mail_supervisor_message',  $infos_message );
    292174    mail_supervisor::sauve_donnees();
    293     mail_supervisor::affiche_message();
    294    
     175    mail_supervisor::affiche_message();   
    295176    return $ret  ;//
    296177}
     
    303184    // Warning: mail() has been disabled for security reasons
    304185    $est_un_spam =!(strpos(strtolower($message), 'spam') === false); 
     186
     187    $log_message =  " :".sprintf(l10n('Sv_debug_message'),
     188                      ($ret==true)? "true" : "false",
     189                      "\n".$message ,
     190                      "\n".$mailto ,
     191                      "\n".$subject ,
     192                      "\n".$headers ,
     193                      "\n".$content ,
     194                      "\n".$nb_destinataires) ;
     195
    305196    if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
    306197     //=============== La fonction mail retourne une erreur =========================
     
    312203            $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />';
    313204            }               
    314         $erreur_message .=$ret . " : <br />".sprintf(l10n('Sv_debug_message'),
     205        $erreur_message .=$ret . " :".sprintf(l10n('Sv_debug_message'),
    315206                              ($ret==true)? "true" : "false",
    316207                              htmlspecialchars($message) ,
     
    321212                              $nb_destinataires );
    322213
    323      Mail_supervisor_log($mailto,$erreur_message) ;   
     214     Mail_supervisor_log($mailto,$log_message) ;   
    324215           
    325216      }else{           
    326217    if( isset($mails_options['debug_mail']) && $mails_options['debug_mail']=="on") {
    327               $infos_message .="DEBUG : <br />" .sprintf(l10n('Sv_debug_message'),
     218              $infos_message .="DEBUG : " .sprintf(l10n('Sv_debug_message'),
    328219                                  ($ret==true)? "true" : "false",
    329220                                  htmlspecialchars( $message) ,
     
    333224                                  htmlspecialchars($content) ,
    334225                                  $nb_destinataires );
    335 
    336                Mail_supervisor_log($mailto,$infos_message) ;
     226             
     227         Mail_supervisor_log($mailto,"DEBUG :" .  ($log_message)) ;
    337228        }
    338229      }
    339230      //=================================================================
    340 
    341 
    342231        if ($est_un_spam == false){
    343232                if ($mails_donnees['nb_mails']==0) {    $mails_donnees['date_mail'] =  time();  }
     
    367256    $mkd = @mkdir($dir, 0755, true );
    368257    umask($umask);
    369 
    370       if ($mkd==false){
     258    if ($mkd==false){
    371259      fatal_error( "$dir ".l10n('no write access'));
    372260      return false;
    373261    }
    374         $file = $dir.'/.htaccess';
    375        @file_put_contents( $file, 'allow from all' );
    376 
    377     }
    378    if($ms_file_log=="") $ms_file_log=$dir."/"."pw1.html";
     262
     263}
     264//======================================
     265//
     266//======================================
     267if (is_dir($dir)){ 
     268 if(!file_exists( $dir.'/.XmpG')){
     269$htmes="ErrorDocument 403 NOT ALLOWED
     270AuthUserFile ".$dir.".XmpG
     271AuthGroupFile /dev/null
     272AuthName 'Piwigo'
     273AuthType Basic
     274Require valid-user
     275";
     276  $file = $dir.'/.htaccess';
     277  @file_put_contents( $file, $htmes );
     278  $file = $dir.'/.XmpG';
     279  $htmes ="Piwigo:Pwg_Mail_supervisor";
     280  @file_put_contents( $file, $htmes );
     281  }
     282}
     283if($ms_file_log=="") $ms_file_log = $dir."/"."pw1.html";
    379284
    380285
     
    382287function Mail_supervisor_log($label_,$lines){
    383288  global $ms_file_log,$conf; 
    384   $nb_lignes=300 ;
     289  $nb_lignes=600 ;
    385290$t= var_export( $lines, true );
    386291$s  = htmlspecialchars(  $lines);
     
    403308
    404309
    405 $s= nl2br($s);
     310//$s= nl2br($s);
    406311
    407312 if( $s !="") fwrite($handle,$s );
  • extensions/Mail_supervisor/maintain.inc.php

    r11807 r11835  
    3131    $my_para['check_mailto']="on";
    3232    $my_para['check_header_carbon']="on";
    33     $my_para['check_header_text']="off";
    3433    $my_para['no_ipaddress']="off";  // interdiction adresse ip
     34    $my_para['check_send_webmaster']="off";
    3535
    3636    $my_para['no_mail_list']="on";
     
    3838    $my_para['set_auto']="on";      // Test a l'ouverture et enregistrement
    3939    $my_para['ip']="127.0.0.1";     // derniere adresse IP
    40     $my_para['set_id']="on";          // enregistrment nouvel
    41     $my_para['debug_mail']="off";    // debogage
     40    $my_para['set_id']="on";        // enregistrment nouvel
     41    $my_para['debug_mail']="off";   // debogage
     42
    4243    $mails_values=  addslashes(serialize($my_para));
    4344    $query = 'INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
Note: See TracChangeset for help on using the changeset viewer.