File: commands.rc

package info (click to toggle)
procmail-lib 1:1995.08.28-4.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 156 kB
  • ctags: 32
  • sloc: perl: 213; makefile: 143
file content (366 lines) | stat: -rw-r--r-- 9,581 bytes parent folder | download | duplicates (3)
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# commands.rc			-*- text -*-
#
# procmailrc file to check for commands in the subject line
#
# $Id: commands.rc,v 1.15 1995/08/28 17:27:36 aks Exp $
#
#    Copyright (C) 1995  Alan K. Stebbens <aks@hub.ucsb.edu>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Usage:
#
#	HELPFILE=commands.help		[optional]
#	INFOFILE=commands.info		[optional]
#       PROCMAILINFO=procmail.info	[optional]
#	COMMANDLOG=commands.log		[optional]
#	NOACKFILE=noacks		[optional]
#
#	INCLUDERC=commands.rc
#
# Notes:
#
# * This recipe consumes the input if it successfully matches.
#   Processing does not continue unless the subject is not a
#   command.
#
# * HELPFILE should contain general help, and be relatively short.
#
# * INFOFILE should contain more detailed information on the
#   supported commands.
#
# * All default filenames are relative to $MAILDIR.
#
# * NOACKFILE is used by "ackmail.rc", with the same default.
#
# * Processed commands are logged in $COMMANDLOG.  The format of the
#   logged information is:
#
#	date : address : command
#
# * To debug your configuration, touch $MAILDIR/commands.rc.log and
#   watch its contents for logged information.  Remove this file when
#   you no longer wish to have a detailed debug log.
#
# * This recipe file uses "comm-reply-file.rc" (which part of the 
#   procmail library).
#
# Current commands are:
#
#	(send | get) help
#	(send | get) info(rmation)?
#	(send | get) pgp key
#	(send | get) procmail info
#	(send | get) procmail lib(rary)
#	(send | get) smartlist lib(rary)
#	(send | get) emacs setup
#	(send | get) procmailrc
#	(en|dis)able (auto *)ack(nowledgments)
#
# Author: Alan K. Stebbens
#
# Check for any of the commands

:0
* ? test -f commands.rc.log
{ OLDCMDLOGFILE=$LOGFILE
  LOGFILE=commands.rc.log
  LOGABSTRACT=all 
  VERBOSE=yes 
}

:0
* ^Subject: *\/\
	((send|get) +(help|info(rmation)?|\
		     procmailrc|\
		     (procmail|smartlist) *(- *)?info(rmation)?|\
	 	     (procmail|smartlist) *(- *)?lib(rary)?|\
	 	     emacs(-| *)setup|\
	 	     pgp *key)|\
	(en|dis)able +(auto *)?ack(nowledge?ment)?s?)
