File: arch_retrieve

package info (click to toggle)
rel 1.3-3
  • links: PTS
  • area: non-free
  • in suites: hamm, potato, slink
  • size: 496 kB
  • ctags: 216
  • sloc: ansic: 1,868; sh: 254; makefile: 142
file content (278 lines) | stat: -rwxr-xr-x 9,343 bytes parent folder | download
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#! /bin/sh
:
#$Id: arch_retrieve,v 1.0 1995/01/15 15:48:25 john Exp $

test=test		# /bin/test
echo=echo		# /bin/echo
sed=sed			# /bin/sed
cat=cat			# /bin/cat
egrep=egrep		# /bin/egrep
rel=rel			# /usr/local/bin/rel
date=date		# /bin/date
touch=touch		# /bin/touch
chmod=chmod		# /bin/chmod
sort=sort		# /bin/sort
find=find		# /bin/find
sed=sed			# /bin/sed
sleep=sleep		# /bin/sleep
formail=formail		# /usr/local/bin/formail

grep_sort()
{
    $find "$2" -type f -print | $sort | while read filename
    do
        $egrep -i -l -e "$1" $filename
    done
}

reverse_grep_sort()
{
    $find "$2" -type f -print | $sort -r | while read filename
    do
        $egrep -i -l -e "$1" $filename
    done
}

date_sort()
{
    $find "$2" -type f -print | $sort | $egrep "$2/[0-9][0-9][0-9][0-9]/$1"
}

reverse_date_sort()
{
    $find "$2" -type f -print | $sort -r | $egrep "$2/[0-9][0-9][0-9][0-9]/$1"
}

$test -z "$listaddr" &&
 $echo "Don't start this script directly, it is used in rc.request" && exit 64

tmprequest=tmp.request
tmpfrom=tmp.from

$chmod u+w tmp.lock		# so that we can touch it

archivetxt=archive.txt		# the helpfile
archivedir=archive

standalone=$1

from="arch_retrieve:  requested"
$echo "arch_retrieve: processing for `$cat $tmpfrom`  `$date`" >$tmpfrom

case "$X_ENVELOPE_TO" in
  *$list-request*) wrongaddress="" ;;
  *) wrongaddress="WARNING:
	Please try to use '$listreq'
	the next time when issuing archive server requests." ;;
esac

