summaryrefslogtreecommitdiff
path: root/mmuegel/src/postclip
blob: 63f6df0f29a7088e8902d1aceb8062fa11c7b644 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/local/bin/perl

# NAME
#    postclip - send only the headers to Postmaster
#
# SYNOPSIS
#    postclip [ -v ] [ to ... ]
#
# AUTHOR
#    Michael S. Muegel <mmuegel@mot.com>
#
# RCS INFORMATION
#    /usr/local/ustart/src/mail-tools/dist/foo/src/postclip,v
#    1.1 of 1993/07/28 08:09:02

# We use this to send off the mail
require "newgetopts.pl";
require "mail.pl";

# Get the basename of the script
($Script_Name = $0) =~ s/.*\///;

# Some famous constants
$USAGE          = "Usage: $Script_Name [ -v ] [ to ... ]\n";
$VERSION        = "${Script_Name} by mmuegel; 1.1 of 1993/07/28 08:09:02";
$SWITCHES       = "v";

# Let getopts parse for switches
$Status = &New_Getopts ($SWITCHES, $USAGE);
exit (0) if ($Status == -1);
exit (1) if (! $Status);

# Who should we send the modified mail to?
@ARGV = ("postmaster") if (! @ARGV);
$Users = join (" ", @ARGV);
@ARGV = ();

# Suck in the original header and save a few interesting lines
while (<>) 
{
    $Buffer .= $_ if (! /^From /);
    $Subject = $1 if (/^Subject:\s+(.*)$/);
    $From = $1 if (/^From:\s+(.*)$/);
    last if (/^$/);
};

# Do not filter the message unless it has a subject and the subject indicates
# it is an NDN
if ($Subject && ($Subject =~ /^returned mail/i))
{
   # Slurp input by paragraph. Keep track of the last time we saw what
   # appeared to be NDN text. We keep this.
   $/ = "\n\n";
   $* = 1;
   while (<>)
   {
      push (@Paragraphs, $_);
      $Last_Error_Para = $#Paragraphs 
	 if (/unsent message follows/i || /was not delivered because/);
   };

   # Now save the NDN text into $Buffer
   $Buffer .= join ("", @Paragraphs [0..$Last_Error_Para]);
}

else
{
   undef $/;
   $Buffer .= <>;
};

# Send off the (possibly) modified mail
($Status, $Msg) = &Send_Mail ($Users, "", $Buffer, 0, $opt_v, 1);
die "$Script_Name: $Msg\n" if (! $Status);