/******************************************************************************/
/*
                                 callmail.h
*/
/******************************************************************************/

#ifndef INCLUDE_CALLMAIL_H
#define INCLUDE_CALLMAIL_H

#ifndef BOOL
#define BOOL int
#define TRUE 1
#define FALSE 0
#endif

#include <descrip.h>

#include "mime.h"

#define CALLMAIL_MSG_SIZE 512*3  /* internal to MAIL.MAI = 3 blocks */

/* will retry for ten seconds */
#define CALLMAIL_RETRY_COUNT    10

/***********************************/
/* list of null-terminated strings */
/***********************************/

typedef struct STRUCT_VMS_MAIL_LIST
{
   int  ListCount,
        ListLength,
        ListMax,
        ListSize;
   char  *ListPtr;
}
VMS_MAIL_LIST;

/******************************/
/* VMS mail message structure */
/******************************/

#ifndef __VAX
#   pragma member_alignment __save
#   pragma member_alignment
#endif

/*
Contains all of the information required to specify, represent and/or
manipulate a single VMS Mail based message.
*/

typedef struct STRUCT_VMS_MAIL_MSG
{
   struct STRUCT_VMS_MAIL_MSG  *PrevPtr,
                               *NextPtr;

   unsigned long  ConfirmHash,
                  CurrentId,
                  HashMisMatch,
                  MessageContext,
                  MessageHash,
                  MessageId,
                  MessageSelectedCount,
                  RecordCount,
                  SearchNotHit,
                  SizeInRecords,
                  VmsForeign;

   unsigned long  BinDate [2];
   unsigned short  MessageFlags,
                   SelectMessageFlags;
   BOOL  ResetNewMsgFlag;

   char  *MessagePtr;
   unsigned long  MessageLength;

   BOOL  BodyProcessed;
   char  *BodyPtr;
   unsigned long  BodyLength;

   char  Cc [255+1];
   unsigned long  CcLength;
   char  Date [23+1];
   unsigned long  DateLength;
   char  From [255+1];
   unsigned long  FromLength;
   char  Subject [255+1];
   unsigned long  SubjectLength;
   char  To [255+1];
   unsigned long  ToLength;
   char  TimeBefore [31+1];
   unsigned long  TimeBeforeLength;
   char  TimeSince [31+1];
   unsigned long  TimeSinceLength;
   char  ExtId [255+1];
   unsigned long  ExtIdLength;

   BOOL  LooksLikeRfc;
   int  RfcErrorLineNumber;
   char  *RfcHeaderPtr;
   int  RfcHeaderLength;
   char  *RfcBodyPtr;
   int  RfcBodyLength;

   char  *RfcBccPtr;
   int  RfcBccLength;
   char  *RfcCcPtr;
   int  RfcCcLength;
   char  *RfcDatePtr;
   int  RfcDateLength;
   char  *RfcFromPtr;
   int  RfcFromLength;
   char  *RfcMessageIdPtr;
   int  RfcMessageIdLength;
   char  *RfcSubjPtr;
   int  RfcSubjLength;
   char  *RfcToPtr;
   int  RfcToLength;
   char  *XVmsToPtr;
   int  XVmsToLength;
   char  *RfcInReplyToPtr;
   int  RfcInReplyToLength;
   char  *RfcReplyToPtr;
   int  RfcReplyToLength;
   char  *RfcReferencesPtr;
   int  RfcReferencesLength;
   char  *RfcReturnPathPtr;
   int  RfcReturnPathLength;

   /*
      These point to the actual data depending on whether it's native VMS
      Mail or one containing as leading RFC822 header.  They are set when the
      message body is scanned for the presence of an Internet mail header.
   */
   char  *MsgFromPtr,
         *MsgToPtr,
         *MsgCcPtr,
         *MsgSubjPtr,
         *MsgDatePtr,
         *MsgBodyPtr;

   /* a pointer to dynamically allocated MIME structure */
   MIME_DATA  *MimeDataPtr;

} VMS_MAIL_MSG;

/*****************/
/* VMS user data */
/*****************/

/*
This data structure represents all the information required to maintain the VMS
Mail user's identity within soyMAIL.
*/

#define DATA_BUFFER_MAX 4096