* ! ^FROM_DAEMON
* $ ! ^X-Loop: $MY_ADDR
{
    # We're forking at this point -- so shutup procmail
    COMSAT=off

    # Tell sendmail we've got control
    DELIVERED=yes

    # Save a copy just in case (in log mode)
    :0 c:
    * LOGFILE ?? commands\.rc\.log
    commands.requests

    # Get the trigger subject
    SUBJ=$MATCH

    # Get the best reply address (used for logging)
    :0
    * ! ^Reply-to: *\/[^ ].*
    * ! ^From: *\/[^ ].*
    * ! ^Sender: *\/[^ ].*
    * ! ^From *\/[^ ]+
    { FROM=nobody }
    :0E
    { FROM=$MATCH }

    # Just in case these aren't defined
    FROMSIG="${FROMSIG:-\"The Mailer-Daemon of $USER\" <$USER>}"
    MY_ADDR="${MY_ADDR:-<$USER>}"

    # The log file
    COMMANDLOG=${COMMANDLOG:-commands.log}

    # The basic processing works like this:
    # Now that we've captured the important information from the 
    # incoming mail, we replace the headers portion with an
    # autoreply header.
    #
    # Then, as part of recognizing the SUBJECT command, we
    # replace the body portion with the response
    #
    # After testing for all the possible subject commands,
    # we then submit the mail unless it is empty.

    # Generate a reply header, and replace the headers
    :0 fhw
    | formail  -rI"From:       $FROMSIG" \
	        -I"Reply-To:   $MY_ADDR" \
	        -I"Subject:    Re: $SUBJ" \
		-I"Precedence: junk" \
		-I"X-Loop:     $MY_ADDR"

    # Now, start a new message body
    :0 fbw
    | echo "This message was sent automatically in reponse to your recent" ; \
      echo "mail with the subject: \"$SUBJ\"." ; \
      echo ""

    # Now process each command

    ##### 	send procmailrc
    #####	send procmail lib
    :0
    * SUBJ ?? procmail(rc| *(- *)?lib(rary)?)
    {
	# **** This is very site specific ****
	PROCMAILDIR=$HOME/src/mail/procmail/procmail-lib
	:0
	* SUBJ ?? procmailrc
	{
	    REPLYFILE=$PROCMAILDIR/procmailrc-example
	    INCLUDERC=comm-reply-file.rc
	}
	:0 E
	{
	    REPLYFILE=$PROCMAILDIR/procmail-lib.shar
	    INCLUDERC=comm-reply-file.rc
	}
    }

    ####	send procmail info
    :0 E
    * SUBJ ?? (procmail|smartlist) *(- *)?info
    {
	PROCMAILINFO=${PROCMAILINFO:-procmail.info}
	REPLYFILE=$PROCMAILINFO
	INCLUDERC=comm-reply-file.rc
    }

    #####	send smartlist library
    :0 E
    * SUBJ ?? smartlist *(- *)?lib(rary)?
    {
	# **** This is very site specific ****
	REPLYFILE=$HOME/src/mail/procmail/smartlist-lib/smartlist-lib.shar
	INCLUDERC=comm-reply-file.rc
    }

    #####	send information
    :0 E
    * SUBJ ?? info(rmation)?
    {
	# The information file with a suitable default
	INFOFILE=${INFOFILE:-commands.info}
	REPLYFILE=$INFOFILE
	INCLUDERC=comm-reply-file.rc
    }

    #####	send emacs setup
    :0 E
    * SUBJ ?? emacs(-| *)setup
    {
	# Send emacs setup (shar archive is several files)
	EMACSSETUP="$HOME/emacs/site-setup.shar*"
	count=`echo $EMACSSETUP | wc -w`

	# For this command, we are responding with several mails
	# so we cannot use procmail to "hold" them all at the
	# same time.  So, we generate several sendmail invocations
	# and leave the current mail buffer empty by filtering it
	# with /dev/null

	:0 fw:tmp.reply.lock
	* $ ? test -f $EMACSSETUP
	| cat - > tmp.reply ; \
	  i=1 ; \
	  for file in $EMACSSETUP ; do \
	      cat tmp.reply $file \
	      | formail -I "Subject: Re: $SUBJ [part $i/$count]" \
	      | $SENDMAIL -oi -t ; \
	      i=`expr $i + 1` ; \
          done ; \
	  cat /dev/null

	:0 Efbw
	| cat - ; \
	  echo "Sorry, the emacs setup archive file is not currently available."
    }

    #####	send pgp key
    :0 E
    * SUBJ ?? pgp *key
    {
	# Add some more headers
	:0 fhw
	| formail -I"Mime-Version: 1.0" \
		   -I"Content-Type: application/pgp; format=keys-only" \
		   -I"Content-Description: PGP key of $MY_ADDR" \
		   -I"Content-Transfer-Encoding: 7bit" 

	# get the text for the body
	:0 fbw
	| cat - ; \
	  sh -c "pgp -kxaf $MY_ADDR 2>/dev/null"

	# If PGP failed somehow, leave a nice return message
	:0 efbw
	| cat - ; \
	  echo "Sorry, my PGP key is not available at the moment."
    }

    #####	(disable|enable) ack(nowledgements)
    :0 E
    * SUBJ ?? (dis|en)able
    {
	# Be sure NOACKFILE is defined
	NOACKFILE=${NOACKFILE:-noacks}

	# remove this address from NOACKS
	WHO=`formail -zxTo:`

	# The content of NOACKS are regexps, so we must carefully convert
	# the address into a regexp which *matches* a regexp.
	REWHO=`echo "$WHO" | sed -e 's/[.]/\\\\\\\\\\\\./g'`

	# See if the user is currently in the list of NO-ACKs
	LOCKFILE=$NOACKFILE.lock

	:0
	* ? grep -s "^$REWHO" $NOACKFILE
	{ 
	    # It is -- If "enable", remove it.
	    :0
	    * SUBJ ?? enable
	    {
		JUNK=`grep -v "^$REWHO" $NOACKFILE > $NOACKFILE.new ;
	    	      mv $NOACKFILE.new $NOACKFILE`
	    }

	    :0 Afbw
	    | cat - ; \
	      echo "Future mail from $WHO will be auto-acknowledged." ; \
	      echo "" ; \
	      echo "If you wish to disable auto-acknowledgements, please" ; \
	      echo "send me an email message with the subject: \"disable autoacks\"."

	    :0 Efbw
	    | cat - ; \
	      echo "Mail from $WHO is already not being auto-acknowledged."
	}

	# Else, $WHO is not in the $NOACKs
	:0 E
	{
	    # If the command was disable, add it to the file
	    # We must convert the address to a regexp as part of adding it
	    # to the file.
	    :0
	    * SUBJ ?? disable
	    { JUNK=`echo "$WHO" | sed -e 's/[.]/\\\\./g' >> $NOACKFILE` }

	    :0 Afbw
	    | cat - ; \
	      echo "Future mail from $WHO will not be acknowledged." ; \
	      echo "" ; \
	      echo "If you wish to enable auto-acknowledgements, please" ; \
	      echo "send me an email message with the subject: \"enable autoacks\"."

	    :0 Efbw
	    | cat - ; \
	      echo "Mail from $WHO is already being acknowledged."
	}

	# Remove the global lockfile
	LOCKFILE
    }

    #####	send help (explicitly or because of some other request)
    :0 E
    {
	# This is a combined recipe -- both the "send help" recipe
	# and the "unknown" command recipes result in the sending
	# of the helpfile.

	# If an unknown subject, append an error message
	:0 fbw
	* ! SUBJ ?? help
	| cat - ; \
	  echo 'Sorry, I don't know how to do this request.' ; \
	  echo ''

	# The help file with a suitable default
	HELPFILE=${HELPFILE:-commands.help}
	REPLYFILE=$HELPFILE
	INCLUDERC=comm-reply.file.rc
    }

    # Okay, procmail should be "holding" some headers and some body
    # text.  Send it (if it is not an empty mail)

    :0 cw
    * > 1
    ! -oi -t
    
    # Don't log anything else
    LOGABSTRACT=off

    # Log this request (and mark the mail as "delivered")
    :0 hw: $COMMANDLOG$LOCKEXT
    | echo "`date` : $FROM : $SUBJ" >> $COMMANDLOG

    HOST=end_of_processing
}

:0
* LOGFILE ?? commands\.rc\.log
{ LOGFILE=$OLDCMDLOGFILE
  LOGABSTRACT=yes
  VERBOSE=no 
}

# End of commands.rc