The EmailNotify feature has a caveat: if you change your e-mail address, your old e-mail address will keep receiving notifications, and there will be no obvious way to remove it from the notification list. (There is a workaround: you change your e-mail in two steps.)
This patch fixes this behavior, changing/removing your e-mail address will now work as you expect it to.
--- wiki.pl 2003-09-11 14:21:02.000000000 +0200
+++ EmailNotify.pl 2007-01-12 10:25:31.440348648 +0100
@@ -3493,7 +3493,6 @@
}
}
if ($EmailNotify) {
- &UpdatePrefCheckbox("notify");
&UpdateEmailList();
}
&UpdatePrefNumber("rcdays", 0, 0, 999999);
@@ -3532,43 +3531,35 @@
# add or remove email address from preferences to $EmailFile
sub UpdateEmailList {
- my (@old_emails);
+ my ($emails, $newEmail, $oldEmail, $newNotify, $oldNotify);
- local $/ = "\n"; # don't slurp whole files in this sub.
- if (my $new_email = $UserData{'email'} = &GetParam("p_email", "")) {
- my $notify = $UserData{'notify'};
- if (-f $EmailFile) {
- open(NOTIFY, $EmailFile)
- or die(Ts('Could not read from %s:', $EmailFile) . " $!\n");
- @old_emails = <NOTIFY>;
- close(NOTIFY);
- } else {
- @old_emails = ();
- }
- my $already_in_list = grep /$new_email/, @old_emails;
- if ($notify and (not $already_in_list)) {
- &RequestLock() or die(T('Could not get mail lock'));
- if (!open(NOTIFY, ">>$EmailFile")) {
- &ReleaseLock(); # Don't leave hangling locks
- die(Ts('Could not append to %s:', $EmailFile) . " $!\n");
- }
- print NOTIFY $new_email, "\n";
- close(NOTIFY);
- &ReleaseLock();
- }
- elsif ((not $notify) and $already_in_list) {
- &RequestLock() or die(T('Could not get mail lock'));
- if (!open(NOTIFY, ">$EmailFile")) {
- &ReleaseLock();
- die(Ts('Could not overwrite %s:', "$EmailFile") . " $!\n");
- }
- foreach (@old_emails) {
- print NOTIFY "$_" unless /$new_email/;
- }
- close(NOTIFY);
- &ReleaseLock();
- }
+ $oldEmail = $UserData{'email'};
+ $newEmail = $UserData{'email'} = &GetParam('p_email', '');
+ $oldNotify = $UserData{'notify'};
+ &UpdatePrefCheckbox("notify");
+ $newNotify = $UserData{'notify'};
+ if ($newNotify == 0 and $oldNotify == 0) {
+ return;
+ }
+ if ($oldEmail eq $newEmail and $newNotify == $oldNotify) {
+ return;
}
+
+ # Remove old e-mail
+ &RequestLock();
+ $emails = '';
+ if ( -f $EmailFile ) {
+ $emails = &ReadFileOrDie($EmailFile);
+ }
+ if ($oldEmail) {
+ $emails =~ s/^\s*$oldEmail\s*\n//m;
+ }
+ # Add new email
+ if ($newNotify) {
+ $emails .= "$newEmail\n";
+ }
+ &WriteStringToFile($EmailFile, $emails);
+ &ReleaseLock();
}
sub UpdatePrefCheckbox {