chiark / gitweb /
Commit 2.4.5-5 as unpacked
[inn-innduct.git] / control / modules / ihave.pl
1 ##  $Id: ihave.pl 4932 2001-07-19 00:32:56Z rra $
2 ##
3 ##  ihave 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_ihave {
21     my ($par, $sender, $replyto, $site, $action, $log, $approved,
22         $headers, $body) = @_;
23
24     if ($action eq 'mail') {
25         my $mail = sendmail("ihave by $sender");
26         print $mail map { s/^~/~~/; "$_\n" } @$body;
27         close $mail or logdie('Cannot send mail: ' . $!);
28     } elsif ($action eq 'log') {
29         if ($log) {
30             logger($log, "ihave $sender", $headers, $body);
31         } else {
32             logmsg("ihave $sender");
33         }
34     } elsif ($action eq 'doit') {
35         my $tempfile = "$inn::tmpdir/ihave.$$";
36         open(GREPHIST, "|grephistory -i > $tempfile")
37             or logdie('Cannot run grephistory: ' . $!);
38         foreach (@$body) {
39             print GREPHIST "$_\n";
40         }
41         close GREPHIST;
42
43         if (-s $tempfile) {
44             my $inews = open("$inn::inews -h")
45                 or logdie('Cannot run inews: ' . $!);
46             print $inews "Newsgroups: to.$site\n"
47                . "Subject: cmsg sendme $inn::pathhost\n"
48                . "Control: sendme $inn::pathhost\n\n";
49             open(TEMPFILE, $tempfile) or logdie("Cannot open $tempfile: $!");
50             print $inews $_ while <TEMPFILE>;  
51             close $inews or die $!;
52             close TEMPFILE;
53         }
54         unlink $tempfile;
55     }
56 }
57
58 1;