File: news2mail.sh

package info (click to toggle)
newsgate 1.6-22
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 340 kB
  • ctags: 313
  • sloc: ansic: 2,686; yacc: 504; sh: 278; lex: 183; perl: 151; makefile: 111
file content (96 lines) | stat: -rwxr-xr-x 2,028 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
#! /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>.
PATH=/usr/local:/usr/ucb:/bin:/usr/bin ; export PATH

case $1 in
"")
    echo "Usage:  `basename $0` address"
    exit 1
    ;;
"-")
    TO="cat -u"
    ;;
*)
    TO="/bin/mail $1"
    ;;
esac

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;
    }
}
header == 0 {
    print $0;
    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