--- comment_notify.module	2011-08-23 13:39:40.000000000 +0200
+++ modified_comment_notify.module	2012-03-05 10:15:04.755366050 +0200
@@ -222,7 +222,11 @@
       break;
     case 'publish':
       // And send notifications - the real purpose of the module.
-      _comment_notify_mailalert($comment);
+      global $_comment_notify_comment;      
+      if (!isset($_comment_notify_comment)) {
+        $_comment_notify_comment = array();
+      }      
+      $_comment_notify_comment[] = $comment;
       break;
     case 'update':
       // In case they have changed their status, save it in the database.
@@ -235,7 +239,11 @@
       }
       // And send notifications - the real purpose of the module.
       if ($comment['status'] == COMMENT_PUBLISHED) {
-        _comment_notify_mailalert($comment);
+        global $_comment_notify_comment;        
+        if (!isset($_comment_notify_comment)) {
+          $_comment_notify_comment = array();
+        }        
+        $_comment_notify_comment[] = $comment;
       }
       break;
     case 'insert':
@@ -259,7 +267,11 @@
 
       // And send notifications - the real purpose of the module.
       if ($comment['status'] == COMMENT_PUBLISHED) {
-        _comment_notify_mailalert($comment);
+        global $_comment_notify_comment;        
+        if (!isset($_comment_notify_comment)) {
+          $_comment_notify_comment = array();
+        }        
+        $_comment_notify_comment[] = $comment;
       }
       break;
     case 'delete':
@@ -269,6 +281,19 @@
 }
 
 /**
+ * Implement hook_exit
+ * Send notifications after all events have been fired
+ */
+function comment_notify_exit() {
+global $_comment_notify_comment;
+  if (!empty($_comment_notify_comment)) {
+    foreach ($_comment_notify_comment as $i) {
+      _comment_notify_mailalert($i);
+    }
+  }
+}
+
+/**
  * Implementation of hook_user().
  */
 function comment_notify_user($type, &$edit, &$user, $category = NULL) {
@@ -377,6 +402,12 @@
   if (db_result(db_query('SELECT cid from {comment_notify} WHERE cid = %d AND notified = %d', $cid, 1))) {
     return;
   }
+  
+  // Check if the comment is really published. Send only for published
+  // comments.
+  if (db_result(db_query('SELECT status FROM {comments} WHERE cid = %d', $cid, 1))) {
+    return;
+  }
 
   $initial_language = $language;
 
