[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Subscriptions feature patch



Hi,

I just subscribed to the maillinglist.

Attached is a patch that adds a subscription feature to the bts that
allows you to subscribe to single bugs, and then you will recieve all
with that bug related mails. (as agreed with aj and colin) It required
confirmation. The interface is only in request@.

The patch is a diff -u against the cvs version from two days ago.

I tested it with a quickly locally set up bugs.localhost thingy, but if
you have a better testbed for debbugs, it might be a good idea to try it
there.

Feedback very welcome.

nomeata aka
Joachim Breitner

-- 
Joachim Breitner 
  e-Mail: mail@joachim-breitner.de | Homepage: http://www.joachim-breitner.de
  JID: joachimbreitner@amessage.de | GPG-Keyid: 4743206C | ICQ#: 74513189
  Geekcode: GCS/IT/S d-- s++:- a--- C++ UL+++ P+++ !E W+++ N-- !W O? M?>+ V?
            PS++ PE PGP++ t? 5? X- R+ tv- b++ DI+ D+ G e+>* h! z?
Bitte senden Sie mir keine Word- oder PowerPoint-Anhänge.
Siehe http://www.fsf.org/philosophy/no-word-attachments.de.html
-- 
Joachim Breitner 
  e-Mail: mail@joachim-breitner.de | Homepage: http://www.joachim-breitner.de
  JID: joachimbreitner@amessage.de | GPG-Keyid: 4743206C | ICQ#: 74513189
  Geekcode: GCS/IT/S d-- s++:- a--- C++ UL+++ P+++ !E W+++ N-- !W O? M?>+ V?
            PS++ PE PGP++ t? 5? X- R+ tv- b++ DI+ D+ G e+>* h! z?
Bitte senden Sie mir keine Word- oder PowerPoint-Anhänge.
Siehe http://www.fsf.org/philosophy/no-word-attachments.de.html

diff -ru source-alt/debian/changelog source/debian/changelog
--- source-alt/debian/changelog	2003-06-25 19:51:51.000000000 +0200
+++ source/debian/changelog	2003-07-15 11:14:12.000000000 +0200
@@ -1,3 +1,9 @@
+debbugs (2.4.3) UNRELEASED; urgency=low
+
+  * Added bug subscription (nomeata)
+
+ -- root <mail@joachim-breitner.de>  Tue, 15 Jul 2003 11:14:12 +0200
+
 debbugs (2.4.2) UNRELEASED; urgency=low
 
   * Colin Watson:
diff -ru source-alt/html/server-refcard.html.in source/html/server-refcard.html.in
--- source-alt/html/server-refcard.html.in	2003-03-05 14:53:04.000000000 +0100
+++ source/html/server-refcard.html.in	2003-07-16 11:04:34.000000000 +0200
@@ -30,6 +30,8 @@
   <li><code>send-unmatched</code> [<code>this</code>|<code>0</code>]
   <li><code>send-unmatched</code> <code>last</code>|<code>-1</code>
   <li><code>send-unmatched</code> <code>old</code>|<code>-2</code>
+  <li><code>subscribe</code> <var>bugnumber</var> [<var>e-mail address</var>]
+  <li><code>unsubscribe</code> <var>bugnumber</var> [<var>e-mail address</var>]
   <li><code>getinfo</code> <var>filename</var> <em>(see below)</em>
   <li><code>help</code>
   <li><code>refcard</code>
diff -ru source-alt/html/server-request.html.in source/html/server-request.html.in
--- source-alt/html/server-request.html.in	2003-03-10 01:45:37.000000000 +0100
+++ source/html/server-request.html.in	2003-07-15 16:50:57.000000000 +0200
@@ -99,6 +99,15 @@
     pseudo-packages.
   </dl>
 
+<dt><code>subscribe</code> <var>bugnumber</var> <var>[email address]</var>
+  
+  <dd>Subscribes <var>email address</var> or the sender to the bug
+  <var>bugnumber</var>, i.e. every mail related to this bug will be forwarded
+
+<dt><code>unsubscribe</code> <var>bugnumber</var> <var>[email address]</var>
+
+  <dd>Unsubscribes <var>email address</var> or the sender from the given bug.
+
 <dt><code>refcard</code>
 
   <dd>Requests that the mailservers' reference card be sent in plain ASCII.
diff -ru source-alt/scripts/expire.in source/scripts/expire.in
--- source-alt/scripts/expire.in	2003-05-25 15:17:14.000000000 +0200
+++ source/scripts/expire.in	2003-07-16 09:28:22.000000000 +0200
@@ -72,9 +72,11 @@
 			link( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" ) || copy( "db-h/$dir/$mref.log", "archive/$dir/$mref.log" );
 			link( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" ) || copy( "db-h/$dir/$mref.status", "archive/$dir/$mref.status" );
 			link( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" ) || copy( "db-h/$dir/$mref.report", "archive/$dir/$mref.report" );
+			link( "db-h/$dir/$mref.subs", "archive/$dir/$mref.subs" ) || copy( "db-h/$dir/$mref.subs", "archive/$dir/$mref.subs" ) if -e "db-h/$dir/$mref.subs";
             		print("archived $mref to archive/$dir (from $ref)\n") || &quit("output old: $!");
 		}
 		unlink("db-h/$dir/$mref.log", "db-h/$dir/$mref.status", "db-h/$dir/$mref.report");
+		unlink("db-h/$dir/$mref.subs") if -e "db-h/$dir/$mref.subs";
 		print("deleted $mref (from $ref)\n") || &quit("output old: $!");
 		bughook_archive($mref);
         }
diff -ru source-alt/scripts/process.in source/scripts/process.in
--- source-alt/scripts/process.in	2003-06-23 13:23:35.000000000 +0200
+++ source/scripts/process.in	2003-07-16 09:20:08.000000000 +0200
@@ -337,7 +337,7 @@
         $x= join('',<O>); close(O);
         if ($codeletter eq 'F') {
 	    &htmllog("Reply","sent",$replyto,"You have marked $gBug as forwarded.");
-            &sendmessage(<<END."---------------------------------------\n".join( "\n", @msg ), '');
+            &sendmessage(<<END."---------------------------------------\n".join( "\n", @msg ), undef, undef, &subscribers);
 From: $gMaintainerEmail ($gProject $gBug Tracking System)
 To: $replyto
 ${noticecc}Subject: $gBug#$ref: marked as forwarded ($data->{subject})
@@ -367,7 +367,7 @@
 
         } else {
 	    &htmllog("Reply","sent",$replyto,"You have taken responsibility.");
-            &sendmessage(<<END."--------------------------------------\n".$x."---------------------------------------\n".join( "\n", @msg ), '');
+            &sendmessage(<<END."--------------------------------------\n".$x."---------------------------------------\n".join( "\n", @msg ), undef, undef, &subscribers);
 From: $gMaintainerEmail ($gProject $gBug Tracking System)
 To: $replyto
 ${noticecc}Subject: $gBug#$ref: marked as done ($data->{subject})
@@ -398,7 +398,7 @@
 END
             &htmllog("Notification","sent",$data->{originator}, 
 		"$gBug acknowledged by developer.");
-            &sendmessage(<<END.join("\n",@msg),'');
+            &sendmessage(<<END.join("\n",@msg),undef,undef,&subscribers);
 From: $gMaintainerEmail ($gProject $gBug Tracking System)
 To: $data->{originator}
 Subject: $gBug#$ref acknowledged by developer
@@ -426,7 +426,7 @@
 (administrator, $gProject $gBugs database)
 
 END
-        }
+        };
 	&appendlog;
     }
     &finish;
