home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume17 / procmail / part02 < prev    next >
Encoding:
Internet Message Format  |  1991-03-02  |  21.2 KB

  1. From: berg@marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg)
  2. Newsgroups: comp.sources.misc
  3. Subject: v17i032:  procmail - mail processing package, Part02/02
  4. Message-ID: <1991Mar2.004814.16945@sparky.IMD.Sterling.COM>
  5. Date: 2 Mar 91 00:48:14 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 8da34447 e26e1f60 b1f6fc1c b93a3a62
  8.  
  9. Submitted-by: Stephen R. van den Berg <berg@marvin.e17.physik.tu-muenchen.de>
  10. Posting-number: Volume 17, Issue 32
  11. Archive-name: procmail/part02
  12. Supersedes: procmail: Volume 16, Issue 103
  13.  
  14. ---- Cut Here and feed the following to sh ----
  15. #!/bin/sh
  16. # This is part 02 of procmail
  17. # ============= procmail/retint.c ==============
  18. if test ! -d 'procmail'; then
  19.     echo 'x - creating directory procmail'
  20.     mkdir 'procmail'
  21. fi
  22. if test -f 'procmail/retint.c' -a X"$1" != X"-c"; then
  23.     echo 'x - skipping procmail/retint.c (File already exists)'
  24. else
  25. echo 'x - extracting procmail/retint.c (Text)'
  26. sed 's/^X//' << 'SHAR_EOF' > 'procmail/retint.c' &&
  27. X/************************************************************************ 
  28. X *    Collection of routines that return an int (sort of anyway :-)    *
  29. X *                                    * 
  30. X *    Copyright (c) 1990-1991, S.R.van den Berg, The Netherlands    * 
  31. X *    The sources can be freely copied for non-commercial use.    * 
  32. X *    See the accompanying README file for more info.            * 
  33. X *                                    *
  34. X *    Don't complain about the formatting, I know it's        * 
  35. X *    unconventional, but it's my standard format (I have my        * 
  36. X *    reasons).  If you don't like it, feed it through your        * 
  37. X *    favourite C beautifier.                        *
  38. X ************************************************************************/
  39. X
  40. X#include "config.h"
  41. X#include "procmail.h"
  42. X#include "sysexits.h"
  43. X#include "shell.h"
  44. X
  45. Xsetdef(name,contents)char*name,*contents;{
  46. X strcat(strcat(strcpy(buf2,name),"="),contents);parse();sputenv(buf);}
  47. X
  48. Xskipblanks(){
  49. X fscanf(rc,"%*[ \t]");}
  50. X
  51. Xskiptoeol(){
  52. X fscanf(rc,"%*[^\n]");return fgetc(rc);}
  53. X
  54. Xskipcomment(){char i[2];                   /* no comment :-) */
  55. X if(tscrc("%1[\n]",i))
  56. X   return 1;
  57. X skipblanks();return scrc("%1[#]",i)?skiptoeol():feof(rc);}
  58. X
  59. Xpipthrough(line,source,len)char*line,*source;long len;{pid_t pidf,pid;
  60. X int pinfd[2],poutfd[2];
  61. X#define PWR2 (pinfd[1])
  62. X#define PRD2 (pinfd[0])
  63. X pipe(poutfd);pipe(pinfd);
  64. X if(!(pidf=sfork())){                   /* the filter is started here */
  65. X   rclose(PWRITE);redirect(PREAD);rclose(STDOUT);dup(PWR2);rclose(PWR2);
  66. X   rclose(PRD2);callnewprog(line);}
  67. X rclose(PREAD);rclose(PWR2);
  68. X if(forkerr(pidf,line)){
  69. X   rclose(PRD2);return 1;}
  70. X flaggerd=0;signal(SIGHUP,flagger);
  71. X if(!(pid=sfork())){        /* this process will read back the filtered mail */
  72. X   rclose(PWRITE);signal(SIGHUP,flagger);kill(getppid(),SIGHUP);redirect(PRD2);
  73. X   if(!pwait&&mother){           /* if the wait chain ends here, notify mother */
  74. X      kill(mother,SIGHUP);mother=0;}  /* everything ok mam, go ahead and die */
  75. X   return 0;}        /* we will go ahead however (with or without mother) */
  76. X rclose(PRD2);
  77. X if(forkerr(pid,"procmail")){     /* An ingenious signal communication system */
  78. X   kill(pidf,SIGTERM);return 1;} /* will ensure that NO lock file and         */
  79. X if(dump(PWRITE,source,len)){     /* NO mail gets lost.                 */
  80. X   kill(pidf,SIGTERM);kill(pid,SIGTERM);writeerr(line);return 1;}
  81. X waitflagger();verrgrandchild=flaggerd=0;signal(SIGQUIT,errgrandchild);
  82. X if(pwait){
  83. X   if(waitfor(pidf)!=EX_OK){    /* if pipe fails, we will continue ourselves */
  84. X      progerr(line);kill(pid,SIGTERM);return 1;}
  85. X   for(kill(pid,SIGHUP),loclock=0;;sleep(SUSPENSION)){
  86. X      if(flaggerd)
  87. X     break;
  88. X      if(verrgrandchild){    /* Check if one of my grandchildren has paniced */
  89. X     signal(SIGQUIT,sterminate);return 1;}}}
  90. X else
  91. X   kill(pid,SIGHUP);      /* if we don't wait, signal that we're bailing out */
  92. X exit(EX_OK);}                 /* go ahead child, you have control */
  93. X
  94. Xwaitflagger(){
  95. X while(!flaggerd)
  96. X   sleep(SUSPENSION);}
  97. X
  98. Xgrepin(expr,source,len,casesens)char*expr,*source;long len;{pid_t pid;
  99. X int poutfd[2];static char*newargv[5]={0,"-e"};
  100. X newargv[3]=casesens?(char*)0:"-i";*newargv=getenv(grep);newargv[2]=expr;
  101. X pipe(poutfd);
  102. X if(!(pid=sfork())){
  103. X   rclose(PWRITE);redirect(PREAD);shexec(newargv);}
  104. X rclose(PREAD);dump(PWRITE,source,len);
  105. X if(!forkerr(pid,*newargv))
  106. X    return waitfor(pid)!=EX_OK;
  107. X return 127;}
  108. X
  109. Xwaitfor(pid)pid_t pid;{int i;
  110. X while(pid!=wait(&i)||(i&127)==127);
  111. X return i>>8&255;}
  112. X
  113. Xredirect(pip){
  114. X getstdinpipe(pip);fclose(rc);}
  115. X
  116. Xgetstdinpipe(pip){
  117. X rclose(STDIN);dup(pip);rclose(pip);}
  118. X
  119. Xcallnewprog(newname)char*newname;{int argc;char*endp,**newargv;
  120. X register char*p;
  121. X p=newname;
  122. X if(sh){char*newargv[4];             /* should we start a shell? */
  123. X   newargv[3]=0;newargv[2]=p;newargv[1]=getenv(shellflags);
  124. X   *newargv=getenv(shell);shexec(newargv);}
  125. X argc=2;
  126. X while(*p){    /* If no shell, we'll have to chop up the arguments ourselves */
  127. X   if(*p==' '||*p=='\t'){
  128. X      argc++;*p='\0';
  129. X      while(*++p==' '||*p=='\t')
  130. X     *p='\0';
  131. X      continue;}
  132. X   p++;}
  133. X endp=p;*(newargv=malloc(argc*sizeof*newargv))=p=newname;argc=1;
  134. X for(;;){
  135. X   while(*p)
  136. X      p++;
  137. X   while(!*p){
  138. X      if(p==endp){
  139. X     newargv[argc]=0;shexec(newargv);}
  140. X      p++;}
  141. X   newargv[argc++]=p;}}
  142. X
  143. Xparse(){int i;char*org,*dest,*bd;      /* Implicitly copies from buf2 to buf */
  144. X dest=buf;org=buf2;
  145. X while(i=*org++)
  146. X   if(i!='$')
  147. X      *dest++=i;
  148. X   else{                      /* substitute the thing... */
  149. X      bd=buf2;
  150. X      while((i=*org)>='A'&&i<='Z'||i>='a'&&i<='z'||i>='0'&&i<='9'||i=='_'){
  151. X     *bd++=i;org++;}
  152. X      *bd='\0';
  153. X      if(bd=getenv(buf2)){
  154. X     strcpy(dest,bd);
  155. X     while(*dest)
  156. X        dest++;}}
  157. X *dest='\0';}
  158. X
  159. Xwriteerr(line)char*line;{
  160. X log("Error while writing to");logqnl(line);}
  161. X
  162. Xforkerr(pid,a)pid_t pid;char*a;{
  163. X if(pid==-1){
  164. X   log("Failed forking");logqnl(a);return 1;}
  165. X return 0;}
  166. X
  167. Xprogerr(line)char*line;{
  168. X log("Program failure of");logqnl(line);}
  169. X
  170. Xlog(a)char*a;{char*b;
  171. X b=a-1;
  172. X while(*++b);
  173. X rwrite(STDERR,a,b-a);}
  174. X
  175. Xopena(a)char*a;{
  176. Xreturn open(a,O_WRONLY|O_APPEND|O_CREAT,0666);}
  177. X
  178. Xfdreopena(a,fd)char*a;{               /* Currently only works for 0,1,2 */
  179. X rclose(fd);return opena(a);}
  180. X
  181. Xshexec(argv)char**argv;{int i;char**newargv,**p;
  182. X execvp(*argv,argv);     /* if this one fails, we retry it as a shell script */
  183. X for(p=argv,i=1;i++,*p++;);
  184. X newargv=malloc(i*sizeof*p);
  185. X for(*(p=newargv)=binsh;*++p=*++argv;);
  186. X execve(*newargv,newargv,environ);          /* no shell script? -> trouble */
  187. X log("Failed to execute");logqnl(*argv);exit(EX_UNAVAILABLE);}
  188. X
  189. Xunlock(lockp)char**lockp;{
  190. X lcking=1;
  191. X if(*lockp){
  192. X   if(unlink(*lockp)){
  193. X      log("Couldn't unlink");logqnl(*lockp);}
  194. X   free(*lockp);*lockp=0;}
  195. X if(nextexit==1){        /* make sure we are not inside terminate already */
  196. X   log(newline);terminate();}
  197. X lcking=0;}
  198. X
  199. Xnomemerr(){
  200. X log("Out of memory\nbuffer 0: \"");log(buf);log("\"\nbuffer 1:");
  201. X logqnl(buf2);retval=EX_OSERR;terminate();}
  202. X
  203. Xlogqnl(a)char*a;{
  204. X log(" \"");log(a);log("\"\n");}
  205. X
  206. Xnextrcfile(){char*p;   /* find the next rcfile specified on the command line */
  207. X while(p=*gargv){
  208. X   gargv++;
  209. X   if(!strchr(p,'=')){
  210. X      rcfile=p;return 1;}}
  211. X return 0;}
  212. X
  213. Xrclose(fd){int i;              /* a sysV secure close (signal immune) */
  214. X while((i=close(fd))&&errno==EINTR);
  215. X return i;}
  216. X
  217. Xrwrite(fd,a,len)void*a;{int i;          /* a sysV secure write (signal immune) */
  218. X while(0>(i=write(fd,a,len))&&errno==EINTR);
  219. X return i;}
  220. X
  221. Xlockit(name,lockp)char*name,**lockp;{int i;struct stat stbuf;
  222. X unlock(lockp);              /* unlock any previous lockfile FIRST         */
  223. X for(lcking=1;;){          /* to prevent deadlocks (I hate deadlocks) */
  224. X   if(0<=(i=open(name,O_WRONLY|O_CREAT|O_EXCL|O_SYNC,0))){
  225. X      rclose(i);*lockp=tstrdup(name);
  226. Xterm: if(nextexit){
  227. X     log(" whilst waiting for lockfile");logqnl(name);terminate();}
  228. X      lcking=0;return;}
  229. X   if(errno==EEXIST){           /* check if it's time for a lock override */
  230. X      if((i=renvint(0,locktimeout))&&!stat(name,&stbuf)&&
  231. X     i<time((time_t*)0)-stbuf.st_mtime){
  232. X     log("Forcing lock on");logqnl(name);
  233. X     if(unlink(name)){
  234. X        log("Forced unlock denied on");logqnl(name);}}}
  235. X   else{               /* maybe filename too long, shorten and retry */
  236. X      if(0<(i=strlen(name)-1)&&name[i-1]!='/'){
  237. X     name[i]='\0';continue;}
  238. X      log("Lockfailure on");logqnl(name);return;}
  239. X   sleep(DEFlocksleep,locksleep);
  240. X   if(nextexit)
  241. X      goto term;}}
  242. X
  243. Xlcllock(){                   /* lock a local file (if need be) */
  244. X if(locknext)
  245. X   if(tolock)
  246. X      lockit(tolock,&loclock);
  247. X   else
  248. X      lockit(strcat(buf2,getenv(lockext)),&loclock);}
  249. X
  250. Xsputenv(a)char*a;{          /* smart putenv, the way it was supposed to be */
  251. X static struct lienv{struct lienv*next;char name[255];}*myenv;
  252. X static alloced;int i,remove;char*split,**preenv;struct lienv*curr,**last;
  253. X remove=0;a=strdup(a);                    /* make working copy */
  254. X if(!(split=strchr(a,'='))){               /* assignment or removal? */
  255. X    remove=1;i=strlen(a);*(split=i+(a=realloc(a,i+2)))='=';
  256. X    split[1]='\0';}
  257. X i=++split-a;
  258. X for(curr=*(last=&myenv);curr;curr=*(last=&curr->next))
  259. X   if(!strncmp(a,curr->name,i)){         /* is it one I created earlier? */
  260. X      split=curr->name;*last=curr->next;free(curr);
  261. X      for(preenv=environ;*preenv!=split;preenv++);
  262. X      goto wipenv;}
  263. X for(preenv=environ;*preenv;preenv++)
  264. X   if(!strncmp(a,*preenv,i)){           /* is it in the standard environment? */
  265. Xwipenv:
  266. X      while(*preenv=preenv[1])       /* wipe this entry out of the environment */
  267. X     preenv++;
  268. X      break;}
  269. X if(alloced)           /* have we ever alloced the environ array before? */
  270. X   environ=realloc(environ,(preenv-environ+2)*sizeof*environ);
  271. X else{
  272. X   alloced=1;i=(preenv-environ+2)*sizeof*environ;
  273. X   environ=tmemmove(malloc(i),environ,i-sizeof*environ);}
  274. X if(!remove){          /* if not remove, then add it to both environments */
  275. X   for(preenv=environ;*preenv;preenv++);
  276. X   curr=malloc(curr->name-(char*)curr+strlen(a)+1);
  277. X   strcpy(*preenv=curr->name,a);free(a);preenv[1]=0;curr->next=myenv;
  278. X   myenv=curr;}}
  279. X
  280. Xrenvint(init,env)char*env;{int i;
  281. X i=init;
  282. X if(env=getenv(env))                  /* check if the env var exists */
  283. X   sscanf(env,"%i",&i);                   /* parse it like a C constant */
  284. X return i;}
  285. X
  286. Xterminate(){
  287. X nextexit=2;            /* prevent multiple invocations of terminate */
  288. X unlock(&loclock);         /* local lock files are removed in any case */
  289. X if(mother&&mother!=getpid())
  290. X   if(retval!=EX_OK) /* tell mam we're in trouble, let her clean up the mess */
  291. X      kill(mother,SIGQUIT);         /* don't try this at home, kids :-) */
  292. X   else{
  293. X      kill(mother,SIGHUP);goto allok;} /* You can go home mam, everything ok */
  294. X else  
  295. Xallok:                    /* global lockfile should be removed */
  296. X   unlock(&globlock);            /* by the last surviving procmail    */
  297. X sync();     /* sorry, but this is mail we're dealing with, safety first */
  298. X exit(retval);}
  299. SHAR_EOF
  300. chmod 0644 procmail/retint.c ||
  301. echo 'restore of procmail/retint.c failed'
  302. Wc_c="`wc -c < 'procmail/retint.c'`"
  303. test 9549 -eq "$Wc_c" ||
  304.     echo 'procmail/retint.c: original size 9549, current size' "$Wc_c"
  305. fi
  306. # ============= procmail/examples/forward ==============
  307. if test ! -d 'procmail/examples'; then
  308.     echo 'x - creating directory procmail/examples'
  309.     mkdir 'procmail/examples'
  310. fi
  311. if test -f 'procmail/examples/forward' -a X"$1" != X"-c"; then
  312.     echo 'x - skipping procmail/examples/forward (File already exists)'
  313. else
  314. echo 'x - extracting procmail/examples/forward (Text)'
  315. sed 's/^X//' << 'SHAR_EOF' > 'procmail/examples/forward' &&
  316. X"|exec /global/bin/procmail"
  317. SHAR_EOF
  318. chmod 0644 procmail/examples/forward ||
  319. echo 'restore of procmail/examples/forward failed'
  320. Wc_c="`wc -c < 'procmail/examples/forward'`"
  321. test 29 -eq "$Wc_c" ||
  322.     echo 'procmail/examples/forward: original size 29, current size' "$Wc_c"
  323. fi
  324. # ============= procmail/examples/1rmail ==============
  325. if test -f 'procmail/examples/1rmail' -a X"$1" != X"-c"; then
  326.     echo 'x - skipping procmail/examples/1rmail (File already exists)'
  327. else
  328. echo 'x - extracting procmail/examples/1rmail (Text)'
  329. sed 's/^X//' << 'SHAR_EOF' > 'procmail/examples/1rmail' &&
  330. X#!/bin/sh
  331. X#
  332. X# specify the mailbox file you want to read on the command line
  333. X#
  334. XMAILDIR=$HOME/Mail
  335. Xcd $MAILDIR
  336. XLOCKFILE=$HOME/.lockmail
  337. Xif lockfile -! -r1 $LOCKFILE
  338. Xthen
  339. X echo Mail is currently arriving, please wait...
  340. X while
  341. X   lockfile -! -4 -r2 $LOCKFILE
  342. X do
  343. X echo Mail is still arriving...
  344. X done
  345. Xfi
  346. X#
  347. X# Call you favourite mailer here.
  348. X#
  349. X/usr/ucb/mail -f $*
  350. X#
  351. X#
  352. X#
  353. Xrm -f $LOCKFILE
  354. SHAR_EOF
  355. chmod 0644 procmail/examples/1rmail ||
  356. echo 'restore of procmail/examples/1rmail failed'
  357. Wc_c="`wc -c < 'procmail/examples/1rmail'`"
  358. test 381 -eq "$Wc_c" ||
  359.     echo 'procmail/examples/1rmail: original size 381, current size' "$Wc_c"
  360. fi
  361. # ============= procmail/examples/2procmailrc ==============
  362. if test -f 'procmail/examples/2procmailrc' -a X"$1" != X"-c"; then
  363.     echo 'x - skipping procmail/examples/2procmailrc (File already exists)'
  364. else
  365. echo 'x - extracting procmail/examples/2procmailrc (Text)'
  366. sed 's/^X//' << 'SHAR_EOF' > 'procmail/examples/2procmailrc' &&
  367. X# Please check if all the paths in PATH are reachable, remove the ones that
  368. X# are not.
  369. X
  370. XPATH=$HOME/bin:/usr/bin:/global/bin:/usr/ucb:/bin:/usr/local/bin:
  371. XMAILDIR=$HOME/Mail    # You'd better make sure it exists
  372. XDEFAULT=$MAILDIR/mbox
  373. XLOGFILE=$MAILDIR/from
  374. X            # We don't use a global lockfile here now
  375. X            # Instead we use local lockfiles everywhere
  376. X
  377. X# Notice the double : in the next recipe, this will cause a lockfile
  378. X# named "$MAILDIR/todd.lock" to be used if and only if this mail is going
  379. X# into the file "todd".
  380. X
  381. X::                # Anything from thf
  382. X^From.*thf\@somewhere.someplace
  383. Xtodd                # will go to $MAILDIR/todd
  384. X
  385. X
  386. X# The next recipe will likewise use $MAILDIR/uunetbox.lock as a lock file.
  387. X
  388. X::                # Anything from people at uunet
  389. X^From.*\@uunet
  390. Xuunetbox            # will go to $MAILDIR/uunetbox
  391. X
  392. X
  393. X# And here the lockfile will be $MAILDIR/henries.lock of course.
  394. X
  395. X:I:                # Anything from Henry or henry (ignore case)
  396. X^From.*henry
  397. Xhenries                # will go to $MAILDIR/henries
  398. X
  399. X
  400. X# But you can specify any lockfile you want, like "myfile".  The following
  401. X# recipe will use "$MAILDIR/myfile" as the lock file.
  402. X
  403. X::myfile            # All 'questions' will go to
  404. X^Subject:.*questions
  405. Xtoread                # $MAILDIR/toread
  406. X
  407. X# Anything that has not been delivered by now will go to $DEFAULT
  408. X# BUT, since we have not specified any global lock file because we
  409. X# were working with local lock files, and since we are sending the mail to
  410. X# $DEFAULT now, we need to specify a lockfile for that too.  We use
  411. X# a global lockfile for that  (it won't be created until procmail 
  412. X# has parsed (needed to parse) up till here.
  413. X
  414. XLOCKFILE=$DEFAULT.lock
  415. SHAR_EOF
  416. chmod 0644 procmail/examples/2procmailrc ||
  417. echo 'restore of procmail/examples/2procmailrc failed'
  418. Wc_c="`wc -c < 'procmail/examples/2procmailrc'`"
  419. test 1587 -eq "$Wc_c" ||
  420.     echo 'procmail/examples/2procmailrc: original size 1587, current size' "$Wc_c"
  421. fi
  422. # ============= procmail/examples/3procmailrc ==============
  423. if test -f 'procmail/examples/3procmailrc' -a X"$1" != X"-c"; then
  424.     echo 'x - skipping procmail/examples/3procmailrc (File already exists)'
  425. else
  426. echo 'x - extracting procmail/examples/3procmailrc (Text)'
  427. sed 's/^X//' << 'SHAR_EOF' > 'procmail/examples/3procmailrc' &&
  428. X# Please check if all the paths in PATH are reachable, remove the ones that
  429. X# are not.
  430. X
  431. XPATH=$HOME/bin:/usr/bin:/global/bin:/usr/ucb:/bin:/usr/local/bin:
  432. XMAILDIR=$HOME/Mail    # You'd better make sure it exists
  433. XDEFAULT=$MAILDIR/mbox
  434. XLOGFILE=$MAILDIR/from
  435. XLOCKFILE=$HOME/.lockmail
  436. X
  437. X            # This will create a local lockfile named todd.lock
  438. X::            # *if* the condition matches
  439. X^From.*thf
  440. Xtodd
  441. X
  442. XLOCKFILE=$MAILDIR/whatever    # This will remove the global lockfile
  443. X                # $HOME/.lockmail and the new lockfile
  444. X                # will be $MAILDIR/whatever
  445. X
  446. X
  447. X                # The next recipe will
  448. X                # filter out all messages from "at"
  449. X                # jobs and will put them in a terse format in
  450. X                # a file called $MAILDIR/atjunk
  451. X:2fh
  452. X^From root
  453. X^Subject: Output from "at" job
  454. X|echo "From at job";echo;egrep "^Date:"
  455. X:b
  456. X^From at job
  457. Xatjunk
  458. X
  459. X
  460. X
  461. XMAILDIR=$HOME/News    # This will change the current directory
  462. X
  463. X
  464. X            # The next recipe will create a local lockfile
  465. X            # named $HOME/News/dustbin.lock (*if* the condition
  466. X            # matches), and will feed the body of the message
  467. X            # through `sort` (sorry, couldn't come up with anything
  468. X            # better :-), after which the result will be
  469. X            # appended to $HOME/News/dustbin
  470. X:b:
  471. X^Subject:.*rubbish
  472. X|sort >>dustbin
  473. X
  474. X# Anything not delivered by now will go to $HOME/Mail/mbox
  475. SHAR_EOF
  476. chmod 0644 procmail/examples/3procmailrc ||
  477. echo 'restore of procmail/examples/3procmailrc failed'
  478. Wc_c="`wc -c < 'procmail/examples/3procmailrc'`"
  479. test 1255 -eq "$Wc_c" ||
  480.     echo 'procmail/examples/3procmailrc: original size 1255, current size' "$Wc_c"
  481. fi
  482. # ============= procmail/examples/2rmail ==============
  483. if test -f 'procmail/examples/2rmail' -a X"$1" != X"-c"; then
  484.     echo 'x - skipping procmail/examples/2rmail (File already exists)'
  485. else
  486. echo 'x - extracting procmail/examples/2rmail (Text)'
  487. sed 's/^X//' << 'SHAR_EOF' > 'procmail/examples/2rmail' &&
  488. X#!/bin/sh
  489. X#
  490. X# specify the mailbox file you want to read on the command line
  491. X#
  492. XMAILDIR=$HOME/Mail
  493. Xcd $MAILDIR
  494. XLOCKFILE=$1.lock
  495. Xif lockfile -! -r1 $LOCKFILE
  496. Xthen
  497. X echo Mail is currently arriving, please wait...
  498. X while
  499. X   lockfile -! -4 -r2 $LOCKFILE
  500. X do
  501. X echo Mail is still arriving...
  502. X done
  503. Xfi
  504. X#
  505. X# Call you favourite mailer here.
  506. X#
  507. X/usr/ucb/mail -f $*
  508. X#
  509. X#
  510. X#
  511. Xrm -f $LOCKFILE
  512. SHAR_EOF
  513. chmod 0644 procmail/examples/2rmail ||
  514. echo 'restore of procmail/examples/2rmail failed'
  515. Wc_c="`wc -c < 'procmail/examples/2rmail'`"
  516. test 373 -eq "$Wc_c" ||
  517.     echo 'procmail/examples/2rmail: original size 373, current size' "$Wc_c"
  518. fi
  519. # ============= procmail/examples/3rmail ==============
  520. if test -f 'procmail/examples/3rmail' -a X"$1" != X"-c"; then
  521.     echo 'x - skipping procmail/examples/3rmail (File already exists)'
  522. else
  523. echo 'x - extracting procmail/examples/3rmail (Text)'
  524. sed 's/^X//' << 'SHAR_EOF' > 'procmail/examples/3rmail' &&
  525. X#!/bin/sh
  526. X#
  527. X# specify the mailbox file you want to read on the command line
  528. X# Use a relative path from your $HOME directory
  529. X#
  530. X# For this kind of chaotic procmailrc there is no uniform neat solution
  531. X# to determine which lockfiles to use.    I'll give just one (suboptimal)
  532. X# solution here.  Use your imagination to extend it :-).
  533. X#
  534. XMAILDIR=$HOME/Mail
  535. Xcd $HOME            # this means all paths are relative to $HOME
  536. XLOCKFILE=$HOME/.lockmail
  537. XLOCKFILE2=$HOME/Mail/whatever
  538. Xif lockfile -! -r1 $LOCKFILE $LOCKFILE2
  539. Xthen
  540. X echo Mail is currently arriving, please wait...
  541. X while
  542. X   lockfile -! -4 -r2 $LOCKFILE $LOCKFILE2
  543. X do
  544. X echo Mail is still arriving...
  545. X done
  546. Xfi
  547. X#
  548. X# Call you favourite mailer here.
  549. X#
  550. X/usr/ucb/mail -f $*
  551. X#
  552. X#
  553. X#
  554. Xrm -f $LOCKFILE $LOCKFILE2
  555. SHAR_EOF
  556. chmod 0644 procmail/examples/3rmail ||
  557. echo 'restore of procmail/examples/3rmail failed'
  558. Wc_c="`wc -c < 'procmail/examples/3rmail'`"
  559. test 738 -eq "$Wc_c" ||
  560.     echo 'procmail/examples/3rmail: original size 738, current size' "$Wc_c"
  561. fi
  562. # ============= procmail/examples/1procmailrc ==============
  563. if test -f 'procmail/examples/1procmailrc' -a X"$1" != X"-c"; then
  564.     echo 'x - skipping procmail/examples/1procmailrc (File already exists)'
  565. else
  566. echo 'x - extracting procmail/examples/1procmailrc (Text)'
  567. sed 's/^X//' << 'SHAR_EOF' > 'procmail/examples/1procmailrc' &&
  568. X# Please check if all the paths in PATH are reachable, remove the ones that
  569. X# are not.
  570. X
  571. XPATH=$HOME/bin:/usr/bin:/global/bin:/usr/ucb:/bin:/usr/local/bin:
  572. XMAILDIR=$HOME/Mail    # You'd better make sure it exists
  573. XDEFAULT=$MAILDIR/mbox
  574. XLOGFILE=$MAILDIR/from
  575. XLOCKFILE=$HOME/.lockmail
  576. X
  577. X:                # Anything from thf
  578. X^From.*thf\@somewhere.someplace
  579. Xtodd                # will go to $MAILDIR/todd
  580. X
  581. X:                # Anything from people at uunet
  582. X^From.*\@uunet
  583. Xuunetbox            # will go to $MAILDIR/uunetbox
  584. X
  585. X:I                # Anything from Henry or henry (ignore case)
  586. X^From.*henry
  587. Xhenries                # will go to $MAILDIR/henries
  588. X
  589. X# Anything that has not been delivered by now will go to $DEFAULT
  590. SHAR_EOF
  591. chmod 0644 procmail/examples/1procmailrc ||
  592. echo 'restore of procmail/examples/1procmailrc failed'
  593. Wc_c="`wc -c < 'procmail/examples/1procmailrc'`"
  594. test 638 -eq "$Wc_c" ||
  595.     echo 'procmail/examples/1procmailrc: original size 638, current size' "$Wc_c"
  596. fi
  597. # ============= procmail/includes.h ==============
  598. if test -f 'procmail/includes.h' -a X"$1" != X"-c"; then
  599.     echo 'x - skipping procmail/includes.h (File already exists)'
  600. else
  601. echo 'x - extracting procmail/includes.h (Text)'
  602. sed 's/^X//' << 'SHAR_EOF' > 'procmail/includes.h' &&
  603. X#include <stdio.h>
  604. X#ifndef NO_ANSI_PROT        /* define this if your headers are not ansi */
  605. X# include <stdlib.h>
  606. X# include <time.h>
  607. X#else
  608. X# include <malloc.h>
  609. X  char*getenv();
  610. X  typedef int pid_t;
  611. X#endif
  612. X#include <fcntl.h>
  613. X#include <pwd.h>
  614. X#include <sys/wait.h>
  615. X#ifndef NOuname
  616. X#include <sys/utsname.h>
  617. X#endif
  618. X#include <sys/types.h>
  619. X#include <sys/stat.h>
  620. X#include <sys/time.h>
  621. X#include <signal.h>
  622. X#include <string.h>
  623. X#include <errno.h>
  624. X
  625. X#ifndef SEEK_SET
  626. X#define SEEK_SET    0
  627. X#endif
  628. X#ifndef O_SYNC
  629. X#define O_SYNC        0
  630. X#endif
  631. Xextern char**environ;
  632. X
  633. X#define STDIN    0
  634. X#define STDOUT    1
  635. X#define STDERR    2
  636. SHAR_EOF
  637. chmod 0644 procmail/includes.h ||
  638. echo 'restore of procmail/includes.h failed'
  639. Wc_c="`wc -c < 'procmail/includes.h'`"
  640. test 589 -eq "$Wc_c" ||
  641.     echo 'procmail/includes.h: original size 589, current size' "$Wc_c"
  642. fi
  643. exit 0
  644. -- 
  645.  
  646. exit 0 # Just in case...
  647. -- 
  648. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  649. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  650. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  651. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  652.