/*****************************************************************************
 *
 * File ..................: tosser/echoout.c
 * Purpose ...............: Forward echomail packets
 * Last modification date : 31-Oct-1999
 * Memory leaks check ....: 20-Feb-1999
 *
 *****************************************************************************
 * Copyright (C) 1997-1999
 *   
 * Michiel Broek		FIDO:		2:2801/16
 * Beekmansbos 10		Internet:	mbroek@ux123.pttnwb.nl
 * 1971 BV IJmuiden
 * the Netherlands
 *
 * This file is part of MBSE BBS.
 *
 * This BBS 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, or (at your option) any
 * later version.
 *
 * MBSE BBS 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 MBSE BBS; see the file COPYING.  If not, write to the Free
 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *****************************************************************************/


#include "../include/libs.h"
#include "../include/structs.h"
#include "../common/common.h"
#include "../dbase/dbnode.h"
#include "../dbase/dbmsgs.h"
#include "putil.h"
#include "addpkt.h"
#include "echoout.h"


#define	MAXPATH	73
#define	MAXSEEN	70


/*
 * External declarations
 */
extern	char	*toname;		/* To user			    */
extern	char	*fromname;		/* From user			    */
extern 	char	*subj;			/* Message subject		    */




void EchoOut(faddr *fa, fidoaddr aka, FILE *fp, int flags, int cost, time_t date)
{
	char		*buf;
	FILE		*qp;

	if ((qp = OpenPkt(msgs.Aka, aka, (char *)"qqq")) == NULL)
		return;

	if (AddMsgHdr(qp, fido2faddr(msgs.Aka), fido2faddr(aka), flags, cost, date, toname, fromname, subj))
		return;

	rewind(fp);
	buf = calloc(2048, sizeof(char));

	while ((fgets(buf, 2048, fp)) != NULL) {
		Striplf(buf);
		fprintf(qp, "%s\r", buf);
	}

	free(buf);
	putc(0, qp);
	fclose(qp);
}