@@ -633,7 +633,7 @@
 
 if ($codeletter eq 'U') {
     &htmllog("Message", "sent on", $data->{originator}, "$gBug#$ref.");
-    &sendmessage(<<END,[$data->{originator},@resentccs],[@bccs]);
+    &sendmessage(<<END,[$data->{originator},@resentccs],[@bccs],&subscribers);
 Subject: $gBug#$ref: $newsubject
 Reply-To: $replyto, $ref-quiet\@$gEmailDomain
 ${orgsender}Resent-To: $data->{originator}
@@ -651,7 +651,7 @@
              "<code>$gBug#$ref</code>".
              (length($data->{package})? "; Package <code>".&sani($data->{package})."</code>" : '').
              ".");
-    &sendmessage(<<END,["$gSubmitList\@$gListDomain",@resentccs],[@bccs]);
+    &sendmessage(<<END,["$gSubmitList\@$gListDomain",@resentccs],[@bccs],&subscribers);
 Subject: $gBug#$ref: $newsubject
 Reply-To: $replyto, $ref\@$gEmailDomain
 Resent-From: $header{'from'}
@@ -681,7 +681,7 @@
                  (length($data->{package}) ? "; Package <code>".&sani($data->{package})."</code>" : '').
                  ".");
     }
-    &sendmessage(<<END,[@resentccs],[@bccs]);
+    &sendmessage(<<END,[@resentccs],[@bccs],&subscribers);
 Subject: $gBug#$ref: $newsubject
 Reply-To: $replyto, $ref-$baddressroot\@$gEmailDomain
 Resent-From: $header{'from'}
