/*
**      $VER: mailpro.h 1.0 (5.3.99)
**
**      main include file for mailpro.library
**
**      (C) Copyright 1999 Sergeev O.V.
**      All Rights Reserved.
*/

#ifndef MAIL_MAILPRO_H
#define MAIL_MAILPRO_H

#ifndef EXEC_LISTS_H
#include "exec/lists.h"
#endif  /* EXEC_LISTS_H */

/* Header of 4D packet which is used at main */
struct PacketHeader
{
  UWORD  ph_OrigNode;    /* Originating node of packet, not of messages in packet */
  UWORD  ph_DestNode;    /* Destination node of packet, not of messages in packet */
  UWORD  ph_Year;        /* Year of packet creation, e.g. 1986                    */
  UWORD  ph_Month;       /* Month of packet creation, 0-11 for Jan-Dec            */
  UWORD  ph_Day;         /* Day of packet creation, 1-31                          */
  UWORD  ph_Hour;        /* Hour of packet creation, 0-23                         */
  UWORD  ph_Minute;      /* Minute of packet creation, 0-59                       */
  UWORD  ph_Second;      /* Second of packet creation, 0-59                       */
  UWORD  ph_Baud;        /* Maximal baud rate of orig and dest                    */
  UWORD  ph_PktVer;      /* PacketType (2); old type (1) packets now obsolete     */
  UWORD  ph_OrigNet;     /* Originating net of packet, not of messages in packet set to -1 if orig = point */
  UWORD  ph_DestNet;     /* Destination net of packet, not of messages in packet  */
  UBYTE  ph_ProdCodeLo;  /* Product Code low byte; 0 for Fido, write to FTSC for others */
  UBYTE  ph_RevisionHi;  /* Binary serial number major byte (otherwise null)      */
  UBYTE  ph_Password[8]; /* Session pasword (null padded)                         */
  UWORD  ph_OrigZone;    /* Originating zone of packet sender (otherwise null)    */
  UWORD  ph_DestZone;    /* Destination zone of packet receiver (otherwise null)  */
  UWORD  ph_AuxNet;      /* Contains OrigNet if Origin is a point                 */
  UWORD  ph_CWValCopy;   /* CWvalidationCopy must be equal to CW to be valid      */
  UBYTE  ph_ProdCodeHi;  /* Product Code high byte                                */
  UBYTE  ph_RevisionLo;  /* Binary serial number minor byte                       */
  UWORD  ph_CapWord;     /* Capabil word                                          */
  UWORD  ph_SZone;       /* Zone of packet sender (otherwise null)                */
  UWORD  ph_RZone;       /* Zone of packet receiver (otherwise null)              */
  UWORD  ph_OrigPoint;   /* Originating point number                              */
  UWORD  ph_DestPoint;   /* Destination point number                              */
  ULONG  ph_Product;     /* Product specific filler                               */
};

/* Header of 3D packet */
struct Packet3DHeader
{
  UWORD  ph_OrigNode;    /* Originating node of packet, not of messages in packet */
  UWORD  ph_DestNode;    /* Destination node of packet, not of messages in packet */
  UWORD  ph_Year;        /* Year of packet creation, e.g. 1986                    */
  UWORD  ph_Month;       /* Month of packet creation, 0-11 for Jan-Dec            */
  UWORD  ph_Day;         /* Day of packet creation, 1-31                          */
  UWORD  ph_Hour;        /* Hour of packet creation, 0-23                         */
  UWORD  ph_Minute;      /* Minute of packet creation, 0-59                       */
  UWORD  ph_Second;      /* Second of packet creation, 0-59                       */
  UWORD  ph_Baud;        /* Maximal baud rate of orig and dest; 0=SEA             */
  UWORD  ph_PktVer;      /* PacketType (2); old type (1) packets now obsolete     */
  UWORD  ph_OrigNet;     /* Originating net of packet, not of messages in packet  */
  UWORD  ph_DestNet;     /* Destination net of packet, not of messages in packet  */
  UBYTE  ph_ProdCode;    /* Product Code; 0 for Fido, write to FTSC for others    */
  UBYTE  ph_SerialNo;    /* Binary serial number                                  */
  UBYTE  ph_Password[8]; /* Session pasword (null padded)                         */
  UWORD  ph_OrigZone;    /* Originating zone of packet sender (otherwise null)    */
  UWORD  ph_DestZone;    /* Destination zone of packet receiver (otherwise null)  */
  UBYTE  ph_Pad[20];     /* Not used                                              */
};

