#ifndef __MAIL_H
#define __MAILER_H

// $Id: mailer.h,v 1.5 1994/02/20 19:15:22 gbj Exp user $

/* $Log: mailer.h,v $
 * Revision 1.5  1994/02/20  19:15:22  gbj
 * Updated global var comments.
 *
 * Revision 1.4  1994/02/20  19:12:52  gbj
 * Added alias global var.
 *
 * Revision 1.3  1994/02/08  23:31:16  gbj
 * First public release.
 *
 * Revision 1.2  1994/02/08  03:07:38  gbj
 * Fixed Log commenting.
 *
 * Revision 1.1  1994/02/08  03:06:26  gbj
 * Initial revision
 *
*/

//=========================================================
//
//	mailer.tos
//
//	A simple mailer for use with NOS on the Atart ST.
//
//	Written by G B Judd, December 1993 (c) G B Judd 1993, 1994.
//
//	email:     gjudd@siward.demon.co.uk
//	           gjudd@cix.compulink.co.uk
//
//
//	This program is supplied under the FSF 'Copyleft' conditions.
//	See the file COPYING.FSF.
//
//	mailer.tos is supplied "as is" without any warranty of any kind.
//	You use it ENTIRELY AT YOUR OWN RISK.  I do not accept ANY
//	responsibility for its use or misuse.
//	
//	You can send bug reports to one, or both, of the email addresses
//	above.  I cannot guarantee to respond to any bug report or
//	suggestion for improvement.
//
//	You have the right to modify the source of this program any way
//	you like bit I would appreciate you indicating what you have done,
//	by whom and when in the Modification Section below.
//
//	I would also appreciate being informed of what you have done.
//
//	I shall not be responsible for any modifications carried out
//	whether by me or otherwise and it is entirely my right to determine 
//	whether any modification was carried out by me.
//
//	MODIFICATION SECTION
//
//  Date	Who							Version
//
//	931220  G B Judd					1.0
//				Initial Version
//
//	940109	G B Judd					1.1
//				Fixed problems with quoting messages, bumping
//				message number when reading a message, and
//				scanning Reply_To:/From: for <....>
//
//	940112	G B Judd					1.2
//				Fixed looping problem in list.c, response
//				to Continue was incorrect.
//
//	940112	G B Judd					1.3
//				Completely changed the processing of the From
//				flag line.  Made it as simplistic as possible
//				because I can't be bothered dealing with the
//				various formats that it can be - will have to
//				handle this properly sometime.  This means that
//				it is possible that a line within the mail body
//				starting 'From ' will be treated as a header.
//
//	940208	G B Judd					1.4
//				Fixed problem where quoted header lines which
//				did not have a > in front of them were being
//				treated as proper header lines in loadix.
//
//	940208	G B Judd					1.5
//				Changed VERSION to reflect RCS revision level
//				of main.c
//
//	940208	G B Judd					1.6
//				Added new command '\n' which reads the next
//				UNREAD message.  The mailbox index is always
//				searched from 0 to maxmsgno.  If an UNREAD
//				message is found, it is shown and then its
//				status is changed to READ.  The current
//				message pointer is updated to this message.
//
//	940208	G B Judd					1.7
//				First which can be released into the Public Domain.
//
//	940211	G B Judd					1.8
//				Enabled blinking cursor.
//
//	940214 G B Judd						1.9
//				Incorporated A K Jones modifications to
//				maintain an outgoing mail log.
//
//	940220 G B Judd						1.10
//				Added mail aliasing.
//=========================================================

extern char VERSION[];

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>
#include <error.h>
#include <osbind.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>

#ifndef TRUE
#	define TRUE	1
#endif
#ifndef FALSE
#	define FALSE 0
#endif


//=========================================================
//	DATA STRUCTURES
//=========================================================

// Runtime mailbox index
typedef struct MAILIX
{
	int msgno;				// message number within mbox
	int rflag;				// 0=not read, !0=read;
	int dflag;				// 0=not marked, !0=marked for delete
	char sender[128];		// Sender Id, truncated to 50 chars
	char subject[128];		// Subject, truncated to 28 chars
	char msgdate[13];		// dd mmm yy
	char replyto[128];		// Reply-To: or From:
	long fpos;				// Start byte of FLAG line for this message
} MAILIX;

typedef enum COMMAND
{
	BAD=0, DELETE, MAIL, SAVE, WRITE, MAILFILE, REPLY, FORWARD,
	UNDELETE, NEXT, PREV, PRINT, HEADER, LIST, NEW, READ, QUIT, QUITX,
	HELP, UNREAD
} COMMAND;

// defined in storage.c
extern MAILIX mailix[];		// Runtime mailbox index

// YUK,YUK,YUK - loads of global variables...
// Should be in a structure so that a pointer to it can be passed
// around - may do this one day!
// All defined in storage.c	
extern int maxmsgno;		// Last used element in mailix[]
extern char mailpath[];		// Full pathname of mail directory
extern char mqueuepath[];	// Full pathname of mqueue directory
extern char mbox[];			// Full pathname of current mailbox
extern char sequence[];		// Full pathname of sequence file
extern char txt[];			// Full pathname of .txt file
extern char wrk[];			// Full pathname of .wrk file
extern char tmp[];			// Full pathname of .tmp file
extern char host[];			// Hostname
extern char reply[];		// Reply-To:
extern char name[];			// Full-name
extern char edit[];			// Full pathname of your editor
extern char from[];			// From:
extern char user[];			// User mailbox id
extern char mail[];			// Path to dir containing mail/mqueue dirs
extern char sig[];			// Path to your signature file
extern char log[];			// Path to your outgoing mail log
extern char alias[];		// Path to your mail alias file
extern FILE *mfd;			// Mailbox fd
extern FILE *sfd;			// Sequence fd
extern FILE *tfd;			// .txt fd
extern FILE *wfd;			// .wrk fd
extern FILE *xfd;			// .tmp fd

extern int cmsg;			// Current message #

//=========================================================
//	PROTOTYPES
//=========================================================

void main(void);
void init(char *version);
int loadix(char *user);
void showix(int from_msg, int cur_msg);
COMMAND getcmd(int *msgno, char *user, char *file);
void mark(int msg, int delete);
void mailto(char *user, char *file);
void saveto(char *file, int header);
void replyto(int msg);
void forwardto(int msg, char *user);
void bump(int direction);
void listqueue(void);
void newmbox(char *mbox);
void quit(int update);
void help(void);

#endif