@@ -953,8 +953,8 @@
 }
 
 sub sendmessage {
-    local ($msg,$recips,$bcc) = @_;
-    if ((!ref($recips) && $recips eq '') || @$recips == 0) {
+    local ($msg,$recips,$bcc,$subscr) = @_;
+    if ((!ref($recips) && $recips eq '') || @$recips == 0 || !defined $recips) {
         $recips = ['-t'];
     }
     $msg = "X-Loop: $gMaintainerEmail\n" . $msg;
@@ -972,6 +972,11 @@
         push @$recips, @$bcc;
     }
 
+    if (ref($subscr)) {	# separate from bcc in case this need special handling
+        shift @$recips if $recips->[0] eq '-t'; 
+        push @$recips, @$subscr;
+    }
+
 #if debugging.. save email to a log
 #    open AP, ">>debug";
 #    print AP join( '|', @$recips )."\n>>";
@@ -1088,3 +1093,31 @@
         }
     }
 }
+
+
+sub subscribers {
+    # Returns a list of sucessfully subscribed email addresses
+    return () unless -e bugfile("subs");
+    my $data = subfile_load(bugfile("subs"));
+    [ grep {$data->{$_} eq "confirmed"} keys %$data ];
+}
+
+sub subfile_load {
+    # Loads all subscriptions from the file into a hashref
+    my $file = shift;
+    my $data = {};
+    open SUBFILE,"<$file" || &quit("open $file: $!");
+    while (<SUBFILE>) {
+      m/^([a-z0-9]+)\s+(.*)$/;
+      $data->{$2} = $1;
+    }
+    close SUBFILE;
+    return $data;
+}
+
+sub bugfile {
+    # Return the path from the spool dir to the bug file with the given extention
+    my $ext = shift;
+    my $hash = get_hashname($ref);
+    return "db-h/$hash/$ref.$ext";
+}
diff -ru source-alt/scripts/service.in source/scripts/service.in
--- source-alt/scripts/service.in	2003-06-23 13:23:35.000000000 +0200
+++ source/scripts/service.in	2003-07-16 09:23:32.000000000 +0200
@@ -7,6 +7,7 @@
 
 use File::Copy;
 use MIME::Parser;
+use Digest::MD5 (qw/md5_hex/);
 
 $config_path = '/etc/debbugs';
 $lib_path = '/usr/lib/debbugs';
@@ -214,18 +215,58 @@
         $ok++;
     } elsif (m/^refcard/i) {
         &sendtxthelp("bug-mailserver-refcard.txt","mail servers' reference card");
-    } elsif (m/^subscribe/i) {
-        &transcript(<<END);
-There is no $gProject $gBug mailing list.  If you wish to review bug reports
-please do so via http://$gWebDomain/ or ask this mail server
-to send them to you.
-soon: MAILINGLISTS_TEXT
-END
-    } elsif (m/^unsubscribe/i) {
-        &transcript(<<END);
-soon: UNSUBSCRIBE_TEXT
-soon: MAILINGLISTS_TEXT
-END
+    } elsif (m/^subscribe\s+\#?(-?\d+)(?:\s+(\w*))?/i) {
+        $ok++;
+        $ref = $1;
+        $email = $2 || ($replyto =~ /<(.*@.*)>/)[0];
+        if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+            $ref = $clonebugs{$ref};
+        }
+        if (-e bugfile("report")) {
+	    &foundbug;
+            &subscribe;
+        } else {
+            &notfoundbug;
+	}
+    } elsif (m/^confirm\s+\#?(-?\d+)\s+([a-z0-9]*)/i) {
+        $ok++;
+        $ref = $1;
+        $hash = $2;
+        if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+            $ref = $clonebugs{$ref};
+        }
+        if (-e bugfile("report")) {
+	    &foundbug;
+            &confirm;
+        } else {
+            &notfoundbug;
+	}
+    } elsif (m/^unsubscribe\s+\#?(-?\d+)(?:\s+(\w*))?/i) {
+        $ok++;
+        $ref = $1;
+        $email = $2 || ($replyto =~ /<(.*@.*)>/)[0];
+        if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+            $ref = $clonebugs{$ref};
+        }
+        if (-e bugfile("report")) {
+	    &foundbug;
+            &unsubscribe;
+        } else {
+            &notfoundbug;
+	}
+    } elsif (m/^confirm\s+\#?(-?\d+)\s+([a-z0-9]*)/i) {
+        $ok++;
+        $ref = $1;
+        $hash = $2;
+        if ($ref =~ m/^-\d+$/ && defined $clonebugs{$ref}) {
+            $ref = $clonebugs{$ref};
+        }
+        if (-e bugfile("report")) {
+	    &foundbug;
+            &confirm;
+        } else {
+            &notfoundbug;
+	}
     } elsif (!$control) {
         &transcript(<<END);
 Unknown command or malformed arguments to command.
@@ -277,6 +318,7 @@
 
 END
                     &sendmailmessage($message,$data->{originator});
+		    &sendsubscriptions($ref,$message,"Closed");
                 } while (&getnextbug);
             }
         }