/* Header of 5D packet */
struct Packet5DHeader
{
  UWORD  ph_OrigNode;    /* Originating node number  */
  UWORD  ph_DestNode;    /* Destination node number  */
  UWORD  ph_OrigPoint;   /* Originating point number - Field only guaranteed accurate in a type 2.2 header */
  UWORD  ph_DestPoint;   /* Destination point number - Field only guaranteed accurate in a type 2.2 header */
  UBYTE  ph_Pad[8];      /* Reserved, must be zero   */
  UWORD  ph_PktSubVer;   /* Packet sub-version (2)   */
  UWORD  ph_PktVer;      /* Packet version (2)       */
  UWORD  ph_OrigNet;     /* Originating network      */
  UWORD  ph_DestNet;     /* Destination network      */
  UBYTE  ph_ProdCode;    /* Product code             */
  UBYTE  ph_Revision;    /* Product revision level   */
  UBYTE  ph_Password[8]; /* Password                 */
  UWORD  ph_OrigZone;    /* Originating zone - Field only guaranteed accurate in a type 2.2 header         */
  UWORD  ph_DestZone;    /* Destination zone - Field only guaranteed accurate in a type 2.2 header         */
  UBYTE  ph_OrigDom[8];  /* Originating domain - Field only guaranteed accurate in a type 2.2 header       */
  UBYTE  ph_DestDom[8];  /* Destination domain - Field only guaranteed accurate in a type 2.2 header       */
  ULONG  ph_Product;     /* Product specific data    */
};

/* Mail packet structure */
struct MailPacket
{
  struct Node          mp_Node;      /* mp_Node.ln_Name shows on mp_Name  */
  UBYTE                mp_Name[256]; /* the name of packet without path   */
  ULONG                mp_Type;      /* type of mail packet; see bellow   */
  ULONG                mp_Status;    /* status of mail packet; see bellow */
  ULONG                mp_Size;      /* the length of mail packet         */
  ULONG                mp_NumMess;   /* the number of messages in packet  */
  struct PacketHeader *mp_Header;    /* header of mail packet             */
  struct MinList       mp_Messages;  /* list of messages                  */
  ULONG                mp_UserData;  /* for external (user's) usage       */
};

/* Header of message */
struct MessageHeader
{
  UWORD  mh_Version;     /* Message type (2); old type (1) is obsolete       */
  UWORD  mh_OrigNode;    /* Originating node of message                      */
  UWORD  mh_DestNode;    /* Destination node of message                      */
  UWORD  mh_OrigNet;     /* Originating network of message                   */
  UWORD  mh_DestNet;     /* Destination network of message                   */
  UWORD  mh_Attr;        /* Message attributes - see below                   */
  UWORD  mh_Cost;        /* In lowest unit of originator's currency          */
};

/* Mail message */
struct MailMessage
{
  struct MinNode        mm_MNode;       /* for link into messages list       */
  ULONG                 mm_Size;        /* the length of message             */
  ULONG                 mm_Status;      /* status of message; see bellow     */
  ULONG                 mm_NumEntries;  /* the number of entries in message  */
  struct MessageHeader *mm_Header;      /* header of message                 */
  struct MinList        mm_Entries;     /* list of entries                   */
  ULONG                 mm_Flags;       /* private field - do NOT modify it! */
};

/* Entry of message */
struct MessageEntry
{
  struct MinNode me_MNode;              /* for link into entries list        */
  ULONG          me_ID;                 /* identifier of entry; see below    */
  ULONG          me_Size;               /* the length of entry               */
  STRPTR         me_Entry;              /* the contents of entry             */
  ULONG          me_Flags;              /* private field - do NOT modify it! */
};

