/*****************************************************************************/
/*
                                 request.h

COPYRIGHT
---------
Copyright (C) 2005-2025 Mark G.Daniel
This program, comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under the
conditions of the GNU GENERAL PUBLIC LICENSE, version 3, or any later version.

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

#ifndef INCLUDE_REQUEST_H
#define INCLUDE_REQUEST_H

#include "callmail.h"
#include "compose.h"
#include "mime.h"

#define VMSok(x) ((x) & STS$M_SUCCESS)
#define VMSnok(x) !(((x) & STS$M_SUCCESS))

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

/*************/
/* constants */
/*************/

/* just ambit numbers! */
#define PAGE_FOLDER         99199
#define PAGE_SEARCH         99299
#define PAGE_OPTIONS        99399
#define PAGE_CONTACTS       99499
#define PAGE_COMPOSE        99599
#define PAGE_MESSAGE        99699
#define PAGE_HELP           99799

/* magic number to indicate all message from 1..n */ 
#define RANGE_ALL_MSGS     999999999
/* magic number to indicate 'the most recent messages' */
#define RANGE_MOST_RECENT  999999998

/*******************/
/* data structures */
/*******************/

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

/* forward references */
typedef struct STRUCT_CONTACTS_ENTRY CONTACTS_ENTRY;
                    
typedef struct STRUCT_USER_OPTIONS
{
   int  Accessability1,
        AllMailFiles,
        CheckNewMailAjax,
        CheckNewMailMins,
        ComposeHTML,
        FolderButtons,
        FontIsMono,
        FontSize,
        ItemsPerPage,
        ImageInline,
        MassageRead,
        MessageAttachmentPanel,
        MessageOrder,
        MessagesPerPage,
        OptionsApplied,
        OptionsLoaded,
        OptionsPanelExpand,
        PmdfImap,
        PreviewAfter,
        PreviewSize,
        ReadPreference,
        SigFile,
        VmsNewMsg;

   char  CharSet [24],
         CharSetDefault [24],
         ComposeCharSets [128],
         ComposeEditCols [48],
         ComposeEditRows [48],
         ComposeWrapAt [48],
         FolderSentItems [39+1],
         FolderDraftItems [39+1],
         FolderWasteItems [39+1],
         FontFamily [96],
         Language [64],
         PersonalName [128],
         QuoteForward [8],
         QuoteReply [8],
         SigFileName [40],
         SmtpFrom [128],
         Theme [32],
         YouGotMail [32],
         YouGotMailAt [64];

} USER_OPTIONS;

/* need 'regex_t' */
#include <regex.h>

typedef struct STRUCT_SEARCH_DATA
{
   BOOL  InProgress,
         SearchProblem,
         SelectNotSearch;

   int  Category,
        DateScope,
        DateDay,
        DateMonth,
        DateYear,
        FirstIdSearched,
        HitCount,
        LastIdSearched,
        ResultsEvery,
        SearchCount,
        SearchSeconds;

   unsigned long BinTimeBefore [2],
                 BinTimeSince [2];

   char  Attachment [31+1],
         Cc [31+1],
         Criteria [127+1],
         From [31+1],
         Message [31+1],
         Subject [31+1],
         To [31+1];

   regex_t  RegexAttachment,
            RegexCc,
            RegexFrom,
            RegexMessage,
            RegexSubject,
            RegexTo;

} SEARCH_DATA;

#define MESSAGE_READ_HISTORY_MAX 30

typedef struct STRUCT_REQUEST_DATA
{
   /* version right up front so it's relative position is constant! */
   char  StateVersion [16];
   /* state data is this same request struct, from any previous request */
   int  StateSaveCount;
   void  *StateDataPtr;

   char  RemoteUser [USERNAME_MAX+1];
   unsigned long  RemoteUserLength;
   char  LoginAlias [96+1];
   unsigned long  LoginAliasLength;

   int  PrevPageIdent,
        ThisPageIdent,
        UserAgent;

   char  *CgiPathInfoPtr,
         *CgiQueryStringPtr,
         *CgiRequestMethodPtr,
         *CgiRequestUriPtr,
         *CgiScriptNamePtr,
         *CgiHttpUserAgentPtr,
         *CharSetPtr,
         *FieldFocusPtr,
         *LoginSetCookiePtr;

   char  UserName [USERNAME_MAX+1];
   unsigned long  UserNameLength;
   char  MailFileName [255+1];
   unsigned long  MailFileNameLength;
   char  DestMailFileName [255+1];
   unsigned long  DestMailFileNameLength;
   char  FolderName [255+1];
   unsigned long  FolderNameLength;
   char  DestFolderName [255+1];
   unsigned long  DestFolderNameLength;
   char  AttachmentName [255+1];
   unsigned long  AttachmentNameLength;
   char  AttachPartName [255+1];
   unsigned long  AttachPartNameLength;

   int  FolderMessageCount,
        FolderRefreshSeconds,
        MessageCountDelta,
        MassageMessage,
        MessageHash,
        MessageId,
        MessageReadPreference,
        NewMessages,
        RangeIdCount,
        RangeIdStart,
        RangeIdVector;

   char  *MsgIdListPtr;
   int  MsgIdListCount;

   BOOL  HtmlTextIsPresent,
         NewMailNoticed,
         NewMailAt,
         NewMailPlay,
         NewMailValid,
         PlainTextIsPresent,
         PostMaster,
         PrivateAccess,
         PublicAccess,
         PublicAuthorized,
         PublicNoNewMail,
         PublicWildcard,
         ReadHtmlText,
         ReadPlainText,
         ResetNewMsgFlag;

   char  FormAction [96],
         PublicAccessPage [255+1],
         PublicAccessString [255+1],
         PublicAccessTitle [255+1];

   USER_OPTIONS  UserOptions;
   COMPOSE_DATA  ComposeData;
   SEARCH_DATA  SearchData;

   char  *ContactsTextPtr;
   int  ContactsTextLength;
   CONTACTS_ENTRY  *ContactsListPtr;
   int  ContactsErrorCount,
        ContactsLoadCount,
        ContactsUnknownCount;

} REQUEST_DATA;

#ifndef __VAX
#   pragma member_alignment __restore
#endif

/**************/
/* prototpyes */
/**************/

int RequestAccessLog (REQUEST_DATA*, char*);
void RequestLastLogin (REQUEST_DATA*);
void RequestParseDestFileFolder (REQUEST_DATA*, char*);
void RequestParseFileFolder (REQUEST_DATA*, char*);
int RequestParsePath (REQUEST_DATA*);
int RequestPrivate (REQUEST_DATA*);
BOOL RequestPrivateDefaults (REQUEST_DATA*);
void RequestPrivateStateSave (REQUEST_DATA*);
int RequestPublic (REQUEST_DATA*);
BOOL RequestPublicDefaults (REQUEST_DATA*);
void RequestPublicStateSave (REQUEST_DATA*);
void RequestVmsMailContext (REQUEST_DATA*);
int RequestStateFolder (char*, VMS_MAIL_LIST*);
BOOL RequestStateRestore (REQUEST_DATA*);

#endif /* INCLUDE_REQUEST_H */

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