chiark / gitweb /
fixes
[inn-innduct.git] / scripts / innmail.in
1 #! /usr/bin/perl
2 # fixscript will replace this line with require innshellvars.pl
3
4 # Author:       James Brister <brister@vix.com> -- berkeley-unix --
5 # Start Date:   Fri, 25 Apr 1997 14:11:23 +0200
6 # Project:      INN
7 # File:         innmail.pl
8 # RCSId:        $Id: innmail.in 2677 1999-11-15 06:33:13Z rra $
9 # Description:  A simple replacement for UCB Mail to avoid nasty security
10 #               problems. 
11
12
13 $0 =~ s!.*/!! ;
14
15 require 5.001 ;
16 require 'getopts.pl' ;
17
18 die "$0: No \$inn::mta  variable defined.\n" 
19     if ! defined ($inn::mta);
20
21 $sm = $inn::mta ;
22
23 die "$0: MTA path is not absolute\n" unless ($sm =~ m!^/!) ;
24
25 $usage = "usage: $0 -s subject addresses\n\n" .
26     "Reads stdin for message body\n" ;
27
28 &Getopts ("s:h") || die $usage ;
29
30 die $usage if $opt_h ;
31
32 if ( !$opt_s ) {
33     warn "No subject given. Hope that's ok\n" ;
34     $opt_s = "NO SUBJECT" ;
35 } else {
36     $opt_s =~ s/\n+\Z//;
37 }
38
39 # fix up any addresses.
40 foreach ( @ARGV ) {
41     s![^-a-zA-Z0-9+_.@%]!!g ;
42
43     push (@addrs,$_) if ($_ ne "") ;
44 }
45
46 die "$0: No addresses specified\n\n$usage" unless @addrs ;
47
48 if ($sm =~ m!%s!) {
49     $sm = sprintf $sm,join (' ',@addrs);
50 } else {
51     $sm .= " " . join(' ', @addrs);
52 }
53
54 @smarr = split(/\s+/,$sm);
55
56 ($t = $inn::mta) =~ s!\s.*!!;
57 die "$0: MTA variable definition is changed after subsitution\n" 
58     if ($t ne $smarr[0]);
59
60 die "$0: MTA excutable doesn't appear to exist: $smarr[0]\n"
61     if ! -x $smarr[0];
62
63 # startup mta without using the shell
64 $pid = open (MTA,"|-") ;
65 if ($pid == 0) {
66     exec (@smarr) || die "$0: exec of $sm failed: $!\n" ;
67 } elsif ($pid < 0) {
68     die "$0: Fork failed: $!\n" ;
69 }
70
71 print MTA "To: ", join (",\n\t",@addrs), "\n" ;
72 print MTA "Subject: $opt_s\n" ;
73 print MTA "\n" ;
74 while (<STDIN>) {
75     print MTA $_ ;
76 }
77 close (MTA) ;
78 exit ;