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

[extensions] mail_supervisor cleaning of the programs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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       
Note: See TracChangeset for help on using the changeset viewer.