/* Archiver's descriptor */
struct ArchiverNode
{
  struct Node            an_Node;      /* for link into archivers' list             */
  STRPTR                 an_Seq;       /* String by which archiver will be detected */
  STRPTR                 an_Pack;      /* String for pack files into archive        */
  STRPTR                 an_UnPack;    /* String for unpack archive                 */
};

/* usefull macroses */
#define MAKE_ID(a,b,c,d)  ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))


/* Attributes' flags for mh_Attr in Message Header */
#define MSGPRIVATE  0x0001    /* Private message              */
#define MSGCRASH    0x0002    /* Crash priority message       */
#define MSGREAD     0x0004    /* Read by addressee            */
#define MSGSENT     0x0008    /* Sent okay                    */
#define MSGFILE     0x0010    /* file attached                */
#define MSGFWD      0x0020    /* being forwarded              */
#define MSGORPHAN   0x0040    /* Unknown destination          */
#define MSGKILL     0x0080    /* Kill after mailing           */
#define MSGLOCAL    0x0100    /* TRUE if message entered here */
#define MSGHOLD     0x0200    /* TRUE if hold for pickup      */
#define MSGX2       0x0400    /* reserved -- sent             */
#define MSGFREQ     0x0800    /* Requesting a file            */
#define MSGRREQ     0x1000    /* Return Receipt requested     */
#define MSGRRCT     0x2000    /* Return Receipt               */
#define MSGAREQ     0x4000    /* Request audit trail          */
#define MSGUREQ     0x8000    /* Requesting a file update     */

/* type of mail packet for mp_Type */
#define MPT_UNKNOWN                  0L
#define MPT_3D                       MAKE_ID('3','D',' ',' ')
#define MPT_4D                       MAKE_ID('4','D',' ',' ')
#define MPT_5D                       MAKE_ID('5','D',' ',' ')

/* status of mail packet for mp_Status */
#define MPS_OK                       0L  /* There are no errors in packet   */
#define MPS_CORRUPTED                1L  /* Packet is too short             */
#define MPS_EMPTY                    2L  /* Packet hasn't any messages      */

/* status of mail message for mm_Status */
#define MMS_OK                       0L  /* There are no errors in message  */
#define MMS_CORRUPTED                1L  /* Message is too short            */
#define MMS_EMPTY                    2L  /* Message hasn't any entries      */

/* Identifiers of recognized messages' entries */

/* main entries: */
#define MEID_DATE            MAKE_ID('D','A','T','E') /* Date of message    */
#define MEID_FROM            MAKE_ID('F','R','O','M') /* Sender of message  */
#define MEID_TO              MAKE_ID('T','O',' ',' ') /* Message receiver   */
#define MEID_SUBJ            MAKE_ID('S','U','B','J') /* Subject of message */
#define MEID_AREA            MAKE_ID('A','R','E','A') /* AREA:              */
#define MEID_BODY            MAKE_ID('B','O','D','Y') /* Message body       */

/* main kludges */
#define MEID_KL_DOMAIN       MAKE_ID('D','O','M','N') /* DOMAIN    */
#define MEID_KL_FMPT         MAKE_ID('F','M','P','T') /* FMPT      */
#define MEID_KL_TOPT         MAKE_ID('T','O','P','T') /* TOPT      */
#define MEID_KL_MSGID        MAKE_ID('M','S','I','D') /* MSGID:    */
#define MEID_KL_PID          MAKE_ID('P','I','D',' ') /* PID:      */
#define MEID_KL_REPLY        MAKE_ID('R','P','L','Y') /* REPLY:    */
#define MEID_KL_CHRS         MAKE_ID('C','H','R','S') /* CHRS:     */
#define MEID_KL_TID          MAKE_ID('T','I','D',' ') /* TID:      */
#define MEID_KL_INTL         MAKE_ID('I','N','T','L') /* INTL      */
#define MEID_KL_PATH         MAKE_ID('P','A','T','H') /* PATH:     */
#define MEID_KL_REALNAME     MAKE_ID('R','N','A','M') /* REALNAME: */
#define MEID_KL_GIF          MAKE_ID('G','I','F',' ') /* GIF:      */
#define MEID_KL_EID          MAKE_ID('E','I','D',' ') /* EID       */
#define MEID_KL_VIA          MAKE_ID('V','I','A',' ') /* Via       */

