Ignore:
Timestamp:
Jul 21, 2011, 7:45:59 PM (13 years ago)
Author:
cljosse
Message:

[extensions] mail_supervisor fix bug.

File:
1 edited

Legend:

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

    r11807 r11808  
    206206        $pattern="---=";
    207207        $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 
    213208        $pattern ="#(?<!\r)\n#si" ;
    214209        if(  preg_match($pattern, $content)  ){
    215210            $infos_message .= $pattern. " <br />";   
     211            $content= preg_replace( $pattern, "\r\n", $content);   // 
     212            //$content = str_replace("\n.", "\n..", $content);
    216213        }
    217214       
    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         }
    238215
    239216      }else{
     
    438415}
    439416
    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  */
    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))  {
    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 }
    621417
    622418
Note: See TracChangeset for help on using the changeset viewer.