/*****************************************************************************/
/*
                                 soymail.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_SOYMAIL_H
#define INCLUDE_SOYMAIL_H

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

#define USERNAME_MAX 15
#define MSG_ID_MAX 100

#define CHARSET_DEFAULT "utf-8"

/* character sets commonly left-to-right directionality */
#define CHARSETS_COMMONLY_LTR \
"ISO-8859-1,ISO-8859-2,ISO-8859-3,ISO-8859-4,ISO-8859-5,\
ISO-8859-7,ISO-8859-9,ISO-8859-10,ISO-8859-11,\
ISO-8859-13,ISO-8859-14,ISO-8859-15,ISO-8859-16,\
Windows-1250,Windows-1251,Windows-1252,Windows-1253,Windows-1254,\
Windows-1257,Windows-1258,\
KOI8-R,KOI8-U,KOI7,US-ASCII"

/* character sets commonly right-to-left directionality */
#define CHARSETS_COMMONLY_RTL \
"ISO-8859-6,ISO-8859-8,\
Windows-1255,Windows-1256"

#define SOYMAIL_DOCTYPE "<!DOCTYPE html>"

/* number of seconds soyMAIL will attempt to open a locked access log file */
#define SOYMAIL_ACCESS_LOG_ATTEMPTS 15

/* adds this string after the generated page <title> */
#define SOYMAIL_TITLE_BETA ""

#define SIZEOF_SOYMAIL_PAGE_TITLE 96

#define FOLDER_REFRESH_SECONDS 180

#define FOLDER_LIST_RECENT_MAX 5
#define FOLDER_DEST_RECENT_MAX 5

#define MSG_LIST_SUBJ_ELLIPSIS 70

#define DEFAULT_EDIT_ROWS "20,30,40,60"
#define DEFAULT_EDIT_COLS "78,96,132,255"
#define DEFAULT_WRAP_AT   "78,96,132,0"

#define DEFAULT_PREVIEW_AFTER 1000  /* milliseconds */
#define DEFAULT_PREVIEW_SIZE   512  /* characters */

/* on the compose page, the contacts list minimum width */
#define CONTACTS_LIST_WIDTH 12

/* maximum number of periods following "Working ..." notice (~5 minutes) */
#define WORKING_PERIOD_MAX 300

#define MSIE_WAV_CLASSID "CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"

#define HTML_IN_DISGUISE "HTML"

#define SAVE_AS_LINK "&nbsp;&nbsp;&#164;&#164;&#164;&nbsp;&nbsp;"

/*************/
/* text data */
/*************/

typedef struct TEXT_DATA_STRUCT {
   void *NextPtr;
   char *TextPtr;
   int TextSize;
   int TextLength;
} TEXT_DATA;

#define TEXT_DATA_SIZEOF (sizeof(void*)+sizeof(char*)+sizeof(int)+sizeof(int))

#define TEXT_DATA_CALLOC(tlptr,size) \
tlptr = (struct TEXT_DATA_STRUCT*)CgiLibVeeMemCalloc (TEXT_DATA_SIZEOF+size); \
if (tlptr) tlptr->TextSize = size;

#define TEXT_DATA_NEXT(tlptr) (((struct TEXT_DATA_STRUCT*)tlptr)->NextPtr)
#define TEXT_DATA_TEXT(tlptr) (((struct TEXT_DATA_STRUCT*)tlptr)->TextPtr)
#define TEXT_DATA_SIZE(tlptr) (((struct TEXT_DATA_STRUCT*)tlptr)->TextSize)
#define TEXT_DATA_LENGTH(tlptr) (((struct TEXT_DATA_STRUCT*)tlptr)->TextLength)

/* if the text follows immediately on from the structure */
#define TEXT_DATA_SELF(tlptr) ((char*)((char*)tlptr+TEXT_DATA_SIZEOF))

/************/
/* includes */
/************/

#include "request.h"
#include "inetmail.h"
#include "callmail.h"
#include "cgilib.h"
#include "contacts.h"
#include "folder.h"
#include "help.h"
#include "lang.h"
#include "mainmenu.h"
#include "other.h"
#include "options.h"
#include "search.h"

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

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

/*********/
/* names */
/*********/

#define SOY_MAIL     "soyMAIL"

#define SOY_CONTACTS       "SOYMAIL_CONTACTS.TXT"
#define SOY_CONTACTS_LDIF  "SOYMAIL_CONTACTS.LDIF"
#define SOY_OPTIONS        "SOYMAIL_OPTIONS.TXT"
#define SOY_SIGFILE        "SOYMAIL_SIGNATURE.TXT"

#define SOY_CONTACT_LIST      "SOYMAIL_CONTACT_LIST"
#define SOY_CONTACT_LIST_FILE "SOYMAIL_CONTACT:SOYMAIL_"
#define SOY_CONTACT_PERSONAL  "_personal"

