/* This program allows you to push mail destined for one host
 * to another (i.e. going on vacation and shutting down your
 * host but want your mail delivered by your "buddy"):
 */
#include <stdio.h>
#ifdef MSDOS
#include <dir.h>
#include <dos.h>
#endif
#ifndef _lint
#include <stdlib.h>
#endif
#include <fcntl.h>
#include <string.h>
#define MAXLINE 256

#if !defined(_lint)
static char rcsid[] OPTIONAL = "$Id: pushmail.c,v 1.9 1997/07/31 00:44:20 root Exp $";
#endif

main(int argc,char *argv[])
{
	struct ffblk block;
	int done,i;
	FILE *fd,*fo;
	char *j,str[MAXLINE+2],*strp;
	
	fprintf(stderr,"\n%s is COPYRIGHT 1989 by John D. Hays (KD7UW)\n",argv[0]);
	fprintf(stderr,"Authorized for unlimited distribution for ");
	fprintf(stderr,"Amateur Radio Use\n");
	fprintf(stderr,"This notice must be retained.  All Rights Reserved.\n\n");
	if (argc < 3)
	{
		fprintf(stderr,"Usage: %s oldhost forwardhost \007\n",argv[0]);
		exit(0);
	}
	
	done = findfirst("*.wrk",&block,0x3F);

	while (!done) {
		if ((fd = fopen(block.ff_name,"r")) != NULL)
		strp = str; /* Turbo-C is not handling fgets right ??? */
		{
			strp = fgets(strp,MAXLINE,fd);
			j = strrchr(strp,'\n');
			if (j != NULL) *j = '\0';
			if (stricmp(argv[1],strp) == 0)
			{
				fprintf(stderr,"Changing: %s\n",block.ff_name);
				i = unlink(block.ff_name);
				fo = fopen(block.ff_name,"w");
				fprintf(fo,"%s\n",argv[2]);
				while ((strp = fgets(strp,MAXLINE,fd)) != NULL)
				{
					fprintf(fo,"%s",strp);
				}
			}
			fclose(fd);
			fclose(fo);
		}
		fprintf(stderr, "%s: Unable to open %s\n",argv[0],block.ff_name);
		done = findnext(&block);
	}
}

