Index: mail-out.pl
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og2list/mail-out.pl,v
retrieving revision 1.36
diff -u -p -r1.36 mail-out.pl
--- mail-out.pl	6 Sep 2006 00:17:10 -0000	1.36
+++ mail-out.pl	20 Oct 2006 15:25:33 -0000
@@ -195,7 +195,9 @@ sub send_bsmtp($$$$) {
     print BSMTP $content;
     print BSMTP "\n.\n";
   }
-  close(BSMTP) && map {$set_sentflag_handle->execute($mid, $_)} @$recipients;
+  foreach my $mid (@$mids) {
+     close(BSMTP) && map {$set_sentflag_handle->execute($mid, $_)} @$recipients;
+  }
 }
 
 sub send_sendmail($$$$) {
@@ -209,7 +211,10 @@ sub send_sendmail($$$$) {
     open(SENDMAIL, '|-') || exec($sendmail_binary, @sendmail_args,
 			       $verp_addr, $rcpt_addr);
     print SENDMAIL $content;
-    close(SENDMAIL) && $set_sentflag_handle->execute($mid, $rcpt_addr);
+    foreach my $mid (@$mids) {
+        # print "-  '$mid' '$rcpt_addr' \n";
+        close(SENDMAIL) && $set_sentflag_handle->execute($mid, $rcpt_addr);
+    }
   }
 }
 
@@ -231,7 +236,9 @@ sub send_smtp($$$$) {
     $smtp->to($rcpt_addr) or do {$smtp->reset(); next};
     $smtp->data($content) or do {$smtp->reset(); next};
 
-    $set_sentflag_handle->execute($mid, $rcpt_addr);
+    foreach my $mid (@$mids) {
+        $set_sentflag_handle->execute($mid, $rcpt_addr);
+    }
   }
   $smtp->quit();
 }
@@ -242,7 +249,9 @@ sub send_blackhole($$$$) {
   my $sender = shift;
   my $recipients = shift;
 
-  map {$set_sentflag_handle->execute($mid, $_)} @$recipients;
+  foreach my $mid (@$mids) {
+    map {$set_sentflag_handle->execute($mid, $_)} @$recipients;
+  }
   return;
 }
 
@@ -289,15 +298,19 @@ if ($do_digest) {
          "Encoding" => "-SUGGEST",
          "Charset"  => "utf-8",
 	 "X-Mailer" => undef);
-
-      # FIXME List of recipients is determined by the recipients that
-      # are associated with the first message found. It should be
-      # determined by the list of addresses that are currently
-      # subscribed to the group.
-      $get_rcpt_handle->execute($mid,OG2LIST_OUTGOING_DIGEST);
-      @{$digest_msgs{$nid}}{recipients} =
-	map {$$_[0] } $get_rcpt_handle->fetchall_arrayref();
     }
+
+    # To ensure recipients for all mids under a nid are considered,
+    # continue to append recipients for each mid added to the digest
+    #
+    $get_rcpt_handle->execute($mid,OG2LIST_OUTGOING_DIGEST);
+
+    my $recipient_address;
+    while ( ($recipient_address = $get_rcpt_handle->fetchrow_array()) ) {
+        # print "- $recipient_address \n";
+        push @{${$digest_msgs{$nid}}{recipients}}, $recipient_address;
+    } 
+
     # Add each message to the multipart/digest container.
     my $msg = MIME::Entity->build
       ("From"       => "$from_name <$from_address>",
@@ -333,13 +346,13 @@ if ($do_digest) {
     while (my @recipients = splice @{$digest_msgs{$_}{recipients}},0,$batch_size) {
       # print "- ".join(', ', @recipients)."\n";
       foreach ($send_method) {
-	/^sendmail$/i && do { send_sendmail([$mid], $content, $sender,
+	/^sendmail$/i && do { send_sendmail([@mids], $content, $sender,
 					    [@recipients]); last; };
-	/^bsmtp$/i && do { send_bsmtp([$mid], $content, $sender,
+	/^bsmtp$/i && do { send_bsmtp([@mids], $content, $sender,
 				      [@recipients]); last; };
-	/^smtp$/i && do { send_smtp([$mid], $content, $sender,
+	/^smtp$/i && do { send_smtp([@mids], $content, $sender,
 				    [@recipients]); last; };
-	/^blackhole$/i && do { send_blackhole([$mid], $content, $sender,
+	/^blackhole$/i && do { send_blackhole([@mids], $content, $sender,
 					      [@recipients]); last; };
 	die("Value of \$send_method not recognized: $send_method");
       }
