/*
 * 3binary.h type 3binary mail include file revision 2
 * contains data types, defines and prototypes for type 3binary
 * sample code.  Public Domain from M. Kimes.  You're welcome.
 */

#ifdef OS2
  /*
   * this includes typedefs we use (SHORT and USHORT, 16-bit ints)
   */
  #define INCL_DOS
  #include <os2.h>
#endif

#ifdef NEEDTYPEDEFS
  /*
   * these definitions are for 16-bit machines
   * they match up with the definitions provided by os2.h
   * as included above and used in the code.  Modify as required.
   */
  typedef SHORT  short
  typedef USHORT unsigned short
#endif

typedef struct CHUNK3 {   /* structure to hold a single element */
  SHORT         len;      /* 2 bytes signed -- max single chunk 32767 bytes */
  USHORT        type;     /* 65536 possible types -- above 32767 for exper. */
  void          *data;    /* pointer to anything */
  struct CHUNK3 *next;    /* for linked listing */
} CHUNK3;

  /* note:  this is unambiguous and won't break like a *nix-style long */
typedef struct {          /* "packed" time/date format */
  USHORT       year;      /* 1993-???? */
  char         mon;       /* 1-12 */
  char         mday;      /* 1-31 as allowed by month */
  char         hour;      /* 0-23 */
  char         min;       /* 0-59 */
  char         sec;       /* 0-59 */
  char         pad;       /* alignment */
  SHORT        gmtoff;    /* in 15 min. increments, -32767 = n/a */
} BINDATE3;

/* attribute bits */

#define ATTR_PRIVATE 0x00000001
#define ATTR_AUDIT   0x00000002
#define ATTR_RRQ     0x00000004

#define IS3PKT     0x0003 /* first word of msg; ids type 3 binary packet */

/* defined chunk types */

#define MAXKNOWN 29

#define EOP3      0   /* end of pkt (always 0 length) */
#define FROM3     1   /* from name@address (ASCII) */
#define TO3       2   /* to name@[address] (ASCII) */
#define SUBJ3     3   /* subject (ASCII) */
#define ID3       4   /* unique identifier (long) */
#define REF3      5   /* reference (long + ASCII) */
#define DATE3     6   /* date/time (BINDATE3 structure) */
#define ATTRIB3   7   /* attributes (ATTR3 structure) */
#define PASSWORD3 8   /* password (ASCII) */
#define PRODUCT3  9   /* product name (ASCII) follow by space w/ version # */
#define AREA3     10  /* ECHO area tag (ASCII) */
#define MSG3      11  /* start of msg, data = (int || long) total msg len */
#define TEXT3     12  /* msg text chunk (ASCII) */
#define ORIG3     13  /* "foreign" origin address of a msg if req'd */
#define ORIGID3   14  /* aw, see FSC-0066 for the rest... */
#define FONT3     15
#define CHARSET3  16
#define RICH3     17
#define SUB3      18
#define GROUP3    19
#define ATTACH3   20
#define DEST3     21
#define QUOTE3    22
#define GLOBAL3   23
#define ENCRYPT3  24
#define ADD3      25
#define DROP3     26
#define REPORT3   27
#define PKT3      28

/* error returns */

#define MAXERR3    13

#define NOERR3     0
#define NOMEM3     1
#define READERR3   2
#define WRITEERR3  3
#define SEEKERR3   4
#define OPENERR3   5
#define NOTPKT3    6
#define BADCHUNK3  7
#define BADPKTHDR3 8
#define SHORTPKT3  9
#define BADLENGTH3 10
#define BADADDR3   11
#define MISSING3   12
#define BADAREA3   13

/* functions I provide */

void error3 (int error);                                    /* 3error.c */

USHORT swap3 (USHORT ab);                                   /* 3swap.c */
long   swap3l (long abcd);                                  /* 3swap.c */

char * nstrdup3 (char *dupme,SHORT len);                    /* 3strdup.c */

USHORT write_chunk3 (FILE *handle,CHUNK3 *info,int *error); /* 3binout.c */
long write_chunk3_list (FILE *handle, USHORT type,
                        CHUNK3 *info,int *error);           /* 3binout.c */
int write_eop3 (FILE *handle);                              /* 3binout.c */
FILE *wopen_pkt3 (char *filename,CHUNK3 *pkt3,int *error);  /* 3binout.c */
FILE *wclose_pkt3 (FILE *handle);                           /* 3binout.c */
size_t align_fwrite (char *data,int size,int count,
                     FILE *handle);                         /* 3binout.c */

long process_pkt3 (void *anon,char *filename,int *error);   /* 3binin.c */
CHUNK3 * free_chunk3 (CHUNK3 *chunk);                       /* 3binin.c */
CHUNK3 * free_chunk3_list (CHUNK3 *chunk);                  /* 3binin.c */
CHUNK3 * verify_chunk3_list_item (CHUNK3 *list,USHORT type);/* 3binin.c */
#define verify_chunk3_list_next(l,t)\
        verify_chunk3_list_item((l) ? (l)->next : (l),(t))
int read_chunk3 (FILE *handle,CHUNK3 *chunk);               /* 3binin.c */
CHUNK3 * read_chunk3_list (FILE *handle,USHORT type,
                           long totallen,int *error);       /* 3binin.c */
CHUNK3 * copy_chunk3 (CHUNK3 *chunk);                       /* 3binin.c */
size_t align_fread (char *data,int size,int count,
                    FILE *handle);                          /* 3binin.c */


/* "callback" functions you provide */

check_3bpkthdr(void *anon,char *filename,CHUNK3 *pkt3,CHUNK3 *globals,
               long hdrlen,int *error);
import_3bmsg(void *anon,CHUNK3 *pkt3,CHUNK3 *msg3,CHUNK3 *globals,
             long msglen,int *error);
void end_3bmsg (void *priv,CHUNK3 *pkt3,CHUNK3 *msg3,CHUNK3 *globals);
void process_unknown_chunk3(FILE *handle,USHORT type,long chunklen,int *error);
