/* 3mail.h
 *
 * type 3 ASCII include file
 * Public Domain from M. Kimes.  You're welcome.
 *
 */

/* types */

typedef struct __tag3__ {   /* singly linked list */
    char *tag;
    char *data;
    struct __tag3__ *next;
} TAG3;

typedef struct __mheader3__ {
    char *from;
    char *to;
    char *subj;
    char *date;
    char *area;
    char *id;
    char *ref;
    TAG3 *head; } MHDR3;

typedef struct __pheader3__ {
  char *from;
  char *to;
  char *creator;
  char *pword;
  char *area;
  TAG3 *head;
} PHDR3;

/* constants */

#define BLKSIZE3    4096
#define MAXERR3     9
#define MAXRESYNC3  15
#define ASCII3ID    "3ASCII"

 /* errors returned in *error */

#define NOERR3      0
#define NOMEM3      1
#define NOOPEN3     2
#define READERR3    3
#define BADPKTHDR3  4
#define BADMSGHDR3  5
#define NOTPKT3     6
#define BADWRITE3   7
#define BADSEEK3    8
#define EOP3        9

/* functions for reading a type 3 ASCII packet (see 3mailin.c) */

int     open_3pkt         (int fhandle,char *fname,int *error);
int     close_3pkt        (int fhandle);
PHDR3 * free_3pkthdr      (PHDR3 *cpkt);
MHDR3 * free_3msghdr      (MHDR3 *cmsg);
PHDR3 * create_3pkthdr    (void);
MHDR3 * create_3msghdr    (void);
PHDR3 * read_3pkthdr      (int fhandle,PHDR3 *cpkt,int *error);
MHDR3 * read_3msghdr      (int fhandle,MHDR3 *cmsg,int *error);
int     read_3msgtext     (int fhandle,char *msg,int buflen,int *error);
long    find_next_3msg    (int fhandle,int *error);
long    process_3pkt      (void *data,char *fname,int *error);

/* bbs/mailer-specific functions called by 3mailin.c (you write 'em) */

int     import_3msg       (void *data,PHDR3 *pkt,MHDR3 *msg,char *body,
                           int len,int *error);
int     appendin_3msg     (void *data,PHDR3 *pkt,MHDR3 *msg,char *body,
                           int len,int *error);
int     check_3pkthdr     (void *data,char *fname,PHDR3 *pkt,int *error);
int     check_3msghdr     (void *data,MHDR3 *msg,int *error);
#ifdef TRANSLATING
  void end_3msg (void *priv,PHDR3 *pkt3,MHDR3 *msg);
#endif

/* functions for writing a type 3 ASCII packet (see 3mailout.c) */

void    finish_3pktpart   (int fhandle,int *error);
int     write_3tag        (int fhandle,char *tag,char *data,int *error);
int     write_3tags       (int fhandle,TAG3 *head,int *error);
int     write_3pkthdr     (int fhandle,PHDR3 *cpkt,int *error);
int     wopen_3pkt        (int fhandle,char *fname,PHDR3 *cpkt,int *error);
int     wclose_3pkt       (int fhandle);
int     write_3msghdr     (int fhandle,MHDR3 *cmsg,int *error);
int     write_3msgtext    (int fhandle,char *text,int textlen,int *error);

/* display an error message to stdout (see 3aerror.c) */

void error3a (int error);

/* support functions (see 3supp.c) */

char *  fgets3            (char *buf,int buflen,int handle);
char *  stripcr3          (char *str);
int     stripjnk3         (char *str,int len);
char *  strdup3           (char *dupme);