#define SOY_YOUGOTMAIL "SOYMAIL_YOUGOTMAIL.WAV"
#define SOY_YOUGOTMAIL_SIZE_KBYTES_MAX  200

/* column at which to wrap incoming message lines */
#define SOY_WRAP_AT 78

/* file-system location for theme CSS files */
#define SOY_THEME_DIR "SOYMAIL_THEME"

/* URL path to the theme files */
#define SOY_PATH "/soymail/-/"

/* URL path to the theme files */
#define SOY_THEME_PATH SOY_PATH "theme/"

/* file-system location for message language files */
#define SOY_LANG_DIR "SOYMAIL_LANG"

/* file-system location for message language files */
#define SOY_HELP_DIR "SOYMAIL_HELP"

/* appended to path and used to uniquely identify a logout request */
#define SOY_LOGOUT_SENTINAL  "?::logout"

#define SOY_DEFAULT_CHARSET "ISO-8859-1"

#define SOY_USER_AGENT_CHROME       1
#define SOY_USER_AGENT_FIREFOX      2
#define SOY_USER_AGENT_MOZILLA      3
#define SOY_USER_AGENT_MSIE         4
#define SOY_USER_AGENT_MSIE10       5
#define SOY_USER_AGENT_OPERA        6
#define SOY_USER_AGENT_SAFARI       7
#define SOY_USER_AGENT_UNSPECIFIED 99

/**********/
/* macros */
/**********/

/* mainly to allow easy use of the __unaligned directive */
#define ULONGPTR __unaligned unsigned long*
#define USHORTPTR __unaligned unsigned short*
#define INT64PTR __unaligned __int64*

#define ISLWS(c) (c == ' ' || c == '\t')

#ifndef CgiLibHtmlDeEntify
int CgiLibHtmlDeEntify (char*);
int CgiLibBodyIsMultipartFormData ();
#endif

/* easy prototypes */
char* SoyCgiVar (char*);
char* SoyCgiVarNull (char*);
#define CGIVAR(p,n) p = SoyCgiVar(n);
#define CGIVARNULL(p,n) p = SoyCgiVarNull(n);

/* CGILIB HTML-escape with dynamic string allocation */
#define HTML_ESCAPE(str) (char*)CgiLibHtmlEscape(str,-1,NULL,0)

/* CGILIB HTML-escape with dynamic string allocation */
#define HTML_ANCHOR(str) (char*)CgiLibAnchorHtmlEscape(str,-1, NULL,0,\
                                 CGILIB_ANCHOR_ALL2|CGILIB_ANCHOR_SPLIT)

/* CGILIB URL-encode with dynamic string allocation */
#define URL_ENCODE(str) (char*)CgiLibUrlEncode(str,-1,NULL,0)

/* process a raw address for inclusion in HTML, dynamic string allocation */
#define HTML_ADDR(str) \
((char*)(CgiLibHtmlEscape(InetMailStripTransport(str),-1,NULL,0)))

/* process a raw string for inclusion in HTML, dynamic string allocation */
#define HTML_TEXT(str) ((char*)(CgiLibHtmlEscape(str,-1,NULL,0)))

/* disable the mouse click */
#define CLICK_DISABLE(exp) ((exp) ? " ONCLICK=\"return false;\"" : "")

/* if true disable the mouse click and display no more messages status */
#define CLICK_NOMORE(exp) ((exp) ? " ONCLICK=\"return noMoreMessages();\"" : "")

/* disable the mouse click and display no more messages status or start */
#define CLICK_NOMORE_STARTWORKING(exp) ((exp) ? \
" ONCLICK=\"return noMoreMessages();\"" : \
" ONCLICK=\"startWorking();\"")

/* when clicked start the working status message */
#define CLICK_STARTWORKING " ONCLICK=\"startWorking();\"" 

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

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

typedef struct STRUCT_VMS_ITEM_LIST2
{
   unsigned short  buf_len;
   unsigned short  item;
   void  *buf_addr;
} VMS_ITEM_LIST2;

typedef struct STRUCT_VMS_ITEM_LIST3
{
   unsigned short  buf_len;
   unsigned short  item;
   void  *buf_addr;
   void  *ret_len;
} VMS_ITEM_LIST3;

typedef struct AnExitHandler
{
   unsigned long  Flink;
   unsigned long  HandlerAddress;
   unsigned long  ArgCount;
   unsigned long  ExitStatusPtr;
} EXIT_HANDLER;

#ifndef __VAX
#   pragma member_alignment __restore
#endif

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

int GetParameters ();
void PeriodMunger (REQUEST_DATA*);
int ProcessRequest ();
void ContextCacheClose ();
void ContextCacheExpire ();
void ContextCacheSet ();

#endif /* INCLUDE_SOYMAIL_H */

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