@@ -363,6 +405,7 @@
 
 END
             &sendmailmessage($message,$oldsubmitter);
+	    &sendsubscriptions($ref,$message,"Submitter changed");
         } else {
             &notfoundbug;
         }
@@ -699,6 +742,13 @@
     $midix++;
 }
 
+sub sendsubscriptions {
+    # Extra funcion in case we want to change the text.
+    local ($ref, $text, $title) = @_;
+    my @subscribers = subscribers($ref);
+    sendmailmessage($text,@subscribers) if @subscribers;
+}
+
 sub sendhelp {
         &sendtxthelpraw("bug-log-mailserver.txt","instructions for request\@$gEmailDomain");
         &sendtxthelpraw("bug-maint-mailcontrol.txt","instructions for control\@$gEmailDomain")
@@ -1077,3 +1127,101 @@
     $ok++;
     &transcript("\n");
 }
+
+sub subscribe {
+    # Enters  a new address to the subs file and creates the confirmation hash
+    my $bhash = get_hashname($ref);
+    my $subfile = bugfile("subs");
+    unless (-e $subfile) {
+	open TMP, ">$subfile" || &quit("create $subfile: $!"); close TMP
+    }
+    &filelock($subfile."lock") || &quit("lock $subfile: $!");
+    my $subs = subfile_load($subfile);
+    my $chash = md5_hex($email.$$);
+    $subs->{$email} = $chash;
+    subfile_write($subfile,$subs);
+    &unfilelock;
+    &sendconfirmationmail($chash);
+}
+
+sub confirm {
+    my $bhash = get_hashname($ref);
+    my $subfile = bugfile("subs");
+    unless (-e $subfile) {
+	open TMP, ">$subfile" || &quit("create $subfile: $!"); close TMP
+    }
+    &filelock($subfile."lock") || &quit("lock $subfile: $!");
+    my $subs = subfile_load($subfile);
+    if (my ($key) = grep {$subs->{$_} eq $hash} keys %$subs)
+    {
+      &transcript("Confirmed Subscription of $key to $gBug $ref\n");
+      $subs->{$key} = "confirmed";
+      subfile_write($subfile,$subs);
+    } else {
+      &transcript("Conritmation failed: $hash not found\n");
+    }
+    &unfilelock;
+}
+
+sub unsubscribe {
+    # Removes an address from the subs file
+    my $bhash = get_hashname($ref);
+    my $subfile = bugfile("subs");
+    unless (-e $subfile) {
+	&transcript("Unsubscribe failed: $email is not subscribed to $gBug $ref\n");
+	return;
+    }
+    &filelock($subfile."lock") || &quit("lock $subfile: $!");
+    my $subs = subfile_load($subfile);
+    if (exists $subs->{$email}) {
+	delete $subs->{$email};
+	subfile_write($subfile,$subs);
+	&transcript("$email sucessfully unsubscribed from $gBug $ref\n");
+    } else {
+	&transcript("Unsubscribe failed: $email is not subscribed to $gBug $ref\n");
+    }
+    &unfilelock;
+}
+
+sub subscribers {
+    # List all addresses sucessfully subscribed to that bug
+    return () unless -e bugfile("subs");
+    my $data = subfile_load(bugfile("subs"));
+    grep {$data->{$_} eq "confirmed"} keys %$data;
+}
+
+sub subfile_load {
+    my $file = shift;
+    my $data = {};
+    open SUBFILE,"<$file" || &quit("open $file: $!");
+    while (<SUBFILE>) {
+      m/^([a-z0-9]+)\s+(.*)$/;
+      $data->{$2} = $1;
+    }
+    close SUBFILE;
+    return $data;
+}
+
+sub subfile_write {
+    my $file = shift;
+    my $data = shift;
+    open SUBFILE,">$file" || &quit("write $file: $!");
+    while (my ($email,$hash) = each %$data) {
+      print SUBFILE "$hash $email\n";
+    }
+    close SUBFILE;
+}
+    
+sub sendconfirmationmail {
+    # Function to create a better mail asking for subscription
+    my $chash = shift;
+    &transcript("Request Recieved. To confirm your subscription, send:\n");
+    &transcript("confirm $ref $chash\n");
+    &transcript("to request@$gEmailDomain\n");
+}
+
+sub bugfile {
+    my $ext = shift;
+    my $hash = get_hashname($ref);
+    return "db-h/$hash/$ref.$ext";
+}

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


Reply to: