Ignore:
Timestamp:
May 8, 2011, 12:50:02 PM (13 years ago)
Author:
cljosse
Message:

[extensions] mail_supervisor fix bug in test

Location:
extensions/Mail_supervisor
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/Mail_supervisor/admin/mail_superv_admin.php

    r10419 r10816  
    287287
    288288 if (function_exists('get_user_language_desc') ) $message = get_user_language_desc($message);
    289 
    290  if ( $_POST['Submit']==l10n('Sv_Envoyer') ) {
     289 if ( $_POST['Submit']==l10n('Sv_Valider') ) {
     290     $mails_donnees['message_test']= str_replace('"',"'",$message) ;
     291    mail_supervisor::sauve_donnees();
     292    $_POST['Submit']="";
     293 }else if ( $_POST['Submit']==l10n('Sv_Envoyer') ) {
    291294     /*
    292295     * send en email to user's group
     
    306309            $_POST['group'],
    307310            get_str_email_format(true),
    308             get_l10n_args('[%s] ---> %s', array($titre,'Information') ), //sujet
    309             'cat_group_info',  // template
    310             array    ('CPL_CONTENT' => $message."\n\n".$user['username'] ),
    311             '' );
     311            get_l10n_args('[%s] %s', array($conf['gallery_title'],'Test Mail_supervisor') ), //sujet
     312            MAIL_SUPERV_PATH_ABS . 'admin/cat_group_info',  // template
     313            array    ( 'titre' => 'Mail_supervisor',
     314                       'CPL_CONTENT' => $message,
     315                       'signature' => $user['username']
     316                      ),
     317            ''
     318              );
    312319
    313320    $mails_donnees['message_test']= str_replace('"',"'",$message) ;
     
    352359        );
    353360//=================================================================
    354 $destinataires= implode("<br />",get_liste($group_id));
    355 if( $destinataires !="" )
    356 $infos_message .= " List :<hr>" .  $destinataires . "<hr>" ;
     361/*   
     362 $List_dest=get_liste($group_id) ;
     363   //$destinataires= implode("<br />".$chk_cl,get_liste($group_id));
     364*/ 
     365
     366
     367  $destinataires="";
     368$List_dest = get_liste($group_id) ;
     369 foreach ($List_dest as $dest_id){
     370  $destinataires .= $dest_id['username']. "&lt" . $dest_id['email'].'><br />';
     371 }
     372  if( $destinataires !="" ) $infos_message .= " List :<hr>" .  $destinataires . "<hr>" ;
    357373
    358374  $template->assign(
    359375                    array(
    360               'Groupe'     => $groups,
    361               'message_test' => $mails_donnees['message_test'] ,
    362               'liste' => $destinataires ,
    363               'version' =>   $version ,
    364               'MAIL_CONTENT' => $mails_donnees['message_test'],
    365               'path_js' => $path_js,
    366               'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS,
    367               'MAIL_SUPERV_PATH' => MAIL_SUPERV_PATH ,
     376                        'Groupe'     => $groups,
     377                        'message_test' => $mails_donnees['message_test'] ,
     378                        'liste' =>  get_liste($group_id) ,
     379                       
     380                        'version' =>   $version ,
     381                        'MAIL_CONTENT' => $mails_donnees['message_test'],
     382                        'path_js' => $path_js,
     383                        'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS,
     384                        'MAIL_SUPERV_PATH' => MAIL_SUPERV_PATH ,
    368385                        )
    369                 );
     386                    );
    370387
    371388   $template->set_filenames(array('plugin_admin_content' => realpath(MAIL_SUPERV_PATH . 'admin/mail_superv_test.tpl')));
  • extensions/Mail_supervisor/admin/mail_superv_test.tpl

    r10419 r10816  
    2020      </td>
    2121          <td  >
    22             {$liste}
     22          {if not empty($liste)}
     23           
     24         {foreach from=$liste item=group name=group_loop }
     25         
     26          {$group.username}&lt{$group.email}><br />
     27         {/foreach}
     28          {/if}
    2329         </td>
    2430    </tr>
     
    2733      <td><strong>{'Sv_mail_content'|@translate}</strong></td>
    2834      <td>
    29 <textarea name="MAIL_CONTENT" id="MAIL_CONTENT" class="description">{$MAIL_CONTENT}</textarea>
     35        <textarea name="MAIL_CONTENT" id="MAIL_CONTENT" class="description">{$MAIL_CONTENT}</textarea>
    3036      </td>
    3137    </tr>
     
    3440    </fieldset>
    3541      <p>
     42      <input class="submit" type="submit" name="Submit" value="{'Sv_Valider'|@translate}" {$tag_input_enabled} />
    3643      <input class="submit" type="submit" name="Submit" value="{'Sv_refresh'|@translate}" {$tag_input_enabled} />
    3744      <input class="submit" type="submit" name="Submit" id="Envoyer"  value="{'Sv_Envoyer'|@translate}" {$tag_input_enabled} />
  • extensions/Mail_supervisor/include/Scripts.js

    r10155 r10816  
    5656         // get_script_geo();
    5757
    58          if( typeof is_supervisor=="boolean" ){
     58         if (typeof is_supervisor == "boolean") {
    5959           jQuery('.cluetip').cluetip({
    6060             width: 300,
     
    7676         });
    7777
     78         jQuery("input").click(function () {
     79
     80           if (this.name != "chk_mail_list") return;
     81           // this.alt
     82           //  this.rel
     83           //form.submit();
     84
     85           return;
     86
     87
     88
     89
     90         });
    7891
    7992         function ajout_action(titre, message, valeur) {
  • extensions/Mail_supervisor/include/fonctions.php

    r10419 r10816  
    159159    while ($group = mysql_fetch_array($datas,MYSQL_ASSOC)){
    160160      if (!empty($group['email'])){
    161          array_push($groups, format_email($group['username'], $group['email'] ));
     161         //array_push($groups, format_email($group['username'], $group['email'] ));
     162        array_push($groups,
     163                   array( 'username' => $group['username'],
     164                'email' => $group['email'],
     165                'format_email' => format_email($group['username'], $group['email'] )
     166                )
     167              );
    162168      }
    163169    }
  • extensions/Mail_supervisor/include/function_test_send.php

    r10419 r10816  
    5555
    5656
    57 $groups=get_liste($group_id);
     57$groups=get_liste($group_id).dest;
    5858
    5959//=======================================================================================
  • extensions/Mail_supervisor/main.inc.php

    r10564 r10816  
    4242  include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
    4343  load_language('plugin.lang', MAIL_SUPERV_PATH);
    44    trigger_event('cl_begin_send_mail');
     44
     45  $arg_trigg= array($mailto, $subject, $content, $headers, $args);
     46
     47    trigger_event('mail_supervisor_clj_mail',$arg_trigg);
    4548
    4649 // remove_event_handler('send_mail', 'pwg_send_mail');
     
    5457
    5558  if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' )    {
    56         if (kill_list()) {
     59    if (kill_list()) {
    5760      $nb_destinataires=0; ;
    5861      $envoie_ok= false ;
    5962      $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ;
    6063      $infos_message = l10n('Sv_mail_not_send')."<BR />";
    61       if ($mails_options['no_connect'] == 'on' ){
     64      if ($mails_options['no_connect'] == 'on' ){         
    6265          if ($user['status'] == 'webmaster'){
    6366          //---------- continuer si web master ----------
    6467          }else{
     68             trigger_event('mail_supervisor_send_mail', "DIE(KILL) : " . $ip . ' = ' . $user['status']);
    6569              if (!isset($_GET['admin'])) {
    6670                      die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!');
     
    7175          }
    7276      }
    73        trigger_event('cl_kill_send_mail', $ip);
    74          return true;
    75         }
     77      trigger_event('mail_supervisor_send_mail', "Kill : " . $ip . ' = ' . $user['status'] . "noconnect==off");
     78      return true;
     79      }
    7680    }
    7781  // lecture donnees       -------------
     
    168172         $infos_message .=  " " ;
    169173    }
    170 
    171 
    172             //=============================================================================
    173             if ($mails_options['check_header_text']=='on')   {
    174               $texte = "This is a multi-part message in MIME format.\n";
    175               $texte .= "-----=".$conf_mail['boundary_key']."\n";
    176               $texte .= "Ceci est un message est au format MIME.\n";
    177               $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n";
    178               $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n";
    179               $texte .= $mails_donnees['header_text']; // A voir texte brut...
    180               $texte .= "\n\n";
    181               $content =$texte .$content ;
    182             }
    183             // corrige erreur 'mail dropped, bare LF found'
    184           /*   if ( preg_match('/\n\./',$content)){
    185              $content=preg_replace('/\n\./', '/\n\.\./', $content);
    186 
    187    //   $infos_message .= $content ;
    188              }
    189              $content = str_replace("\n.", "\n/./.", $content);
    190              $headers = str_replace("\n.", "\n..", $headers);
    191             $subject = str_replace("\n.", "\n..", $subject);
    192              $mailto = str_replace("\n.", "\n..", $mailto);
    193        */
     174   
     175  $content= cl_pwg_mail($args);
     176 
     177
     178    if (  !preg_match('/'. $conf_mail['boundary_key'] .'/', $headers)){
     179        $erreur_message .=   "ERREUR manque : boundary_key dans le headers <br />";
     180        $infos_message = l10n('Sv_mail_not_send');
     181         $envoie_ok= false ;
     182    }
     183 
     184
     185
     186    if( isset($conf['debug_mail']) && $conf['debug_mail']=="true") {
     187
     188    //    $erreur_message .="DEBUG:"."<br />Theme: ".    $file. "<br />";
     189
     190        $content1 =   htmlspecialchars( var_export($headers, true ) );   
     191        $erreur_message .="<br />DEBUG -> "." Header: <br />".   $content1 ."<br />";
     192
     193        $content1 =   htmlspecialchars( var_export($mailto, true ) );   
     194        $erreur_message .="<br />DEBUG -> "." Mail to: <br />".   $content1 ."<br />";
     195
     196        $content1 =   htmlspecialchars( var_export($subject ,true ) );   
     197        $erreur_message .="<br />DEBUG -> "." Sujet: <br />".   $content1 ."<br />";
     198
     199        $content1 =   htmlspecialchars( var_export($content, true ) );   
     200        $erreur_message .="<br />DEBUG -> "." Contenu:<br />" . $content1 ."<br />";
     201    }
     202
    194203
    195204            $ret=false;
     
    199208            ob_start();
    200209              if ($nb_destinataires > 0) {
    201 
    202             if( $envoie_ok)  $ret = mail($mailto, $subject,$content, $headers);
    203 
    204           }else{
    205             $message .= l10n('Sv_no_receiver_available');
    206           }
    207         $message .= ob_get_contents();
    208         ob_end_clean();
    209         $mails_donnees['message']=$message;
    210         Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
     210                if( $envoie_ok)  $ret = mail($mailto, $subject,$content, $headers);
     211              }else{
     212                $message .= l10n('Sv_no_receiver_available');
     213              }
     214              $message .= ob_get_contents();
     215              ob_end_clean();
     216              $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message);
     217              trigger_event('mail_supervisor_mail', $arg_trigg );
     218              $mails_donnees['message']=$message;
     219              Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
    211220            } else {
    212221                //================== Est en quarantaine =======================
     
    243252            $infos_message .= l10n('Sv_mail_not_send');
    244253            }
    245            $infos_message .= "<hr>";
     254           $infos_message .= "<hr>";
     255           trigger_event('mail_supervisor_message',  $infos_message );
    246256    mail_supervisor::sauve_donnees();
    247257    mail_supervisor::affiche_message();
     258   
    248259    return true ;
    249260}
     
    298309 return $ret ;
    299310}
     311
     312/*
     313 *
     314 *
     315 * @param:
     316 *   
     317 *   - args: function params of mail function:
     318 *       o from: sender [default value webmaster email]
     319 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
     320 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
     321 *       o subject  [default value 'Piwigo']
     322 *       o content: content of mail    [default value '']
     323 *       o content_format: format of mail content  [default value 'text/plain']
     324 *       o email_format: global mail format  [default value $conf_mail['default_email_format']]
     325 *       o theme: template to use [default get_default_theme()]
     326 *
     327 * @return boolean (Ok or not)
     328 */
     329function cl_pwg_mail(  $args = array())
     330{
     331  global $conf, $conf_mail, $lang_info, $page;   
     332  global $erreur_message ;
     333  if (!isset($conf_mail)) {
     334    $conf_mail = get_mail_configuration();
     335  }
     336  if (empty($args['email_format']))  {
     337    $args['email_format'] = $conf_mail['default_email_format'];
     338  }
     339  // Compute root_path in order have complete path
     340  set_make_full_url();
     341  if (!isset($args['content'])) {
     342    $args['content'] = '';
     343  }
     344  if (empty($args['content_format']))  {
     345    $args['content_format'] = 'text/plain';  }
     346  if (empty($args['theme']))  {
     347    $args['theme'] = get_default_theme();
     348  }
     349
     350  // List on content-type
     351  $content_type_list[] = $args['email_format'];
     352  if (!empty($conf_mail['alternative_email_format']))  {
     353    $content_type_list[] = $conf_mail['alternative_email_format'];
     354  }
     355  $content = '';
     356  foreach (array_unique($content_type_list) as $content_type)
     357  {
     358    // key compose of indexes witch allow ti cache mail data
     359    $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
     360    unset($conf_mail[$cache_key]);
     361    if (!isset($conf_mail[$cache_key])){
     362      if (!isset($conf_mail[$cache_key]['theme'])){
     363        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']);
     364      }
     365      $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
     366      $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
     367      $conf_mail[$cache_key]['theme']->assign(
     368        array(
     369          //Header
     370          'BOUNDARY_KEY' => $conf_mail['boundary_key'],
     371          'CONTENT_TYPE' => $content_type,
     372          'CONTENT_ENCODING' => get_pwg_charset(),
     373
     374          // Footer
     375          'GALLERY_URL' => get_gallery_home_url(),
     376          'GALLERY_TITLE' =>
     377            isset($page['gallery_title']) ?
     378                  $page['gallery_title'] : $conf['gallery_title'],
     379          'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
     380          'PHPWG_URL' => PHPWG_URL,
     381
     382          'TITLE_MAIL' => urlencode(l10n('A comment on your site')),
     383          'MAIL' => get_webmaster_mail_address()
     384          ));
     385
     386      if ($content_type == 'text/html'){
     387        if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl')){
     388          $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');
     389          $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
     390        }
     391
     392        $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl';
     393        if (is_file($file)){
     394          $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file));
     395          $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');
     396        }
     397      }
     398
     399      // what are displayed on the header of each mail ?
     400      $conf_mail[$cache_key]['header'] =
     401        $conf_mail[$cache_key]['theme']->parse('mail_header', true);
     402
     403      // what are displayed on the footer of each mail ?
     404      $conf_mail[$cache_key]['footer'] =
     405        $conf_mail[$cache_key]['theme']->parse('mail_footer', true);
     406    }
     407
     408    // Header
     409   $content.= $conf_mail[$cache_key]['header'];
     410       // Content
     411    if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html')){
     412      $content.= '<p>'.
     413                  nl2br(
     414                    preg_replace("/(http:\/\/)([^\s,]*)/i",
     415                                 "<a href='$1$2' class='thumblnk'>$1$2</a>",
     416                                 htmlspecialchars($args['content']))).
     417                  '</p>';
     418    } else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain')) {
     419      // convert html text to plain text
     420      $content.= strip_tags($args['content']);
     421    } else {
     422      $content.= $args['content'];
     423    }
     424
     425    // Footer 
     426    $content.= $conf_mail[$cache_key]['footer']."\n\n";
     427   
     428    // Close boundary
     429    $content.= "\n\n".'-----='.$conf_mail['boundary_key'].'--'."\n\n";
     430  }
     431   // Undo Compute root_path in order have complete path
     432  unset_make_full_url();
     433
     434  $pattern = '/(http:\/\/)([0-9].*)([0-9]\/)/';
     435  if(preg_match($pattern, $content)){
     436  //remplace 192.168.1.25 par rien ??
     437      $replacement = '${1}';
     438      $content = preg_replace( $pattern, $replacement,  $content );
     439      //$content1 =   htmlspecialchars( var_export($content, true ) );     
     440}
     441
     442      $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content); //drop LF barre
     443
     444  return    $content;
     445 
     446}
     447
    300448?>
Note: See TracChangeset for help on using the changeset viewer.