Index: /extensions/Mail_supervisor/admin/cat_group_info.tpl
===================================================================
--- /extensions/Mail_supervisor/admin/cat_group_info.tpl	(revision 10816)
+++ /extensions/Mail_supervisor/admin/cat_group_info.tpl	(revision 10816)
@@ -0,0 +1,7 @@
+<div id="cat_group_info">
+<h2>{$titre|@translate}</h2>
+<p>{'Hello,'|@translate}</p>
+<p>{$CPL_CONTENT}</p>
+<p>{'See you soon.'|@translate}</p><br />
+<p> {$signature}</p>
+</div>
Index: /extensions/Mail_supervisor/admin/mail_superv_admin.php
===================================================================
--- /extensions/Mail_supervisor/admin/mail_superv_admin.php	(revision 10815)
+++ /extensions/Mail_supervisor/admin/mail_superv_admin.php	(revision 10816)
@@ -287,6 +287,9 @@
 
  if (function_exists('get_user_language_desc') ) $message = get_user_language_desc($message);
-
- if ( $_POST['Submit']==l10n('Sv_Envoyer') ) {
+ if ( $_POST['Submit']==l10n('Sv_Valider') ) {
+     $mails_donnees['message_test']= str_replace('"',"'",$message) ;
+    mail_supervisor::sauve_donnees();
+    $_POST['Submit']="";
+ }else if ( $_POST['Submit']==l10n('Sv_Envoyer') ) {
      /*
      * send en email to user's group
@@ -306,8 +309,12 @@
             $_POST['group'],
             get_str_email_format(true),
-            get_l10n_args('[%s] ---> %s', array($titre,'Information') ), //sujet
-            'cat_group_info',  // template
-            array    ('CPL_CONTENT' => $message."\n\n".$user['username'] ),
-            '' );
+            get_l10n_args('[%s] %s', array($conf['gallery_title'],'Test Mail_supervisor') ), //sujet
+            MAIL_SUPERV_PATH_ABS . 'admin/cat_group_info',  // template
+            array    ( 'titre' => 'Mail_supervisor',
+                       'CPL_CONTENT' => $message,
+                       'signature' => $user['username']
+                      ),
+            '' 
+              );
 
     $mails_donnees['message_test']= str_replace('"',"'",$message) ;
@@ -352,20 +359,30 @@
         );
 //=================================================================
-$destinataires= implode("<br />",get_liste($group_id));
-if( $destinataires !="" )
-$infos_message .= " List :<hr>" .  $destinataires . "<hr>" ;
+/*   
+ $List_dest=get_liste($group_id) ;
+   //$destinataires= implode("<br />".$chk_cl,get_liste($group_id));
+*/  
+
+
+  $destinataires="";
+$List_dest = get_liste($group_id) ;
+ foreach ($List_dest as $dest_id){
+  $destinataires .= $dest_id['username']. "&lt" . $dest_id['email'].'><br />';
+ }
+  if( $destinataires !="" ) $infos_message .= " List :<hr>" .  $destinataires . "<hr>" ;
 
   $template->assign(
                     array(
-              'Groupe'     => $groups,
-              'message_test' => $mails_donnees['message_test'] ,
-              'liste' => $destinataires ,
-              'version' =>   $version ,
-              'MAIL_CONTENT' => $mails_donnees['message_test'],
-              'path_js' => $path_js,
-              'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS,
-              'MAIL_SUPERV_PATH' => MAIL_SUPERV_PATH ,
+                        'Groupe'     => $groups,
+                        'message_test' => $mails_donnees['message_test'] ,
+                        'liste' =>  get_liste($group_id) ,
+                       
+                        'version' =>   $version ,
+                        'MAIL_CONTENT' => $mails_donnees['message_test'],
+                        'path_js' => $path_js,
+                        'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS,
+                        'MAIL_SUPERV_PATH' => MAIL_SUPERV_PATH ,
                         )
-                );
+                    );
 
    $template->set_filenames(array('plugin_admin_content' => realpath(MAIL_SUPERV_PATH . 'admin/mail_superv_test.tpl')));
Index: /extensions/Mail_supervisor/admin/mail_superv_test.tpl
===================================================================
--- /extensions/Mail_supervisor/admin/mail_superv_test.tpl	(revision 10815)
+++ /extensions/Mail_supervisor/admin/mail_superv_test.tpl	(revision 10816)
@@ -20,5 +20,11 @@
       </td>
           <td  >
-            {$liste}
+          {if not empty($liste)}
+           
+         {foreach from=$liste item=group name=group_loop }
+         
+          {$group.username}&lt{$group.email}><br />
+         {/foreach} 
+          {/if}
          </td>
     </tr>
@@ -27,5 +33,5 @@
       <td><strong>{'Sv_mail_content'|@translate}</strong></td>
       <td>
-<textarea name="MAIL_CONTENT" id="MAIL_CONTENT" class="description">{$MAIL_CONTENT}</textarea>
+        <textarea name="MAIL_CONTENT" id="MAIL_CONTENT" class="description">{$MAIL_CONTENT}</textarea>
       </td>
     </tr>
@@ -34,4 +40,5 @@
     </fieldset>
       <p>
+      <input class="submit" type="submit" name="Submit" value="{'Sv_Valider'|@translate}" {$tag_input_enabled} />
       <input class="submit" type="submit" name="Submit" value="{'Sv_refresh'|@translate}" {$tag_input_enabled} />
       <input class="submit" type="submit" name="Submit" id="Envoyer"  value="{'Sv_Envoyer'|@translate}" {$tag_input_enabled} />
Index: /extensions/Mail_supervisor/include/Scripts.js
===================================================================
--- /extensions/Mail_supervisor/include/Scripts.js	(revision 10815)
+++ /extensions/Mail_supervisor/include/Scripts.js	(revision 10816)
@@ -56,5 +56,5 @@
          // get_script_geo();
 
-         if( typeof is_supervisor=="boolean" ){
+         if (typeof is_supervisor == "boolean") {
            jQuery('.cluetip').cluetip({
              width: 300,
@@ -76,4 +76,17 @@
          });
 
+         jQuery("input").click(function () {
+
+           if (this.name != "chk_mail_list") return;
+           // this.alt
+           //  this.rel
+           //form.submit();
+
+           return;
+
+
+
+
+         });
 
          function ajout_action(titre, message, valeur) {
Index: /extensions/Mail_supervisor/include/fonctions.php
===================================================================
--- /extensions/Mail_supervisor/include/fonctions.php	(revision 10815)
+++ /extensions/Mail_supervisor/include/fonctions.php	(revision 10816)
@@ -159,5 +159,11 @@
     while ($group = mysql_fetch_array($datas,MYSQL_ASSOC)){
       if (!empty($group['email'])){
-         array_push($groups, format_email($group['username'], $group['email'] ));
+         //array_push($groups, format_email($group['username'], $group['email'] ));
+        array_push($groups,
+                   array( 'username' => $group['username'],
+                'email' => $group['email'],
+                'format_email' => format_email($group['username'], $group['email'] )
+                )
+              );
       }
     }
Index: /extensions/Mail_supervisor/include/function_test_send.php
===================================================================
--- /extensions/Mail_supervisor/include/function_test_send.php	(revision 10815)
+++ /extensions/Mail_supervisor/include/function_test_send.php	(revision 10816)
@@ -55,5 +55,5 @@
 
 
-$groups=get_liste($group_id);
+$groups=get_liste($group_id).dest;
 
 //=======================================================================================
Index: /extensions/Mail_supervisor/main.inc.php
===================================================================
--- /extensions/Mail_supervisor/main.inc.php	(revision 10815)
+++ /extensions/Mail_supervisor/main.inc.php	(revision 10816)
@@ -42,5 +42,8 @@
   include_once (MAIL_SUPERV_PATH.'include/fonctions.php');
   load_language('plugin.lang', MAIL_SUPERV_PATH);
-   trigger_event('cl_begin_send_mail');
+
+  $arg_trigg= array($mailto, $subject, $content, $headers, $args);
+
+    trigger_event('mail_supervisor_clj_mail',$arg_trigg);
 
  // remove_event_handler('send_mail', 'pwg_send_mail');
@@ -54,13 +57,14 @@
 
   if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' )    {
-        if (kill_list()) {
+    if (kill_list()) {
       $nb_destinataires=0; ;
       $envoie_ok= false ;
       $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ;
       $infos_message = l10n('Sv_mail_not_send')."<BR />";
-      if ($mails_options['no_connect'] == 'on' ){
+      if ($mails_options['no_connect'] == 'on' ){          
           if ($user['status'] == 'webmaster'){
           //---------- continuer si web master ----------
           }else{
+             trigger_event('mail_supervisor_send_mail', "DIE(KILL) : " . $ip . ' = ' . $user['status']);
               if (!isset($_GET['admin'])) {
                       die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!');
@@ -71,7 +75,7 @@
           }
       }
-       trigger_event('cl_kill_send_mail', $ip);
-         return true;
-        }
+      trigger_event('mail_supervisor_send_mail', "Kill : " . $ip . ' = ' . $user['status'] . "noconnect==off");
+      return true;
+      }
     }
   // lecture donnees       -------------
@@ -168,28 +172,33 @@
          $infos_message .=  " " ;
     }
-
-
-            //=============================================================================
-            if ($mails_options['check_header_text']=='on')   {
-              $texte = "This is a multi-part message in MIME format.\n";
-              $texte .= "-----=".$conf_mail['boundary_key']."\n";
-              $texte .= "Ceci est un message est au format MIME.\n";
-              $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n";
-              $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n";
-              $texte .= $mails_donnees['header_text']; // A voir texte brut...
-              $texte .= "\n\n";
-              $content =$texte .$content ;
-            }
-            // corrige erreur 'mail dropped, bare LF found'
-          /*   if ( preg_match('/\n\./',$content)){
-             $content=preg_replace('/\n\./', '/\n\.\./', $content);
-
-   //   $infos_message .= $content ;
-             }
-             $content = str_replace("\n.", "\n/./.", $content);
-             $headers = str_replace("\n.", "\n..", $headers);
-            $subject = str_replace("\n.", "\n..", $subject);
-             $mailto = str_replace("\n.", "\n..", $mailto);
-       */
+   
+  $content= cl_pwg_mail($args);
+  
+
+    if (  !preg_match('/'. $conf_mail['boundary_key'] .'/', $headers)){
+        $erreur_message .=   "ERREUR manque : boundary_key dans le headers <br />";
+        $infos_message = l10n('Sv_mail_not_send'); 
+         $envoie_ok= false ;
+    }
+ 
+
+
+    if( isset($conf['debug_mail']) && $conf['debug_mail']=="true") {
+
+    //    $erreur_message .="DEBUG:"."<br />Theme: ".    $file. "<br />";
+
+        $content1 =   htmlspecialchars( var_export($headers, true ) );   
+        $erreur_message .="<br />DEBUG -> "." Header: <br />".   $content1 ."<br />";
+
+        $content1 =   htmlspecialchars( var_export($mailto, true ) );   
+        $erreur_message .="<br />DEBUG -> "." Mail to: <br />".   $content1 ."<br />";
+
+        $content1 =   htmlspecialchars( var_export($subject ,true ) );   
+        $erreur_message .="<br />DEBUG -> "." Sujet: <br />".   $content1 ."<br />";
+
+        $content1 =   htmlspecialchars( var_export($content, true ) );    
+        $erreur_message .="<br />DEBUG -> "." Contenu:<br />" . $content1 ."<br />";
+    }
+
 
             $ret=false;
@@ -199,14 +208,14 @@
             ob_start();
               if ($nb_destinataires > 0) {
-
-            if( $envoie_ok)  $ret = mail($mailto, $subject,$content, $headers);
-
-          }else{
-            $message .= l10n('Sv_no_receiver_available');
-          }
-        $message .= ob_get_contents();
-        ob_end_clean();
-        $mails_donnees['message']=$message;
-        Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
+                if( $envoie_ok)  $ret = mail($mailto, $subject,$content, $headers);
+              }else{
+                $message .= l10n('Sv_no_receiver_available');
+              }
+              $message .= ob_get_contents();
+              ob_end_clean();
+              $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message);
+              trigger_event('mail_supervisor_mail', $arg_trigg );
+              $mails_donnees['message']=$message;
+              Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto);
             } else {
                 //================== Est en quarantaine =======================
@@ -243,7 +252,9 @@
             $infos_message .= l10n('Sv_mail_not_send');
             }