typedef struct STRUCT_VMS_MAIL_USER
{
   int  DestFolderMaxLen,
        ListMessageIdStart,
        ListMessageIdCount,
        ListMessageIdMax,
        ListMessageIdVector,
        MailDotMai,
        MailFileDeletedCount,
        MailFolderMaxLen,
        MessageCopiedCount,
        MessageDeletedCount,
        MoveNewMailCount,
        NewMsgFlagCopiedCount,
        NewMsgFlagDeletedCount,
        RetryCount,
        VmsNewMsg;

   char  UserName [USERNAME_MAX+1];
   unsigned long  UserNameLength;

   unsigned long  CurrentMessageCount,
                  TotalReclaimBytes;

   unsigned long  MailVmsStatus,
                  VmsMailUserContext;

   unsigned short  VmsMailNewMessages;
   unsigned long  VmsMailAutoPurge,
                  VmsMailCcPrompt,
                  VmsMailCopyForward,
                  VmsMailCopyReply,
                  VmsMailCopySend;

   unsigned long  DiskQuotaPerm,
                  DiskQuotaUsed;

   char  VmsMailDirectory [255+1];
   unsigned long  VmsMailDirectoryLength;
   char  VmsMailEditor [255+1];
   unsigned long  VmsMailEditorLength;
   char  VmsMailForm [255+1];
   unsigned long  VmsMailFormLength;
   char  VmsMailForwarding [255+1];
   unsigned long  VmsMailForwardingLength;
   char  VmsMailFullDirectory [255+1];
   unsigned long  VmsMailFullDirectoryLength;
   char  VmsMailPersonalName [127+1];
   unsigned long  VmsMailPersonalNameLength;
   char  VmsMailQueue [255+1];
   unsigned long  VmsMailQueueLength;
   char  VmsMailSigFile [255+1];
   unsigned long  VmsMailSigFileLength;

   unsigned long  VmsMailFileContext;
   char OpenMailFileName [255+1];
   unsigned long  OpenMailFileNameLength;
   char VmsMailFileName [255+1];
   unsigned long  VmsMailFileNameLength;
   char  VmsMailFolderName [255+1];
   unsigned long  VmsMailFolderNameLength;
   char  VmsMailWasteBasketName [63+1];
   unsigned long  VmsMailWasteBasketNameLength;

   unsigned long  VmsMailDestFileContext;
   char VmsMailDestFileName [255+1];
   unsigned long  VmsMailDestFileNameLength;
   char  VmsMailDestFolderName [255+1];
   unsigned long  VmsMailDestFolderNameLength;

   VMS_MAIL_LIST  MailFileList;
   VMS_MAIL_LIST  DestFolderList;
   VMS_MAIL_LIST  MailFolderList;
   VMS_MAIL_LIST  TempFolderList;
   VMS_MAIL_LIST  RecentDestFolderList;
   VMS_MAIL_LIST  RecentMailFolderList;

   VMS_MAIL_MSG  *MessageList;
   int  MessageListCount;

   char  *MsgIdListPtr;
   int  MsgIdListCount;

   VMS_MAIL_MSG  VmsMailMsg;

   char  DataBuffer [DATA_BUFFER_MAX];
   char  *DataBufferPtr;
   unsigned long  DataBufferLength;

   char  *SignaturePtr;
   int  SignatureLength;

   /* a pointer to the message (text) search function */
   int  (*SearchFunction)();
   void  *SearchDataPtr;
   /* a boolean to enable callable mail 'select' functionality */
   int  SelectNotSearch;

} VMS_MAIL_USER;

#ifndef __VAX
#   pragma member_alignment __restore
#endif

/**************/
/* prototypes */
/**************/

unsigned int CallMailElfHash (char*, int);
int CallMailBuildMailFileName (VMS_MAIL_USER*, char*, char*, int);
int CallMailCopyFile (VMS_MAIL_USER*, char*, char*, char*);
int CallMailDeleteIfEmpty (VMS_MAIL_USER*);
int CallMailFileClose (VMS_MAIL_USER*);
int CallMailFileList (VMS_MAIL_USER*);
char* CallMailFileIn (VMS_MAIL_USER*, char*, char*);
int CallMailFileOpen (VMS_MAIL_USER*, char*);
int CallMailFolderList (VMS_MAIL_USER*, BOOL, BOOL);
int CallMailFolderListCallback (VMS_MAIL_USER*, struct dsc$descriptor*);
int CallMailGetUserProfile (VMS_MAIL_USER*);
int CallMailGoToNewMail (VMS_MAIL_USER*);
VMS_MAIL_MSG* CallMailMessageInit (VMS_MAIL_USER*);
int CallMailMessageContext (VMS_MAIL_USER*, VMS_MAIL_MSG*);
int CallMailMessageContextEnd (VMS_MAIL_USER*, VMS_MAIL_MSG*);
int CallMailMessageCopy (VMS_MAIL_USER*);
int CallMailMessageCopyMove (VMS_MAIL_USER*, BOOL);
int CallMailMessageDelete (VMS_MAIL_USER*);
int CallMailMessageFlags (VMS_MAIL_USER*, VMS_MAIL_MSG*, unsigned short);
void CallMailMessageFree (VMS_MAIL_MSG*);
int CallMailMessageGet (VMS_MAIL_USER*, VMS_MAIL_MSG*);
int CallMailMessageHeader (VMS_MAIL_USER*, VMS_MAIL_MSG*);
int CallMailMessageList (VMS_MAIL_USER*);
unsigned int CallMailHeaderHash (VMS_MAIL_MSG*);
int CallMailMessageMove (VMS_MAIL_USER*);
int CallMailMessageSelect (VMS_MAIL_USER*);
void CallMailMessageSelectReset (VMS_MAIL_USER*);
int CallMailPmdfImapMailBox (VMS_MAIL_USER*);
int CallMailPmdfImapMbxDir (VMS_MAIL_USER*, char*, char*, int);
int CallMailPmdfImapSort (VMS_MAIL_USER*);
int CallMailPmdfImapSortCmp (const void*, const void*);
int CallMailSetUserProfile (VMS_MAIL_USER*);
int CallMailSetUserNewMessages (VMS_MAIL_USER*, int);
int CallMailUserClose (VMS_MAIL_USER*);
int CallMailUserDiskQuota (VMS_MAIL_USER*);
int CallMailVolumeStruct (char*);

#endif /* INCLUDE_CALLMAIL_H */

/******************************************************************************/

