chiark / gitweb /
wip compile
[inn-innduct.git] / control / modules / sendsys.pl
1 ##  $Id: sendsys.pl 4932 2001-07-19 00:32:56Z rra $
2 ##
3 ##  sendsys control message handler.
4 ##
5 ##  Copyright 2001 by Marco d'Itri <md@linux.it>
6 ##
7 ##  Redistribution and use in source and binary forms, with or without
8 ##  modification, are permitted provided that the following conditions
9 ##  are met:
10 ##
11 ##   1. Redistributions of source code must retain the above copyright
12 ##      notice, this list of conditions and the following disclaimer.
13 ##
14 ##   2. Redistributions in binary form must reproduce the above copyright
15 ##      notice, this list of conditions and the following disclaimer in the
16 ##      documentation and/or other materials provided with the distribution.
17
18 use strict;
19
20 sub control_sendsys {
21     my ($par, $sender, $replyto, $site, $action, $log, $approved,
22         $headers, $body) = @_;
23     my ($where) = @$par;
24
25     if ($action eq 'mail') {
26         my $mail = sendmail("sendsys $sender");
27         print $mail <<END;
28 $sender has requested that you send a copy
29 of your newsgroups file.
30
31 If this is acceptable, type:
32   $inn::mailcmd -s "sendsys reply from $inn::pathhost" $replyto < $inn::newsfeeds
33
34 The control message follows:
35
36 END
37         print $mail map { s/^~/~~/; "$_\n" } @$headers;
38         print $mail "\n";
39         print $mail map { s/^~/~~/; "$_\n" } @$body;
40         close $mail or logdie("Cannot send mail: $!");
41     } elsif ($action eq 'log') {
42         if ($log) {
43             logger($log, "sendsys $sender", $headers, $body);
44         } else {
45             logmsg("sendsys $sender");
46         }
47     } elsif ($action =~ /^(doit|doifarg)$/) {
48         if ($action eq 'doifarg' and $where ne $inn::pathhost) {
49             logmsg("skipped sendsys $sender");
50             return;
51         }
52         my $mail = sendmail("sendsys reply from $inn::pathhost", $replyto);
53         open(NEWSFEEDS, $inn::newsfeeds)
54             or logdie("Cannot open $inn::newsfeeds: $!");
55         print $mail $_ while <NEWSFEEDS>;
56         print $mail "\n";
57         close NEWSFEEDS;
58         close $mail or logdie("Cannot send mail: $!");
59
60         logger($log, "sendsys $sender to $replyto", $headers, $body) if $log;
61     }
62 }
63
64 1;