File: news2mail.sh.more

package info (click to toggle)
newsgate 1.6-9
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 332 kB
  • ctags: 310
  • sloc: ansic: 2,683; yacc: 499; sh: 278; lex: 183; perl: 151; makefile: 113
file content (144 lines) | stat: -rw-r--r-- 3,715 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
From kim@loose.canberra.edu.au Sat Nov 25 06:03:50 1995
Received: from csc.canberra.edu.au (csc.canberra.edu.au [137.92.1.1]) by nntp.com (8.6.9/) with SMTP id GAA01451 for <rsalz@nntp.com>; Sat, 25 Nov 1995 06:03:42 -0500
Received: from loose.canberra.edu.au by csc.canberra.edu.au (5.65/1.35)
	id AA25869; Sat, 25 Nov 95 22:03:37 +1100
Received: by loose.canberra.edu.au (5.x/SMI-SVR4)
	id AA17231; Sat, 25 Nov 1995 22:03:34 +1100
Date: Sat, 25 Nov 1995 22:03:34 +1100
From: kim@loose.canberra.edu.au (Kim Holburn)
Message-Id: <9511251103.AA17231@loose.canberra.edu.au>
To: rsalz@nntp.com
Subject: Re: News/mail gateway package
Status: R

#! /bin/sh
##  $Header: /nfs/papaya/u2/rsalz/src/newsgate/RCS/news2mail.sh,v 1.3 91/02/12 14:50:28 rsalz Exp $
##  A short, mostly-awk, script to send news on stdin out as mail.
##  Usage:  news2mail <address>
##  Written by John S. Quarterman <jsq@longway.tic.com>.
##  Light editing by Rich $alz <rsalz@bbn.com>.
##  Some additions by Kim Holburn <kim@canberra.edu.au>.
PATH=/usr/local:/usr/ucb:/bin:/usr/bin ; export PATH

fail_usage () {
 echo "Usage: `basename $0` [-Evar=xx] [-] listname address listadmin host"
 exit 1
}

while [ -n "$1" ]
do
  case "$1" in
  -E*)
      $cmd=`echo "$1"|cut -c3-`
      if [ `expr "$1" : "[^ 	=][^ 	=]*="` -gt 0 ]; then
      # check it's a set statement don't want to eval anything!
      # could still get around this with a ; tricky
        eval "$cmd"
      fi
      shift
      ;;
  "") fail_usage ;;
  "-")
      TO="cat -u"
      shift
      ;;
  *)  
      if [ ! -n "$TO" ]; then
        TO="/bin/mail $2"
      fi
      break
      ;;
  esac
done
if [ $# -lt 4 ]; then
  fail_usage
fi
myto=$1
if [ `expr "$myto" : '.*@'` -eq 0 ]; then
  myto=$1@$4
fi
sender=$3
if [ `expr "$sender" : '.*@'` -eq 0 ]; then
  sender=$3@$4
fi

awk '
BEGIN {
    header = 1;
    date = "";
}
header == 1 && /^$/ {
    # End of headers; print dates.
    header = 0;
    if (pdate != "" && date ~ /GMT/ && pdate !~ /GMT/) {
       print "Date: "pdate;
       print "Posted-Date: "date;
    } else {
       if (date != "")
           print "Date: "date;
       if (pdate != "")
           print "Posted-Date: "pdate;
    }
    print "Sender: '$sender'";
    print "To: '$myto'";
}
header == 0 {
    print $0;
    next;
}
$1 == "Sender:"               { next; }
$1 == "To:"                   { next; }
$1 == "Relay-Version:"         { next; }
$1 == "Posting-Version:"       { next; }
$1 == "Path:"                  { next; }
$1 == "From"                   { next; }
$1 == "Date-Received:"         { next; }
$1 == "Received-Date:"         { next; }
#$1 == "Newsgroups:"           { next; }
#$1 == "Organization:"         { next; }
$1 == "Approved:"              { next; }
$1 == "Lines:"                 { next; }
$1 == "Date:" {
    date = $2;
    for (i = 3; i <= NF; i++)
       date = date " " $i;
    next;
}
$1 == "Posted-Date:" {
    pdate = $2;
    for (i = 3; i <= NF; i++)
       pdate = pdate " " $i;
    next;
}
$1 == "From:" {
    address=$2;
    name = "";
    surround = 0;
    for (f = 3; f <= NF; f++) {
       if ($f ~ /,/)
           surround=1;
       if (split ($f, parts, "(") > 1)
           it = parts[2];
       else
           it = $f;
       if (split ($f, parts, ")") > 1)
           it = parts[1];
       if (name == "")
           name = it;
       else
           name = name " " it;
    }
    if (address ~ /.UUCP$/) {
       split(address, parts, "@");
       address = sprintf ("%s%%%s@%s", parts[1], parts[2], "'`hostname`'");
    }
    if (surround != 0)
           printf ("From: %s (%s)\n", address, name);
    else
           printf ("From: %s <%s>\n", name, address);
    next;
}
{
    print $0;
}' | eval $TO