-           $infos_message .= "<hr>";
+           $infos_message .= "<hr>"; 
+           trigger_event('mail_supervisor_message',  $infos_message );
     mail_supervisor::sauve_donnees();
     mail_supervisor::affiche_message();
+    
     return true ;
 }
@@ -298,3 +309,140 @@
  return $ret ;
 }
+
+/*
+ * 
+ *
+ * @param:
+ *    
+ *   - args: function params of mail function:
+ *       o from: sender [default value webmaster email]
+ *       o Cc: array of carbon copy receivers of the mail. [default value empty]
+ *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
+ *       o subject  [default value 'Piwigo']
+ *       o content: content of mail    [default value '']
+ *       o content_format: format of mail content  [default value 'text/plain']
+ *       o email_format: global mail format  [default value $conf_mail['default_email_format']]
+ *       o theme: template to use [default get_default_theme()]
+ *
+ * @return boolean (Ok or not)
+ */
+function cl_pwg_mail(  $args = array())
+{
+  global $conf, $conf_mail, $lang_info, $page;   
+  global $erreur_message ;
+  if (!isset($conf_mail)) {
+    $conf_mail = get_mail_configuration();
+  }
+  if (empty($args['email_format']))  {
+    $args['email_format'] = $conf_mail['default_email_format'];
+  }
+  // Compute root_path in order have complete path
+  set_make_full_url(); 
+  if (!isset($args['content'])) {
+    $args['content'] = '';
+  }
+  if (empty($args['content_format']))  {
+    $args['content_format'] = 'text/plain';  }
+  if (empty($args['theme']))  {
+    $args['theme'] = get_default_theme();
+  }
+
+  // List on content-type
+  $content_type_list[] = $args['email_format'];
+  if (!empty($conf_mail['alternative_email_format']))  {
+    $content_type_list[] = $conf_mail['alternative_email_format'];
+  }
+  $content = '';
+  foreach (array_unique($content_type_list) as $content_type)
+  {
+    // key compose of indexes witch allow ti cache mail data
+    $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
+    unset($conf_mail[$cache_key]);
+    if (!isset($conf_mail[$cache_key])){
+      if (!isset($conf_mail[$cache_key]['theme'])){
+        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']);
+      }
+      $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
+      $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
+      $conf_mail[$cache_key]['theme']->assign(
+        array(
+          //Header
+          'BOUNDARY_KEY' => $conf_mail['boundary_key'],
+          'CONTENT_TYPE' => $content_type,
+          'CONTENT_ENCODING' => get_pwg_charset(),
+
+          // Footer
+          'GALLERY_URL' => get_gallery_home_url(),
+          'GALLERY_TITLE' =>
+            isset($page['gallery_title']) ?
+                  $page['gallery_title'] : $conf['gallery_title'],
+          'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
+          'PHPWG_URL' => PHPWG_URL,
+
+          'TITLE_MAIL' => urlencode(l10n('A comment on your site')),
+          'MAIL' => get_webmaster_mail_address()
+          ));
+
+      if ($content_type == 'text/html'){
+        if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl')){
+          $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');
+          $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
+        }
+
+        $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl';
+        if (is_file($file)){
+          $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file));
+          $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');
+        }
+      } 
+
+      // what are displayed on the header of each mail ?
+      $conf_mail[$cache_key]['header'] =
+        $conf_mail[$cache_key]['theme']->parse('mail_header', true);
+
+      // what are displayed on the footer of each mail ?
+      $conf_mail[$cache_key]['footer'] =
+        $conf_mail[$cache_key]['theme']->parse('mail_footer', true);
+    }
+
+    // Header
+   $content.= $conf_mail[$cache_key]['header'];
+       // Content
+    if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html')){
+      $content.= '<p>'.
+                  nl2br(
+                    preg_replace("/(http:\/\/)([^\s,]*)/i",
+                                 "<a href='$1$2' class='thumblnk'>$1$2</a>",
+                                 htmlspecialchars($args['content']))).
+                  '</p>';
+    } else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain')) {
+      // convert html text to plain text
+      $content.= strip_tags($args['content']);
+    } else {
+      $content.= $args['content'];
+    }
+
+    // Footer  
+    $content.= $conf_mail[$cache_key]['footer']."\n\n";
+    
+    // Close boundary
+    $content.= "\n\n".'-----='.$conf_mail['boundary_key'].'--'."\n\n";
+  }
+   // Undo Compute root_path in order have complete path
+  unset_make_full_url(); 
+
+  $pattern = '/(http:\/\/)([0-9].*)([0-9]\/)/'; 
+  if(preg_match($pattern, $content)){
+  //remplace 192.168.1.25 par rien ??
+      $replacement = '${1}'; 
+      $content = preg_replace( $pattern, $replacement,  $content ); 
+      //$content1 =   htmlspecialchars( var_export($content, true ) );     
+}
+
+      $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content); //drop LF barre
+
+  return    $content;
+ 
+}
+
 ?>