$formail -k -xSubject: |
 $sed -e '/^[^a-zA-Z	 ]/,$ d' -e 's/^[	 ]*archive/ARCHIVE/' \
  -e 's/[	 ]archive\/\/*/ /g' |
 (  oldwrongaddress="$wrongaddress"
    wrongaddress="WARNING:
	Please make sure to start the Subject: of requests to the archive-
	server with the word archive.${wrongaddress:+
$wrongaddress}"
   sendhelp=""
   ILLEGAL=""
   while read line
   do
      set `cd $archivedir; $echo dummy $line`
      shift
      case "$1" in
	 archive|ARCHIVE|archive:|ARCHIVE:) shift
	    $test ! -z "$wrongaddress" && wrongaddress="$oldwrongaddress";;
      esac
      #
      # Now call up the local extension file (if any)...
      #
      if test -f retrieve.local
      then
	 . retrieve.local
      elif test -f ../.bin/retrieve.local
      then
	 . ../.bin/retrieve.local
      elif test -f ../.bin/retrieve.local
      then
	 . ../.bin/retrieve.local
      fi
      #
      # The extension file should have used "set" to clear $1 and tell that
      # it has processed the current command
      #
      case "$1" in
	 search|rel|relevance|\
	 SEARCH|REL|RELEVANCE)
	    shift
	    $echo $from "$line" >>$tmpfrom
	    ( $formail -rt -I"Subject: archive retrieval: $line" \
	      -i"From: $listreq" -A"X-Loop: $listaddr" \
	      -i"Content-Type: multipart/digest; boundary=\"-----------------------------------------------------\""\
	      -I"Precedence: bulk" <$tmprequest
	      $test ! -z "$wrongaddress" && $echo "$wrongaddress"
	      $echo "-------------------------------------------------------"
	      $echo ""
	      $echo "Content-Type: text/plain"
	      $echo ""
	      $echo "Relevance Digest $*"
	      for file in `$rel "$*" ${archivedir}`
	      do
		  $echo ""
		  $echo "-------------------------------------------------------"
		  $echo ""
		  $sed "s/^-/- -/"  "./$file" | $formail -I "From "
	      done
	      $echo "---------------------------------------------------------"
	      $echo "End of Relevance Digest $*"
	      $echo "**********************************************************"
	    ) | $SENDMAIL $sendmailOPT -t ;;
	 grep|egrep|fgrep|\
	 GREP|EGREP|FGREP)
	    shift
	    $echo $from "$line" >>$tmpfrom
	    ( $formail -rt -I"Subject: archive retrieval: $line" \
	      -i"From: $listreq" -A"X-Loop: $listaddr" \
	      -i"Content-Type: multipart/digest; boundary=\"-----------------------------------------------------\""\
	      -I"Precedence: bulk" <$tmprequest
	      $test ! -z "$wrongaddress" && $echo "$wrongaddress"
	      $echo "-------------------------------------------------------"
	      $echo ""
	      $echo "Content-Type: text/plain"
	      $echo ""
	      $echo "Regular Expression Digest $* (Chronological Order)"
	      for file in `grep_sort "$*" ${archivedir}`
	      do
		  $echo ""
		  $echo "-------------------------------------------------------"
		  $echo ""
		  $sed "s/^-/- -/"  "./$file" | $formail -I "From "
	      done
	      $echo "---------------------------------------------------------"
	      $echo "End of Regular Expression Digest $* (Chronological Order)"
	      $echo "**********************************************************"
	    ) | $SENDMAIL $sendmailOPT -t ;;
	 rgrep|regrep|rfgrep|\
	 RGREP|REGREP|RFGREP)
	    shift
	    $echo $from "$line" >>$tmpfrom
	    ( $formail -rt -I"Subject: archive retrieval: $line" \
	      -i"From: $listreq" -A"X-Loop: $listaddr" \
	      -i"Content-Type: multipart/digest; boundary=\"-----------------------------------------------------\""\
	      -I"Precedence: bulk" <$tmprequest
	      $test ! -z "$wrongaddress" && $echo "$wrongaddress"
	      $echo "-------------------------------------------------------"
	      $echo ""
	      $echo "Content-Type: text/plain"
	      $echo ""
	      $echo "Regular Expression Digest $* (Reverse Chronological Order)"
	      for file in `reverse_grep_sort "$*" ${archivedir}`
	      do
		  $echo ""
		  $echo "-------------------------------------------------------"
		  $echo ""
		  $sed "s/^-/- -/"  "./$file" | $formail -I "From "
	      done
	      $echo "---------------------------------------------------------"
	      $echo "End of Regular Expression Digest $* (Reverse Chronological Order)"
	      $echo "**********************************************************"
	    ) | $SENDMAIL $sendmailOPT -t ;;
	 date|chron|chronological|\
	 DATE|CHRON|CHRONOLOGICAL)
	    shift
	    $echo $from "$line" >>$tmpfrom
	    ( $formail -rt -I"Subject: archive retrieval: $line" \
	      -i"From: $listreq" -A"X-Loop: $listaddr" \
	      -i"Content-Type: multipart/digest; boundary=\"-----------------------------------------------------\""\
	      -I"Precedence: bulk" <$tmprequest
	      $test ! -z "$wrongaddress" && $echo "$wrongaddress"
	      $echo "-------------------------------------------------------"
	      $echo ""
	      $echo "Content-Type: text/plain"
	      $echo ""
	      $echo "Chronological Digest $* (Chronological Order)"
	      for file in `date_sort "$*" ${archivedir}`
	      do
		  $echo ""
		  $echo "-------------------------------------------------------"
		  $echo ""
		  $sed "s/^-/- -/"  "./$file" | $formail -I "From "
	      done
	      $echo "---------------------------------------------------------"
	      $echo "End of Chronological Digest $* (Chronological Order)"
	      $echo "**********************************************************"
	    ) | $SENDMAIL $sendmailOPT -t ;;
	 rdate|rchron|rchronological|\
	 RDATE|RCHRON|RCHRONOLOGICAL)
	    shift
	    $echo $from "$line" >>$tmpfrom
	    ( $formail -rt -I"Subject: archive retrieval: $line" \
	      -i"From: $listreq" -A"X-Loop: $listaddr" \
	      -i"Content-Type: multipart/digest; boundary=\"-----------------------------------------------------\""\
	      -I"Precedence: bulk" <$tmprequest
	      $test ! -z "$wrongaddress" && $echo "$wrongaddress"
	      $echo "-------------------------------------------------------"
	      $echo ""
	      $echo "Content-Type: text/plain"
	      $echo ""
	      $echo "Chronological Digest $* (Reverse Chronological Order)"
	      for file in `reverse_date_sort "$*" ${archivedir}`
	      do
		  $echo ""
		  $echo "-------------------------------------------------------"
		  $echo ""
		  $sed "s/^-/- -/"  "./$file" | $formail -I "From "
	      done
	      $echo "---------------------------------------------------------"
	      $echo "End of Chronological Digest $* (Reverse Chronological Order)"
	      $echo "**********************************************************"
	    ) | $SENDMAIL $sendmailOPT -t ;;
	 version|VERSION)
	       $touch tmp.lock
		( $formail -rt -I"Subject: archive retrieval: $line" \
		   -i"From: $listreq" -A"X-Loop: $listaddr" \
		   <$tmprequest
		  $test ! -z "$wrongaddress" && $echo "$wrongaddress"
		  flist -v 2>&1 | sed -e "/^User:/,$ d"
		  echo ""
		  procmail -v 2>&1
		) | $SENDMAIL $sendmailOPT -t ;;
	 ""|\#*) ;;
	 *) $test -z "$sendhelp" && sendhelp="$1" ;;
      esac
   done
   if $test ! -z "$sendhelp" -o ! -z "$ILLEGAL"
   then
       ( $formail -rt -I"Subject: archive retrieval info" \
	  -i"From: $listreq" -A"X-Loop: $listaddr" -I"Precedence: bulk" \
	  <$tmprequest
	 $test ! -z "$wrongaddress" && $echo "$wrongaddress"
	 case "X$sendhelp" in
	    X[Hh][Ee][Ll][Pp]|X[Ii][Nn][Ff][Oo]|X)
	       $echo "$from $sendhelp." >>$tmpfrom ;;
	    *) $echo "$from unknown command $sendhelp." >>$tmpfrom
	       $echo "Unknown command $sendhelp." ;;
	 esac
	 $test ! -z "$ILLEGAL" && $echo "Illegal filename $ILLEGAL requested."
	 $echo ""
	 $cat $archivetxt
	 if $test ! -z "$standalone"
	 then
	    $echo ""
	    $test -f help.txt && $cat help.txt
	    $test -f info.txt && $cat info.txt
	 fi
       ) | $SENDMAIL $sendmailOPT -t
   fi
 )

if $test ! -z "$archive_log"
then
  $echo "arch_retrieve: done  `$date`" >>$tmpfrom
  $cat $tmpfrom >>$archive_log
fi

if $test ! -z "$sendmailQflush"
then
  $sendmailQflush 2>/dev/null &
fi