? .patch
? brief.patch
Index: project_issue.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.install,v
retrieving revision 1.68
diff -u -F '^f' -p -r1.68 project_issue.install
--- project_issue.install	19 Aug 2010 16:31:29 -0000	1.68
+++ project_issue.install	1 Sep 2010 15:41:21 -0000
@@ -382,6 +382,27 @@ function project_issue_schema() {
     ),
     'primary key' => array('nid', 'uid'),
   );
+  
+  $schema['project_issue_users'] = array(
+    'description' => 'User preferences for issues.',
+    'fields' => array(
+      'uid' => array(
+        'description' => 'The {users}.uid for this subscriber.',
+        'type' => 'int',
+        'unsigned' => 1,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'mail_length' => array(
+        'description' => 'User preference for brief or verbose emails.',
+        'type' => 'int',
+        'size' => 'tiny',
+        'unsigned' => 1,
+        'not null' => FALSE,
+      ),
+    ),
+    'primary key' => array('uid'),
+  );
   return $schema;
 }
 
@@ -627,3 +648,33 @@ function project_issue_update_6006() {
 
   return $ret;
 }
+
+/**
+ * Add the {project_issue_users} table.
+ */
+function project_issue_update_6007() {
+  $ret = array();
+  
+  $table = array(
+    'description' => 'User preferences for issues.',
+    'fields' => array(
+      'uid' => array(
+        'description' => 'The {users}.uid for this user.',
+        'type' => 'int',
+        'unsigned' => 1,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'mail_length' => array(
+        'description' => 'User preference for brief or verbose emails.',
+        'type' => 'int',
+        'size' => 'tiny',
+        'unsigned' => 1,
+        'not null' => FALSE,
+      ),
+    ),
+    'primary key' => array('uid'),
+  );
+  db_create_table($ret, 'project_issue_users', $table);
+  return $ret;
+}
Index: project_issue.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.module,v
retrieving revision 1.181
diff -u -F '^f' -p -r1.181 project_issue.module
--- project_issue.module	19 Aug 2010 16:31:29 -0000	1.181
+++ project_issue.module	1 Sep 2010 15:41:22 -0000
@@ -10,6 +10,11 @@ define('PROJECT_ISSUE_AUTO_CLOSE_DAYS', 
 define('PROJECT_ISSUE_STATE_FIXED', 2);
 /// Project issue state = closed.
 define('PROJECT_ISSUE_STATE_CLOSED', 7);
+// Long email notification emails containing all follow-ups
+define('PROJECT_ISSUE_MAIL_LENGTH_VERBOSE', 0);
+// Brief email notification emails.
+define('PROJECT_ISSUE_MAIL_LENGTH_BRIEF', 1);
+
 
 /**
  * Implementation of hook_init().
@@ -1839,3 +1844,60 @@ function project_issue_project_page_link
     $links['development']['links'] = $patches + $links['development']['links'];
   }
 }
+
+/**
+ * Implementation of hook_user().
+ *
+ * Allows the user the option of enabling/disabling brief email notifications.
+ */
+function project_issue_user($type, &$edit, &$account, $category = NULL) {
+  if ($type == 'form' && $category == 'account') {
+    $form['project_issue'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Issue settings'),
+      '#weight' => 5,
+      '#collapsible' => TRUE,
+    );
+    $form['project_issue']['project_issue_mail_length'] = array(
+      '#type' => 'radios',
+      '#title' => t('Email notification length'),
+      '#options' => array(
+        PROJECT_ISSUE_MAIL_LENGTH_VERBOSE => t('Complete'),
+        PROJECT_ISSUE_MAIL_LENGTH_BRIEF => t('Brief'),
+      ),
+      '#default_value' => !empty($edit['project_issue_mail_length']) ? $edit['project_issue_mail_length'] : PROJECT_ISSUE_MAIL_LENGTH_VERBOSE,
+      '#description' => t('Brief email notifications are usually preferred when reading email on a mobile device. Complete emails are better if one wants the whole issue history within a single email.'),
+    );
+    return $form;
+  }
+  elseif ($type == 'load') {
+    $sql = 'SELECT mail_length FROM {project_issue_users} WHERE uid = %d';
+    $row = db_fetch_object(db_query($sql, $account->uid));
+    $account->project_issue_mail_length = isset($row->mail_length) ? $row->mail_length : NULL;  
+  }
+  elseif ($type == 'insert') {
+    var_dump(isset($edit['project_issue_mail_length']));die(sd);
+    if (isset($edit['project_issue_mail_length'])) {
+      $sql = 'INSERT INTO {project_issue_users} (uid, mail_length) VALUES (%d, %d)';
+      db_query($sql, $account->uid, $edit['project_issue_mail_length']);
+      $edit['project_issue_mail_length'] = NULL;
+    } 
+  }
+  elseif ($type == 'update') {
+    // TODO: In Drupal 7, this is a merge query.
+    if (db_result(db_query('SELECT COUNT(*) FROM {project_issue_users} WHERE uid=%d', $account->uid))) {
+      $sql = 'UPDATE {project_issue_users} SET mail_length = %d WHERE uid = %d';
+      db_query($sql, $edit['project_issue_mail_length'], $account->uid);
+    }
+    else {
+      $sql = 'INSERT INTO {project_issue_users} (uid, mail_length) VALUES (%d, %d)';
+      db_query($sql, $account->uid, $edit['project_issue_mail_length']);
+    }
+    
+    $edit['project_issue_mail_length'] = NULL;
+  }
+  elseif ($type == 'delete') {
+    $sql = 'DELETE FROM {project_issue_users} WHERE uid = %d';
+    db_query($sql, $account->uid);
+  }
+}
Index: includes/mail.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/mail.inc,v
retrieving revision 1.126
diff -u -F '^f' -p -r1.126 mail.inc
--- includes/mail.inc	24 Apr 2010 01:58:18 -0000	1.126
+++ includes/mail.inc	1 Sep 2010 15:41:22 -0000
@@ -290,6 +290,7 @@ function project_issue_mail_notify($nid)
   // some punctuation) are used.  See example in Appendix A.1.2.
   $from = '"' . mime_header_encode($sender->name) . "\" <$sender->mail>";
 
+  // Send notification to each connected user.
   while ($recipient = db_fetch_object($result)) {
     // To save work, only go through a user_load if we need it.
     if ($check_file_perms || $check_node_access) {
@@ -298,6 +299,8 @@ function project_issue_mail_notify($nid)
     }
     else {
       $language = language_default();
+      // Populate length preference
+      project_issue_user('load', $recipient, $recipient);
     }
 
     $can_access = $check_node_access ? node_access('view', $node, $account) : TRUE;
@@ -306,6 +309,7 @@ function project_issue_mail_notify($nid)
       $display_files = $check_file_perms ? user_access('view uploaded files', $account) : TRUE;
 
       $params['display_files'] = $display_files;
+      $params['recipient'] = $recipient;
       drupal_mail('project_issue', 'project_issue_update_notification', $recipient->mail, $language, $params, $from);
     }
   }
@@ -369,13 +373,22 @@ function _project_issue_mail($key, &$mes
       }
 
       project_issue_mail_output($node->title, 0);
-      $message['subject'] = t('[!short_name] [!category] !title', array('!short_name' => $project->project['uri'], '!category' => $node->project_issue['category'], '!title' => $node->title));
 
       // Create link to related node
       $links = t('Issue status update for !link', array('!link' => "\n". url("node/$node->nid", array('absolute' => TRUE)))) ."\n";
       $links .= t('Post a follow up: !link', array('!link' => "\n". url("comment/reply/$node->nid", array('fragment' => 'comment-form', 'absolute' => TRUE)))) ."\n";
-      $message['body'][] = $links;
-      $message['body'][] = project_issue_mail_generate_followup_mail_body($node, $history, $params['display_files']);
+      $body = project_issue_mail_generate_followup_mail_body($node, $history, $params['display_files'], $params['recipient']);
+      
+      if ($params['recipient']->project_issue_mail_length == PROJECT_ISSUE_MAIL_LENGTH_VERBOSE) {
+        $message['subject'] = t('[!short_name] [!category] !title', array('!short_name' => $project->project['uri'], '!category' => $node->project_issue['category'], '!title' => $node->title));
+        $message['body'][] = "$links\n$body";
+      }
+      else {
+        // Omit short_name and category in brief mode.
+        $message['subject'] = $node->title;
+        // Show links last since recipient is less likely to follow-up using mobile device.
+        $message['body'][] = "$body\n$links";
+      }
 
       break;
 
@@ -417,23 +430,20 @@ function _project_issue_mail($key, &$mes
  *   An array containing the history of issue followups.
  * @param $display_files
  *   Boolean indicating if file attachments should be displayed.
+ * @param $recipient
+  *   User object indicating recipient's preferred mail length.
  * @return
  *   A string of the email body.
  */
-function project_issue_mail_generate_followup_mail_body($node, $history, $display_files) {
+function project_issue_mail_generate_followup_mail_body($node, $history, $display_files, $recipient = NULL) {
   global $user;
-  static $output_with_files =  NULL, $output_without_files = NULL;
+  static $cache = array();
+  
+  $mail_length = isset($recipient->project_issue_mail_length) ? $recipient->project_issue_mail_length : PROJECT_ISSUE_MAIL_LENGTH_VERBOSE;
 
   // Return cached output if available.
-  if ($display_files) {
-    if (isset($output_with_files)) {
-      return $output_with_files;
-    }
-  }
-  else {
-    if (isset($output_without_files)) {
-      return $output_without_files;
-    }
+  if (isset($cache[$display_files][$mail_length])) {
+    return $cache[$display_files][$mail_length];
   }
 
   // Get most recent update.
@@ -483,32 +493,32 @@ function project_issue_mail_generate_fol
   // Create main body content
   project_issue_mail_output($content, 1, $entry->format);
   $body = "$content\n$entry->name\n";
+  
+  // Append complete follow-up history if recient prefers that.
+  if ($mail_length == PROJECT_ISSUE_MAIL_LENGTH_VERBOSE) {
+    $hr = str_repeat('-', 72);
 
-  $hr = str_repeat('-', 72);
-
-  if (count($history)) {
-
-    $body .= "\n\n";
-    $body .= t('Original issue:') ."\n";
-    $body .= project_issue_mail_format_entry(array_shift($history), $display_files, TRUE);
     if (count($history)) {
-      $body .= "\n". t('Previous comments (!count):', array('!count' => count($history))) ."\n";
-      foreach ($history as $entry) {
-        $body .= project_issue_mail_format_entry($entry, $display_files);
+
+      $body .= "\n\n";
+      $body .= t('Original issue:') ."\n";
+      $body .= project_issue_mail_format_entry(array_shift($history), $display_files, TRUE);
+      if (count($history)) {
+        $body .= "\n". t('Previous comments (!count):', array('!count' => count($history))) ."\n";
+        foreach ($history as $entry) {
+          $body .= project_issue_mail_format_entry($entry, $display_files);
+        }
       }
     }
-  }
-
-  $output = "$summary\n$body";
-
-  // Set cached output.
-  if ($display_files) {
-    $output_with_files = $output;
+    $output = "$summary\n$body"; 
   }
   else {
-    $output_without_files = $output;
+    $output = "$body\n$summary";
   }
 
+  // Set cached output.
+  $cache[$display_files][$mail_length] = $output;
+
   return $output;
 }
 
@@ -687,4 +697,4 @@ function project_issue_mail_format_entry
     $output .= "\n$content";
   }
   return $output;
-}
+}
\ No newline at end of file
