10 sub userinfo_retrieve () { #{{{
11 my $userinfo=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
15 sub userinfo_store ($) { #{{{
18 my $oldmask=umask(077);
19 my $ret=Storable::lock_store($userinfo, "$config{wikistatedir}/userdb");
24 sub userinfo_get ($$) { #{{{
28 my $userinfo=userinfo_retrieve();
29 if (! defined $userinfo ||
30 ! exists $userinfo->{$user} || ! ref $userinfo->{$user} ||
31 ! exists $userinfo->{$user}->{$field}) {
34 return $userinfo->{$user}->{$field};
37 sub userinfo_set ($$$) { #{{{
42 my $userinfo=userinfo_retrieve();
43 if (! defined $userinfo ||
44 ! exists $userinfo->{$user} || ! ref $userinfo->{$user}) {
48 $userinfo->{$user}->{$field}=$value;
49 return userinfo_store($userinfo);
52 sub userinfo_setall ($$) { #{{{
56 my $userinfo=userinfo_retrieve();
57 if (! defined $userinfo) {
60 $userinfo->{$user}=$info;
61 return userinfo_store($userinfo);
64 sub is_admin ($) { #{{{
67 return grep { $_ eq $user_name } @{$config{adminuser}};
70 sub get_banned_users () { #{{{
72 my $userinfo=userinfo_retrieve();
73 foreach my $user (keys %{$userinfo}) {
74 push @ret, $user if $userinfo->{$user}->{banned};
79 sub set_banned_users (@) { #{{{
80 my %banned=map { $_ => 1 } @_;
81 my $userinfo=userinfo_retrieve();
82 foreach my $user (keys %{$userinfo}) {
83 $userinfo->{$user}->{banned} = $banned{$user};
85 return userinfo_store($userinfo);
88 sub commit_notify_list ($@) { #{{{
92 foreach my $file (@_) {
93 push @pages, grep { $pagesources{$_} eq $file } keys %pagesources;
97 my $userinfo=userinfo_retrieve();
98 foreach my $user (keys %{$userinfo}) {
99 next if $user eq $committer;
100 if (exists $userinfo->{$user}->{subscriptions} &&
101 length $userinfo->{$user}->{subscriptions} &&
102 exists $userinfo->{$user}->{email} &&
103 length $userinfo->{$user}->{email} &&
104 grep { pagespec_match($_, $userinfo->{$user}->{subscriptions}) } @pages) {
105 push @ret, $userinfo->{$user}->{email};
111 sub send_commit_mails ($$$@) { #{{{
112 my $messagesub=shift;
115 my @changed_pages=shift;
117 my @email_recipients=commit_notify_list($user, @changed_pages);
118 if (@email_recipients) {
119 # TODO: if a commit spans multiple pages, this will send
120 # subscribers a diff that might contain pages they did not
121 # sign up for. Should separate the diff per page and
122 # reassemble into one mail with just the pages subscribed to.
123 my $diff=$diffsub->();
124 my $message=$messagesub->();
126 my $subject="update of $config{wikiname}'s ";
127 if (@changed_pages > 2) {
128 $subject.="$changed_pages[0] $changed_pages[1] etc";
131 $subject.=join(" ", @changed_pages);
133 $subject.=" by $user";
135 my $template=template("notifymail.tmpl");
137 wikiname => $config{wikiname},
143 # Daemonize, in case the mail sending takes a while.
144 eval q{use POSIX ’setsid’};
146 open STDIN, '/dev/null';
147 open STDOUT, '>/dev/null';
148 defined(my $pid = fork) or error("Can't fork: $!");
150 setsid() or error("Can't start a new session: $!");
151 open STDERR, '>&STDOUT' or error("Can’t dup stdout: $!");
153 unlockwiki(); # don't need to keep a lock on the wiki
155 eval q{use Mail::Sendmail};
157 foreach my $email (@email_recipients) {
160 From => "$config{wikiname} <$config{adminemail}>",
162 Message => $template->output,
163 ) or error("Failed to send update notification mail");
166 exit 0; # daemon process done