/*****************************************************************************
 *
 * File ..................: bbs/offline.c
 * Purpose ...............: Offline Reader
 * Last modification date : 25-Sep-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.
 *****************************************************************************/

#define	DB_USERS
#define	DB_MSGAREA
#define DB_ARCHIVE

#include "../include/libs.h"
#include "../include/structs.h"
#include "../include/mbse.h"
#include "../include/records.h"
#ifndef	BIG_ENDIAN
#define	BIG_ENDIAN
#endif
#include "../include/bluewave.h"
#include "../common/common.h"
#include "../msgbase/msgtext.h"
#include "../msgbase/msg.h"
#include "mail.h"
#include "funcs.h"
#include "funcs4.h"
#include "language.h"
#include "file.h"
#include "filesub.h"
#include "exitinfo.h"
#include "timeout.h"
#include "msgutil.h"
#include "offline.h"



long		Total, TotalPersonal, Current, Personal;
unsigned long	TotalPack;
unsigned short	BarWidth;
lastread	LR;
extern int	do_mailout;


typedef struct	_msg_high {
	struct	_msg_high	*next;
	unsigned long		Area;
	unsigned long		LastMsg;
	unsigned long		Personal;
} msg_high;



/*
 *  Internal prototypes.
 */
void		tidy_high(msg_high **);
void		fill_high(msg_high **, unsigned long, unsigned long, unsigned long);
void		Add_Kludges(fidoaddr, int, char *);
int		OLR_Prescan(void);
unsigned long	BlueWave_PackArea(unsigned long, long);
void		BlueWave_Fetch(void);



/****************************************************************************
 *
 *                           Global Functions
 */


void tidy_high(msg_high **hdp)
{
	msg_high *tmp, *old;

	for (tmp = *hdp; tmp; tmp = old) {
		old = tmp->next;
		free(tmp);
	}
	*hdp = NULL;
}



/*
 *  Add an area to the array
 */
void fill_high(msg_high **hdp, unsigned long Area, unsigned long Last, unsigned long Pers)
{
	msg_high *tmp;

	Syslog('m', "fill_high Area %lu Msg %lu, Pers %lu", Area, Last, Pers);

	tmp = (msg_high *)xmalloc(sizeof(msg_high));
	tmp->next = *hdp;
	tmp->Area = Area;
	tmp->LastMsg = Last;
	tmp->Personal = Pers;
	*hdp = tmp;
}



/*
 *  Add message kludges at the start, append the message text and add 
 *  trailing kludges, tearline and originline.
 */
void Add_Kludges(fidoaddr dest, int IsReply, char *fn)
{
	char		*temp, *aka;
	FILE		*tp;

	temp = calloc(2048, sizeof(char));
	aka  = calloc(81,   sizeof(char));

	Add_Headkludges(fido2faddr(dest), IsReply);
	Syslog('m', "Kludges done, start textfile %s", fn);

	if ((tp = fopen(fn, "r")) != NULL) {
		Msg_Write(tp);
		fclose(tp);
	}

	Syslog('m', "Add footer");
	Add_Footkludges(FALSE);

	Syslog('m', "Add message now");
	Msg_AddMsg();
	Syslog('m', "Msg added");

	free(aka);
	free(temp);
}



/****************************************************************************
 *
 *                          Offline Configuration
 */


/*
 *  Tag areas, called from menu.
 */
void OLR_TagArea()
{
	char	*Msgname, *Tagname;
	FILE	*ma, *tf;
	char	*buf;
	long	total, Offset, Area;

	WhosDoingWhat(OLR);

	Msgname = calloc(128, sizeof(char));
	Tagname = calloc(128, sizeof(char));
	buf     = calloc(81,  sizeof(char));

	sprintf(Msgname, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
	sprintf(Tagname, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name);

	clear();
	colour(14, 0);
	printf("Tag Offline Reader message areas\n");

	do {
		colour(15, 0);
		printf("\nEnter the name of the conference, or ? for a list: ");
		colour(CFG.InputColourF, CFG.InputColourB);
		GetstrC(buf, 12);

		if (buf[0] == '?') {
			colour(11, 0);
			printf("Conference      Area  Msgs   Description\n");
			if ((ma = fopen(Msgname, "r")) != NULL) {
				fread(&msgshdr, sizeof(msgshdr), 1, ma);
				Area = 0;
				if ((tf = fopen(Tagname, "r")) != NULL) {
					while (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
						fseek(ma, msgshdr.syssize, SEEK_CUR);
						fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
						Area++;
						if (Msg_Open(msgs.Base)) {
							total = Msg_Number();
							Msg_Close();
						} else
							total = 0;
						colour(3, 0);
						if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && (!olrtagrec.Tagged) && strlen(msgs.QWKname)) {
							printf("%-15.15s %-5ld %-5ld  %s\n", msgs.QWKname, Area, total, msgs.Name);
						}
					}
					fclose(tf);
				} 
				fclose(ma);
			}
		} else 
			if (buf[0] != '\0') {
				if (atoi(buf) != 0) {
					if ((ma = fopen(Msgname, "r")) != NULL) {
						fread(&msgshdr, sizeof(msgshdr), 1, ma);
						Offset = msgshdr.hdrsize + ((atoi(buf)-1) * (msgshdr.recsize + msgshdr.syssize));
						fseek(ma, Offset, SEEK_SET);
						if (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
							if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname)) {
								if ((tf = fopen(Tagname, "r+")) != NULL) {
									fseek(tf, (atoi(buf)-1) * sizeof(olrtagrec), SEEK_SET);
									fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
									if (!olrtagrec.Tagged) {
										olrtagrec.Tagged = TRUE;
										fseek(tf, - sizeof(olrtagrec), SEEK_CUR);
										fwrite(&olrtagrec, sizeof(olrtagrec), 1, tf);
										Syslog('+', "OLR Tagged %d %s", atoi(buf), msgs.QWKname);
									}
									fclose(tf);
								}
							}
						}
						fclose(ma);
					}
				} else {
					if ((ma = fopen(Msgname, "r")) != NULL) {
						fread(&msgshdr, sizeof(msgshdr), 1, ma);
						Area = 0;
						while (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
							fseek(ma, msgshdr.syssize, SEEK_CUR);
							Area++;
							if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname)) {
								if (strcasecmp(msgs.QWKname, buf) == 0) {
									if ((tf = fopen(Tagname, "r+")) != NULL) {
										fseek(tf, (Area-1) * sizeof(olrtagrec), SEEK_SET);
										fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
										if (!olrtagrec.Tagged) {
											olrtagrec.Tagged = TRUE;
											fseek(tf, - sizeof(olrtagrec), SEEK_CUR);
											fwrite(&olrtagrec, sizeof(olrtagrec), 1, tf);
											Syslog('+', "OLR Tagged %d %s", Area, msgs.QWKname);
										}
										fclose(tf);
									}
								}
							}
						}
						fclose(ma);
					}
				}
			}

	} while (buf[0] != '\0');

	free(buf);
	free(Tagname);
	free(Msgname);
}



/*
 *  Untag areas, called from menu.
 */
void OLR_UntagArea()
{
	char	*Msgname, *Tagname, *buf;
	FILE	*ma, *tf;
	long	total, Offset, Area;

	WhosDoingWhat(OLR);

	Msgname = calloc(128, sizeof(char));
	Tagname = calloc(128, sizeof(char));
	buf	= calloc(81,  sizeof(char));

	sprintf(Msgname, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
	sprintf(Tagname, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name);

	clear();
	colour(14, 0);
	printf("Untag Offline Reader message areas\n");

	do {
		colour(15, 0);
		printf("\nEnter the name of the conference, or ? for a list: ");
		colour(CFG.InputColourF, CFG.InputColourB);
		GetstrC(buf, 12);

		if (buf[0] == '?') {
			colour(11, 0);
			printf("Conference      Area  Msgs   Description\n");
			if ((ma = fopen(Msgname, "r")) != NULL) {
				fread(&msgshdr, sizeof(msgshdr), 1, ma);
				Area = 0;
				if ((tf = fopen(Tagname, "r")) != NULL) {
					while (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
						fseek(ma, msgshdr.syssize, SEEK_CUR);
						fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
						Area++;
						if (Msg_Open(msgs.Base)) {
							total = Msg_Number();
							Msg_Close();
						} else
							total = 0;
						colour(3, 0);
						if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && olrtagrec.Tagged && strlen(msgs.QWKname)) {
							printf("%-15.15s %-5ld %-5ld  %s\n", msgs.QWKname, Area, total, msgs.Name);
						}
					}
					fclose(tf);
				} 
				fclose(ma);
			}
		} else 
			if (buf[0] != '\0') {
				if (atoi(buf) != 0) {
					if ((ma = fopen(Msgname, "r")) != NULL) {
						fread(&msgshdr, sizeof(msgshdr), 1, ma);
						Offset = msgshdr.hdrsize + ((atoi(buf)-1) * (msgshdr.recsize + msgshdr.syssize));
						fseek(ma, Offset, SEEK_SET);
						if (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
							if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname)) {
								if ((tf = fopen(Tagname, "r+")) != NULL) {
									fseek(tf, (atoi(buf)-1) * sizeof(olrtagrec), SEEK_SET);
									fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
									if (olrtagrec.Tagged) {
										if (msgs.OLR_Forced) {
											printf("Area cannot be switched off\n");
										} else {
											olrtagrec.Tagged = FALSE;
											fseek(tf, - sizeof(olrtagrec), SEEK_CUR);
											fwrite(&olrtagrec, sizeof(olrtagrec), 1, tf);
											Syslog('+', "OLR Untagged %d %s", atoi(buf), msgs.QWKname);
										}
									}
									fclose(tf);
								}
							}
						}
						fclose(ma);
					}
				} else {
					if ((ma = fopen(Msgname, "r")) != NULL) {
						fread(&msgshdr, sizeof(msgshdr), 1, ma);
						Area = 0;
						while (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
							fseek(ma, msgshdr.syssize, SEEK_CUR);
							Area++;
							if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname)) {
								if (strcasecmp(msgs.QWKname, buf) == 0) {
									if ((tf = fopen(Tagname, "r+")) != NULL) {
										fseek(tf, (Area-1) * sizeof(olrtagrec), SEEK_SET);
										fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
										if (olrtagrec.Tagged) {
											if (msgs.OLR_Forced) {
												printf("Area cannot be switched off\n");
											} else {
												olrtagrec.Tagged = FALSE;
												fseek(tf, - sizeof(olrtagrec), SEEK_CUR);
												fwrite(&olrtagrec, sizeof(olrtagrec), 1, tf);
												Syslog('+', "OLR Untagged %d %s", Area, msgs.QWKname);
											}
										}
										fclose(tf);
									}
								}
							}
						}
						fclose(ma);
					}
				}
			}

	} while (buf[0] != '\0');

	free(buf);
	free(Tagname);
	free(Msgname);
}



void New_Hdr(void);
void New_Hdr()
{
	char	*temp;

	temp = calloc(81, sizeof(char));
	clear();
	colour(14, 0);
	/* New or deleted mail areas at */
	sprintf(temp, "%s%s", (char *) Language(364), CFG.bbs_name);
	Center(temp);
	free(temp);
	printf("\n");
	colour(15, 1);
	/* Area  State  Type     Description */
	printf("%-79s\n", (char *) Language(365));
}



void New_Area(long);
void New_Area(long Area)
{
	colour(11, 0);
	printf("%4ld  New    ", Area);
	switch (msgs.Type) {
		case LOCALMAIL:	printf("Local    ");
				break;
		case NETMAIL:	printf("Netmail  ");
				break;
		case ECHOMAIL:	printf("Echomail ");
				break;
		case NEWS:	printf("News     ");
				break;
		case EMAIL:	printf("E-Mail   ");
	}
	printf("%s\n", msgs.Name);
}



void Old_Area(long);
void Old_Area(long Area)
{
	colour(12, 0);
	printf("%4ld  Del\n", Area);
}



