File: sendme.pl

package info (click to toggle)
inn2 2.5.2-2~squeeze1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,072 kB
  • ctags: 8,521
  • sloc: ansic: 91,418; sh: 13,249; perl: 12,311; makefile: 2,928; yacc: 868; python: 342; lex: 266
file content (57 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
##  $Id: sendme.pl 8281 2009-01-10 11:52:16Z iulius $
##
##  sendme control message handler.
##
##  Copyright 2001 by Marco d'Itri <md@linux.it>
##
##  Redistribution and use in source and binary forms, with or without
##  modification, are permitted provided that the following conditions
##  are met:
##
##   1. Redistributions of source code must retain the above copyright
##      notice, this list of conditions and the following disclaimer.
##
##   2. Redistributions in binary form must reproduce the above copyright
##      notice, this list of conditions and the following disclaimer in the
##      documentation and/or other materials provided with the distribution.

use strict;

sub control_sendme {
    my ($par, $sender, $replyto, $site, $action, $log, $approved,
        $article) = @_;

    my @body = split(/\r?\n/, $article->stringify_body);

    if ($action eq 'mail') {
        my $mail = sendmail("sendme by $sender");
        print $mail map { s/^~/~~/; "$_\n" } @body;
        close $mail or logdie('Cannot send mail: ' . $!);
    } elsif ($action eq 'log') {
        if ($log) {
            logger($log, "sendme $sender", $article);
        } else {
            logmsg("sendme from $sender");
        }
    } elsif ($action eq 'doit') {
        my $tempfile = "$INN::Config::tmpdir/sendme.$$";
        open(GREPHIST, "| $INN::Config::newsbin/grephistory -s > $tempfile")
            or logdie("Cannot run grephistory: $!");
	foreach (@body) {
            print GREPHIST "$_\n";
	}
        close GREPHIST or logdie("Cannot run grephistory: $!");

        if (-s $tempfile and $site =~ /^[a-zA-Z0-9.-_]+$/) {
            open(TEMPFILE, $tempfile) or logdie("Cannot open $tempfile: $!");
            open(BATCH, ">>$INN::Config::batch/$site.work")
                or logdie("Cannot open $INN::Config::batch/$site.work: $!");
            print BATCH $_ while <TEMPFILE>;
            close BATCH;
            close TEMPFILE;
        }
        unlink $tempfile;
    }
}

1;