2 package IkiWiki::Plugin::changemail;
9 hook(type => "getsetup", id => "changemail", call => \&getsetup);
10 hook(type => "change", id => "changemail", call => \¬ify);
26 eval q{use Mail::Sendmail};
28 eval q{use IkiWiki::UserInfo};
30 # Daemonize, in case the mail sending takes a while.
31 defined(my $pid = fork) or error("Can't fork: $!");
32 return if $pid; # parent
34 open STDIN, '/dev/null';
35 open STDOUT, '>/dev/null';
36 POSIX::setsid() or error("Can't start a new session: $!");
37 open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
39 # Don't need to keep a lock on the wiki as a daemon.
40 IkiWiki::unlockwiki();
42 my $userinfo=IkiWiki::userinfo_retrieve();
43 exit 0 unless defined $userinfo;
45 foreach my $user (keys %$userinfo) {
46 my $pagespec=$userinfo->{$user}->{"subscriptions"};
47 next unless defined $pagespec && length $pagespec;
48 my $email=$userinfo->{$user}->{email};
49 next unless defined $email && length $email;
51 foreach my $file (@files) {
52 my $page=pagename($file);
53 next unless pagespec_match($page, $pagespec);
54 my $ispage=defined pagetype($file);
56 if (! IkiWiki::isinternal($page)) {
57 $url=urlto($page, undef, 1);
59 elsif (defined $pagestate{$page}{meta}{permalink}) {
60 # need to use permalink for an internal page
61 $url=$pagestate{$page}{meta}{permalink};
64 $url=$config{wikiurl}; # crummy fallback url
66 my $template=template("changemail.tmpl");
68 wikiname => $config{wikiname},
70 prefsurl => IkiWiki::cgiurl(do => "prefs"),
72 content => $ispage ? readfile(srcfile($file)) : "",
74 #translators: The two variables are the name of the wiki,
75 #translators: and a page that was changed.
76 #translators: This is used as the subject of a commit email.
77 my $subject=sprintf(gettext("%s: change notification for %s"),
78 $config{wikiname}, $page);
81 From => "$config{wikiname} <$config{adminemail}>",
83 Message => $template->output,
88 exit 0; # daemon child