/*
 *  Sync tagged areas file. If CFG.NewAreas is on then we show the
 *  changed areas to the user. This one is called by user.c during login.
 */
void OLR_SyncTags()
{
	char	Tagname[128], Msgname[128];
	FILE	*fp, *ma;
	long	Area;
	int	Changed = FALSE;

	sprintf(Tagname, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name);
	sprintf(Msgname, "%s/etc/mareas.data", getenv("MBSE_ROOT"));

	if ((fp = fopen(Tagname, "r+")) == NULL) {

		/*
		 *  If the user has no .olrtagsfile yet, we silently create
		 *  a new one. The user will not be notified of new areas
		 *  of coarse.
		 */
		Syslog('m', "Creating %s", Tagname);
		if ((fp = fopen(Tagname, "w")) != NULL) {

			if ((ma = fopen(Msgname, "r")) != NULL) {
				fread(&msgshdr, sizeof(msgshdr), 1, ma);

				while (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
					memset(&olrtagrec, 0, sizeof(olrtagrec));
					if ((msgs.Active) && Access(exitinfo.Security, msgs.RDSec)) {
						olrtagrec.Available = TRUE;
						olrtagrec.ScanNew = TRUE;
						if (msgs.OLR_Forced || msgs.OLR_Default)
							olrtagrec.Tagged = TRUE;
					}
					fwrite(&olrtagrec, sizeof(olrtagrec), 1, fp);
					fseek(ma, msgshdr.syssize, SEEK_CUR);
				}

				fclose(ma);
			}
		}
	} else {
		/*
		 *  The user has been here before...
		 */
		if ((ma = fopen(Msgname, "r")) != NULL) {
			fread(&msgshdr, sizeof(msgshdr), 1, ma);
			Area = 0;

			while (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
				Area++;

				if (fread(&olrtagrec, sizeof(olrtagrec), 1, fp) == 1) {

					/*
					 *  Check if this is a new area for the user.
					 */
					if ((msgs.Active) && Access(exitinfo.Security, msgs.RDSec) && (!olrtagrec.Available)) {
						Syslog('m', "New msg area %ld %s", Area, msgs.Name);
						fseek(fp, - sizeof(olrtagrec), SEEK_CUR);
						olrtagrec.Available = TRUE;
						olrtagrec.ScanNew = TRUE;
						if (msgs.OLR_Forced || msgs.OLR_Default)
							olrtagrec.Tagged = TRUE;
						fwrite(&olrtagrec, sizeof(olrtagrec), 1, fp);
						if (CFG.NewAreas) {
							if (!Changed) {
								New_Hdr();
								Changed = TRUE;
							}
							New_Area(Area);
						}
					} else {
						/*
						 *  Check if this area is no longer
						 *  available for the user.
						 */
						if (((!msgs.Active) || (!Access(exitinfo.Security, msgs.RDSec))) && olrtagrec.Available) {
							Syslog('m', "Deleted msg area %ld", Area);
							fseek(fp, - sizeof(olrtagrec), SEEK_CUR);
							olrtagrec.Available = FALSE;
							olrtagrec.ScanNew = FALSE;
							olrtagrec.Tagged = FALSE;
							fwrite(&olrtagrec, sizeof(olrtagrec), 1, fp);
							if (CFG.NewAreas) {
								if (!Changed) {
									New_Hdr();
									Changed = TRUE;
								}
								Old_Area(Area);
							}
						}
					}

				} else {
					/*
					 * If the number if msg areas was increased,
					 * append a new tagrecord.
					 */
					memset(&olrtagrec, 0, sizeof(olrtagrec));
					if ((msgs.Active) && Access(exitinfo.Security, msgs.RDSec)) {
						Syslog('m', "Append new area %ld %s", Area, msgs.Name);
						olrtagrec.Available = TRUE;
						olrtagrec.ScanNew = TRUE;
						if (msgs.OLR_Forced || msgs.OLR_Default)
							olrtagrec.Tagged = TRUE;
						if (CFG.NewAreas) {
							if (!Changed) {
								New_Hdr();
								Changed = TRUE;
							}
							New_Area(Area);
						}
					}
					fwrite(&olrtagrec, sizeof(olrtagrec), 1, fp);
				}
				fseek(ma, msgshdr.syssize, SEEK_CUR);
			}

			fclose(ma);
		}
	}

	fclose(fp);

	if (Changed) {
		colour(10, 0);
		fLine(79);
		Pause();
	}

	SetMsgArea(exitinfo.iLastMsgArea);
}



/*
 *  View tagged areas, called from menu.
 */
void OLR_ViewTags()
{
	char	Tagname[128], Msgname[128];
	FILE	*tf, *ma;
	long	total, Area = 0;

	WhosDoingWhat(OLR);

	sprintf(Tagname, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name);
	sprintf(Msgname, "%s/etc/mareas.data", getenv("MBSE_ROOT"));

	if ((tf = fopen(Tagname, "r")) == NULL) {
		WriteError("$Can't open %s", Tagname);
		return;
	}

	if ((ma = fopen(Msgname, "r")) == NULL) {
		WriteError("$Can't open %s", Msgname);
		fclose(tf);
		return;
	}
	fread(&msgshdr, sizeof(msgshdr), 1, ma);

	clear();
	colour(14, 0);
	printf ("You have selected the following Conference(s):\n");
	colour(11, 0);
	printf ("\nConference       Area  Msgs   Description\n");
	colour(3, 0);
	fflush(stdout);

	while (fread(&msgs, msgshdr.recsize, 1, ma) == 1) {
		fseek(ma, msgshdr.syssize, SEEK_CUR);
		fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
		Area++;

		if (olrtagrec.Tagged) {
			if (Msg_Open(msgs.Base)) {
				total = Msg_Number();
				Msg_Close();
			} else
				total = 0;
			printf("%-15.15s  %-5ld %-5ld  %s\n", msgs.QWKname, Area, total, msgs.Name);
			fflush(stdout);
		}
	}

	fclose(tf);
	fclose(ma);
	Pause();
}



/*
 *  Prescan all selected areas. Show the user the areas and messages in it.
 */
int OLR_Prescan()
{
	unsigned short	RetVal = FALSE, Areas;
	unsigned long	Number;
	char		Temp[128];
	FILE		*mf, *tf;
	int		x;

	WhosDoingWhat(OLR);
	clear();
	colour(13, 0);
	printf("Offline Reader Download\n\n");
	fflush(stdout);

	sprintf(Temp, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
	mf = fopen(Temp, "r");
	fread(&msgshdr, sizeof(msgshdr), 1, mf);

	sprintf(Temp, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name);
	tf = fopen(Temp, "r");
	Total = TotalPersonal = Areas = 0;

	colour(15, 1);
//		  123456789012345 12345678901234567890123456789012345678901 12345 12345
	printf("\nForum           Description                               Msgs. Pers.\n");

	while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) {
		fseek(mf, msgshdr.syssize, SEEK_CUR);
		fread(&olrtagrec, sizeof(olrtagrec), 1, tf);

		if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname) && olrtagrec.Tagged) {
			if (Msg_Open(msgs.Base)) {
				Areas++;
				Current = Personal = 0;
				colour(11, 0);
				printf("%-15.15s %-41.41s ", msgs.QWKname, msgs.Name);
				fflush(stdout);

				memset(&LR, 0, sizeof(LR));
				LR.UserID = grecno;
				if (Msg_GetLastRead(&LR))
					Number = LR.HighReadMsg;
				else
					Number = Msg_Lowest() -1;
				if (Number > Msg_Highest())
					Number = Msg_Highest();
				if (Msg_Next(&Number)) {
					do {
						Msg_ReadHeader(Number);
						Current++;
						Total++;
						if ((strcasecmp(Msg.To, exitinfo.sUserName) == 0) ||
						    (strcasecmp(Msg.To, exitinfo.sHandle) == 0)) {
							Personal++;
							TotalPersonal++;
						} else if (msgs.Type == NETMAIL) {
							Current--;
							Total--;
						}
					} while (Msg_Next(&Number));
				}

				colour(10, 0);
				printf("%5lu %5lu\n", Current, Personal);
				fflush(stdout);
				Msg_Close();
			}
		}
	}

	Syslog('+', "OLR Prescan: %u Areas, %lu Messages", Areas, Total);

	colour(9, 0);
	printf("\nTotal messages found: %lu\n\n", Total);
	if (Total == 0L) {
		colour(14, 0);
		printf("No messages found to download!\n\007");
		Pause();
	} else {
		if (CFG.OLR_MaxMsgs != 0 && Total > CFG.OLR_MaxMsgs) {
			printf("Too much messages. Only the first %d will be packed!\n\n\007", CFG.OLR_MaxMsgs);
			Total = CFG.OLR_MaxMsgs;
		}

		colour(CFG.HiliteF, CFG.HiliteB);
		printf("Do you want to download these messages [Y/n]? ");
		fflush(stdout);
		alarm_on();
		x = toupper(Getone());

		if (x != 'N') {
			RetVal = TRUE;
			TotalPack = Total;
			BarWidth = 0;
		}
	}

	if (mf != NULL)	
		fclose(mf);
	if (tf != NULL)
		fclose(tf);

	return(RetVal);
}



void OLR_RestrictDate()
{
	WhosDoingWhat(OLR);

	printf("Not Yet Implemented\n");
	Pause();
}


/*
VOID TOffline::RestrictDate (VOID)
{
   int dd, mm, yy;
   CHAR Temp[32];
   ULONG Restrict;
   struct tm ltm;
   class TMsgTag *MsgTag = User->MsgTag;

   memcpy (&ltm, localtime ((time_t *)&User->LastCall), sizeof (struct tm));
   Embedded->Printf ("\n\026\001\017Enter date of oldest message to pack, or press <enter> for %d-%02d-%d: ", ltm.tm_mday, ltm.tm_mon + 1, ltm.tm_year % 100);
   Embedded->Input (Temp, 10);

   if (Embedded->AbortSession () == FALSE) {
      Restrict = User->LastCall;
      if (Temp[0] != '\0') {
         sscanf (Temp, "%d-%d-%d", &dd, &mm, &yy);
         if (yy < 90)
            yy += 100;
         memset (&ltm, 0, sizeof (struct tm));
         ltm.tm_mday = dd;
         ltm.tm_mon = mm - 1;
         ltm.tm_year = yy;
         Restrict = mktime (&ltm);
      }

      if (MsgTag->First () == TRUE)
         do {
            if (MsgTag->Tagged == TRUE) {
               MsgTag->LastRead = 0L;
               MsgTag->OlderMsg = Restrict;
               MsgTag->Update ();
            }
         } while (MsgTag->Next () == TRUE);
   }
}
*/

/*
USHORT TOffline::TooOld (ULONG Restrict, class TMsgBase *Msg)
{
   USHORT RetVal = FALSE;
   struct tm ltm;

   memset (&ltm, 0, sizeof (struct tm));
   ltm.tm_mday = Msg->Written.Day;
   ltm.tm_mon = Msg->Written.Month - 1;
   ltm.tm_year = Msg->Written.Year - 1900;
   if (mktime (&ltm) < Restrict)
      RetVal = TRUE;

   return (RetVal);
}
*/



/*
 *  Upload offline mail. Filenames: BBSID.NEW or BBSID.REP.
 *  Should also do hhhhhhhh.SU0 for point uploads.
 *  NOTE: THE FIRST PART OF THE CODE IS FROM UPLOAD_HOME
 */