/* i-net gate kludges */
#define MEID_KL_XMAILER      MAKE_ID('X','M','L','R') /* X-Mailer:       */
#define MEID_KL_REPLYADDR    MAKE_ID('R','P','L','A') /* REPLYADDR       */
#define MEID_KL_INREPLYTO    MAKE_ID('I','R','T','O') /* In-Reply-To:    */
#define MEID_KL_RFC_PATH     MAKE_ID('R','P','T','H') /* RFC-Path:       */
#define MEID_KL_RFC_REF      MAKE_ID('R','R','E','F') /* RFC-References: */

/* MIME compression kludges */
#define MEID_KL_MIMEVERSION  MAKE_ID('M','I','M','V') /* MIME-Version:              */
#define MEID_KL_CONTENTTYPE  MAKE_ID('C','N','T','T') /* Content-Type:              */
#define MEID_KL_CONTENTTREN  MAKE_ID('C','N','T','E') /* Content-Transfer-Encoding: */
#define MEID_KL_RFC_MIMEVER  MAKE_ID('R','M','I','V') /* RFC-Path:                  */
#define MEID_KL_RFC_CONTYPE  MAKE_ID('R','C','N','T') /* RFC-Content-Type:          */

/* special identifiers */
#define MEID_ENTRY_CORRUPTED MAKE_ID('C','R','P','T') /* bad entry      */
#define MEID_ENTRY_EMPTY     MAKE_ID('E','M','P','T') /* empty entry    */
#define MEID_ENTRY_UNKNOWN   MAKE_ID('U','N','K','N') /* unknown kludge */

/* Special values for pattern in MP_IsFile() */
/* for pattern: */
#define MPISFP_DONT_USE              ((STRPTR)0)
#define MPISFP_SIMPLE_PACKET         ((STRPTR)1)
#define MPISFP_SIMPLE_PACKET_SUFFIX  ((STRPTR)2)
#define MPISFP_PACKED_PACKET         ((STRPTR)3)
#define MPISFP_PACKED_PACKET_SUFFIX  ((STRPTR)4)
#define MPISFP_FILE_LIST             ((STRPTR)5)
#define MPISFP_TIC_FILE              ((STRPTR)6)
#define MPISFP_RDM_FILE              ((STRPTR)7)

/* for mailtype: */
#define MPISFT_DONT_USE              0L
#define MPISFT_PKT           MAKE_ID('T','P','K','T')
#define MPISFT_BINARY        MAKE_ID('T','B','I','N')
#define MPISFT_TEXT          MAKE_ID('T','T','X','T')

/* error codes (returned by some functions) */
#define MP_ERROR_OUT_OF_MEMORY       -1L /* Not enough memory                              */
#define MP_ERROR_CANT_OPEN_FILE      -2L /* DOS Open() fault                               */
#define MP_ERROR_CANT_EXAM_FILE      -3L /* DOS ExamineFH() fault                          */
#define MP_ERROR_CANT_READ_FILE      -4L /* DOS Read() fault                               */
#define MP_ERROR_CANT_WRITE_FILE     -5L /* DOS Write() fault                              */
#define MP_ERROR_CANT_LOCK_DIR       -6L /* DOS Lock() fault                               */
#define MP_ERROR_CANT_EXAM_DIR       -7L /* DOS Examine() or ExNext() fault                */
#define MP_ERROR_CANT_PARSE_PATTERN  -8L /* DOS ParsePatternNoCase() fault                 */
#define MP_ERROR_ARCHIVER_NOT_FOUND  -9L /* Needed archiver was not found in archiver list */
#define MP_ERROR_CANT_RUN_SHELL     -10L /* DOS SystemTags() returned -1                   */

#endif /* MAIL_MAILPRO_H */
