Changeset 11807 for extensions/Mail_supervisor/main.inc.php
- Timestamp:
- Jul 21, 2011, 5:57:36 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Mail_supervisor/main.inc.php
r10822 r11807 22 22 add_event_handler('get_admin_plugin_menu_links', array(&$mail_supervisor,'admin_menu') ); 23 23 24 $mails_options = mail_supervisor::Get_Options($mails_options,"mail_superv"); 24 mail_supervisor::Get_Options($mails_options,"mail_superv"); 25 25 26 /* EVENT_HANDLER_PRIORITY_NEUTRAL */ 26 27 // … … 28 29 include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' ); 29 30 include_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 31 34 add_event_handler('loc_after_page_header', array(&$mail_supervisor,'init') ); 32 35 add_event_handler('loc_begin_page_tail', array(&$mail_supervisor,'affiche_message') ); 33 36 37 include_once(MAIL_SUPERV_PATH.'mail_send.inc.php'); 38 $clj = new clj(); 39 40 add_event_handler('send_mail',array(&$clj,'send_mail'),EVENT_HANDLER_PRIORITY_NEUTRAL - 1, 6); 41 add_event_handler('send_mail_to',array(&$clj,'send_mail_to') ); 42 add_event_handler('send_mail_subject',array(&$clj,'send_mail_subject') ); 43 add_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 ); 45 34 46 //========================================================================================== 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 49 function clj_send_mail($result, $mailto, $subject, $content, $headers, $args) { 37 50 global $conf, $user, $lang_info; 38 51 global $conf_mail,$mails_options,$mails_donnees ; … … 40 53 global $errors; 41 54 // lecture config table ------------- 55 56 42 57 include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); 43 58 load_language('plugin.lang', MAIL_SUPERV_PATH); … … 173 188 } 174 189 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 //===================================================================== 185 254 if (!preg_match('/'. $conf_mail['boundary_key'] .'/', $headers)){ 186 255 $erreur_message .= "<br />ERREUR manque : boundary_key dans le headers <br />"; 187 256 $infos_message = l10n('Sv_mail_not_send'); 188 257 $envoie_ok= false ; 189 } 190 $ret=false; 258 return false ; 259 260 } 261 //===================================================================== 262 $ret="false"; 191 263 ob_start(); 192 264 //======== Non mise en quarantaine ============= … … 195 267 196 268 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 } 198 272 }else{ 199 273 $message .= l10n('Sv_no_receiver_available'); … … 204 278 trigger_event('mail_supervisor_mail', $arg_trigg ); 205 279 $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); 207 281 } else { 208 282 //================== Est en quarantaine ======================= 283 209 284 $erreur_message .= l10n('Sv_To_day_is')."<br />"; 210 285 if ($alerte_spam ) { … … 237 312 $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; 238 313 } 314 $ret = "Error ". $type." : "; 315 $ret .= l10n('Sv_mail_not_send'); 316 239 317 $infos_message .= l10n('Sv_mail_not_send'); 240 318 } … … 244 322 mail_supervisor::affiche_message(); 245 323 246 return true ;324 return $ret ;// 247 325 } 248 326 //=========================================================================================== … … 255 333 $est_un_spam =!(strpos(strtolower($message), 'spam') === false); 256 334 if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { 335 //=============== La fonction mail retourne une erreur ========================= 336 $ret="Error"; 257 337 // Bad recipient address syntax 258 338 $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); … … 261 341 $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; 262 342 } 263 264 $erreur_message .=sprintf(l10n('Sv_debug_message'), 343 $erreur_message .=$ret . " : <br />".sprintf(l10n('Sv_debug_message'), 265 344 ($ret==true)? "true" : "false", 266 345 htmlspecialchars($message) , … … 272 351 273 352 Mail_supervisor_log($mailto,$erreur_message) ; 274 //=============== La fonction mail retourne une erreur =========================275 }else{276 353 354 }else{ 277 355 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", 280 358 htmlspecialchars( $message) , 281 359 htmlspecialchars( $mailto) , … … 285 363 $nb_destinataires ); 286 364 287 Mail_supervisor_log($mailto,$erreur_message) ;288 } 289 } 290 365 Mail_supervisor_log($mailto,$infos_message) ; 366 } 367 } 368 //================================================================= 291 369 292 370 … … 295 373 $mails_donnees['nb_mails'] += $nb_destinataires; 296 374 } else { 375 $ret="Error spam"; 297 376 $mails_donnees['nb_spams'] += $nb_destinataires; 298 377 //--- Detection de spam ------------------ … … 308 387 } 309 388 } 310 $ret=true;311 389 return $ret ; 312 390 } … … 361 439 362 440 /* 363 * 441 * sends an email, using Piwigo specific informations 364 442 * 365 443 * @param: 366 * 444 * - to: receiver(s) of the mail (list separated by comma). 367 445 * - args: function params of mail function: 368 446 * o from: sender [default value webmaster email] … … 377 455 * @return boolean (Ok or not) 378 456 */ 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)) { 457 function 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)) { 384 463 $conf_mail = get_mail_configuration(); 385 464 } 386 if (empty($args['email_format'])) 465 if (empty($args['email_format'])) { 387 466 $args['email_format'] = $conf_mail['default_email_format']; 388 467 } 389 468 // 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'])) { 392 484 $args['content'] = ''; 393 485 } 486 394 487 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 396 495 if (empty($args['theme'])) { 397 496 $args['theme'] = get_default_theme(); 398 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"; 399 515 400 516 // List on content-type … … 403 519 $content_type_list[] = $conf_mail['alternative_email_format']; 404 520 } 521 405 522 $content = ''; 406 foreach (array_unique($content_type_list) as $content_type) 407 {523 524 foreach (array_unique($content_type_list) as $content_type) { 408 525 // key compose of indexes witch allow ti cache mail data 409 526 $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'])) { 413 530 $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']); 414 531 } 532 415 533 $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl'); 416 534 $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl'); 535 417 536 $conf_mail[$cache_key]['theme']->assign( 418 537 array( … … 434 553 )); 435 554 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 { 438 558 $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl'); 439 559 $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css'); … … 441 561 442 562 $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl'; 443 if (is_file($file)) {563 if (is_file($file)) { 444 564 $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file)); 445 565 $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css'); 446 566 } 447 } 567 } 448 568 449 569 // what are displayed on the header of each mail ? … … 457 577 458 578 // 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')) { 462 583 $content.= '<p>'. 463 584 nl2br( … … 466 587 htmlspecialchars($args['content']))). 467 588 '</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 { 469 592 // convert html text to plain text 470 593 $content.= strip_tags($args['content']); 471 } else{594 } else { 472 595 $content.= $args['content']; 473 596 } 474 597 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 481 608 // 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 ); 488 620 } 489 621 622 490 623 ?>
Note: See TracChangeset
for help on using the changeset viewer.