void OLR_Upload(void)
{
	char		*File, *temp, *Arc;
	time_t		ElapstimeStart, ElapstimeFin, iTime;
	int		err, Strlen, RetVal = FALSE;
	struct stat	statbuf;
	FILE		*fp;

	WhosDoingWhat(OLR);
	clear();
	colour(13, 0);
	printf("Offline Reader Upload\n");

	if (!ForceProtocol())
		return;

	File  = calloc(81, sizeof(char));
	temp  = calloc(81, sizeof(char));

	if (!uProtBatch) {
		Enter(1);
		/* Please enter file to upload: */
		pout(14, 0, (char *) Language(276));

		colour(CFG.InputColourF, CFG.InputColourB);
		GetstrC(File, 80);

		Syslog('+', "Filename entered \"%s\"", File);

		if ((strcmp(File, "")) == 0)
			return;

		if (File[0] == '.' || File[0] == '*' || File[0] == ' ') {
			colour(CFG.HiliteF, CFG.HiliteB);
			/* Illegal filename! */
			printf("\n%s\n\n", (char *) Language(247));
			Pause();
			return;
		}

		Strlen = strlen(File);
		Strlen--;

		if (File[Strlen] == '.' || File[Strlen] == '/' || File[Strlen] == ' ') {
			colour(CFG.HiliteF, CFG.HiliteB);
			/* Illegal Filename! */
			printf("\n%s\n\n", (char *) Language(247));
			Pause();
			return;
		}

		if (strncasecmp(File, CFG.bbsid, strlen(CFG.bbsid))) {
			colour(CFG.HiliteF, CFG.HiliteB);
			/* Illegal filename! */
			printf("\n%s\n\n", (char *) Language(247));
			Pause();
			return;
		}
		Syslog('+', "Filename accepted");
	}

	colour(CFG.HiliteF, CFG.HiliteB);
	/* Please start your upload now */
	printf("\n%s, %s\n\n", sProtAdvice, (char *) Language(283));
	if (uProtBatch)
		Syslog('+', "Upload using %s", sProtName);
	else
		Syslog('+', "Upload \"%s\" using %s", File, sProtName);

	sprintf(temp, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name);

	if (chdir(temp)) {
		WriteError("$Can't chdir to %s", temp);
		return;
	}

	sprintf(temp, "%s", sProtUp);
	Syslog('+', "Upload command %s", temp);
	fflush(stdout);
	fflush(stdin);
	sleep(2);
	time(&ElapstimeStart);

	/*
	 *  Get the file
	 */
	Altime(7200);
	alarm_set(7190);
	if ((err = system(temp)) != 0) {
		colour(CFG.HiliteF, CFG.HiliteB);
		WriteError("$Upload error %d, prot: %s", err, sProtUp);
	}
	Altime(0);
	alarm_off();
	alarm_on();
	printf("\n");
	fflush(stdout);
	fflush(stdin);
	time(&ElapstimeFin);

	/*
	 *  Get the upload time.
	 */
	iTime = ElapstimeFin - ElapstimeStart;
	if (!iTime)
		iTime = 1;

	Syslog('m', "Transfer time %ld", iTime);
	Home();

	if (!RetVal) {
		sprintf(File, "%s/%s/upl/%s.NEW", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
		Syslog('m', "Check %s", File);
		if (stat(File, &statbuf) == 0)
			RetVal = TRUE;
	}

	if (!RetVal) {
		File = tl(File);
		Syslog('m', "Check %s", File);
		if (stat(File, &statbuf) == 0)
			RetVal = TRUE;
	}

	if (!RetVal) {
		sprintf(File, "%s/%s/upl/%s.REP", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
		Syslog('m', "Check %s", File);
		if (stat(File, &statbuf) == 0)
			RetVal = TRUE;
	}

	if (!RetVal) {
		File = tl(File);
		Syslog('m', "Check %s", File);
		if (stat(File, &statbuf) == 0)
			RetVal = TRUE;
	}

	if (RetVal == FALSE) {
		WriteError("Invalid OLR packed received");
		printf("Invalid packet received\n\n");
		sleep(2);
		return;
	}
	Syslog('+', "Received OLR packet %s", File);

	if ((Arc = GetFileType(File)) == NULL) {
		printf("Unknown compression type\n");
		Syslog('+', "Unknown compression type");
		Pause();
		return;
	}

	Syslog('m', "File type is %s", Arc);

	sprintf(temp, "%s/etc/archiver.data", getenv("MBSE_ROOT"));
	if ((fp = fopen(temp, "r")) == NULL)
		return;

	fread(&archiverhdr, sizeof(archiverhdr), 1, fp);

	while (fread(&archiver, archiverhdr.recsize, 1, fp) == 1) {
		if ((strcmp(Arc, archiver.name) == 0) && archiver.available)
			break;
	}
	fclose(fp);

	if (strcmp(Arc, archiver.name) || (!archiver.available)) {
		Syslog('+', "Archiver %s not available", Arc);
		printf("Archiver not available\n");
		Pause();
		return;
	}

	Syslog('m', "Archiver %s", archiver.comment);

	colour(CFG.TextColourF, CFG.TextColourB);
	/* Unpacking archive */
	printf("%s ", (char *) Language(201));
	fflush(stdout);
	sprintf(temp, "%s %s", archiver.funarc, File);
	Syslog('m', "Unarc %s", temp);
	colour(CFG.HiliteF, CFG.HiliteB);

	if ((err = system(temp))) {
		WriteError("$Failed %s", temp);
		/* ERROR */
		printf("%s\n", (char *) Language(217));
		fflush(stdout);
		Pause();
		return;
	}

	/* Ok */
	printf("%s\n", (char *) Language(200));
	fflush(stdout);
	unlink(File);

	/*
	 * Check for BlueWave files, upper and lowercase.
	 */
	RetVal = FALSE;
	sprintf(temp, "%s/%s/%s.UPL", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if (!file_exist(temp, R_OK)) 
		RetVal = TRUE;

	temp = tl(temp);
	if (!file_exist(temp, R_OK))
		RetVal = TRUE;

	sprintf(temp, "%s/%s/%s.UPI", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if (!file_exist(temp, R_OK)) 
		RetVal = TRUE;

        temp = tl(temp);
        if (!file_exist(temp, R_OK))
                RetVal = TRUE;

	sprintf(temp, "%s/%s/%s.NET", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if (!file_exist(temp, R_OK)) 
		RetVal = TRUE;

        temp = tl(temp);
        if (!file_exist(temp, R_OK))
                RetVal = TRUE;

	sprintf(temp, "%s/%s/%s.REQ", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if (!file_exist(temp, R_OK)) 
		RetVal = TRUE;

        temp = tl(temp);
        if (!file_exist(temp, R_OK))
                RetVal = TRUE;

	sprintf(temp, "%s/%s/%s.PDQ", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if (!file_exist(temp, R_OK)) 
		RetVal = TRUE;

        temp = tl(temp);
        if (!file_exist(temp, R_OK))
                RetVal = TRUE;

	sprintf(temp, "%s/%s/%s.OLC", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if (!file_exist(temp, R_OK)) 
		RetVal = TRUE;

        temp = tl(temp);
        if (!file_exist(temp, R_OK))
                RetVal = TRUE;

	if (RetVal) {
		Syslog('+', "OLR packet is BlueWave");
		free(File);
		free(temp);
		BlueWave_Fetch();
		return;
	}

	sprintf(temp, "%s/%s/%s.MSG", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if (!file_exist(temp, R_OK)) 
		RetVal = TRUE;

        temp = tl(temp);
        if (!file_exist(temp, R_OK))
                RetVal = TRUE;

	if (RetVal) {
		Syslog('+', "OLR packet is QWK: NOT SUPPORTED");
//		QWK_Fetch();
		free(File);
		free(temp);
		return;
	}

	WriteError("OLR_Upload: Garbage in mailpacket, clean directory!");
	printf("Unknown type mailpacket\n");
	Pause();
	free(File);
	free(temp);
}



/***************************************************************************
 *
 *                    BlueWave specific functions.
 *
 */

char *Extensions[] = {
   (char *)".SU0", (char *)".MO0", (char *)".TU0", (char *)".WE0", 
   (char *)".TH0", (char *)".FR0", (char *)".SA0"
};



/*
 *  Download a BlueWave mailpacket, called from menu.
 */
void OLR_DownBW()
{
	struct	tm	*tp;
	time_t		Now;
	char		Pktname[32];
	char		*Work, *Temp;
	long		Area = 0;
	int		RetVal = FALSE, rc;
	FILE		*fp, *tf, *mf, *af;
	INF_HEADER	Inf;
	INF_AREA_INFO	AreaInf;
	unsigned long	Start, High;
	msg_high	*tmp, *mhl = NULL;

	if (!OLR_Prescan())
		return;

	Total = TotalPersonal = 0;
	clear();
	colour(9, 0);
	printf("BlueWave Offline download\n");

	Work = calloc(128, sizeof(char));
	Temp = calloc(128, sizeof(char));

	Now = time(NULL);
	tp = localtime(&Now);
	Syslog('+', "Preparing BlueWave packet");

	sprintf(Pktname, "%s%s", CFG.bbsid , Extensions[tp->tm_wday]);
	Syslog('m', "Packet name %s", Pktname);
	sprintf(Work, "%s/%s/tmp", CFG.bbs_usersdir, exitinfo.Name);
	Syslog('m', "Work path %s", Work);

	sprintf(Temp, "%s/%s.INF", Work, CFG.bbsid);
	if ((fp = fopen(Temp, "w+")) == NULL) {
		WriteError("$Can't create %s", Temp);
		return;
	}

	/*
	 *  Write the info header.
	 */
	memset(&Inf, 0, sizeof(Inf));
	Inf.ver = PACKET_LEVEL;
	strcpy((char *)Inf.loginname, exitinfo.sUserName);
	strcpy((char *)Inf.aliasname, exitinfo.sHandle);
	Inf.zone  = CFG.aka[0].zone;
	Inf.net   = CFG.aka[0].net;
	Inf.node  = CFG.aka[0].node;
	Inf.point = CFG.aka[0].point;
	strcpy((char *)Inf.sysop, CFG.sysop_name);
	strcpy((char *)Inf.systemname, CFG.bbs_name);
	Inf.maxfreqs = CFG.OLR_MaxReq;
	if (exitinfo.HotKeys)
		Inf.uflags |= INF_HOTKEYS;
	if (exitinfo.GraphMode)
		Inf.uflags |= INF_GRAPHICS;
	if (exitinfo.OL_ExtInfo)
		Inf.uflags |= INF_EXT_INFO;
	Inf.credits = exitinfo.Credit;
	Inf.inf_header_len = sizeof(INF_HEADER);
	Inf.inf_areainfo_len = sizeof(INF_AREA_INFO);
	Inf.mix_structlen = sizeof(MIX_REC);
	Inf.fti_structlen = sizeof(FTI_REC);
	Inf.uses_upl_file = TRUE;
	Inf.can_forward = TRUE;
	strcpy((char *)Inf.packet_id, CFG.bbsid);
	fwrite(&Inf, sizeof(INF_HEADER), 1, fp);

	/*
	 *  Check to see if this stuff is compiled packed. If not the
	 *  download packet is useless.
	 */
	if ((sizeof(Inf) != ORIGINAL_INF_HEADER_LEN) ||
	    (sizeof(AreaInf) != ORIGINAL_INF_AREA_LEN)) {
		WriteError("PANIC: Probably not \"packed\" compiled!");
		fclose(fp);
		return;
	}

	sprintf(Temp, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
	if ((mf = fopen(Temp, "r")) == NULL) {
		WriteError("$Can't open %s", Temp);
		fclose(fp);
		return;
	}
	fread(&msgshdr, sizeof(msgshdr), 1, mf);

	sprintf(Temp, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name);
	if ((tf = fopen(Temp, "r")) == NULL) {
		WriteError("$Can't open %s", Temp);
		fclose(fp);
		fclose(mf);
		return;
	}

	/*
	 *  Write the areas information
	 */
	while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) {
		fseek(mf, msgshdr.syssize, SEEK_CUR);
		fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
		Area++;

		if (msgs.Active && Access(exitinfo.Security, msgs.RDSec)) {
			memset(&AreaInf, 0, sizeof(AreaInf));
			sprintf((char *)AreaInf.areanum, "%lu", Area);
			strcpy((char *)AreaInf.echotag, msgs.QWKname);
			strcpy((char *)AreaInf.title, msgs.Name);
			if (olrtagrec.Tagged) {
				AreaInf.area_flags |= INF_SCANNING;
				RetVal = TRUE;
			}

			switch(msgs.Type) {
				case LOCALMAIL:
						break;

				case NETMAIL:	AreaInf.area_flags |= (INF_ECHO+INF_NETMAIL);
						break;

				case ECHOMAIL:	AreaInf.area_flags |= INF_ECHO;
						break;

				case EMAIL:	AreaInf.area_flags |= (INF_ECHO+INF_NETMAIL);
						AreaInf.network_type |= INF_NET_INTERNET;
						break;

				case NEWS:	AreaInf.area_flags |= INF_ECHO;
						AreaInf.network_type |= INF_NET_INTERNET;
						break;
			}
			switch(msgs.MsgKinds) {
				case BOTH:	if (Access(exitinfo.Security, msgs.WRSec))
							AreaInf.area_flags |= INF_POST;
						break;

				case PRIVATE:	if (Access(exitinfo.Security, msgs.WRSec))
							AreaInf.area_flags |= INF_POST;
						AreaInf.area_flags |= INF_NO_PUBLIC;
						break;

				case PUBLIC:	if (Access(exitinfo.Security, msgs.WRSec))
							AreaInf.area_flags |= INF_POST;
						AreaInf.area_flags |= INF_NO_PRIVATE;
						break;

				case RONLY:	break;

				case NOREPLY:	break;
			}

			if (msgs.FileAtt)
				AreaInf.area_flags |= INF_HASFILE;

			if (msgs.Aliases)
				AreaInf.area_flags |= INF_ALIAS_NAME;

			fwrite(&AreaInf, sizeof(AreaInf), 1, fp);
		}
	}
	fclose(fp);

	if (RetVal) {
		Area = 0;
		colour(14, 0);
		printf("\nPreparing %s packet...\n\n", Pktname);
		colour(10, 0);
		printf("0%%    10%%  20%%   30%%   40%%   50%%   60%%   70%%   80%%   90%%   100%%\n|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\r");
		fflush(stdout);
		fseek(mf, sizeof(msgshdr), SEEK_SET);
		fseek(tf, 0, SEEK_SET);

		while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) {
			fseek(mf, msgshdr.syssize, SEEK_CUR);
			fread(&olrtagrec, sizeof(olrtagrec), 1, tf);
			Area++;
			if (olrtagrec.Tagged) {
				if (Msg_Open(msgs.Base)) {
					Current = Personal = 0;
					if (Msg_Highest() != 0) {
						memset(&LR, 0, sizeof(LR));
						LR.UserID = grecno;
						if (Msg_GetLastRead(&LR))
							Start = LR.HighReadMsg;
						else
							Start = Msg_Lowest() -1;
						if (Start > Msg_Highest())
							Start = Msg_Highest();
						if (Start < Msg_Highest()) {
							Syslog('m', "First %lu, Last %lu, Start %lu", Msg_Lowest(), Msg_Highest(), Start);
							High = BlueWave_PackArea(Start, Area);
							fill_high(&mhl, Area, High, Personal);
						}
					}
					Syslog('+', "Area %-20s %5ld (%ld personal)", msgs.QWKname, Current, Personal);
					Msg_Close();
				}
			}
		}
		Syslog('+', "Packed %ld messages (%ld personal)", Total, TotalPersonal);
	}
	fclose(tf);

	rc = FALSE;
	alarm_on();

	if (Total) {
		printf("\nPacking with ");
		sprintf(Temp, "%s/etc/archiver.data", getenv("MBSE_ROOT"));
		if ((af = fopen(Temp, "r")) != NULL) {
			fread(&archiverhdr, sizeof(archiverhdr), 1, af);
			while (fread(&archiver, archiverhdr.recsize, 1, af) == 1) {
				if (archiver.available && (!strcmp(archiver.name, exitinfo.Archiver))) {
					Syslog('+', "Archiver %s", archiver.comment);
					printf("%s ", archiver.comment);
					sprintf(Temp, "%s/%s.DAT", Work, CFG.bbsid);
					execute((char *)archiver.marc, (char *)Pktname, Temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
					unlink(Temp);
					printf(".");
					fflush(stdout);
					alarm_on();
					sprintf(Temp, "%s/%s.FTI", Work, CFG.bbsid);
					execute((char *)archiver.marc, (char *)Pktname, Temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
					unlink(Temp);
					printf(".");
					fflush(stdout);
					sprintf(Temp, "%s/%s.INF", Work, CFG.bbsid);
					execute((char *)archiver.marc, (char *)Pktname, Temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
					unlink(Temp);
					printf(".");
					fflush(stdout);
					sprintf(Temp, "%s/%s.MIX", Work, CFG.bbsid);
					execute((char *)archiver.marc, (char *)Pktname, Temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
					unlink(Temp);
					printf(".");
					fflush(stdout);
					sprintf(Temp, "%s/%s/%s", CFG.bbs_usersdir, exitinfo.Name, Pktname);
					rc = DownloadDirect(Temp, FALSE);
					Syslog('m', "Download result %d", rc);
					unlink(Temp);
				}
			}
			fclose(af);
		}
	}

	colour(CFG.HiliteF, CFG.HiliteB);
	if (rc == FALSE) {
		Syslog('+', "BlueWave download failed");
		printf("BlueWave download failed");
	} else {
		Syslog('+', "BlueWave download successfull");
		printf("\rDownload successfull.\n");

		if (mhl != NULL) {
			colour(14, 0);
			printf("Updating lastread pointers\n");
			colour(13, 0);
			Syslog('m', "Updating lastread pointers");
	
			for (tmp = mhl; tmp; tmp = tmp->next) {
				Syslog('m', "Area %lu, Msg %lu", tmp->Area, tmp->LastMsg);
				printf(".");
				fflush(stdout);
				fseek(mf, ((tmp->Area -1) * (msgshdr.recsize + msgshdr.syssize)) + msgshdr.hdrsize, SEEK_SET);
				fread(&msgs, msgshdr.recsize, 1, mf);
				Syslog('m', "%s", msgs.Base);
				if (Msg_Open(msgs.Base)) {
					if (Msg_Lock(30L)) {
						if (tmp->Personal) 
							Syslog('?', "Personal messages to update");

						LR.UserID = grecno;
						if (Msg_GetLastRead(&LR) == TRUE) {
							LR.LastReadMsg = tmp->LastMsg;
							if (tmp->LastMsg > LR.HighReadMsg)
								LR.HighReadMsg = tmp->LastMsg;
							if (LR.HighReadMsg > Msg_Highest()) {
								Syslog('?', "Highread was too high");
								LR.HighReadMsg = Msg_Highest();
							}
							LR.UserCRC = StringCRC32(tl(strdup(exitinfo.sUserName)));
							if (!Msg_SetLastRead(LR))
								WriteError("Error update lastread");
						} else {
							/*
							 * Append new lastread pointer
							 */
							LR.UserCRC = StringCRC32(tl(strdup(exitinfo.sUserName)));
							LR.UserID = grecno;
							LR.LastReadMsg = tmp->LastMsg;
							LR.HighReadMsg = tmp->LastMsg;
							if (!Msg_NewLastRead(LR))
								WriteError("Can't append new lastread");
						}
						Msg_UnLock();
					}
					Msg_Close();
				}
			}
		}
	}

	fclose(mf);
	tidy_high(&mhl);

	free(Temp);
	free(Work);
	printf("\n\n");
	Pause();
}



/*
 *  BlueWave Fetch reply packet.
 */
void BlueWave_Fetch()
{
	char		*temp;
	FILE		*up, *mf, *tp;
	UPL_HEADER	Uph;
	UPL_REC		Upr;
	PDQ_HEADER	Pdh;
	PDQ_REC		Pdr;
	REQ_REC		Req;
	int		i, Found;
	fidoaddr	dest;

	colour(9, 0);
	printf("Processing BlueWave reply packet\n");
	temp = calloc(128, sizeof(char));

	/*
	 *  Process uploaded mail
	 */
	sprintf(temp, "%s/%s/%s.UPL", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if ((up = fopen(temp, "r")) == NULL) {
		temp = tl(temp);
		up = fopen(temp, "r");
	}
	if (up != NULL) {
		fread(&Uph, sizeof(UPL_HEADER), 1, up);
		Syslog('+', "Processing BlueWave .UPL file");
		Syslog('+', "Client: %s %d.%d", Uph.reader_name, Uph.reader_major, Uph.reader_minor);
		if (Uph.upl_header_len != sizeof(UPL_HEADER)) {
			WriteError("Recordsize mismatch");
			fclose(up);
			printf("ERROR in packet\n");
			Pause();
			return;
		}
		Syslog('+', "Login %s, Alias %s", Uph.loginname, Uph.aliasname);
		/* MORE CHECKS HERE */

		colour(CFG.TextColourF, CFG.TextColourB);
		printf("Import messages ");
		colour(CFG.HiliteF, CFG.HiliteB);
		fflush(stdout);
		i = 0;

		memset(&Upr, 0, sizeof(UPL_REC));
		while (fread(&Upr, Uph.upl_rec_len, 1, up) == 1) {
			printf(".");
			fflush(stdout);
			Syslog('m', "  From  : %s", Upr.from);
			Syslog('m', "  To    : %s", Upr.to);
			Syslog('m', "  Subj  : %s", Upr.subj);
			Syslog('m', "  Date  : %ld", Upr.unix_date);
			Syslog('m', "  Dest  : %d:%d/%d.%d", Upr.destzone, Upr.destnet, Upr.destnode, Upr.destpoint);
			if (Upr.msg_attr & UPL_INACTIVE)
				Syslog('m', "  Message is Inactive");
			if (Upr.msg_attr & UPL_PRIVATE)
				Syslog('m', "  Message is Private");
			if (Upr.msg_attr & UPL_HAS_FILE)
				Syslog('m', "  File Attach");
			if (Upr.msg_attr & UPL_NETMAIL)
				Syslog('m', "  Is Netmail");
			if (Upr.msg_attr & UPL_IS_REPLY)
				Syslog('m', "  Is Reply");
			if (Upr.network_type)
				Syslog('m', "  Type  : Internet");
			else
				Syslog('m', "  Type  : Fidonet");
			Syslog('m', "  File  : %s", Upr.filename);
			Syslog('m', "  Tag   : %s", Upr.echotag);

			sprintf(temp, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
			if ((mf = fopen(temp, "r+")) != NULL) {
				fread(&msgshdr, sizeof(msgshdr), 1, mf);
				Found = FALSE;

				if (strlen(Upr.echotag)) {
					while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) {
						fseek(mf, msgshdr.syssize, SEEK_CUR);
						if (msgs.Active && (strcasecmp(msgs.QWKname, Upr.echotag) == 0)) {
							Found = TRUE;
							break;
						}
					}
				} else {
					/*
					 *  If there is no echotag, the filename is used
					 *  this is "areanum.msgnum" so we pick the part
					 *  before the dot and pray that it's ok.
					 */
					temp = strtok(strdup(Upr.filename), ".");
					if (fseek(mf, ((atoi(temp) -1) * (msgshdr.recsize + msgshdr.syssize)) + msgshdr.hdrsize, SEEK_SET) == 0)
						if (fread(&msgs, msgshdr.recsize, 1, mf) == 1) {
							Found = TRUE;
							fseek(mf, msgshdr.syssize, SEEK_CUR);
						}
				}

				/* SHOULD ALSO CHECK FROM FIELD */
				if (!Found) {
					WriteError("No msg area, File \"%s\"", Upr.filename);
				} else {
					if ((Access(exitinfo.Security, msgs.WRSec)) &&
					    (msgs.MsgKinds != RONLY) &&
					    (msgs.MsgKinds != NOREPLY)) {

						if (Open_Msgbase(msgs.Base, 'w')) {
							Msg_New();
							Syslog('m', "Msgbase open and locked");
							strcpy(Msg.From, Upr.from);
							strcpy(Msg.To, Upr.to);
							strcpy(Msg.Subject, Upr.subj);
							if (Upr.msg_attr & UPL_PRIVATE)
								Msg.Private = TRUE;
							if (msgs.MsgKinds == PRIVATE)
								Msg.Private = TRUE;
							Msg.Written = Upr.unix_date;
							Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60);
							Msg.Local  = TRUE;
							dest.zone  = Upr.destzone;
							dest.net   = Upr.destnet;
							dest.node  = Upr.destnode;
							dest.point = Upr.destpoint;
							Syslog('m', "Header fields are set, starting kludges");
							Add_Kludges(dest, FALSE, Upr.filename);
							Syslog('+', "Msg (%ld) to \"%s\", \"%s\", in %s", Msg.Id, Msg.To, Msg.Subject, msgs.QWKname);
							sprintf(temp, "%s/%s/%s", CFG.bbs_usersdir, exitinfo.Name, Upr.filename);
							unlink(temp);
							i++;
							Close_Msgbase();
							Syslog('m', "Msgbase closed again");
							fseek(mf, - (msgshdr.recsize + msgshdr.syssize), SEEK_CUR);
							msgs.Posted.total++;
							msgs.Posted.tweek++;
							msgs.Posted.tdow[Diw]++;
							msgs.Posted.month[Miy]++;
							msgs.LastPosted = time(NULL);
							fwrite(&msgs, msgshdr.recsize, 1, mf);
						}
					} else {
						printf("\nNo Write access to area %s\n", msgs.Name);
						WriteError("No Write Access to area %s", msgs.Name);
					}
				}
				fclose(mf);
			}
			memset(&Upr, 0, sizeof(UPL_REC));
		}
		printf("\n");
		colour(CFG.TextColourF, CFG.TextColourB);
		if (i) {
			printf("%d Messages imported\n", i);
			ReadExitinfo();
			exitinfo.iPosted += i;
			WriteExitinfo();
			do_mailout = TRUE;
		}
		fflush(stdout);
		fclose(up);

		/*
		 *  Remove processed files.
		 */
		sprintf(temp, "%s/%s/%s.UPL", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
		unlink(temp);
		temp = tl(temp);
		unlink(temp);
		sprintf(temp, "%s/%s/%s.UPI", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
		unlink(temp);
		temp = tl(temp);
		unlink(temp);
		sprintf(temp, "%s/%s/%s.NET", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
		unlink(temp);
		temp = tl(temp);
		unlink(temp);
	}

	/*
	 * If a .UPL file was not found it is possible we received an version 2
	 * reply packet.
	 */
	sprintf(temp, "%s/%s/%s.UPI", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if ((up = fopen(temp, "r")) == NULL) {
		temp = tl(temp);
		up = fopen(temp, "r");
	}
	if (up != NULL) {
		Syslog('+', "Received Version 2 .UPI packet, not supported");
		fclose(up);
	}
	sprintf(temp, "%s/%s/%s.NET", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if ((up = fopen(temp, "r")) == NULL) {
		temp = tl(temp);
		up = fopen(temp, "r");
	}
	if (up != NULL) {
		Syslog('+', "Received Version 2 .NET packet, not supported");
		fclose(up);
	}

	/*
	 *  Process offline configuration
	 */
	sprintf(temp, "%s/%s/%s.PDQ", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if ((tp = fopen(temp, "r")) == NULL) {
		temp = tl(temp);
		tp = fopen(temp, "r");
	}
	if (tp != NULL) {
		colour(9, 0);
		printf("Processing Offline Configuration\n");
		Syslog('+', "Processing offline configuration");

		fread(&Pdh, sizeof(PDQ_HEADER), 1, tp);
		for (i = 0; i < 10; i++)
			if (strlen(Pdh.keywords[i]))
				Syslog('m', "  Kwrd %2d : %s", i+1, Pdh.keywords[i]);
		for (i = 0; i < 10; i++)
			if (strlen(Pdh.filters[i]))
				Syslog('m', "  Filt %2d : %s", i+1, Pdh.filters[i]);
		for (i = 0; i < 3; i++)
			if (strlen(Pdh.macros[i]))
				Syslog('m', "  Macro %d : %s", i+1, Pdh.macros[i]);
		Syslog('m', "  Pwtype  : %d", Pdh.passtype);
		Syslog('m', "  Flags   : %08x", Pdh.flags);

		/*
		 *  If the changes flag is set there are records with
		 *  active areas. Reset all areas first and then set
		 *  the active areas back on.
		 */
		if (Pdh.flags & PDQ_AREA_CHANGES) {
			Syslog('m', "  New Area Configuration present");
			i = 0;

			sprintf(temp, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name);
			if ((up = fopen(temp, "r+")) != NULL) {

				sprintf(temp, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
				if ((mf = fopen(temp, "r")) != NULL) {

					fread(&msgshdr, sizeof(msgshdr), 1, mf);

					while (fread(&olrtagrec, sizeof(olrtagrec), 1, up) == 0) {
						fread(&msgs, msgshdr.recsize, 1, mf);
						fseek(mf, msgshdr.syssize, SEEK_CUR);
						if (!msgs.OLR_Forced)
							olrtagrec.Tagged = FALSE;
						fseek(up, - sizeof(olrtagrec), SEEK_CUR);
						fwrite(&olrtagrec, sizeof(olrtagrec), 1, up);
					}

					while (fread(&Pdr, sizeof(PDQ_REC), 1, tp) == 1) {
						if (strlen(Pdr.echotag)) {
							fseek(mf, msgshdr.hdrsize, SEEK_SET);
							fseek(up, 0, SEEK_SET);
							while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) {
								fseek(mf, msgshdr.syssize, SEEK_CUR);
								fread(&olrtagrec, sizeof(olrtagrec), 1, up);
								if ((strcmp(msgs.QWKname, Pdr.echotag) == 0) &&
								    (msgs.Active) &&
								    (Access(exitinfo.Security, msgs.RDSec))) {
									Syslog('m', "  Area %s", Pdr.echotag);
									olrtagrec.Tagged = TRUE;
									fseek(up, - sizeof(olrtagrec), SEEK_CUR);
									fwrite(&olrtagrec, sizeof(olrtagrec), 1, up);
									i++;
									break;
								}
							}
						}
					}
					fclose(mf);
					colour(3, 0);
					printf("%d Message areas selected\n", i);
				}
				fclose(up);
			}
		}
		fclose(tp);
		sprintf(temp, "%s/%s/%s.PDQ", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
		unlink(temp);
	}

	/*
	 *  Check for .REQ file.
	 */
	sprintf(temp, "%s/%s/%s.REQ", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	if ((tp = fopen(temp, "r")) == NULL) {
		temp = tl(temp);
		tp = fopen(temp, "r");
	}
	if (tp != NULL) {
		i = 0;
		colour(9, 0);
		printf("Processing file requests\n");
		Syslog('+', "Processing file requests");

		while (fread(&Req, sizeof(REQ_REC), 1, tp) == 1) {
			Syslog('m', "  File %s", Req.filename);
			colour(CFG.TextColourF, CFG.TextColourB);
			printf("%-12s ", Req.filename);
			colour(CFG.HiliteF, CFG.HiliteB);
			fflush(stdout);

			printf("\n");
		}

		fclose(tp);
	}

	free(temp);
	Pause();
}



/*
 *  Add one area to the BlueWave download packet
 */
unsigned long BlueWave_PackArea(unsigned long ulLast, long Area)
{
	FILE		*fdm, *fdfti, *fdmix;
	char		Temp[128], *Text;
	unsigned long	Number;
	MIX_REC		Mix;
	FTI_REC		Fti;
	struct	tm	*tp;
	int		Pack;

	Number = ulLast;

	sprintf(Temp, "%s/%s/tmp/%s.FTI", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	fdfti = fopen(Temp, "a+");

	sprintf(Temp, "%s/%s/tmp/%s.MIX", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	fdmix = fopen(Temp, "a+");

	sprintf(Temp, "%s/%s/tmp/%s.DAT", CFG.bbs_usersdir, exitinfo.Name, CFG.bbsid);
	fdm = fopen(Temp, "a+");

	memset(&Mix, 0, sizeof(MIX_REC));
	sprintf((char *)Mix.areanum, "%lu", Area);
	Mix.msghptr = ftell(fdfti);

	if ((fdfti != NULL) && (fdmix != NULL) && (fdm != NULL)) {
		if (Msg_Next(&Number)) {
			do {
				Msg_ReadHeader(Number);
				Msg_Read(Number, 78);
				Pack = TRUE;

				if ((strcasecmp(Msg.To, exitinfo.sUserName) == 0) ||
				    (strcasecmp(Msg.To, exitinfo.sHandle) == 0)) {
					Personal++;
					TotalPersonal++;
				} else if (msgs.Type == NETMAIL) {
					Pack = FALSE;
				}

				if (Pack) {
					Current++;
					Total++;
					memset (&Fti, 0, sizeof (FTI_REC));

					Msg.From[sizeof(Fti.from) - 1] = '\0';
					strcpy((char *)Fti.from, Msg.From);
					Msg.To[sizeof(Fti.to) - 1] = '\0';
					strcpy((char *)Fti.to, Msg.To);
					Msg.Subject[sizeof(Fti.subject) - 1] = '\0';
					strcpy((char *)Fti.subject, Msg.Subject);
					tp = localtime(&Msg.Written);
					sprintf((char *)Fti.date, "%2d %.3s %2d %2d:%02d:%02d", tp->tm_mday, (char *) Language(398 + tp->tm_mon), tp->tm_year, tp->tm_hour, tp->tm_min, tp->tm_sec);
					Fti.msgnum = Number;
					Fti.msgptr = ftell(fdm);
					Fti.replyto = Msg.Original;
					Fti.replyat = Msg.Reply;
					if (msgs.Type == NETMAIL) {
						Fti.orig_zone = msgs.Aka.zone;
						Fti.orig_net  = msgs.Aka.net;
						Fti.orig_node = msgs.Aka.node;
					}

					Fti.msglength += fwrite(" ", 1, 1, fdm);

					if ((Text = (char *)MsgText_First()) != NULL)
						do {
							if ((Text[0] != 0x01 && strncmp(Text, "SEEN-BY: ", 9))||
							    (strncmp(Text, "\001MSGID", 6) == 0) /* || 
							    (exitinfo.OL_ExtInfo) */ ) {
								Fti.msglength += fwrite(Text, 1, strlen(Text), fdm);
								Fti.msglength += fwrite("\r\n", 1, 2, fdm);
							}
						} while ((Text = (char *)MsgText_Next()) != NULL);

					fwrite(&Fti, sizeof (Fti), 1, fdfti);
				}

				if (BarWidth != (unsigned short)((Total * 61L) / TotalPack)) {
					BarWidth = (unsigned short)((Total * 61L) / TotalPack);
					colour(3, 0);
					printf("\r%.*s", BarWidth, "ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл");
					fflush(stdout);
				}
			} while (Msg_Next(&Number));
		}
	}

	Mix.totmsgs = (tWORD)Current;
	Mix.numpers = (tWORD)Personal;
	fwrite(&Mix, sizeof (Mix), 1, fdmix);

	if (fdfti != NULL)
		fclose(fdfti);
	if (fdmix != NULL)
		fclose(fdmix);
	if (fdm != NULL)
		fclose(fdm);

	return Number;
}



// ----------------------------------------------------------------------


void OLR_DownQWK(void)
{
	printf("Not Yet Implemented\n");
	Pause();
}


/*
USHORT TQWK::Create (VOID)
{
   int i;
   FILE *fp;
   USHORT RetVal = FALSE;
   CHAR Temp[128], PktName[32];
   struct dosdate_t date;
   struct dostime_t dtime;

   if (Log != NULL)
      Log->Write ("+Preparing QWK packet");
   MsgTag = User->MsgTag;
   sprintf (PktName, "%s.QWK", Id);

   Total = 0L;
   TotalPersonal = 0L;

   sprintf (Work, "%s%s\\", Cfg->TempPath, User->MailBox);
   sprintf (Path, "%s%s\\", Cfg->UsersHomePath, User->MailBox);

   if (BuildPath (Work) == TRUE) {
      if (MsgTag->First () == TRUE)
         do {
            if (MsgTag->Tagged == TRUE)
               RetVal = TRUE;
         } while (RetVal == FALSE && MsgTag->Next () == TRUE);

      if (RetVal == TRUE) {
         Embedded->Printf ("\n\x16\x01\012Preparing %s packet...\n\n", PktName);

         Embedded->Printf ("\x16\x01\0170%%    10%%  20%%   30%%   40%%   50%%   60%%   70%%   80%%   90%%   100%%\n|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\r");
         Area = 1;
         NewMsgTag.Clear ();
         Blocks = 2L;

         if ((MsgArea = new TMsgData (Cfg->SystemPath)) != NULL) {
            if (MsgTag->First () == TRUE)
               do {
                  if (MsgTag->Tagged == TRUE) {
                     if (MsgArea->Read (MsgTag->Area) == TRUE) {
                        strcpy (NewMsgTag.Area, MsgTag->Area);
                        NewMsgTag.LastRead = MsgTag->LastRead;
                        NewMsgTag.Add ();

                        PackArea (NewMsgTag.LastRead);
                        if (Log != NULL)
                           Log->Write (":  Area %s, %ld msgs. (%ld personal)", NewMsgTag.Area, Current, Personal);

                        NewMsgTag.Update ();
                     }
                     Area++;
                  }
               } while (MsgTag->Next () == TRUE);

            delete MsgArea;
         }

         sprintf (Temp, "%sCONTROL.DAT", Work);
         if ((fp = _fsopen (Temp, "wt", SH_DENYNO)) != NULL) {
            fprintf (fp, "%s\n", Cfg->SystemName);
            fprintf (fp, " \n");
            fprintf (fp, " \n");
            fprintf (fp, "%s\n", Cfg->SysopName);
            fprintf (fp, "00000,%s\n", Id);
            _dos_getdate (&date);
            _dos_gettime (&dtime);
            fprintf (fp, "%02d-%02d-%04d,%02d:%02d:%02d\n", date.month, date.day, date.year, dtime.hour, dtime.minute, dtime.second);
            strcpy (Temp, User->Name);
            fprintf (fp, "%s\n", strupr (Temp));
            fprintf (fp, " \n");
            fprintf (fp, "0\n");
            fprintf (fp, "%lu\n", Total);

            i = 0;
            if (MsgTag->First () == TRUE)
               do {
                  if (MsgTag->Tagged == TRUE)
                     i++;
               } while (MsgTag->Next () == TRUE);
            fprintf (fp, "%d\n", i - 1);

            i = 1;
            if (MsgTag->First () == TRUE)
               do {
                  if (MsgTag->Tagged == TRUE)
                     fprintf (fp, "%d\n%s\n", i++, MsgTag->Area);
               } while (MsgTag->Next () == TRUE);

            fprintf (fp, "WELCOME\n");
            fprintf (fp, "NEWS\n");
            fprintf (fp, "GOODBYE\n");

            fclose (fp);
         }

         sprintf (Temp, "%sDOOR.ID", Work);
         if ((fp = _fsopen (Temp, "wt", SH_DENYNO)) != NULL) {
            fprintf (fp, "DOOR = %s\n", NAME);
            fprintf (fp, "VERSION = %s\n", VERSION);
            fprintf (fp, "SYSTEM = %s\n", NAME);
            fprintf (fp, "CONTROLNAME = LoraQWK\n");
            fprintf (fp, "CONTROLTYPE = ADD\n");
            fprintf (fp, "CONTROLTYPE = DROP\n");
            fclose (fp);
         }

         Log->Write ("*Packed %ld messages (%ld personal)", Total, TotalPersonal);

         if (Total > 0L) {
            if (BuildPath (Path) == TRUE) {
               sprintf (Temp, "%s%s", Path, PktName);
               if (Compress (Temp) == TRUE)
                  Download (Temp, PktName);
            }
         }
      }
   }
   else
      Log->Write ("!Path Error: %s", Work);

   return (RetVal);
}
*/

/*
USHORT TQWK::FetchReply (VOID)
{
   int fdh;
   USHORT RetVal = FALSE, i, r, x, nCol, nWidth, nReaded, nRec;
   CHAR Temp[128], szLine[132], szWrp[132], *pLine, *pBuff;
   ULONG t, Number;
   struct tm *ltm;
   class TMsgTag *MsgTag = User->MsgTag;
   class TCollection MsgText;

   sprintf (Work, "%s%s\\", Cfg->TempPath, User->MailBox);
   BuildPath (Work);

   nWidth = (USHORT)(sizeof (szLine) - 1);
   MsgArea = new TMsgData (Cfg->SystemPath);

   sprintf (Temp, "%s%s.msg", Work, Id);
   if ((fdh = sopen (Temp, O_RDONLY|O_BINARY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
      read (fdh, Temp, 128);
      Temp[8] = '\0';

      while (read (fdh, &Qwk, sizeof (Qwk)) == sizeof (Qwk)) {
         Msg = NULL;

         Area = 1;
         strcpy (Temp, StripSpaces ((PSZ)Qwk.Msgnum, (USHORT)sizeof (Qwk.Msgnum)));

         if (MsgTag->First () == TRUE)
            do {
               if (MsgTag->Tagged == TRUE && Area == (USHORT)atoi (Temp)) {
                  if (MsgArea->Read (MsgTag->Area) == TRUE) {
                     if (Log != NULL)
                        Log->Write (":Message Area: %s - %s", MsgArea->Key, MsgArea->Display);

                     Msg = NULL;
                     if (MsgArea->Storage == ST_JAM)
                        Msg = new JAM (MsgArea->Path);
                     else if (MsgArea->Storage == ST_SQUISH)
                        Msg = new SQUISH (MsgArea->Path);
                     else if (MsgArea->Storage == ST_FIDO)
                        Msg = new FIDOSDM (MsgArea->Path);
                     else if (MsgArea->Storage == ST_ADEPT)
                        Msg = new ADEPT (MsgArea->Path);
                     else if (MsgArea->Storage == ST_HUDSON)
                        Msg = new HUDSON (MsgArea->Path, (UCHAR)MsgArea->Board);
                  }
                  break;
               }
               if (MsgTag->Tagged == TRUE)
                  Area++;
            } while (MsgTag->Next () == TRUE);

         if (Msg == NULL && Log != NULL)
            Log->Write ("!Unknown Forum %s, Skipping", Temp);

         MsgText.Clear ();
         nRec = (USHORT)atoi (StripSpaces ((PSZ)Qwk.Msgrecs, (USHORT)sizeof (Qwk.Msgrecs)));
         pLine = szLine;
         nCol = 0;

         for (r = 1; r < nRec; r++) {
            nReaded = (USHORT)read (fdh, Temp, 128);
            if (r == (USHORT)(nRec - 1)) {
               x = 127;
               while (x > 0 && Temp[x] == ' ') {
                  nReaded--;
                  x--;
               }
            }

            for (i = 0, pBuff = Temp; i < nReaded; i++, pBuff++) {
               if (*pBuff == '\r' || *pBuff == (CHAR)0xE3) {
                  *pLine = '\0';
                  MsgText.Add (szLine);
                  pLine = szLine;
                  nCol = 0;
               }
               else if (*pBuff != '\n') {
                  *pLine++ = *pBuff;
                  nCol++;
                  if (nCol >= nWidth) {
                     *pLine = '\0';
                     while (nCol > 1 && *pLine != ' ') {
                        nCol--;
                        pLine--;
                     }
                     if (nCol > 0) {
                        while (*pLine == ' ')
                           pLine++;
                        strcpy (szWrp, pLine);
                     }
                     *pLine = '\0';
                     MsgText.Add (szLine);
                     strcpy (szLine, szWrp);
                     pLine = strchr (szLine, '\0');
                     nCol = (SHORT)strlen (szLine);
                  }
               }
            }
         }

         if (nCol > 0) {
            *pLine = '\0';
            MsgText.Add (szLine);
         }

         if (MsgArea->EchoMail == TRUE)
            AddKludges (MsgText, MsgArea);

         if (Msg != NULL) {
            Msg->New ();

            strcpy (Msg->From, StripSpaces ((PSZ)Qwk.MsgFrom, (USHORT)sizeof (Qwk.MsgFrom)));
            if (stricmp (Msg->From, User->Name) && stricmp (Msg->From, User->RealName))
               strcpy (Msg->From, User->Name);
            strcpy (Msg->To, StripSpaces ((PSZ)Qwk.MsgTo, (USHORT)sizeof (Qwk.MsgTo)));
            strcpy (Msg->Subject, StripSpaces ((PSZ)Qwk.MsgSubj, (USHORT)sizeof (Qwk.MsgSubj)));

            strcpy (Temp, StripSpaces ((PSZ)Qwk.Msgdate, (USHORT)sizeof (Qwk.Msgdate)));
            Msg->Written.Day = (UCHAR)(atoi (&Temp[3]));
            Msg->Written.Month = (UCHAR)(atoi (Temp));
            Msg->Written.Year = (USHORT)(atoi (&Temp[6]));
            if (Msg->Written.Year < 96)
               Msg->Written.Year += 2000;
            else
               Msg->Written.Year += 1900;

            strcpy (Temp, StripSpaces ((PSZ)Qwk.Msgtime, (USHORT)sizeof (Qwk.Msgtime)));
            Msg->Written.Hour = (UCHAR)(atoi (Temp));
            Msg->Written.Minute = (UCHAR)(atoi (&Temp[3]));
            Msg->Written.Second = 0;

            t = time (NULL);
            ltm = localtime ((time_t *)&t);
            Msg->Arrived.Day = (UCHAR)ltm->tm_mday;
            Msg->Arrived.Month = (UCHAR)(ltm->tm_mon + 1);
            Msg->Arrived.Year = (USHORT)(ltm->tm_year + 1900);
            Msg->Arrived.Hour = (UCHAR)ltm->tm_hour;
            Msg->Arrived.Minute = (UCHAR)ltm->tm_min;
            Msg->Arrived.Second = (UCHAR)ltm->tm_sec;

            Msg->Add (MsgText);
            MsgArea->ActiveMsgs++;
            MsgArea->Update ();

            Number = Msg->Highest ();
            Log->Write (":Written message #%lu (%lu)", Msg->UidToMsgn (Number), Number);
            Embedded->Printf ("\n\x16\x01\x0E<<< CONFIRMED: MESSAGE #%lu WRITTEN TO DISK >>>\n\006\007", Msg->UidToMsgn (Number));

            Msg->Close ();
            delete Msg;
         }

         MsgText.Clear ();
      }

      RetVal = TRUE;
      close (fdh);
   }

   if (MsgArea != NULL)
      delete MsgArea;

   sprintf (Temp, "%s%s.msg", Work, Id);
   unlink (Temp);

   return (RetVal);
}
*/

/*
float TQWK::IEEToMSBIN (float f)
{
   short sign, exp;
   QWKCONV t;

   t.f[0] = f;
   sign = (short)(t.uc[3] / 0x80);
   exp = (short)(((t.ui[1] >> 7) - 0x7F + 0x81) & 0xFF);
   t.ui[1] = (USHORT)((t.ui[1] & 0x7F) | (sign << 7) | (exp << 8));

   return (t.f[0]);
}
*/

/*
VOID TQWK::PackArea (ULONG &ulLast)
{
   int fdm, fdi, fdp;
   float out, in;
   CHAR Temp[128], *Text;
   ULONG Number, Pos, Size;

   Number = ulLast;
   Current = Personal = 0L;

   if (Limit == 0 || Total < Limit) {
      Msg = NULL;
      if (MsgArea->Storage == ST_JAM)
         Msg = new JAM (MsgArea->Path);
      else if (MsgArea->Storage == ST_SQUISH)
         Msg = new SQUISH (MsgArea->Path);
      else if (MsgArea->Storage == ST_FIDO)
         Msg = new FIDOSDM (MsgArea->Path);
      else if (MsgArea->Storage == ST_ADEPT)
         Msg = new ADEPT (MsgArea->Path);
      else if (MsgArea->Storage == ST_HUDSON)
         Msg = new HUDSON (MsgArea->Path, (UCHAR)MsgArea->Board);

      sprintf (Temp, "%s%03d.NDX", Work, Area);
      fdi = sopen (Temp, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, SH_DENYNO, S_IREAD|S_IWRITE);
      lseek (fdi, 0L, SEEK_END);

      sprintf (Temp, "%sPERSONAL.NDX", Work);
      fdp = sopen (Temp, O_WRONLY|O_BINARY|O_CREAT|O_APPEND, SH_DENYNO, S_IREAD|S_IWRITE);
      lseek (fdp, 0L, SEEK_END);

      sprintf (Temp, "%sMESSAGES.DAT", Work);
      if ((fdm = sopen (Temp, O_WRONLY|O_BINARY|O_CREAT, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
         lseek (fdm, 0L, SEEK_END);
         if (tell (fdm) == 0L) {
// ----------------------------------------------------------------------
// The first record of the MESSAGE.DAT file must be the Sparkware id
// block, otherwise some applications may complain.
// ----------------------------------------------------------------------
            write (fdm, "Produced by Qmail...", 20);
            write (fdm, "Copywright (c) 1987 by Sparkware.  ", 35);
            write (fdm, "All Rights Reserved", 19);
            memset (Temp, ' ', 54);
            write (fdm, Temp, 54);
         }
      }

      if (Msg != NULL && fdi != -1 && fdp != -1 && fdm != -1) {
         Msg->Lock (0L);
         if (Msg->Next (Number) == TRUE) {
            do {
               Msg->ReadHeader (Number);
               if (TooOld (MsgTag->OlderMsg, Msg) == FALSE || !stricmp (Msg->To, User->Name) || !stricmp (Msg->To, User->RealName)) {
                  Msg->Read (Number);

                  Current++;
                  Total++;
                  sprintf (Temp, "%lu", Blocks);
                  in = atof (Temp);
                  out = IEEToMSBIN (in);
                  write (fdi, &out, sizeof (float));
                  write (fdi, "", 1);
                  if (!stricmp (Msg->To, User->Name) || !stricmp (Msg->To, User->RealName)) {
                     Personal++;
                     TotalPersonal++;
                     write (fdp, &out, sizeof (float));
                     write (fdp, "", 1);
                  }

                  memset (&Qwk, ' ', sizeof (Qwk));
                  sprintf (Temp, "%-*lu", sizeof (Qwk.Msgnum), Msg->UidToMsgn (Number));
                  memcpy (Qwk.Msgnum, Temp, sizeof (Qwk.Msgnum));
                  sprintf (Temp, "%02d-%02d-%02d", Msg->Written.Month, Msg->Written.Day, Msg->Written.Year % 100);
                  memcpy (Qwk.Msgdate, Temp, sizeof (Qwk.Msgdate));
                  sprintf (Temp, "%02d:%02d", Msg->Written.Hour, Msg->Written.Minute);
                  memcpy (Qwk.Msgtime, Temp, sizeof (Qwk.Msgtime));
                  Msg->From[sizeof (Qwk.MsgFrom) - 1] = '\0';
                  memcpy (Qwk.MsgFrom, Msg->From, strlen (Msg->From));
                  Msg->To[sizeof (Qwk.MsgTo) - 1] = '\0';
                  memcpy (Qwk.MsgTo, Msg->To, strlen (Msg->To));
                  Msg->Subject[sizeof (Qwk.MsgSubj) - 1] = '\0';
                  memcpy (Qwk.MsgSubj, Msg->Subject, strlen (Msg->Subject));
                  Qwk.Msglive = 0xE1;
                  Qwk.Msgarealo = (UCHAR)(Area & 0xFF);
                  Qwk.Msgareahi = (UCHAR)((Area & 0xFF00) >> 8);

                  Pos = tell (fdm);
                  write (fdm, &Qwk, sizeof (Qwk));

                  Size = 128L;
                  if ((Text = (PSZ)Msg->Text.First ()) != NULL)
                     do {
                        if (Text[0] != 0x01 && strnicmp (Text, "SEEN-BY: ", 9)) {
                           Size += (ULONG)write (fdm, Text, strlen (Text));
                           Size += (ULONG)write (fdm, "\xE3", 1);
                        }
                     } while ((Text = (PSZ)Msg->Text.Next ()) != NULL);

                  if ((Size % 128L) != 0) {
                     memset (Temp, ' ', 128);
                     Size += (ULONG)write (fdm, Temp, (int)(128L - (Size % 128L)));
                  }

                  Blocks += (Size / 128L);
                  sprintf (Temp, "%-*lu", sizeof (Qwk.Msgrecs), Size / 128L);
                  memcpy (Qwk.Msgrecs, Temp, sizeof (Qwk.Msgrecs));
                  lseek (fdm, Pos, SEEK_SET);
                  write (fdm, &Qwk, sizeof (Qwk));
                  lseek (fdm, 0L, SEEK_END);
#if defined(__OS2__)
                  if ((Total % 16L) == 0L)
                     DosSleep (1L);
#elif defined(__NT__)
                  if ((Total % 16L) == 0L)
                     Sleep (1L);
#endif
                  if (BarWidth != (USHORT)((Total * 61L) / TotalPack)) {
                     BarWidth = (USHORT)((Total * 61L) / TotalPack);
                     Embedded->Printf ("\r%.*s", BarWidth, "ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл");
                  }
               }
            } while ((Limit == 0 || Total < Limit) && Msg->Next (Number) == TRUE);
         }
         Msg->UnLock ();
      }

      if (Msg != NULL) {
         Msg->Close ();
         delete Msg;
      }
      if (fdm != -1)
         close (fdm);
      if (fdi != -1)
         close (fdi);
      if (fdp != -1)
         close (fdp);
   }

   ulLast = Number;
}
*/

/*
PSZ TQWK::StripSpaces (PSZ pszString, USHORT usSize)
{
   USHORT x;

   memcpy (TempStr, pszString, usSize);
   TempStr[usSize] = '\0';
   if ((x = (USHORT)(usSize - 1)) > 0) {
      while (x > 0 && TempStr[x] == ' ')
         TempStr[x--] = '\0';
   }

   return (TempStr);
}
*/

// ----------------------------------------------------------------------


void OLR_DownASCII(void)
{
	printf("Not Yet Implemented\n");
	Pause();
}


/*
USHORT TAscii::Create (VOID)
{
   USHORT RetVal = FALSE;
   CHAR Temp[128], PktName[32];

   if (Log != NULL)
      Log->Write ("+Preparing Ascii packet");
   MsgTag = User->MsgTag;
   sprintf (PktName, "%s.MSG", Id);

   Total = 0L;
   TotalPersonal = 0L;

   sprintf (Work, "%s%s\\", Cfg->TempPath, User->MailBox);
   sprintf (Path, "%s%s\\", Cfg->UsersHomePath, User->MailBox);

   if (BuildPath (Work) == TRUE) {
      if (MsgTag->First () == TRUE)
         do {
            if (MsgTag->Tagged == TRUE)
               RetVal = TRUE;
         } while (RetVal == FALSE && MsgTag->Next () == TRUE);

      if (RetVal == TRUE) {
         Embedded->Printf ("\n\x16\x01\012Preparing %s packet...\n\n", PktName);

         Embedded->Printf ("\x16\x01\0170%%    10%%  20%%   30%%   40%%   50%%   60%%   70%%   80%%   90%%   100%%\n|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\r");
         Area = 1;
         NewMsgTag.Clear ();

         if ((MsgArea = new TMsgData (Cfg->SystemPath)) != NULL) {
            if (MsgTag->First () == TRUE)
               do {
                  if (MsgTag->Tagged == TRUE) {
                     if (MsgArea->Read (MsgTag->Area) == TRUE) {
                        strcpy (NewMsgTag.Area, MsgTag->Area);
                        NewMsgTag.LastRead = MsgTag->LastRead;
                        NewMsgTag.Add ();

                        PackArea (NewMsgTag.LastRead);
                        if (Log != NULL)
                           Log->Write (":  Area %s, %ld msgs. (%ld personal)", NewMsgTag.Area, Current, Personal);

                        NewMsgTag.Update ();
                        Area++;
                     }
                  }
               } while (MsgTag->Next () == TRUE);

            delete MsgArea;
         }

         if (Log != NULL)
            Log->Write ("*Packed %ld messages (%ld personal)", Total, TotalPersonal);

         if (Total > 0L) {
            if (BuildPath (Path) == TRUE) {
               sprintf (Temp, "%s%s", Path, PktName);
               if (Compress (Temp) == TRUE)
                  Download (Temp, PktName);
            }
         }
      }
   }
   else if (Log != NULL)
      Log->Write ("!Path Error: %s", Work);

   return (RetVal);
}
*/

/*
VOID TAscii::PackArea (ULONG &ulLast)
{
   FILE *fp;
   CHAR Temp[128], *Text;
   ULONG Number;

   Number = ulLast;
   Current = Personal = 0L;

   if (Limit == 0 || Total < Limit) {
      if (MsgArea->Storage == ST_JAM)
         Msg = new JAM (MsgArea->Path);
      else if (MsgArea->Storage == ST_SQUISH)
         Msg = new SQUISH (MsgArea->Path);
      else if (MsgArea->Storage == ST_FIDO)
         Msg = new FIDOSDM (MsgArea->Path);
      else if (MsgArea->Storage == ST_ADEPT)
         Msg = new ADEPT (MsgArea->Path);
      else if (MsgArea->Storage == ST_HUDSON)
         Msg = new HUDSON (MsgArea->Path, (UCHAR)MsgArea->Board);

      sprintf (Temp, "%s%03d.TXT", Work, Area);
      fp = _fsopen (Temp, "wt", SH_DENYNO);

      if (Msg != NULL && fp != NULL) {
         Msg->Lock (0L);
         if (Msg->Next (Number) == TRUE) {
            do {
               Msg->ReadHeader (Number);
               if (TooOld (MsgTag->OlderMsg, Msg) == FALSE || !stricmp (Msg->To, User->Name) || !stricmp (Msg->To, User->RealName)) {
                  Msg->Read (Number);

                  fprintf (fp, "\n==============================================\n    Msg. #%ld of %ld (%s)\n", Msg->UidToMsgn (Number), Msg->Number (), MsgArea->Display);
                  fprintf (fp, "   Date: %d %s %d %2d:%02d\n", Msg->Written.Day, Language->Months[Msg->Written.Month - 1], Msg->Written.Year, Msg->Written.Hour, Msg->Written.Minute);
                  fprintf (fp, "   From: %s\n", Msg->From);
                  if (Msg->To[0])
                     fprintf (fp, "     To: %s\n", Msg->To);
                  fprintf (fp, "Subject: %s\n----------------------------------------------\n", Msg->Subject);

                  Current++;
                  Total++;
                  if (!stricmp (Msg->To, User->Name) || !stricmp (Msg->To, User->RealName)) {
                     Personal++;
                     TotalPersonal++;
                  }

                  if ((Text = (PSZ)Msg->Text.First ()) != NULL)
                     do {
                        if (Text[0] != 0x01 && strnicmp (Text, "SEEN-BY: ", 9))
                           fprintf (fp, "%s\n", Text);
                     } while ((Text = (PSZ)Msg->Text.Next ()) != NULL);
#if defined(__OS2__)
                  if ((Total % 16L) == 0L)
                     DosSleep (1L);
#elif defined(__NT__)
                  if ((Total % 16L) == 0L)
                     Sleep (1L);
#endif
                  if (BarWidth != (USHORT)((Total * 61L) / TotalPack)) {
                     BarWidth = (USHORT)((Total * 61L) / TotalPack);
                     Embedded->Printf ("\r%.*s", BarWidth, "ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл");
                  }
               }
            } while ((Limit == 0 || Total < Limit) && Msg->Next (Number) == TRUE);
         }
         Msg->UnLock ();
      }

      if (Msg != NULL) {
         Msg->Close ();
         delete Msg;
      }
      if (fp != NULL)
         fclose (fp);
   }

   ulLast = Number;
}
*/

// ----------------------------------------------------------------------


void OLR_DownPnt()
{
	printf("Not Yet Implemented\n");
	Pause();
}


/*

USHORT TPoint::Create (VOID)
{
   USHORT RetVal = FALSE;
   CHAR Temp[128], PktName[32];
   struct dosdate_t date;

   if (Log != NULL)
      Log->Write ("+Preparing PointMail packet");
   MsgTag = User->MsgTag;
   _dos_getdate (&date);
   sprintf (PktName, "%08lX%s", StringCrc32 (Id, 0xFFFFFFFFL), Extensions[date.dayofweek]);

   Total = 0L;
   TotalPersonal = 0L;

   sprintf (Work, "%s%s\\", Cfg->TempPath, User->MailBox);
   sprintf (Path, "%s%s\\", Cfg->UsersHomePath, User->MailBox);

   if (BuildPath (Work) == TRUE) {
      if (MsgTag->First () == TRUE)
         do {
            if (MsgTag->Tagged == TRUE)
               RetVal = TRUE;
         } while (RetVal == FALSE && MsgTag->Next () == TRUE);

      if (RetVal == TRUE) {
         Embedded->Printf ("\n\x16\x01\012Preparing %s packet...\n\n", PktName);

         Embedded->Printf ("\x16\x01\0170%%    10%%  20%%   30%%   40%%   50%%   60%%   70%%   80%%   90%%   100%%\n|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\r");
         Area = 1;
         NewMsgTag.Clear ();

         if ((MsgArea = new TMsgData (Cfg->SystemPath)) != NULL) {
            if (MsgTag->First () == TRUE)
               do {
                  if (MsgTag->Tagged == TRUE) {
                     if (MsgArea->Read (MsgTag->Area) == TRUE) {
                        strcpy (NewMsgTag.Area, MsgTag->Area);
                        NewMsgTag.LastRead = MsgTag->LastRead;
                        NewMsgTag.Add ();

                        PackArea (NewMsgTag.LastRead);
                        if (Log != NULL)
                           Log->Write (":  Area %s, %ld msgs. (%ld personal)", NewMsgTag.Area, Current, Personal);

                        NewMsgTag.Update ();
                        Area++;
                     }
                  }
               } while (MsgTag->Next () == TRUE);

            delete MsgArea;
         }

         if (Log != NULL)
            Log->Write ("*Packed %ld messages (%ld personal)", Total, TotalPersonal);

         if (Total > 0L) {
            if (BuildPath (Path) == TRUE) {
               sprintf (Temp, "%s%s", Path, PktName);
               if (Compress (Temp) == TRUE)
                  Download (Temp, PktName);
            }
         }
      }
   }
   else if (Log != NULL)
      Log->Write ("!Path Error: %s", Work);

   return (RetVal);
}
*/

/*
VOID TPoint::PackArea (ULONG &ulLast)
{
   CHAR Temp[128], *Text;
   ULONG Number;
   class PACKET *Packet;

   Number = ulLast;
   Current = Personal = 0L;

   if (Limit == 0 || Total < Limit) {
      if (MsgArea->Storage == ST_JAM)
         Msg = new JAM (MsgArea->Path);
      else if (MsgArea->Storage == ST_SQUISH)
         Msg = new SQUISH (MsgArea->Path);
      else if (MsgArea->Storage == ST_FIDO)
         Msg = new FIDOSDM (MsgArea->Path);
      else if (MsgArea->Storage == ST_ADEPT)
         Msg = new ADEPT (MsgArea->Path);
      else if (MsgArea->Storage == ST_HUDSON)
         Msg = new HUDSON (MsgArea->Path, (UCHAR)MsgArea->Board);

      if ((Packet = new PACKET) != NULL) {
         if (Cfg->MailAddress.First () == TRUE) {
            strcpy (Packet->FromAddress, Cfg->MailAddress.String);
            strcpy (Packet->ToAddress, Cfg->MailAddress.String);
         }
         sprintf (Temp, "%s%08lX.PKT", Work, time (NULL));
         Packet->Open (Temp);
      }

      if (Msg != NULL && Packet != NULL) {
         Msg->Lock (0L);
         if (Msg->Next (Number) == TRUE) {
            do {
               Msg->ReadHeader (Number);
               if (TooOld (MsgTag->OlderMsg, Msg) == FALSE || !stricmp (Msg->To, User->Name) || !stricmp (Msg->To, User->RealName)) {
                  Msg->Read (Number);

                  Current++;
                  Total++;
                  if (!stricmp (Msg->To, User->Name) || !stricmp (Msg->To, User->RealName)) {
                     Personal++;
                     TotalPersonal++;
                  }

                  if ((Text = (CHAR *)Msg->Text.First ()) != NULL)
                     do {
                        if (!strncmp (Text, "SEEN-BY: ", 9) || !strncmp (Text, "\001PATH: ", 7)) {
                           Msg->Text.Remove ();
                           Text = (CHAR *)Msg->Text.Value ();
                        }
                        else
                           Text = (CHAR *)Msg->Text.Next ();
                     } while (Text != NULL);

                  if (Cfg->MailAddress.First () == TRUE) {
                     sprintf (Temp, "SEEN-BY: %u/%u", Cfg->MailAddress.Net, Cfg->MailAddress.Node);
                     Msg->Text.Add (Temp, (USHORT)(strlen (Temp) + 1));
                     sprintf (Temp, "\001PATH: %u/%u", Cfg->MailAddress.Net, Cfg->MailAddress.Node);
                     Msg->Text.Add (Temp, (USHORT)(strlen (Temp) + 1));
                  }

                  if ((Text = (CHAR *)Msg->Text.First ()) != NULL) {
                     if (MsgArea->EchoTag[0] != '\0')
                        sprintf (Temp, "AREA:%s", MsgArea->EchoTag);
                     else
                        sprintf (Temp, "AREA:%s", MsgArea->Key);
                     Msg->Text.Insert (Temp, (USHORT)(strlen (Temp) + 1));
                     Msg->Text.Insert (Text, (USHORT)(strlen (Text) + 1));
                     Msg->Text.First ();
                     Msg->Text.Remove ();
                  }

                  Packet->Add (Msg);
#if defined(__OS2__)
                  if ((Total % 16L) == 0L)
                     DosSleep (1L);
#elif defined(__NT__)
                  if ((Total % 16L) == 0L)
                     Sleep (1L);
#endif
                  if (BarWidth != (USHORT)((Total * 61L) / TotalPack)) {
                     BarWidth = (USHORT)((Total * 61L) / TotalPack);
                     Embedded->Printf ("\r%.*s", BarWidth, "ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл");
                  }
               }
            } while ((Limit == 0 || Total < Limit) && Msg->Next (Number) == TRUE);
         }
         Msg->UnLock ();
      }

      if (Msg != NULL) {
         Msg->Close ();
         delete Msg;
      }
      if (Packet != NULL) {
         Packet->Close ();
         delete Packet;
      }
   }

   ulLast = Number;
}
*/

/*
USHORT TPoint::FetchReply (VOID)
{
   DIR *dir;
   USHORT RetVal = FALSE, Found;
   CHAR Temp[128], LastTag[64], *Text;
   ULONG Number, Written;
   class PACKET *Packet;
   class dirent *ent;

   sprintf (Work, "%s%s\\", Cfg->TempPath, User->MailBox);
   BuildPath (Work);

   MsgArea = new TMsgData (Cfg->SystemPath);
   LastTag[0] = '\0';
   Msg = NULL;

   if ((dir = opendir (Work)) != NULL) {
      while ((ent = readdir (dir)) != NULL) {
         if (strstr (ent->d_name, ".pk") != NULL || strstr (ent->d_name, ".PK") != NULL) {
            sprintf (Temp, "%s%s", Work, ent->d_name);
            if ((Packet = new PACKET) != NULL) {
               if (Packet->Open (Temp) == TRUE) {
                  Number = Packet->Lowest ();
                  do {
                     if (Packet->Read (Number) == TRUE) {
                        if ((Text = (CHAR *)Packet->Text.First ()) != NULL) {
                           if (!strncmp (Text, "AREA:", 5)) {
                              if (stricmp (&Text[5], LastTag)) {
                                 if (Msg != NULL) {
                                    Msg->Close ();
                                    delete Msg;
                                    Msg = NULL;
                                 }
                                 strcpy (LastTag, &Text[5]);
                                 Found = FALSE;
                                 if (MsgArea->First () == TRUE)
                                    do {
                                       if (MsgArea->EchoTag[0] != '\0' && !stricmp (MsgArea->EchoTag, LastTag)) {
                                          Found = TRUE;
                                          break;
                                       }
                                       else if (MsgArea->EchoTag[0] == '\0' && !stricmp (MsgArea->Key, LastTag)) {
                                          Found = TRUE;
                                          break;
                                       }
                                    } while (MsgArea->Next () == TRUE);
                                 if (Found == TRUE) {
                                    if (Log != NULL)
                                       Log->Write (":Message Area: %s - %s", MsgArea->Key, MsgArea->Display);

                                    Msg = NULL;
                                    if (MsgArea->Storage == ST_JAM)
                                       Msg = new JAM (MsgArea->Path);
                                    else if (MsgArea->Storage == ST_SQUISH)
                                       Msg = new SQUISH (MsgArea->Path);
                                    else if (MsgArea->Storage == ST_FIDO)
                                       Msg = new FIDOSDM (MsgArea->Path);
                                    else if (MsgArea->Storage == ST_ADEPT)
                                       Msg = new ADEPT (MsgArea->Path);
                                    else if (MsgArea->Storage == ST_HUDSON)
                                       Msg = new HUDSON (MsgArea->Path, (UCHAR)MsgArea->Board);
                                 }
                              }

                              // Toglie la prima linea che contiene il kludge AREA:
                              Packet->Text.Remove ();

                              // Nel caso di un'area echomail, aggiunge tutti i kludges
                              // Necessari.
                              if (MsgArea->EchoMail == TRUE)
                                 AddKludges (Packet->Text, MsgArea);

                              if (Msg != NULL) {
                                 if (stricmp (Packet->From, User->Name) && stricmp (Packet->From, User->RealName))
                                    strcpy (Packet->From, User->Name);
                                 if ((Text = (CHAR *)Packet->Text.First ()) != NULL)
                                    do {
                                       if (!strncmp (Text, "SEEN-BY: ", 9) || !strncmp (Text, "\001PATH: ", 7)) {
                                          Packet->Text.Remove ();
                                          Text = (CHAR *)Packet->Text.Value ();
                                       }
                                       else
                                          Text = (CHAR *)Packet->Text.Next ();
                                    } while (Text != NULL);

                                 Msg->Add (Packet);
                                 MsgArea->ActiveMsgs++;
                                 MsgArea->Update ();

                                 Written = Msg->Highest ();
                                 Log->Write (":Written message #%lu (%lu)", Msg->UidToMsgn (Number), Number);
                                 Embedded->Printf ("\n\x16\x01\x0E<<< CONFIRMED: MESSAGE #%lu WRITTEN TO DISK >>>\n\006\007", Msg->UidToMsgn (Number));
                              }
                           }
                        }
                     }
                  } while (Packet->Next (Number) == TRUE);
               }
               Packet->Close ();
               delete Packet;
            }
            sprintf (Temp, "%s%s", Work, ent->d_name);
            unlink (Temp);
         }
      }
      closedir (dir);
   }

   if (Msg != NULL) {
      Msg->Close ();
      delete Msg;
   }
   if (MsgArea != NULL)
      delete MsgArea;

   return (RetVal);
}
*/


