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

Last change on this file since 11807 was 11807, checked in by cljosse, 13 years ago

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

File size: 24.7 KB
Line 
1<?php
2/*
3Plugin Name: Mail supervisor
4Version: auto
5Description: Mail supervisor surveille l'envoie des mails.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=315
7Author: cljosse
8Author URI:http://cljosse.free.fr
9*/
10if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
11if (!defined('mail_superv_DIR')) define('mail_superv_DIR' , basename(dirname(__FILE__)));
12if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
13
14$MAIL_SUPERV_PATH_ABS = str_replace('\\','/',dirname(__FILE__) );
15if (!defined('MAIL_SUPERV_PATH_ABS')) define(  'MAIL_SUPERV_PATH_ABS',   $MAIL_SUPERV_PATH_ABS."/");
16
17global $conf,$mails_options ;
18include_once (MAIL_SUPERV_PATH.'include/constants.php');
19include_once(MAIL_SUPERV_PATH.'mail_super.inc.php');
20
21$mail_supervisor = new mail_supervisor();
22add_event_handler('get_admin_plugin_menu_links', array(&$mail_supervisor,'admin_menu')  );
23
24mail_supervisor::Get_Options($mails_options,"mail_superv");
25
26/* EVENT_HANDLER_PRIORITY_NEUTRAL  */
27//
28//
29include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' );
30include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
31//===============loc_begin_index
32//====           loc_begin_page_header
33//==========     loc_after_page_header
34add_event_handler('loc_after_page_header',  array(&$mail_supervisor,'init')  );
35add_event_handler('loc_begin_page_tail',  array(&$mail_supervisor,'affiche_message')  );
36
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
46//==========================================================================================
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) {
50  global $conf, $user, $lang_info;
51  global $conf_mail,$mails_options,$mails_donnees ;
52  global  $template,$page ,$erreur_message,$infos_message, $lang;
53  global $errors;
54  // lecture config table -------------
55 
56
57  include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
58  load_language('plugin.lang', MAIL_SUPERV_PATH);
59
60  $arg_trigg= array($mailto, $subject, $content, $headers, $args);
61
62    trigger_event('mail_supervisor_clj_mail',$arg_trigg);
63
64 // remove_event_handler('send_mail', 'pwg_send_mail');
65    $message ="";
66  if (!isset($infos_message))   {   $infos_message = "";    }
67  if (!isset($erreur_message))  {   $erreur_message = '';   }
68
69  // $mails_options = explode("," , $conf['mail_superv']);
70  $envoie_ok=true ;
71  //======== verification si envoie de mail ou blocage connexion =====================
72
73  if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' )    {
74    if (kill_list()) {
75      $nb_destinataires=0; ;
76      $envoie_ok= false ;
77      $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ;
78      $infos_message = l10n('Sv_mail_not_send')."<BR />";
79      if ($mails_options['no_connect'] == 'on' ){         
80          if ($user['status'] == 'webmaster'){
81          //---------- continuer si web master ----------
82          }else{
83             trigger_event('mail_supervisor_send_mail', "DIE(KILL) : " . $ip . ' = ' . $user['status']);
84              if (!isset($_GET['admin'])) {
85                      die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!');
86                        }elseif   ($_GET['admin'] != 'piwigo')
87                            {
88                      die('blacklist Hacking attempt!');
89              }
90          }
91      }
92      trigger_event('mail_supervisor_send_mail', "Kill : " . $ip . ' = ' . $user['status'] . "noconnect==off");
93      return true;
94      }
95    }
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'] ;
101    $rest_mail =    $mails_donnees['rest_mail'] ;
102    if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){
103       $mails_donnees['nb_mails'] =0 ;
104       $mails_donnees['date_mail'] = time();
105    }
106    $rest_spam =    $mails_donnees['rest_spam'] ;
107    if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){
108       $mails_donnees['nb_spams'] =0 ;
109       $mails_donnees['date_spam'] = time();
110    }
111    $alerte =   ( $mails_donnees['reste'] >0 ) ? true : false ;
112    $alerte_mail =    ( $mails_donnees['nb_mails'] >   $mails_donnees['nb_mails_maxi']-1 ) ? true : false ;
113    $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);
125      }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      // 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  //=====================================================================
254    if (!preg_match('/'. $conf_mail['boundary_key'] .'/', $headers)){
255        $erreur_message .=   "<br />ERREUR manque : boundary_key dans le headers <br />";
256        $infos_message = l10n('Sv_mail_not_send'); 
257        $envoie_ok= false ;
258        return false ;
259
260    }
261  //=====================================================================
262            $ret="false"; 
263             ob_start();
264            //======== Non mise en quarantaine =============
265            //echo "warning spam" ;
266           // echo " Warning: mail() has been disabled for security reasons";
267         
268              if ($nb_destinataires > 0) {
269                if( $envoie_ok) { 
270                  $ret = mail($mailto, $subject,$content, $headers);   
271                }
272              }else{
273                $message .= l10n('Sv_no_receiver_available');
274              }
275              $message .= ob_get_contents();
276              ob_end_clean();
277              $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message);
278              trigger_event('mail_supervisor_mail', $arg_trigg );
279              $mails_donnees['message']=$message;
280              $ret= Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content);
281            } else {
282                //================== Est en quarantaine =======================
283               
284                $erreur_message .=  l10n('Sv_To_day_is')."<br />";
285                if ($alerte_spam ) {
286                        $type="Spams";
287                        $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
288                        $d2=$mails_donnees['nb_spams'];
289                        $d3= $mails_donnees['rest_spam'];
290                        $d4=time()+$d3 ;
291                }
292                if ($alerte_mail) {
293                    $type="Mails";
294                    $d1=$mails_donnees['nb_mails']. '  \\  ' . $mails_donnees['nb_mails_maxi'];;
295                    $d2=$mails_donnees['date_mail'];
296                    $d3= $mails_donnees['rest_mail'];
297                    $d4=time()+$d3 ;
298                }
299                if ($alerte) {
300                $type="Spams(Quarantaine)";
301                    $d1=$mails_donnees['nb_spams'] . '  \\  ' . $mails_donnees['nb_spams_maxi'];
302                    $d2=$mails_donnees['date_quarantaine'];
303                    $d3= $mails_donnees['reste'];
304                    $d4=time()+$d3 ;
305                }
306            $d2=date(l10n('Sv_formatdate'),$d2);
307            $d3=int_to_heure($d3) ;
308            $d4=date(l10n('Sv_formatdate'),$d4);
309            if ($alerte_mail) {
310                $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
311            }else{
312                $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />';
313            }
314                $ret = "Error ". $type." : ";
315                $ret .=  l10n('Sv_mail_not_send');
316               
317            $infos_message .= l10n('Sv_mail_not_send');
318            }
319           $infos_message .= "<hr>"; 
320           trigger_event('mail_supervisor_message',  $infos_message );
321    mail_supervisor::sauve_donnees();
322    mail_supervisor::affiche_message();
323   
324    return $ret  ;//
325}
326//===========================================================================================
327function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content){
328     global $conf, $user,  $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info;
329     $match=array("<",">");
330     $string=array("&lt;","&gt;") ;
331     //  $headers=str_replace( $match,$string, $headers);
332    // Warning: mail() has been disabled for security reasons
333    $est_un_spam =!(strpos(strtolower($message), 'spam') === false); 
334    if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) {
335     //=============== La fonction mail retourne une erreur =========================
336        $ret="Error";
337        // Bad recipient address syntax
338        $pos1 = strpos(strtolower($message), 'bad recipient address syntax');
339        if (  !($pos1 === false) ){
340            $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .';
341            $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />';
342            }               
343        $erreur_message .=$ret . " : <br />".sprintf(l10n('Sv_debug_message'),
344                              ($ret==true)? "true" : "false",
345                              htmlspecialchars($message) ,
346                              htmlspecialchars( $mailto) ,
347                              htmlspecialchars($subject) ,
348                              htmlspecialchars($headers) ,
349                              htmlspecialchars($content) ,
350                              $nb_destinataires );
351
352     Mail_supervisor_log($mailto,$erreur_message) ;   
353           
354      }else{           
355    if( isset($mails_options['debug_mail']) && $mails_options['debug_mail']=="on") {
356              $infos_message .="DEBUG : <br />" .sprintf(l10n('Sv_debug_message'),
357                                  ($ret==true)? "true" : "false",
358                                  htmlspecialchars( $message) ,
359                                  htmlspecialchars( $mailto) ,
360                                  htmlspecialchars($subject) ,
361                                  htmlspecialchars($headers) ,
362                                  htmlspecialchars($content) ,
363                                  $nb_destinataires );
364
365               Mail_supervisor_log($mailto,$infos_message) ; 
366        }
367      }
368      //=================================================================
369
370
371        if ($est_un_spam == false){
372                if ($mails_donnees['nb_mails']==0) {    $mails_donnees['date_mail'] =  time();  }
373                $mails_donnees['nb_mails'] += $nb_destinataires;
374            } else {
375                $ret="Error spam";
376                $mails_donnees['nb_spams'] += $nb_destinataires;
377                //--- Detection de spam ------------------
378                if ($mails_donnees['nb_spams']==0) {$mails_donnees['date_spam'] = time();   }
379
380                $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false);
381                if ( $trop_de_spam ) {
382                        $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams'];
383
384                        $mails_donnees['date_quarantaine']= time()  ;
385                        $mails_donnees['quarantaine']= true    ;
386                        $infos_message .= mail_supervisor::Memo_Var($mails_donnees);
387                    }
388            }
389 return $ret ;
390}
391//============================================================
392global $ms_file_log;
393$dir=$conf['local_data_dir'].'/Mail_supervisor_log';
394 if (!is_dir($dir)){ 
395    $umask = umask(0);
396    $mkd = @mkdir($dir, 0755, true );
397    umask($umask);
398
399      if ($mkd==false){
400      fatal_error( "$dir ".l10n('no write access'));
401      return false;
402    }
403        $file = $dir.'/.htaccess';
404       @file_put_contents( $file, 'allow from all' );
405
406    }
407   if($ms_file_log=="") $ms_file_log=$dir."/"."pw1.html";
408
409
410//============================================================
411function Mail_supervisor_log($label_,$lines){
412  global $ms_file_log,$conf; 
413  $nb_lignes=300 ;
414$t= var_export( $lines, true );
415$s  = htmlspecialchars(  $lines);
416 $s  =  (  $lines);
417    if (!file_exists($ms_file_log)) { 
418    $handle = fopen($ms_file_log, 'w');
419    fwrite($handle, "\n");
420    fclose($handle);
421    }
422  $tableau=file($ms_file_log);
423  $handle = fopen($ms_file_log, 'a');
424  $nb=count ($tableau);
425   if($nb>$nb_lignes) {
426      $handle = fopen($ms_file_log, 'w');
427      fwrite($handle, $nb. " > " . $nb_lignes . "  RAZ " ."\n");
428   }
429 //rewind ($handle); // Go back to the beginning
430 //fwrite ($handle, sprintf("%5d ", $nb)); // Don't forget to increment the counter
431 $s="\n".date('Y m d H:m:s ')."\n".$s;
432
433
434$s= nl2br($s);
435
436 if( $s !="") fwrite($handle,$s );
437      fclose($handle);
438}
439
440/*
441 * sends an email, using Piwigo specific informations
442 *
443 * @param:
444 *   - to: receiver(s) of the mail (list separated by comma).
445 *   - args: function params of mail function:
446 *       o from: sender [default value webmaster email]
447 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
448 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
449 *       o subject  [default value 'Piwigo']
450 *       o content: content of mail    [default value '']
451 *       o content_format: format of mail content  [default value 'text/plain']
452 *       o email_format: global mail format  [default value $conf_mail['default_email_format']]
453 *       o theme: template to use [default get_default_theme()]
454 *
455 * @return boolean (Ok or not)
456 */
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))  {
463    $conf_mail = get_mail_configuration();
464  }
465  if (empty($args['email_format'])) {
466    $args['email_format'] = $conf_mail['default_email_format'];
467  }
468  // Compute root_path in order have complete path
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']))  {
484    $args['content'] = '';
485  }
486
487  if (empty($args['content_format']))  {
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
495  if (empty($args['theme']))  {
496    $args['theme'] = get_default_theme();
497  }
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";
515
516  // List on content-type
517  $content_type_list[] = $args['email_format'];
518  if (!empty($conf_mail['alternative_email_format']))  {
519    $content_type_list[] = $conf_mail['alternative_email_format'];
520  }
521
522  $content = '';
523
524  foreach (array_unique($content_type_list) as $content_type)  {
525    // key compose of indexes witch allow ti cache mail data
526    $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
527
528    if (!isset($conf_mail[$cache_key]))    {
529      if (!isset($conf_mail[$cache_key]['theme']))      {
530        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']);
531      }
532
533      $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
534      $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
535
536      $conf_mail[$cache_key]['theme']->assign(
537        array(
538          //Header
539          'BOUNDARY_KEY' => $conf_mail['boundary_key'],
540          'CONTENT_TYPE' => $content_type,
541          'CONTENT_ENCODING' => get_pwg_charset(),
542
543          // Footer
544          'GALLERY_URL' => get_gallery_home_url(),
545          'GALLERY_TITLE' =>
546            isset($page['gallery_title']) ?
547                  $page['gallery_title'] : $conf['gallery_title'],
548          'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
549          'PHPWG_URL' => PHPWG_URL,
550
551          'TITLE_MAIL' => urlencode(l10n('A comment on your site')),
552          'MAIL' => get_webmaster_mail_address()
553          ));
554
555      if ($content_type == 'text/html')     {
556        if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl'))
557        {
558          $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');
559          $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
560        }
561
562        $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl';
563        if (is_file($file))   {
564          $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file));
565          $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');
566        }
567      }
568
569      // what are displayed on the header of each mail ?
570      $conf_mail[$cache_key]['header'] =
571        $conf_mail[$cache_key]['theme']->parse('mail_header', true);
572
573      // what are displayed on the footer of each mail ?
574      $conf_mail[$cache_key]['footer'] =
575        $conf_mail[$cache_key]['theme']->parse('mail_footer', true);
576    }
577
578    // Header
579    $content.= $conf_mail[$cache_key]['header'];
580
581    // Content
582    if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html'))    {
583      $content.= '<p>'.
584                  nl2br(
585                    preg_replace("/(http:\/\/)([^\s,]*)/i",
586                                 "<a href='$1$2' class='thumblnk'>$1$2</a>",
587                                 htmlspecialchars($args['content']))).
588                  '</p>';
589    }
590    else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain'))
591    {
592      // convert html text to plain text
593      $content.= strip_tags($args['content']);
594    }    else    {
595      $content.= $args['content'];
596    }
597
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
608   // Undo Compute root_path in order have complete path
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    );
620}
621
622
623?>
Note: See TracBrowser for help on using the repository browser.