Index: casetracker_mail.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/casetracker/casetracker_mail.module,v
retrieving revision 1.13
diff -u -p -r1.13 casetracker_mail.module
--- casetracker_mail.module     9 Jan 2007 17:18:20 -0000       1.13
+++ casetracker_mail.module     16 Mar 2007 17:18:22 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: casetracker_mail.module,v 1.13 2007/01/09 17:18:20 morbus Exp $
+// $Id: casetracker_mail.module,v 1.12.2.3 2007/01/15 17:38:47 morbus Exp $
 
 /**
  * @file
@@ -26,7 +26,7 @@ function casetracker_mail_menu($may_cach
     $items[] = array(
       'access'             => user_access('administer case tracker'),
       'callback'           => 'drupal_get_form',
-      'callback arguments' => 'casetracker_mail_settings',
+      'callback arguments' => array('casetracker_mail_settings'),
       'description'        => t('Configure the various Case Tracker mail options with these settings.'),
       'path'               => 'admin/settings/casetracker/mail',
       'title'              => t('CT Mail'),
@@ -75,8 +75,11 @@ function casetracker_mail_send($case, $c
     ));
   }
 
-  // make our own message ID so we can log it and allow responses via mailhandler.
-  $msg_id = '<'. time() .'.'. mt_rand() .'@'. drupal_strtolower($_SERVER['SERVER_NAME']) .'>';
+  // our own message ID to log and allow responses.
+  $server = drupal_strtolower($_SERVER['SERVER_NAME']);
+  $msg_id = '<'. time() .'.'. mt_rand() .'@'. $server .'>';
+  $in_reply_to = '<'. $case->pid .'-'. $case->id .'@'. $server .'>';
+  $headers = array('Message-ID' => $msg_id, 'In-Reply-To' => $in_reply_to);
   $from    = variable_get('casetracker_mail_address', variable_get('site_mail', ini_get('sendmail_from')));
   $subject = strtr(variable_get('casetracker_mail_subject', _casetracker_mail_subject()), $variables);
   $body    = strtr(variable_get('casetracker_mail_case_message', _casetracker_mail_case_message()), $variables);
@@ -84,12 +87,23 @@ function casetracker_mail_send($case, $c
 
   // @todo this currently sends to only author and assigned. there needs to be
   // finer-grain control here, like an OG subscribers or all commenters, etc.
-  $results = db_query("SELECT mail FROM {users} WHERE uid IN (%d, %d, %d)", $comment['uid'], $case->uid, is_numeric($case->assign_to) ? $case->assign_to : casetracker_get_uid($case->assign_to));
+  $results = db_query("SELECT mail, uid FROM {users} WHERE uid IN (%d, %d, %d)", $comment['uid'], $case->uid, is_numeric($case->assign_to) ? $case->assign_to : casetracker_get_uid($case->assign_to));
   while ($result = db_fetch_object($results)) {
     if (!$result->mail) { continue; } // don't fire blanks.
-    $mail_status = drupal_mail('casetracker_mail', $result->mail, $subject, $body, $from, array('Message-ID' => $msg_id));
-    if (!$mail_status) { // mail failure doesn't actually tell us much, since PHP returns no error string, but hey, feel good, right?
-      watchdog('casetracker_mail', t('E-mail notification failed for %address.', array('%address' => $result->mail)));
+    $receive_roles = FALSE; 
+    $mail_user = user_load(array('uid' => $result->uid));
+    $roles = $mail_user->roles;
+    foreach ($roles as $key => $value) {
+      if (variable_get('casetracker_mail_role_' . $key, '1') == 1) {
+        $receive_roles = TRUE;
+      }
+    }  
+    if ($receive_roles == TRUE) {
+      drupal_set_message("after running, role = " . $receive_roles);
+      $mail_status = drupal_mail('casetracker_mail', $result->mail, $subject, $body, $from, $headers);
+      if (!$mail_status) { // mail failure doesn't actually tell us much, since PHP returns no error string, but hey, feel good, right?
+        watchdog('casetracker_mail', t('E-mail notification failed for %address.', array('%address' => $result->mail)));
+      }
     }
   }
 }
@@ -225,7 +239,20 @@ function casetracker_mail_settings() {
     '#default_value' => variable_get('casetracker_mail_comment_message', _casetracker_mail_comment_message()),
     '#description'   => t('Enter the comment message body of Case Tracker generated mails. The %comment variable in the \'Case message\' text above will be replaced by this value (if applicable). Available additional variables are %comment_author, %comment_title, %comment_description.'),
   );
-
+  $form['casetracker_mail']['casetracker_mail_roles'] = array(
+    '#type' => 'fieldset',
+    '#title' =>  t("Send Case Tracker mails to members of these roles"),
+    );
+  $roles = user_roles();
+  foreach ($roles as $key => $value) {
+    $form['casetracker_mail']['casetracker_mail_roles']['casetracker_mail_role_' . $key] = array(
+      '#type' => 'checkbox',
+      '#title' => t($value),
+      '#return_value' => 1, 
+      '#default_value' => variable_get('casetracker_mail_role_' . $key, 1)
+    );
+    
+  }
   return system_settings_form($form);
 }
 
