Ignore:
Timestamp:
Jul 21, 2011, 5:57:36 PM (13 years ago)
Author:
cljosse
Message:

[extensions] mail_supervisor add 'title' and subject in tab test

File:
1 edited

Legend:

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

    r10822 r11807  
    2222add_event_handler('get_admin_plugin_menu_links', array(&$mail_supervisor,'admin_menu')  );
    2323
    24 $mails_options = mail_supervisor::Get_Options($mails_options,"mail_superv");
     24mail_supervisor::Get_Options($mails_options,"mail_superv");
     25
    2526/* EVENT_HANDLER_PRIORITY_NEUTRAL  */
    2627//
     
    2829include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' );
    2930include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
    30 //===============loc_begin_index====loc_begin_page_header==========loc_after_page_header=============================================================
     31//===============loc_begin_index
     32//====           loc_begin_page_header
     33//==========     loc_after_page_header
    3134add_event_handler('loc_after_page_header',  array(&$mail_supervisor,'init')  );
    3235add_event_handler('loc_begin_page_tail',  array(&$mail_supervisor,'affiche_message')  );
    3336
     37include_once(MAIL_SUPERV_PATH.'mail_send.inc.php');
     38$clj = new clj();
     39
     40add_event_handler('send_mail',array(&$clj,'send_mail'),EVENT_HANDLER_PRIORITY_NEUTRAL - 1, 6);
     41add_event_handler('send_mail_to',array(&$clj,'send_mail_to') );
     42add_event_handler('send_mail_subject',array(&$clj,'send_mail_subject') );
     43add_event_handler('send_mail_content',array(&$clj,'send_mail_content') );
     44add_event_handler('send_mail_headers',array(&$clj,'send_mail_headers'),EVENT_HANDLER_PRIORITY_NEUTRAL,6 );
     45
    3446//==========================================================================================
    35 add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 10, 6);
    36 function clj_mail($result, $mailto, $subject, $content, $headers, $args) {
     47//add_event_handler('send_mail', 'clj_send_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 10, 6);
     48
     49function clj_send_mail($result, $mailto, $subject, $content, $headers, $args) {
    3750  global $conf, $user, $lang_info;
    3851  global $conf_mail,$mails_options,$mails_donnees ;
     
    4053  global $errors;
    4154  // lecture config table -------------
     55 
     56
    4257  include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
    4358  load_language('plugin.lang', MAIL_SUPERV_PATH);
     
    173188    }
    174189   
    175      $pattern = '/(http:\/\/)([0-9].*)([0-9]\/)/';
    176      //---- si adresse avec ip , certaine boite aux lettres traite ces messages en spam (orange+windowsmail)
    177   if(preg_match($pattern, $content)){
    178       // remplace 192.168.1.25 par rien ??
    179       $replacement = '${1}';
    180       $content = preg_replace( $pattern, $replacement,  $content );     
    181 }
    182 
    183       $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content); //drop LF barre
    184 
     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      // drop LF barre 
     203      //======================================================
     204      $pattern="/xxxxx/";
     205      if(  preg_match($pattern, $mailto) ||  preg_match($pattern, $headers) ){
     206        $pattern="---=";
     207        $pattern ="/" . preg_quote($pattern, '/')."/" ;
     208
     209      // site legtux ; adresse @lextux OK
     210       //  $content=$content                                          // Ok legtux
     211       //  $content= preg_replace('#(?<!\r)\n#si', "\n", $content); // Ok legtux
     212
     213        $pattern ="#(?<!\r)\n#si" ;
     214        if(  preg_match($pattern, $content)  ){
     215            $infos_message .= $pattern. " <br />";   
     216        }
     217       
     218        $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content);   // 
     219        $content = str_replace("\n.", "\n..", $content);
     220
     221    $message = "<h2>local</h2> ";
     222    $nheaders = 'From: cl_josse@orange.fr' . "\r\n" .
     223    'Reply-To: cl_josse@orange.fr' . "\r\n" .
     224    'X-Mailer: PHP/' . phpversion();
     225
     226
     227     mail("cl_josse@hotmail.fr", $subject, "Test1  ".$message);
     228  mail("cl_josse@hotmail.fr", $subject,"TEST 2 ". $message,$nheaders);
     229
     230     return true ;
     231
     232
     233
     234
     235       if(  preg_match($pattern, $content)  ){
     236            $infos_message .= "OK". " <br />";   
     237        }
     238
     239      }else{
     240          $pattern="/hotmail/";
     241          if(  preg_match($pattern, $mailto) ||  preg_match($pattern, $headers) ){
     242             // 
     243          }else{
     244            $pattern="/free.fr|club/";
     245            if(  preg_match($pattern, $mailto) ||  preg_match($pattern, $headers) ){
     246                $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content); //drop LF barre   
     247            }else{
     248               
     249            }
     250          }
     251      }
     252
     253  //=====================================================================
    185254    if (!preg_match('/'. $conf_mail['boundary_key'] .'/', $headers)){
    186255        $erreur_message .=   "<br />ERREUR manque : boundary_key dans le headers <br />";
    187256        $infos_message = l10n('Sv_mail_not_send');
    188257        $envoie_ok= false ;
    189     }
    190             $ret=false; 
     258        return false ;
     259
     260    }
     261  //=====================================================================
     262            $ret="false"; 
    191263             ob_start();
    192264            //======== Non mise en quarantaine =============
     
    195267         
    196268              if ($nb_destinataires > 0) {
    197                 if( $envoie_ok)  $ret = mail($mailto, $subject,$content, $headers);
     269                if( $envoie_ok) {
     270                  $ret = mail($mailto, $subject,$content, $headers);   
     271                }
    198272              }else{
    199273                $message .= l10n('Sv_no_receiver_available');
     
    204278              trigger_event('mail_supervisor_mail', $arg_trigg );
    205279              $mails_donnees['message']=$message;
    206               Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content);
     280              $ret= Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content);
    207281            } else {
    208282                //================== Est en quarantaine =======================
     283               
    209284                $erreur_message .=  l10n('Sv_To_day_is')."<br />";
    210285                if ($alerte_spam ) {
     
    237312                $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
    238313            }
     314                $ret = "Error ". $type." : ";
     315                $ret .=  l10n('Sv_mail_not_send');
     316               
    239317            $infos_message .= l10n('Sv_mail_not_send');
    240318            }
     
    244322    mail_supervisor::affiche_message();
    245323   
    246     return true ;
     324    return $ret  ;//
    247325}
    248326//===========================================================================================
     
    255333    $est_un_spam =!(strpos(strtolower($message), 'spam') === false); 
    256334    if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
     335     //=============== La fonction mail retourne une erreur =========================
     336        $ret="Error";
    257337        // Bad recipient address syntax
    258338        $pos1 = strpos(strtolower($message), 'bad recipient address syntax');
     
    261341            $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />';
    262342            }               
    263 
    264     $erreur_message .=sprintf(l10n('Sv_debug_message'),
     343        $erreur_message .=$ret . " : <br />".sprintf(l10n('Sv_debug_message'),
    265344                              ($ret==true)? "true" : "false",
    266345                              htmlspecialchars($message) ,
     
    272351
    273352     Mail_supervisor_log($mailto,$erreur_message) ;   
    274      //=============== La fonction mail retourne une erreur =========================
    275       }else{
    276353           
     354      }else{           
    277355    if( isset($mails_options['debug_mail']) && $mails_options['debug_mail']=="on") {
    278         $erreur_message .="DEBUG : <br />" .sprintf(l10n('Sv_debug_message'),
    279                                   "DEBUG",
     356              $infos_message .="DEBUG : <br />" .sprintf(l10n('Sv_debug_message'),
     357                                  ($ret==true)? "true" : "false",
    280358                                  htmlspecialchars( $message) ,
    281359                                  htmlspecialchars( $mailto) ,
     
    285363                                  $nb_destinataires );
    286364
    287          Mail_supervisor_log($mailto,$erreur_message) ;
    288         }
    289       }
    290 
     365               Mail_supervisor_log($mailto,$infos_message) ;
     366        }
     367      }
     368      //=================================================================
    291369
    292370
     
    295373                $mails_donnees['nb_mails'] += $nb_destinataires;
    296374            } else {
     375                $ret="Error spam";
    297376                $mails_donnees['nb_spams'] += $nb_destinataires;
    298377                //--- Detection de spam ------------------
     
    308387                    }
    309388            }
    310  $ret=true;
    311389 return $ret ;
    312390}
     
    361439
    362440/*
    363  *
     441 * sends an email, using Piwigo specific informations
    364442 *
    365443 * @param:
    366  *    
     444 *   - to: receiver(s) of the mail (list separated by comma).
    367445 *   - args: function params of mail function:
    368446 *       o from: sender [default value webmaster email]
     
    377455 * @return boolean (Ok or not)
    378456 */
    379 function cl_pwg_mail(  $args = array())
    380 {
    381   global $conf, $conf_mail, $lang_info, $page;   
    382   global $erreur_message ;
    383   if (!isset($conf_mail)) {
     457function cl_pwg_mail($to, $args = array()){
     458  global $conf, $conf_mail, $lang_info, $page;
     459  if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) {
     460    return true;
     461  }
     462  if (!isset($conf_mail))  {
    384463    $conf_mail = get_mail_configuration();
    385464  }
    386   if (empty($args['email_format']))  {
     465  if (empty($args['email_format'])) {
    387466    $args['email_format'] = $conf_mail['default_email_format'];
    388467  }
    389468  // Compute root_path in order have complete path
    390   set_make_full_url();
    391   if (!isset($args['content'])) {
     469  set_make_full_url();
     470  if (empty($args['from']))  {
     471    $args['from'] = $conf_mail['formated_email_webmaster'];
     472  }  else  {
     473    $args['from'] = format_email('', $args['from']);
     474  }
     475  if (empty($args['subject']))  {
     476    $args['subject'] = 'Piwigo';
     477  }
     478  // Spring cleaning
     479  $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
     480  // Ascii convertion
     481  $cvt_subject = encode_mime_header($cvt_subject);
     482
     483  if (!isset($args['content']))  {
    392484    $args['content'] = '';
    393485  }
     486
    394487  if (empty($args['content_format']))  {
    395     $args['content_format'] = 'text/plain';  }
     488    $args['content_format'] = 'text/plain';
     489  }
     490
     491  if ($conf_mail['send_bcc_mail_webmaster'])  {
     492    $args['Bcc'][] = $conf_mail['formated_email_webmaster'];
     493  }
     494
    396495  if (empty($args['theme']))  {
    397496    $args['theme'] = get_default_theme();
    398497  }
     498
     499  $headers = 'From: '.$args['from']."\n";
     500  $headers.= 'Reply-To: '.$args['from']."\n";
     501
     502  if (!empty($args['Cc']))  {
     503    $headers.= 'Cc: '.implode(',', $args['Cc'])."\n";
     504  }
     505
     506  if (!empty($args['Bcc']))  {
     507    $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";
     508  }
     509
     510  $headers.= 'Content-Type: multipart/alternative;'."\n";
     511  $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'."\n";
     512  $headers.= '  reply-type=original'."\n";
     513  $headers.= 'MIME-Version: 1.0'."\n";
     514  $headers.= 'X-Mailer: Piwigo Mailer'."\n";
    399515
    400516  // List on content-type
     
    403519    $content_type_list[] = $conf_mail['alternative_email_format'];
    404520  }
     521
    405522  $content = '';
    406   foreach (array_unique($content_type_list) as $content_type)
    407   {
     523
     524  foreach (array_unique($content_type_list) as $content_type)  {
    408525    // key compose of indexes witch allow ti cache mail data
    409526    $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
    410     unset($conf_mail[$cache_key]);
    411     if (!isset($conf_mail[$cache_key])){
    412       if (!isset($conf_mail[$cache_key]['theme'])){
     527
     528    if (!isset($conf_mail[$cache_key]))    {
     529      if (!isset($conf_mail[$cache_key]['theme']))      {
    413530        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']);
    414531      }
     532
    415533      $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
    416534      $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
     535
    417536      $conf_mail[$cache_key]['theme']->assign(
    418537        array(
     
    434553          ));
    435554
    436       if ($content_type == 'text/html'){
    437         if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl')){
     555      if ($content_type == 'text/html')     {
     556        if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl'))
     557        {
    438558          $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');
    439559          $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
     
    441561
    442562        $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl';
    443         if (is_file($file)){
     563        if (is_file($file))   {
    444564          $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file));
    445565          $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');
    446566        }
    447       } 
     567      }
    448568
    449569      // what are displayed on the header of each mail ?
     
    457577
    458578    // Header
    459    $content.= $conf_mail[$cache_key]['header'];
    460        // Content
    461     if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html')){
     579    $content.= $conf_mail[$cache_key]['header'];
     580
     581    // Content
     582    if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html'))    {
    462583      $content.= '<p>'.
    463584                  nl2br(
     
    466587                                 htmlspecialchars($args['content']))).
    467588                  '</p>';
    468     } else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain')) {
     589    }
     590    else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain'))
     591    {
    469592      // convert html text to plain text
    470593      $content.= strip_tags($args['content']);
    471     } else {
     594    }    else    {
    472595      $content.= $args['content'];
    473596    }
    474597
    475     // Footer 
    476     $content.= $conf_mail[$cache_key]['footer']."\n\n";
    477    
    478     // Close boundary
    479     $content.= "\n\n".'-----='.$conf_mail['boundary_key'].'--'."\n\n";
    480   }
     598    // Footer
     599    $content.= $conf_mail[$cache_key]['footer'];
     600
     601  // Close boundary
     602  $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
     603  }
     604
     605  //~ // Close boundary
     606  //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
     607
    481608   // Undo Compute root_path in order have complete path
    482   unset_make_full_url();
    483 
    484 
    485 
    486   return    $content;
    487  
     609  unset_make_full_url();
     610
     611  return
     612    trigger_event('send_mail',
     613      false, /* Result */
     614      trigger_event('send_mail_to', get_strict_email_list($to)),
     615      trigger_event('send_mail_subject', $cvt_subject),
     616      trigger_event('send_mail_content', $content),
     617      trigger_event('send_mail_headers', $headers),
     618      $args
     619    );
    488620}
    489621
     622
    490623?>
Note: See TracChangeset for help on using the changeset viewer.