/*****************************************************************************/
/*
                                  options.c

Load and administer user options.

  [accessability-1]**         heavy underscore below each message detail on
                                the folder message listing page (1 enables)
  [charset-default]           if not otherwise specified use this
                                e.g. UTF-8 (default), ISO-8859-1, Windows-1252
  [check-new-mail]            check for new mail every this many minutes
  [compose-charsets]          comma-separated list of character sets
                                provided on the message composition page
  [compose-edit-cols]         per-user overrides for default
  [compose-edit-rows]           and/or soyMAIL configuration
  [compose-wrap-at]             directives
  [compose-HTML]              default to an HTML editor (if available)
  [draft-items]               folder for draft items
  [folder-buttons]            0 = off, 1 column, 2 columns, etc.
  [font-family]               Arial, Helvetica, sans-serif
  [font-size]                 10 (in points)
  [language]                  en, es, de, etc.
  [massage-read]              wrap long lines and collapse extra line breaks
  [message-attachment-panel]**  0 below (default), 1 above message body
  [message-order]             message listing order; 1 is ascending (more 
                                recent at top) -1 is descending (older at top)
  [message-read-preference]   plain text and/or HTML and their order
  [message-read-history]      OBSOLETE as of v1.3.4
  [messages-per-page]         this many messages listed on a folder page
  [options-panel-expand]**    expand option panels to window width (Wm(B)K special :-)
  [personal-name]             Mark Daniel (or as appropriate :-)
  [PMDF-IMAP]                 PMDF_IMAP.MAILBOX read compatibility
  [preview-after]             milliseconds before preview window is opened
  [preview-size]              number of characters in preview
  [quote-forward]             character(s) to use in quoting line in forwards
  [quote-reply]               character(s) to use in quoting line in replies
  [sent-items]                folder name for sent items
  [sig-file]                  0 = default (VMS), 1 = soymail, 999 = none
                                or the name of the user signature
  [SMTP-from]                 prefered "From:" email address
  [theme]                     the CSS file selected
  [use-only-MAIL]             do not show mail files other than MAIL.MAI
  [VMS-newmsg]**              see configuration directive of same name
  [you-got-mail]              name of 'you've got mail' audio
  [you-got-mail-at]           email address to forward note


FOOTNOTES**
-----------
These items are not accessable via the user options page (to save clutter with
non-general functionality).  The directive must be manually edited into the
user's SOYMAIL_OPTIONS.TXT.  Once entered they will be propagated with each
save.  To disable they (of course) must be manually deleted.


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 2.


VERSION HISTORY
---------------
12-JUL-2025  MGD  add further font sizes
02-OCT-2023  MGD  [image-inline]
27-DEC-2017  MGD  [charset-default]
18-APR-2014  MGD  remove "Requires JavaScript" advice (it now all does)
16-FEB-2010  MGD  [preview-after], [preview-size]
14-FEB-2010  MGD  [you-got-mail-at]
13-NOV-2008  MGD  [VMS-newmsg]
27-JUL-2008  MGD  modify options page layout
20-JUL-2008  MGD  [compose-charsets]
07-JUL-2008  MGD  [compose-edit-cols]   per-user overrides for default
                  [compose-edit-rows]   and/or soyMAIL configuration
                  [compose-wrap-at]     directives
                  [PMDF-IMAP] enables PMDF IMAP read compatibility
02-JUL-2008  MGD  [smtp-from] can be specified as an exclamation mark which
                     allows config *user options override* to disable 
14-JUN-2008  MGD  [massage-read] becomes numeric (was boolean)
31-MAY-2008  MGD  optional beep! for YouGotMail
03-NOV-2007  MGD  support multiple signature files
30-SEP-2007  MGD  any options specified using [user-options-override]
                    disables the corresponding option in the user setup page
                  remove [message-read-history]
12-APR-2007  MGD  OptionsMunge() ensure draft and waste items
                    folder names cannot be set to MAIL or NEWMAIL
03-FEB-2007  MGD  [draft-items] and [sent-items]
27-JAN-2007  MGD  [message-attachment-panel]
30-DEC-2006  MGD  implement message-order in options menu
                  [quote-forward] for quoting forwarded messages
                  rename [quote-char] to [quote-reply]
20-JUL-2006  MGD  note monospace font usage
19-JUL-2006  MGD  [message-order] to control message listing order
                  [quote-char] character(s) inside quotes to allow spaces
21-JUN-2006  MGD  [sig-file] option to control signature file usage
12-JUN-2006  MGD  remove [check-new-mail-nonajax] and [check-new-mail-MSIE]
                    user options and associated processing kludges
26-APR-2006  MGD  [accessability-1] manually edit to 1 to enable
02-APR-2006  MGD  bugfix; OptionsSoyMail() propagation of personal
                    you-got-mail when when changing language option
25-MAR-2006  MGD  [wrap-text-at] transmogrified to [massage-read]
08-MAR-2006  MGD  bugfix; propagate and reload selected language
25-FEB-2006  MGD  OptionsMunge() make default OPTIONS_READ_PLAIN1_HTML2
                  bugfix; OptionsVmsSave() VMS option copy-send
16-FEB-2006  MGD  better handle MAIL$_NOSUCHUSER from CallMailGetUserProfile()
07-FEB-2006  MGD  modified [reply-to] option to [smtp-from] and in conjunction
                    with [personal-name] have ComposePageRequest() generate a
                    "From:" header more in line with TCPIP$SMTP_FROM behaviour
                  [folder-buttons] to allow configuration of folder buttons
01-FEB-2005  MGD  initial
*/
/*****************************************************************************/

#ifdef SOYMAIL_VMS_V7
#undef _VMS_V6_SOURCE
#define _VMS_V6_SOURCE
#undef __VMS_VER
#define __VMS_VER 70000000
#undef __CRTL_VER
#define __CRTL_VER 70000000
#endif

#pragma nomember_alignment

/* standard C header files */
#include <descrip.h>
#include <ctype.h>
#include <errno.h>
#include <ints.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unixio.h>

/* VMS related header files */
#include <rmsdef.h>
#include <ssdef.h>
#include <stsdef.h>

/* application header file */
#include "soymail.h"
#include "config.h"
#include "gmt.h"
#include "newmail.h"
#include "request.h"
#include "other.h"

#define FI_LI "OPTIONS", __LINE__

#define MAIL$_NOSUCHUSER 8290346

/* can't get the include dependencies settled (this'll do in the interim) */
int ComposeWrapAt (int, USER_OPTIONS*);

/******************/
/* global storage */
/******************/

char *OptionsFontFamily [] =
{
   "Arial, Helvetica, sans-serif",
   "Verdana, Arial, Helvetica, sans-serif",
   "\"Courier New\", Courier, monospace",
   "\"Times New Roman\", Times, serif",
   "\"Comic Sans MS\", cursive",
   NULL,
};

/********************/
/* external storage */
/********************/

extern BOOL  Debug,
             WatchEnabled;

extern int  SoyMailVolumeStruct,
            VmsVersion;

extern char  CallMailNoSuchUser[],
             CurrentVmsTimeString[],
             SoftwareId[],
             SoftwareVn[];

extern CONFIG_DATA  SoyMailConfig;
extern VMS_MAIL_USER VmsMailUser;

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

BOOL OptionsPageRequest (REQUEST_DATA *rdptr)

{
   char  *cptr;
   VMS_MAIL_USER  *muptr;
   USER_OPTIONS  *uoptr;
                  
   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsPageRequest()\n");

   /* a bit of sanity checking */
   if (!rdptr->PrivateAccess) ErrorExit (SS$_BUGCHECK, FI_LI);

   muptr = &VmsMailUser;
   uoptr = &rdptr->UserOptions;

   CGIVARNULL (cptr, "FORM_OPTION_BTN");
   if (cptr)
   {
      if (rdptr->PrevPageIdent != PAGE_OPTIONS) ErrorExit (SS$_BUGCHECK, FI_LI);

      if (LangSame ("option_soy_save", cptr))
         OptionsSoyApplySave (rdptr, TRUE);
      else
      if (LangSame ("option_soy_apply", cptr))
         OptionsSoyApplySave (rdptr, FALSE);
      else
      if (LangSame ("option_soy_restore", cptr))
         OptionsLoadSoy (rdptr);
      else
      if (LangSame ("option_vms_save", cptr))
         OptionsVmsSave (rdptr);
      else
      if (LangSame ("option_sigfile_save", cptr))
         OptionsSigFileSave (rdptr);
      else
      if (LangSame ("listen", cptr))
         StatusMessage (FI_LI, 1, "%s", LangFor("listen_not_supported"));
      else
         ErrorExit (SS$_BUGCHECK, FI_LI);
   }

   OptionsPage (rdptr);

   return (TRUE);
}

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

void OptionsPage (REQUEST_DATA *rdptr)

{
   int  status;
   REQUEST_DATA  *sdptr;
   USER_OPTIONS  *uoptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsPage()\n");

   muptr = &VmsMailUser;
   uoptr = &rdptr->UserOptions;

   if (uoptr->CharSetDefault[0])
      CgiLibResponseSetCharset (uoptr->CharSetDefault);
   else
   if (SoyMailConfig.CharSetDefault && SoyMailConfig.CharSetDefault[0])
      CgiLibResponseSetCharset (SoyMailConfig.CharSetDefault);
   else
      CgiLibResponseSetCharset (CHARSET_DEFAULT);

   StatusMessage (FI_LI, 0, "%s %s",
                  LangFor("options"), LangFor("page_opened"));

   OptionsSigFileLoad (rdptr, NULL);

   MainMenuPageBegin (rdptr, PAGE_OPTIONS);
   MainMenuBar (rdptr);
   StatusInfoPanel (rdptr);

   if (rdptr->UserAgent == SOY_USER_AGENT_MSIE)
      fprintf (stdout,
"<script language=\"JavaScript\">\n\
var soy_YouGotMailPath = \'%s/yougotmail.mp3?yougotmail.mp3';\n\
</script>\n",
               rdptr->FormAction);
   else
      fprintf (stdout,
"<script language=\"JavaScript\">\n\
var soy_YouGotMailPath = \'%s?yougotmail.mp3';\n\
</script>\n",
               rdptr->FormAction);

   fprintf (stdout,
"<p class=\"css_p06\">\
<table width=\"100%%\" cellpadding=\"1\" \
cellspacing=\"0\" align=\"center\" valign=\"top\">\n\
<tr><td align=\"center\" valign=\"top\">\n\n");

   OptionsSoyMail (rdptr);

   if (!SoyMailConfig.VmsOccluded) OptionsVms (rdptr);

   fprintf (stdout,
"</div></td></tr>\n\
</table>\n");

   MainMenuPageEnd (rdptr);
}

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

void OptionsSoyMail (REQUEST_DATA *rdptr)

{
   BOOL  GotYouGot,
         OneSelected;
   int  idx, value,
        FileCount,
        YouGotMailFileCount;
   char  *cptr, *sptr, *selptr, *zptr;
   REQUEST_DATA  *sdptr;
   USER_OPTIONS  *uoptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSoyMail()\n");

   muptr = &VmsMailUser;
   uoptr = &rdptr->UserOptions;

   /****************/
   /* you got mail */
   /****************/

   if (FileSpecSearch (FALSE, muptr->VmsMailFullDirectory, SOY_YOUGOTMAIL))
      GotYouGot = TRUE;
   else
      GotYouGot = FALSE;

   if (uoptr->OptionsPanelExpand)
      fprintf (stdout,
"<script language=\"JavaScript\">\n\
var soy_OptionsPanelMaxWidth = 100;\n\
</script>\n");

   /***********/
   /* general */
   /***********/

   fprintf (stdout,
"<!-- soyMAIL options begin -->\n\
<table cellpadding=\"3\" cellspacing=\"1\" \
align=\"center\" class=\"css_panel_4\" id=\"options_general_tab\">\n\
<tr class=\"css_panel_2\" id=\"options_general_tr\"><td colspan=\"5\" \
style=\"font-weight:bold;text-align:center;padding:5px;\">%s</td></tr>\n\
<tr>",
            LangFor("option_soy_general_options"));

   OptionsSoyName ("theme", LangFor("option_soy_theme"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_select_theme\"%s>\n",
            OptionsUserOverride("theme") ? " disabled" : "");

   FileCount = OptionsSelectFile (SOY_THEME_DIR, "*.CSS", uoptr->Theme);
   if (!FileCount)
      fprintf (stdout, "<option value=\"%s\">%s\n",
               LangFor("sanity_check"), LangFor("sanity_check"));

   fputs ("</select>\n</td><td>&nbsp;&nbsp;</td>\n", stdout);

   OptionsSoyName ("language", LangFor("option_soy_lang"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_select_lang\"%s>\n",
            OptionsUserOverride("language") ? " disabled" : "");

   OptionsSelectLanguage (uoptr);

   fputs ("</select>\n</td></tr>\n<tr>", stdout);

   OptionsSoyName ("check-new-mail",LangFor("option_soy_check_new"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_select_check\"%s>\n\
<option value=\"0\"%s>%s\n\
<option value=\"1\"%s>1 %s\n\
<option value=\"2\"%s>2 %s\n\
<option value=\"5\"%s>5 %s\n\
<option value=\"10\"%s>10 %s\n\
<option value=\"15\"%s>15 %s\n\
<option value=\"30\"%s>30 %s\n\
<option value=\"60\"%s>60 %s\n\
</select>\n\
<input type=\"hidden\" name=\"option_soy_check_newmail_ajax\" value=\"%d\">\n\
</td><td>&nbsp;&nbsp;</td>\n",
            OptionsUserOverride("check-new-mail") ? " disabled" : "",
            uoptr->CheckNewMailMins == 0 ? " selected" : "",
            LangFor("(none)"),
            uoptr->CheckNewMailMins == 1 ? " selected" : "",
            LangFor("minutes"),
            uoptr->CheckNewMailMins == 2 ? " selected" : "",
            LangFor("minutes"),
            uoptr->CheckNewMailMins == 5 ? " selected" : "",
            LangFor("minutes"),
            uoptr->CheckNewMailMins == 10 ? " selected" : "",
            LangFor("minutes"),
            uoptr->CheckNewMailMins == 15 ? " selected" : "",
            LangFor("minutes"),
            uoptr->CheckNewMailMins == 30 ? " selected" : "",
            LangFor("minutes"),
            uoptr->CheckNewMailMins == 60 ? " selected" : "",
            LangFor("minutes"),
            uoptr->CheckNewMailAjax);

   OptionsSoyName ("font-size", LangFor("option_soy_font_size"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_select_font_size\"%s>\n\
<option value=\"8\"%s>8\n\
<option value=\"9\"%s>9\n\
<option value=\"10\"%s>10\n\
<option value=\"11\"%s>11\n\
<option value=\"12\"%s>12\n\
<option value=\"13\"%s>13\n\
<option value=\"14\"%s>14\n\
<option value=\"15\"%s>15\n\
<option value=\"16\"%s>16\n\
</select>\n\
</td></tr>\n",
            OptionsUserOverride("font-size") ? " disabled" : "",
            uoptr->FontSize == 8 ? " selected" : "",
            uoptr->FontSize == 9 ? " selected" : "",
            uoptr->FontSize == 10 ? " selected" : "",
            uoptr->FontSize == 11 ? " selected" : "",
            uoptr->FontSize == 12 ? " selected" : "",
            uoptr->FontSize == 13 ? " selected" : "",
            uoptr->FontSize == 14 ? " selected" : "",
            uoptr->FontSize == 15 ? " selected" : "",
            uoptr->FontSize == 16 ? " selected" : "");

   fputs ("<tr>", stdout);

   OptionsSoyName ("you-got-mail", LangFor("option_soy_you_got_mail"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_select_yougotmail\"%s>\n\
<option value=\"\"%s>%s\n\
<option value=\"%s\"%s>%s\n",
            OptionsUserOverride("you-got-mail") ? " disabled" : "",
            !uoptr->YouGotMail[0] ? " selected" : "",
            LangFor("(none)"),
            LangFor("option_soy_you_got_mail_beep"),
            strchr(uoptr->YouGotMail,'!') ? " selected" : "",
            LangFor("option_soy_you_got_mail_beep"));

   if (GotYouGot)
   {
      /* user has a personal you-got-mail audio file */
      fprintf (stdout, "<option value=\"(personal)\"%s>%s\n",
               strsame (uoptr->YouGotMail, "(personal)", -1) ? " selected" : "",
               LangFor("option_soy_you_got_mail_personal"));
   }

   OptionsSelectFile (SOY_THEME_DIR, "*.MP3", uoptr->YouGotMail);

   fprintf (stdout,
"</select>\n\
<script language=\"JavaScript\">\
document.write(\'&nbsp;&nbsp;<input class=\"css_button_panel_1\" \
type=\"submit\" name=\"option_btn\" value=\"%s\" \
onclick=\"return listenYouGotMail();\">\\n\');\
</script>\n\
</td><td>&nbsp;&nbsp;</td>\n",
            LangFor ("listen"));

   OptionsSoyName ("font-family", LangFor("option_soy_font_family"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_select_font_family\" \
onchange=\"document.soymail_form.option_soy_text_font_family.value=\
document.soymail_form.option_soy_select_font_family.options\
[document.soymail_form.option_soy_select_font_family.selectedIndex].value\
\"%s>\n",
            OptionsUserOverride("font-family") ? " disabled" : "");

   OneSelected = FALSE;

   for (idx = 0; OptionsFontFamily[idx]; idx++)
   {
      if (strsame (uoptr->FontFamily, OptionsFontFamily[idx], -1))
      {
         selptr = " selected";
         OneSelected = TRUE;
      }
      else
         selptr = "";
      sptr = HTML_ESCAPE(OptionsFontFamily[idx]);
      fprintf (stdout, "<option value=\"%s\"%s>%s\n", sptr, selptr, sptr);
   }

   cptr = SoyMailConfig.FontFamilyLocal;
   while (cptr && *cptr)
   {
      for (zptr = cptr; *zptr && *zptr != '\n'; zptr++);
      if (*zptr) *zptr++ = '\0';
      if (strsame (uoptr->FontFamily, OptionsFontFamily[idx], -1))
      {
         selptr = " selected";
         OneSelected = TRUE;
      }
      else
         selptr = "";
      sptr = HTML_ESCAPE(cptr);
      fprintf (stdout, "<option value=\"%s\"%s>%s\n", sptr, selptr, sptr);
      cptr = zptr;
   }

   fputs ("</select></td></tr>\n", stdout);

   fprintf (stdout,
"<tr><td class=\"css_right\">\
</td><td>\
<div class=\"css_button_panel_1 css_input_type_file\">\
<input class=\"css_text_1\" id=\"option_soy_file_yougotmail\" \
type=\"file\" name=\"option_soy_file_yougotmail\" size=\"20\"%s%s>\n\
<span onclick=\"document.getElementById(\
\'option_soy_file_yougotmail\').click();return false;\">%s</span>\
</div>\
</td><td>&nbsp;&nbsp;</td>",
         GotYouGot ? " onclick=\"document.soymail_form.\
option_soy_select_yougotmail.selectedIndex = 1;\"" : "",
         OptionsUserOverride("you-got-mail") ? " disabled" : "",
         LangFor("select_file"));

   fprintf (stdout,
"<td class=\"css_right\"></td><td>\
<input class=\"css_text_1\" type=\"text\" size=\"40\" \
name=\"option_soy_text_font_family\" value=\"%s\">\
</td></tr>\n\
<tr>",
            uoptr->FontFamily);

   OptionsSoyName ("you-got-mail@", LangFor("option_soy_you_got_mail_at"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"40\" maxlength=\"63\" \
name=\"option_soy_yougotmailat\" value=\"%s\"%s>\
</td>\n<td>&nbsp;&nbsp;</td>\n",
         HTML_ESCAPE(uoptr->YouGotMailAt),
         OptionsUserOverride("you-got-mail-at") ? " disabled" : "");

   OptionsSoyName ("charset-default", LangFor("option_soy_charset_default"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"20\" maxlength=\"20\" \
name=\"option_soy_charset_default\" value=\"%s\"%s>\
</td></tr>\n",
         HTML_ESCAPE(uoptr->CharSetDefault),
         OptionsUserOverride("charset-default") ? " disabled" : "");

   OptionsSaveApplyRestore (uoptr->OptionsApplied);

   /**********************/
   /* message management */
   /**********************/

   fprintf (stdout,
"</table>\n\n\
<p><table cellpadding=\"3\" cellspacing=\"1\" \
align=\"center\" class=\"css_panel_4\" id=\"options_management_tab\">\n\
<tr class=\"css_panel_2\" id=\"options_management_tr\">\
<td colspan=\"5\" \
style=\"font-weight:bold;text-align:center;padding:5px;\">%s</td></tr>\n\
<tr>",
            LangFor("option_soy_message_management"));

   if (uoptr->PmdfImap)
      OptionsSoyName (NULL, LangFor("option_soy_use_only_MAIL"));
   else
      OptionsSoyName ("use-only-MAIL", LangFor("option_soy_use_only_MAIL"));

   fprintf (stdout,
"<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_soy_use_only_MAIL\" value=\"1\"%s%s>",
            (OptionsUserOverride("use-only-MAIL") ||
               uoptr->PmdfImap) ? " disabled" : "",
            uoptr->AllMailFiles ? "" : " checked");

   fputs ("</td><td>&nbsp;&nbsp;</td>\n", stdout);

   OptionsSoyName ("message-read-preference", LangFor("option_soy_read_preference"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_read_preference\"%s>\n\
<option value=\"%d\"%s>%s\n\
<option value=\"%d\"%s>%s\n\
<option value=\"%d\"%s>%s\n\
</select>\n",
            OptionsUserOverride("message-read-preference") ? " disabled" : "",
            OPTIONS_READ_PLAIN1_HTML0,
            uoptr->ReadPreference == OPTIONS_READ_PLAIN1_HTML0 ?
              " selected" : "",
            LangFor("option_soy_read_plain1_html0"),
            OPTIONS_READ_PLAIN1_HTML2,
            uoptr->ReadPreference == OPTIONS_READ_PLAIN1_HTML2 ?
              " selected" : "",
            LangFor("option_soy_read_plain1_html2"),
            OPTIONS_READ_PLAIN2_HTML1,
            uoptr->ReadPreference == OPTIONS_READ_PLAIN2_HTML1 ?
              " selected" : "",
            LangFor("option_soy_read_plain2_html1"));

   fputs ("</td></tr>\n<tr>", stdout);

   OptionsSoyName ("PMDF-IMAP", "PMDF IMAP");

   fprintf (stdout,
"<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_soy_PMDF_IMAP\" value=\"1\"%s%s>",
            OptionsUserOverride("PMDF-IMAP") ? " disabled" : "",
            uoptr->PmdfImap ? " checked" : "");

   fputs ("</td>\n<td>&nbsp;&nbsp;</td>\n", stdout);

   OptionsSoyName ("massage-read", LangFor("option_soy_massage"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_massage\"%s>\n",
            OptionsUserOverride("massage-read") ? " disabled" : "");

   value = ComposeWrapAt (-1, uoptr);
   while (value >= 0)
   {
      if (value)
         fprintf (stdout, "<option value=\"%d\"%s>%d",
                  value,
                  uoptr->MassageRead == value ? " selected" : "",
                  value);
      else
         fprintf (stdout, "<option value=\"0\"%s>%s",
                  uoptr->MassageRead == 0 ? " selected" : "",
                  LangFor("(none)"));
      value = ComposeWrapAt (value, uoptr);
   }

   fputs ("</select>\n</td></tr>\n<tr>", stdout);

   OptionsSoyName ("message-order", LangFor("option_soy_message_order"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_message_order\"%s>\n\
<option value=\"1\"%s>%s\n\
<option value=\"-1\"%s>%s\n\
</select>\n",
            OptionsUserOverride("message-order") ? " disabled" : "",
            uoptr->MessageOrder == 1 ? " selected" : "",
            LangFor("option_soy_message_order_more"),
            uoptr->MessageOrder == -1 ? " selected" : "",
            LangFor("option_soy_message_order_less"));

   fputs ("</td>\n<td>&nbsp;&nbsp;</td>\n", stdout);

   OptionsSoyName ("image_inline", LangFor("option_soy_image_inline"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_image_inline\"%s>\n\
<option value=\"0\"%s>0\n\
<option value=\"25\"%s>25%%\n\
<option value=\"50\"%s>50%%\n\
<option value=\"75\"%s>80%%\n\
<option value=\"100\"%s>100%%\n\
</select>&nbsp;\n",
            OptionsUserOverride("image_inline") ? " disabled" : "",
            uoptr->ImageInline == 0 ? " selected" : "",
            uoptr->ImageInline == 25 ? " selected" : "",
            uoptr->ImageInline == 50 ? " selected" : "",
            uoptr->ImageInline == 75 ? " selected" : "",
            uoptr->ImageInline == 100 ? " selected" : "");

   fputs ("</td></tr>\n<tr>", stdout);

   OptionsSoyName ("messages-per-page", LangFor("option_soy_per_page"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_per_page\"%s>\n\
<option value=\"5\"%s>5\n\
<option value=\"10\"%s>10\n\
<option value=\"15\"%s>15\n\
<option value=\"20\"%s>20\n\
<option value=\"25\"%s>25\n\
<option value=\"30\"%s>30\n\
<option value=\"40\"%s>40\n\
<option value=\"50\"%s>50\n\
<option value=\"75\"%s>75\n\
<option value=\"100\"%s>100\n\
</select>\n",
            OptionsUserOverride("messages-per-page") ? " disabled" : "",
            uoptr->MessagesPerPage == 5 ? " selected" : "",
            uoptr->MessagesPerPage == 10 ? " selected" : "",
            uoptr->MessagesPerPage == 15 ? " selected" : "",
            uoptr->MessagesPerPage == 20 ? " selected" : "",
            uoptr->MessagesPerPage == 25 ? " selected" : "",
            uoptr->MessagesPerPage == 30 ? " selected" : "",
            uoptr->MessagesPerPage == 40 ? " selected" : "",
            uoptr->MessagesPerPage == 50 ? " selected" : "",
            uoptr->MessagesPerPage == 75 ? " selected" : "",
            uoptr->MessagesPerPage == 100 ? " selected" : "");

   fputs ("</td><td>&nbsp;&nbsp;</td>\n", stdout);

   OptionsSoyName ("draft-items", LangFor("option_soy_draft_items"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"40\" maxlength=\"39\" \
name=\"option_soy_draft_items\" value=\"%s\"%s>",
            HTML_ESCAPE(uoptr->FolderDraftItems),
            OptionsUserOverride("draft-items") ? " disabled" : "");

   fputs ("</td></tr>\n<tr>", stdout);

   OptionsSoyName ("folder-buttons", LangFor("option_soy_folder_buttons"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_folder_buttons\"%s>\n\
<option value=\"0\"%s>%s\n\
<option value=\"1\"%s>1\n\
<option value=\"2\"%s>2\n\
<option value=\"3\"%s>3\n\
</select>\n",
            OptionsUserOverride("folder-buttons") ? " disabled" : "",
            !uoptr->FolderButtons ? " selected" : "",
            LangFor("(none)"),
            uoptr->FolderButtons == 1 ? " selected" : "",
            uoptr->FolderButtons == 2 ? " selected" : "",
            uoptr->FolderButtons == 3 ? " selected" : "");

   fputs ("</td><td>&nbsp;&nbsp;</td>\n", stdout);

   OptionsSoyName ("sent-items", LangFor("option_soy_sent_items"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"40\" maxlength=\"39\" \
name=\"option_soy_sent_items\" value=\"%s\"%s>",
            HTML_ESCAPE(uoptr->FolderSentItems),
            OptionsUserOverride("sent-items") ? " disabled" : "");

   fputs ("</td></tr>\n<tr>", stdout);

   OptionsSoyName ("preview-after", LangFor("option_soy_preview_after"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_preview_after\"%s>\n\
<option value=\"0\"%s>%s\n\
<option value=\"800\"%s>0.8\n\
<option value=\"1000\"%s>1.0\n\
<option value=\"1200\"%s>1.2\n\
<option value=\"1400\"%s>1.4\n\
<option value=\"1600\"%s>1.6\n\
<option value=\"1800\"%s>1.8\n\
<option value=\"2000\"%s>2.0\n\
<option value=\"3000\"%s>3.0\n\
<option value=\"5000\"%s>5.0\n\
</select>&nbsp;%s\n",
            OptionsUserOverride("preview-after") ? " disabled" : "",
            !uoptr->PreviewAfter ? " selected" : "",
            LangFor("(none)"),
            uoptr->PreviewAfter == 800 ? " selected" : "",
            uoptr->PreviewAfter == 1000 ? " selected" : "",
            uoptr->PreviewAfter == 1200 ? " selected" : "",
            uoptr->PreviewAfter == 1400 ? " selected" : "",
            uoptr->PreviewAfter == 1600 ? " selected" : "",
            uoptr->PreviewAfter == 1800 ? " selected" : "",
            uoptr->PreviewAfter == 2000 ? " selected" : "",
            uoptr->PreviewAfter == 3000 ? " selected" : "",
            uoptr->PreviewAfter == 5000 ? " selected" : "",
            LangFor("seconds"));

   fputs ("</td><td>&nbsp;&nbsp;</td>\n", stdout);

   OptionsSoyName ("waste-items", LangFor("option_soy_waste_items"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"40\" maxlength=\"39\" \
name=\"option_soy_waste_items\" value=\"%s\"%s>",
            HTML_ESCAPE(uoptr->FolderWasteItems),
            OptionsUserOverride("waste-items") ? " disabled" : "");

   fputs ("</td></tr>\n<tr>", stdout);

   if (uoptr->VmsNewMsg > 0)
   {
      /* merely show that this option is enabled */
      OptionsSoyName ("VMS-newmsg", "VMS newmsg");

      fprintf (stdout,
"<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_soy_vms_newmsg\" value=\"1\"%s%s>\
</td>\n",
               " disabled" , " checked");
   }

   fputs ("</tr>\n", stdout);

   OptionsSaveApplyRestore (uoptr->OptionsApplied);

   /***********************/
   /* message composition */
   /***********************/

   fprintf (stdout,
"</table>\n\n\
<p><table cellpadding=\"3\" cellspacing=\"1\" \
align=\"center\" class=\"css_panel_4\" id=\"options_composition_tab\">\n\
<tr class=\"css_panel_2\" id=\"options_composition_tr\"><td colspan=\"5\" \
style=\"font-weight:bold;text-align:center;padding:5px;\">%s</td></tr>\n\
<tr>",
            LangFor("option_soy_message_composition"));

   OptionsSoyName ("quote-reply", LangFor("option_soy_quote_reply"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"5\" \
name=\"option_soy_quote_reply\" value=\"%s\"%s>\
</td><td>&nbsp;&nbsp;</td>\n",
            HTML_ESCAPE(uoptr->QuoteReply),
            OptionsUserOverride("quote-reply") ? " disabled" : "");

   OptionsSoyName ("compose-edit-rows", LangFor("option_soy_edit_rows"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"20\" \
name=\"option_soy_compose_edit_rows\" value=\"%s\"%s>\
</td></tr>\n<tr>\n",
            HTML_ESCAPE(uoptr->ComposeEditRows),
            OptionsUserOverride("compose-edit-rows") ? " disabled" : "");

   OptionsSoyName ("quote-forward", LangFor("option_soy_quote_forward"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"5\" \
name=\"option_soy_quote_forward\" value=\"%s\"%s>\
</td><td>&nbsp;&nbsp;</td>\n",
            HTML_ESCAPE(uoptr->QuoteForward),
            OptionsUserOverride("quote-forward") ? " disabled" : "");

   OptionsSoyName ("compose-edit-cols", LangFor("option_soy_edit_cols"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"20\" \
name=\"option_soy_compose_edit_cols\" value=\"%s\"%s>\
</td></tr>\n<tr>",
            HTML_ESCAPE(uoptr->ComposeEditCols),
            OptionsUserOverride("compose-edit-cols") ? " disabled" : "");

   if (SoyMailConfig.HtmlEditorLoad)
      OptionsSoyName ("compose-HTML", LangFor("option_soy_compose_HTML"));
   else
      OptionsSoyName (NULL, LangFor("option_soy_compose_HTML"));

   fprintf (stdout,
"<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_soy_compose_html\" value=\"1\"%s%s>\
</td>\n<td>&nbsp;&nbsp;</td>\n",
            OptionsUserOverride("compose-HTML") ||
               !SoyMailConfig.HtmlEditorLoad ? " disabled" : "",
            uoptr->ComposeHTML ? " checked" : "");

   OptionsSoyName ("compose-wrap-at", LangFor("option_soy_wrap_at"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"20\" \
name=\"option_soy_compose_wrap_at\" value=\"%s\"%s>\
</td></tr>\n<tr><td colspan=\"3\"></td>\n",
            HTML_ESCAPE(uoptr->ComposeWrapAt),
            OptionsUserOverride("compose-wrap-at") ? " disabled" : "");

   OptionsSoyName ("compose-charsets", LangFor("option_soy_compose_charsets"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"40\" \
name=\"option_soy_compose_charsets\" value=\"%s\"%s>\
</td></tr>\n",
            HTML_ESCAPE(uoptr->ComposeCharSets),
            OptionsUserOverride("compose-charsets") ? " disabled" : "");

   OptionsSaveApplyRestore (uoptr->OptionsApplied);

   /*******************/
   /* mailing persona */
   /*******************/

   fprintf (stdout,
"</table>\n\n\
<p><table cellpadding=\"3\" cellspacing=\"1\" \
align=\"center\" class=\"css_panel_4\" id=\"options_persona_tab\">\n\
<tr class=\"css_panel_2\" id=\"options_ident_tr\"><td colspan=\"5\" \
style=\"font-weight:bold;text-align:center;padding:5px;\">%s</td></tr>\n\
<tr>",
            LangFor("option_soy_sender_ident"));

   OptionsSoyName ("sig-file", LangFor("option_soy_sigfile"));

   fprintf (stdout,
"<select class=\"css_select_1\" name=\"option_soy_sigfile\"%s>\n",
            OptionsUserOverride("sig-file") ? " disabled" : "");

   fprintf (stdout, "<option value=\"(0)\"%s>%s\n",
            uoptr->SigFile == OPTIONS_SOY_SIGFILE_NONE ? " selected" : "",
            LangFor("option_soy_sigfile_none"));

   if (!SoyMailConfig.VmsOccluded)
      fprintf (stdout, "<option value=\"(1)\"%s>%s (VMS)\n",
               uoptr->SigFile == OPTIONS_SOY_SIGFILE_DEFAULT ? " selected" : "",
               LangFor("option_soy_sigfile_default"));

   fprintf (stdout, "<option value=\"(2)\"%s>%s\n",
            uoptr->SigFile == OPTIONS_SOY_SIGFILE_SOYMAIL ? " selected" : "",
            LangFor("option_soy_sigfile_soymail"));

   OptionsSigSelectFile (rdptr, uoptr->SigFileName);

   fputs ("</select></td><td>&nbsp;&nbsp;</td>\n", stdout);

   OptionsSoyName ("personal-name", LangFor("option_soy_name"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"20\" \
name=\"option_soy_name\" value=\"%s\"%s>\
</td></tr>\n",
            HTML_ESCAPE(uoptr->PersonalName),
            OptionsUserOverride("personal-name") ? " disabled" : "");

   fprintf (stdout,
"<tr><td></td><td>\
<input class=\"css_text_1\" type=\"text\" size=\"20\" maxlength=\"20\" \
name=\"option_soy_sigfile_name\" value=\"\"%s></td>\n\
<td>&nbsp;&nbsp;</td>\n",
            OptionsUserOverride("sig-file") ? " disabled" : "");

   OptionsSoyName ("SMTP-from", LangFor("option_soy_smtpfrom"));

   fprintf (stdout,
"<input class=\"css_text_1\" type=\"text\" size=\"40\" \
name=\"option_soy_smtpfrom\" value=\"%s\"%s>\n\
</td></tr>\n",
            HTML_ESCAPE(uoptr->SmtpFrom),
            OptionsUserOverride("SMTP-from") ? " disabled" : "");

   OptionsSaveApplyRestore (uoptr->OptionsApplied);

   OptionsSigFile (rdptr, muptr->SignaturePtr);

   fputs ("</table>\n<!-- soyMAIL options end -->\n\n", stdout);
}

/*****************************************************************************/
/*
For user-override options italicise the option title.
*/

void OptionsSoyName
(
char *OptionName,
char *OptionLang
)
{
   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSoyName()\n");

   fputs ("<td class=\"css_right\">", stdout);

   if (!OptionName || OptionsUserOverride(OptionName))
      fprintf (stdout, "<I>%s</I>", OptionLang);
   else
      fprintf (stdout, "%s", OptionLang);

   fputs (":</td><td class=\"css_left\">\n", stdout);
}

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

void OptionsSaveApplyRestore (BOOL ProvideRestore)

{
   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSaveApplyRestore()\n");

   fprintf (stdout,
"<tr>\
<td style=\"text-align:left;padding:5px;padding-top:15px;\" colspan=\"4\">\
<input class=\"css_button_panel_1\" type=\"submit\" \
name=\"option_btn\" value=\"%s\">&nbsp;\n\
<input class=\"css_button_panel_1\" type=\"submit\" \
name=\"option_btn\" value=\"%s\">",
            LangFor("option_soy_save"),
            LangFor("option_soy_apply"));

   if (ProvideRestore)
      fprintf (stdout,
"&nbsp;\n\
<input class=\"css_button_panel_1\" type=\"submit\" \
name=\"option_btn\" value=\"%s\">",
      LangFor("option_soy_restore"));

   fputs ("</td></tr>\n", stdout);
}

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

void OptionsVms (REQUEST_DATA *rdptr)

{
   REQUEST_DATA  *sdptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsVms()\n");

   muptr = &VmsMailUser;

   fprintf (stdout,
"<!-- VMS options begin -->\n\
<p><table cellpadding=\"3\" cellspacing=\"1\" \
align=\"center\" class=\"css_panel_4\" id=\"options_vms_tab\">\n\
<tr class=\"css_panel_2\" id=\"options_vms_tr\"><td colspan=\"5\" \
style=\"font-weight:bold;text-align:center;padding:5px;\">%s</td></tr>\n\
\
<tr>\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_vms_autopurge\" value=\"1\"%s>\
</td>\n\
<td>&nbsp;&nbsp;</td>\n\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input class=\"css_text_1\" type=\"text\" size=\"20\" \
name=\"option_vms_editor\" value=\"%s\">\
</td></tr>\n\
\
<tr>\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_vms_ccprompt\" value=\"1\"%s>\
</td>\n\
<td>&nbsp;&nbsp;</td>\n\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input class=\"css_text_1\" type=\"text\" size=\"40\" \
name=\"option_vms_forwarding\" value=\"%s\">\
</td></tr>\n\
\
<tr>\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_vms_copyfwd\" value=\"1\"%s>\
</td>\n\
<td>&nbsp;&nbsp;</td>\n\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input class=\"css_text_1\" type=\"text\" size=\"40\" \
name=\"option_vms_personal\" value=\"%s\">\
</td></tr>\n\
\
<tr>\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_vms_copyreply\" value=\"1\"%s>\
</td>\n\
<td>&nbsp;&nbsp;</td>\n\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input class=\"css_text_1\" type=\"text\" size=\"20\" \
name=\"option_sigfile\" value=\"%s\">\
</td></tr>\n\
\
<tr>\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input type=\"checkbox\" style=\"border:none;\" \
name=\"option_vms_copysend\" value=\"1\"%s>\
</td>\n\
<td>&nbsp;&nbsp;</td>\n\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input class=\"css_text_1\" type=\"text\" size=\"20\" \
name=\"option_vms_queue\" value=\"%s\">\
</td></tr>\n\
\
<tr><td colspan=\"3\"></td>\
\
<td class=\"css_right\">%s:</td>\
<td class=\"css_left\">\
<input class=\"css_text_1\" type=\"text\" size=\"20\" \
name=\"option_vms_form\" value=\"%s\">\
</td></tr>\n\
\
<tr>\
<td style=\"text-align:left;padding:5px;padding-top:15px;\" colspan=\"5\">\
<input class=\"css_button_panel_1\" type=\"submit\" \
name=\"option_btn\" value=\"%s\">\n\
</td></tr>\n\
\
</table>\n\
<!-- VMS options end -->\n\n",
            "VMS Mail",
            LangFor("option_vms_autopurge"), 
            muptr->VmsMailAutoPurge ? " checked" : "",
            LangFor("option_vms_editor"),
            HTML_ESCAPE(muptr->VmsMailEditor),
            LangFor("option_vms_ccprompt"),
            muptr->VmsMailCcPrompt ? " checked" : "",
            LangFor("option_vms_forwarding"),
            HTML_ESCAPE(muptr->VmsMailForwarding),
            LangFor("option_vms_copyfwd"), 
            muptr->VmsMailCopyForward ? " checked" : "",
            LangFor("option_vms_personalname"),
            HTML_ESCAPE(muptr->VmsMailPersonalName),
            LangFor("option_vms_copyreply"),
            muptr->VmsMailCopyReply ? " checked" : "",
            LangFor("option_vms_signature"),
            HTML_ESCAPE(muptr->VmsMailSigFile),
            LangFor("option_vms_copysend"),
            muptr->VmsMailCopySend ? " checked" : "",
            LangFor("option_vms_printqueue"),
            HTML_ESCAPE(muptr->VmsMailQueue),
            LangFor("option_vms_printform"),
            HTML_ESCAPE(muptr->VmsMailForm),
            LangFor("option_vms_save"));
}

/*****************************************************************************/
/*
Edit the signature.
*/

void OptionsSigFile
(
REQUEST_DATA *rdptr,
char *SignaturePtr
)
{
   int  status;
   char  *cptr;
   REQUEST_DATA  *sdptr;
   USER_OPTIONS  *uoptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSigFile()\n");

   muptr = &VmsMailUser;
   if (!muptr->VmsMailFullDirectoryLength) ErrorExit (SS$_BUGCHECK, FI_LI);

   uoptr = &rdptr->UserOptions;

   if (uoptr->SigFile == OPTIONS_SOY_SIGFILE_NONE) return;

   if (uoptr->SigFile == OPTIONS_SOY_SIGFILE_DEFAULT)
      if (!muptr->VmsMailSigFile[0]) return;

   if (!SignaturePtr) SignaturePtr = "";

   fprintf (stdout,
"<tr><td colspan=\"5\" \
style=\"padding:5px;padding-top:10px;\">\
<input type=\"hidden\" name=\"option_soy_sigfile\" value=\"%s\">\n\
<textarea class=\"css_text_edit\" rows=\"8\" cols=\"80\" \
name=\"option_sigfile_text\" \
wrap=\"off\" style=\"width:80ch!important;\">%s</textarea>\
</td></tr>\n\
\
<tr><td colspan=\"5\" \
style=\"text-align:left;padding:5px;\">\n\
<input class=\"css_button_panel_1\" type=\"submit\" \
name=\"option_btn\" value=\"%s\">&nbsp;\n\
<input class=\"css_button_panel_1\" type=\"reset\" \
onclick=\"return confirm(\'%s\')\" value=\"%s\">\n\
</td></tr>\n",
            uoptr->SigFileName,
            HTML_ESCAPE(SignaturePtr),
            LangFor("option_sigfile_save"),
            LANG_FOR_CONFIRM("sure?"),
            LangFor("reset")); 
}

/*****************************************************************************/
/*
Apply or save to file the options.
*/

void OptionsSoyApplySave
(
REQUEST_DATA *rdptr,
BOOL SaveToFile
)
{
   int  retval, status;
   char  *cptr, *fnptr, *sptr, *zptr;
   char  CurrentLanguage [64];
   FILE  *fp;
   REQUEST_DATA  *sdptr;
   USER_OPTIONS  *uoptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSoyApplySave()\n");

   muptr = &VmsMailUser;
   if (!muptr->VmsMailFullDirectoryLength) ErrorExit (SS$_BUGCHECK, FI_LI);

   uoptr = &rdptr->UserOptions;
   sdptr = (REQUEST_DATA*)rdptr->StateDataPtr;

   if (!muptr->VmsMailFullDirectoryLength) ErrorExit (SS$_BUGCHECK, FI_LI);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_COMPOSE_HTML");
   if (cptr)
      uoptr->ComposeHTML = 1;
   else
      uoptr->ComposeHTML = 0;

   CGIVARNULL (cptr, "FORM_OPTION_SOY_TEXT_FONT_FAMILY");
   if (!cptr || !*cptr)
      CGIVARNULL (cptr, "FORM_OPTION_SOY_SELECT_FONT_FAMILY");
   if (cptr) strzcpy (uoptr->FontFamily, cptr, sizeof(uoptr->FontFamily));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SELECT_FONT_SIZE");
   if (cptr && isdigit(*cptr)) uoptr->FontSize = atoi(cptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_USE_ONLY_MAIL");
   if (cptr)
      uoptr->AllMailFiles = 0;
   else
      uoptr->AllMailFiles = 1;

   CGIVARNULL (cptr, "FORM_OPTION_SOY_PMDF_IMAP");
   if (cptr)
   {
      uoptr->PmdfImap = 1;
      /* PMDF IMAP processing has precedence */
      uoptr->AllMailFiles = 0;
   }
   else
      uoptr->PmdfImap = 0;

   CGIVARNULL (cptr, "FORM_OPTION_SOY_CHECK_NEWMAIL_AJAX");
   if (cptr && isdigit(*cptr)) uoptr->CheckNewMailAjax = atoi(cptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SELECT_CHECK");
   if (cptr && isdigit(*cptr)) uoptr->CheckNewMailMins = atoi(cptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SELECT_YOUGOTMAIL");
   if (cptr) strzcpy (uoptr->YouGotMail, cptr, sizeof(uoptr->YouGotMail));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_FILE_YOUGOTMAIL");
   if (cptr && *cptr) OptionsPersonalYouGotMail (rdptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_FILE_YOUGOTMAIL");

   CGIVARNULL (cptr, "FORM_OPTION_SOY_YOUGOTMAILAT");
   if (cptr) strzcpy (uoptr->YouGotMailAt, cptr, sizeof(uoptr->YouGotMailAt));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_FOLDER_BUTTONS");
   if (cptr && isdigit(*cptr))
      uoptr->FolderButtons = atoi(cptr);
   else
      uoptr->FolderButtons = 0;

   CGIVARNULL (cptr, "FORM_OPTION_SOY_PREVIEW_AFTER");
   if (cptr && isdigit(*cptr))
      uoptr->PreviewAfter = atoi(cptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_IMAGE_INLINE");
   if (cptr && isdigit(*cptr))
      uoptr->ImageInline = atoi(cptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_PER_PAGE");
   if (cptr && isdigit(*cptr)) uoptr->MessagesPerPage = atoi(cptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_MASSAGE");
   if (cptr)
   {
      uoptr->MassageRead = atoi(cptr);
      if (uoptr->MassageRead && uoptr->MassageRead < atoi(DEFAULT_WRAP_AT))
         uoptr->MassageRead = atoi(DEFAULT_WRAP_AT);
   }
   else
      uoptr->MassageRead = 0;

   CGIVARNULL (cptr, "FORM_OPTION_SOY_MESSAGE_ORDER");
   if (cptr) uoptr->MessageOrder = atoi(cptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_NAME");
   if (cptr) strzcpy (uoptr->PersonalName, cptr, sizeof(uoptr->PersonalName));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_COMPOSE_CHARSETS");
   if (cptr) strzcpy (uoptr->ComposeCharSets, cptr,
                      sizeof(uoptr->ComposeCharSets));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_COMPOSE_EDIT_COLS");
   if (cptr) strzcpy (uoptr->ComposeEditCols, cptr,
                      sizeof(uoptr->ComposeEditCols));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_COMPOSE_EDIT_ROWS");
   if (cptr) strzcpy (uoptr->ComposeEditRows, cptr,
                      sizeof(uoptr->ComposeEditRows));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_COMPOSE_WRAP_AT");
   if (cptr) strzcpy (uoptr->ComposeWrapAt, cptr,
                      sizeof(uoptr->ComposeWrapAt));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_DRAFT_ITEMS");
   if (cptr) strzcpy (uoptr->FolderDraftItems, cptr,
                      sizeof(uoptr->FolderDraftItems));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SENT_ITEMS");
   if (cptr) strzcpy (uoptr->FolderSentItems, cptr,
                      sizeof(uoptr->FolderSentItems));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_WASTE_ITEMS");
   if (cptr) strzcpy (uoptr->FolderWasteItems, cptr,
                      sizeof(uoptr->FolderWasteItems));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_QUOTE_REPLY");
   if (cptr) strzcpy (uoptr->QuoteReply, cptr, sizeof(uoptr->QuoteReply));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_QUOTE_FORWARD");
   if (cptr) strzcpy (uoptr->QuoteForward, cptr, sizeof(uoptr->QuoteForward));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_READ_PREFERENCE");
   if (cptr && isdigit(*cptr)) uoptr->ReadPreference = atoi(cptr);

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SIGFILE");
   if (cptr) strzcpy (uoptr->SigFileName, cptr, sizeof(uoptr->SigFileName));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SIGFILE_NAME");
   if (cptr)
   {
      while (*cptr && isspace(*cptr)) cptr++;
      if (*cptr) strzcpy (uoptr->SigFileName, cptr, sizeof(uoptr->SigFileName));
   }

   if (isalnum(uoptr->SigFileName[0]) && SoyMailVolumeStruct != 5)
   {
      /* capitalise all leading alphabetics while lower-casing all others */
      cptr = uoptr->SigFileName;
      if (isalpha(*cptr)) *cptr = toupper(*cptr);
      for (cptr++; *cptr; cptr++)
         if (!isalnum(*(cptr-1)) && isalpha(*cptr))
            *cptr = toupper(*cptr);
         else
            *cptr = tolower(*cptr);
   }

   strcpy (CurrentLanguage, uoptr->Language);
   CGIVARNULL (cptr, "FORM_OPTION_SOY_SELECT_LANG");
   if (cptr) strzcpy (uoptr->Language, cptr, sizeof(uoptr->Language));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SELECT_THEME");
   if (cptr) strzcpy (uoptr->Theme, cptr, sizeof(uoptr->Theme));

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SMTPFROM");
   if (cptr) strzcpy (uoptr->SmtpFrom, cptr, sizeof(uoptr->SmtpFrom));

   /* make sure they are reasonable */
   OptionsMunge (uoptr);

   if (!SaveToFile)
   {
      /* gets a bit messy with attachments when just applying the language */
      strcpy (uoptr->Language, CurrentLanguage);
      uoptr->OptionsApplied = TRUE;
      return;
   }

   /* if the language has been changed just reload */
   if (strcmp (CurrentLanguage, uoptr->Language))
      LangLoad (rdptr->UserOptions.Language);

   uoptr->OptionsApplied = FALSE;

   fnptr = CallMailFileIn (muptr, NULL, SOY_OPTIONS);
   if (WatchEnabled) WatchThis (FI_LI, "OPTIONS !AZ", fnptr);

   fp = fopen (fnptr, "w");
   if (!fp)
   {
      status = vaxc$errno;
      StatusMessage (FI_LI, 1, "%s: %s.", SOY_MAIL, SysGetMsg(status));
      return;
   }

   status = SS$_NORMAL;

   fprintf (fp, "# soyMAIL options as at %s\n\n", CurrentVmsTimeString);

   fprintf (fp, "[version]  %s\n", SoftwareVn);

   if (uoptr->Accessability1)  /* manual edit */
      fprintf (fp, "[accessability-1]  %d\n", uoptr->Accessability1);

   fprintf (fp, "[charset-default]  %s\n", uoptr->CharSetDefault);
   if (uoptr->CheckNewMailAjax)
      fprintf (fp, "[check-newmail-ajax]  %d\n", uoptr->CheckNewMailAjax);
   fprintf (fp, "[check-new-mail]  %d\n", uoptr->CheckNewMailMins);
   fprintf (fp, "[compose-charsets]  %s\n", uoptr->ComposeCharSets);
   fprintf (fp, "[compose-edit-rows]  %s\n", uoptr->ComposeEditRows);
   fprintf (fp, "[compose-edit-cols]  %s\n", uoptr->ComposeEditCols);
   fprintf (fp, "[compose-HTML]  %d\n", uoptr->ComposeHTML);
   fprintf (fp, "[compose-wrap-at]  %s\n", uoptr->ComposeWrapAt);
   fprintf (fp, "[draft-items]  %s\n", uoptr->FolderDraftItems);
   fprintf (fp, "[folder-buttons]  %d\n", uoptr->FolderButtons);
   fprintf (fp, "[font-family]  %s\n", uoptr->FontFamily);
   fprintf (fp, "[font-size]  %d\n", uoptr->FontSize);
   fprintf (fp, "[image-inline]  %d\n", uoptr->ImageInline);
   fprintf (fp, "[language]  %s\n", uoptr->Language);
   fprintf (fp, "[massage-read]  %d\n", uoptr->MassageRead);

   if (uoptr->MessageAttachmentPanel)  /* manual edit */
      fprintf (fp, "[message-attachment-panel]  %d\n",
               uoptr->MessageAttachmentPanel);

   fprintf (fp, "[message-order]  %d\n", uoptr->MessageOrder);
   fprintf (fp, "[message-read-preference]  %d\n", uoptr->ReadPreference);
   fprintf (fp, "[messages-per-page]  %d\n", uoptr->MessagesPerPage);

   if (uoptr->OptionsPanelExpand)  /* manual edit */
      fprintf (fp, "[options-panel-expand]  %d\n", uoptr->OptionsPanelExpand);

   fprintf (fp, "[personal-name]  %s\n", uoptr->PersonalName);
   fprintf (fp, "[PMDF-IMAP]  %d\n", uoptr->PmdfImap);
   fprintf (fp, "[preview-after]  %d\n", uoptr->PreviewAfter);
   fprintf (fp, "[preview-size]  %d\n", uoptr->PreviewSize);
   fprintf (fp, "[quote-forward]  \"%s\"\n", uoptr->QuoteForward);
   fprintf (fp, "[quote-reply]  \"%s\"\n", uoptr->QuoteReply);
   fprintf (fp, "[sent-items]  %s\n", uoptr->FolderSentItems);
   fprintf (fp, "[sig-file]  %s\n", uoptr->SigFileName);
   fprintf (fp, "[SMTP-from]  %s\n", uoptr->SmtpFrom);
   fprintf (fp, "[theme]  %s\n", uoptr->Theme);
   fprintf (fp, "[use-only-MAIL]  %d\n", uoptr->AllMailFiles ? 0 : 1);

   if (uoptr->VmsNewMsg)  /* manual edit */
      fprintf (fp, "[VMS-newmsg]  %d\n", uoptr->VmsNewMsg);

   fprintf (fp, "[waste-items]  %s\n", uoptr->FolderWasteItems);
   fprintf (fp, "[you-got-mail]  %s\n", uoptr->YouGotMail);
   fprintf (fp, "[you-got-mail-at]  %s\n", uoptr->YouGotMailAt);

   retval = fprintf (fp, "\n# end\n");
   if (retval < 0) status = vaxc$errno;
   fclose (fp);
   if (VMSok (status))
   {
      /* purge the versions back */
      strcat (fnptr, ";-1");
      while (!remove (fnptr));
      StatusMessage (FI_LI, 0, LangFor("option_saved"));
   }
   else
   {
      /* remove just this latest version */
      strcat (fnptr, ";0");
      remove (fnptr);
      StatusMessage (FI_LI, 1, "%s: %s.", SOY_MAIL, SysGetMsg(status));
   }

   if (!uoptr->AllMailFiles)
   {
      /* ensure we're back in the default mail area */
      if (strcmp (rdptr->MailFileName, "MAIL"))
      {
         strcpy (rdptr->MailFileName, "MAIL");
         rdptr->MailFileNameLength = 4;
         strcpy (rdptr->FolderName, "NEWMAIL");
         rdptr->FolderNameLength = 7;
      }
   }
}

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

void OptionsVmsSave (REQUEST_DATA *rdptr)

{
   char  *cptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsVmsSave()\n");

   muptr = &VmsMailUser;
   if (!muptr->VmsMailFullDirectoryLength) ErrorExit (SS$_BUGCHECK, FI_LI);

   if (SoyMailConfig.VmsOccluded) return;

   CGIVARNULL (cptr, "FORM_OPTION_VMS_AUTOPURGE");
   if (cptr)
      muptr->VmsMailAutoPurge = TRUE;
   else
      muptr->VmsMailAutoPurge = FALSE;

   CGIVARNULL (cptr, "FORM_OPTION_VMS_CCPROMPT");
   if (cptr)
      muptr->VmsMailCcPrompt = TRUE;
   else
      muptr->VmsMailCcPrompt = FALSE;

   CGIVARNULL (cptr, "FORM_OPTION_VMS_COPYFWD");
   if (cptr)
      muptr->VmsMailCopyForward = TRUE;
   else
      muptr->VmsMailCopyForward = FALSE;

   CGIVARNULL (cptr, "FORM_OPTION_VMS_COPYREPLY");
   if (cptr)
      muptr->VmsMailCopyReply = TRUE;
   else
      muptr->VmsMailCopyReply = FALSE;

   CGIVARNULL (cptr, "FORM_OPTION_VMS_COPYSEND");
   if (cptr)
      muptr->VmsMailCopySend = TRUE;
   else
      muptr->VmsMailCopySend = FALSE;

   CGIVARNULL (cptr, "FORM_OPTION_VMS_EDITOR");
   if (cptr)
      muptr->VmsMailEditorLength =
         strzcpy (muptr->VmsMailEditor, cptr, sizeof(muptr->VmsMailEditor));
   else
   {
      muptr->VmsMailEditor[0] = '\0';
      muptr->VmsMailEditorLength = 0;
   }

   CGIVARNULL (cptr, "FORM_OPTION_VMS_FORWARDING");
   if (cptr)
      muptr->VmsMailForwardingLength =
         strzcpy (muptr->VmsMailForwarding, cptr,
                  sizeof(muptr->VmsMailForwarding));
   else
   {
      muptr->VmsMailForwarding[0] = '\0';
      muptr->VmsMailForwardingLength = 0;
   }

   CGIVARNULL (cptr, "FORM_OPTION_VMS_PERSONAL");
   if (cptr)
      muptr->VmsMailPersonalNameLength =
         strzcpy (muptr->VmsMailPersonalName, cptr,
                  sizeof(muptr->VmsMailPersonalName));
   else
   {
      muptr->VmsMailPersonalName[0] = '\0';
      muptr->VmsMailPersonalNameLength = 0;
   }

   CGIVARNULL (cptr, "FORM_OPTION_SIGFILE");
   if (cptr)
      muptr->VmsMailSigFileLength =
         strzcpy (muptr->VmsMailSigFile, cptr, sizeof(muptr->VmsMailSigFile));
   else
   {
      muptr->VmsMailSigFile[0] = '\0';
      muptr->VmsMailSigFileLength = 0;
   }

   CGIVARNULL (cptr, "FORM_OPTION_VMS_QUEUE");
   if (cptr)
      muptr->VmsMailQueueLength =
         strzcpy (muptr->VmsMailQueue, cptr, sizeof(muptr->VmsMailQueue));
   else
   {
      muptr->VmsMailQueue[0] = '\0';
      muptr->VmsMailQueueLength = 0;
   }

   CGIVARNULL (cptr, "FORM_OPTION_VMS_FORM");
   if (cptr)
      muptr->VmsMailFormLength =
         strzcpy (muptr->VmsMailForm, cptr, sizeof(muptr->VmsMailForm));
   else
   {
      muptr->VmsMailForm[0] = '\0';
      muptr->VmsMailFormLength = 0;
   }

   CallMailSetUserProfile (muptr);

   if (VMSok (muptr->MailVmsStatus))
      StatusMessage (FI_LI, 0, LangFor("option_saved"));
   else
      StatusMessage (FI_LI, 1, "MAIL: %s.", SysGetMsg(muptr->MailVmsStatus));
}

/*****************************************************************************/
/*
Load the file contents representing the signature.
*/

void OptionsSigFileLoad
(
REQUEST_DATA *rdptr,
char *ThisSigFile
)
{
   int  status;
   char  *cptr, *fnptr, *sptr, *zptr;
   char  SigFileName [128];
   USER_OPTIONS  *uoptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug)
      fprintf (stdout, "OptionsSigFileLoad() |%s|\n",
               ThisSigFile ? ThisSigFile : "(null)");

   muptr = &VmsMailUser;
   if (!muptr->VmsMailFullDirectoryLength) ErrorExit (SS$_BUGCHECK, FI_LI);

   uoptr = &rdptr->UserOptions;

   if (ThisSigFile)
   {
      /* OPTIONS_SOY_SIGFILE_DEFAULT */
      if (!strcmp (ThisSigFile, "(1)"))
         fnptr = muptr->VmsMailSigFile;
      else
      /* OPTIONS_SOY_SIGFILE_SOYMAIL */
      if (!strcmp (ThisSigFile, "(2)"))
         fnptr = SOY_SIGFILE;
      /* OPTIONS_SOY_SIGFILE_NAME */
      else
      {
         zptr = (sptr = SigFileName) + sizeof(SigFileName)-1;
         for (cptr = SOYMAIL_SIGNATURE_NAME;
              *cptr && sptr < zptr;
              *sptr++ = *cptr++); 
         for (cptr = ThisSigFile; *cptr && sptr < zptr; *sptr++ = *cptr++);
         for (cptr = ".TXT"; *cptr && sptr < zptr; *sptr++ = *cptr++);
         *sptr = '\0';
         fnptr = SigFileName;
      }
   }
   else
   if (uoptr->SigFile == OPTIONS_SOY_SIGFILE_DEFAULT)
      fnptr = muptr->VmsMailSigFile;
   else
   if (uoptr->SigFile == OPTIONS_SOY_SIGFILE_SOYMAIL)
      fnptr = SOY_SIGFILE;
   else
   if (uoptr->SigFile == OPTIONS_SOY_SIGFILE_NAME &&
       isalnum(uoptr->SigFileName[0]))
   {
      zptr = (sptr = SigFileName) + sizeof(SigFileName)-1;
      for (cptr = SOYMAIL_SIGNATURE_NAME;
           *cptr && sptr < zptr;
           *sptr++ = *cptr++); 
      for (cptr = uoptr->SigFileName; *cptr && sptr < zptr; *sptr++ = *cptr++);
      for (cptr = ".TXT"; *cptr && sptr< zptr; *sptr++ = *cptr++);
      *sptr = '\0';
      fnptr = SigFileName;
   }
   else
      return;

   fnptr = CallMailFileIn (muptr, NULL, fnptr);
   if (WatchEnabled) WatchThis (FI_LI, "SIGNATURE !AZ", fnptr);

   status = ReadFileIntoMemory (fnptr, &muptr->SignaturePtr,
                                       &muptr->SignatureLength);
   if (VMSnok (status) && status != RMS$_FNF)
      StatusMessage (FI_LI, 1, "%s: %s.",
                     LangFor("option_sigfile"), SysGetMsg(status));
   if (VMSnok (status))
   {
      muptr->SignaturePtr = NULL;
      muptr->SignatureLength = 0;
   }
}

/*****************************************************************************/
/*
Save the contents of the signature file text field in the VMS specified
signature file name in the VMS Mail directory.
*/

void OptionsSigFileSave (REQUEST_DATA *rdptr)

{
   int  status;
   char  *cptr, *fnptr, *sptr, *zptr,
         *SigFileText;
   char  SigFileName [128];
   FILE  *fp;
   USER_OPTIONS  *uoptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSigFileSave()\n");

   muptr = &VmsMailUser;
   if (!muptr->VmsMailFullDirectoryLength) ErrorExit (SS$_BUGCHECK, FI_LI);

   uoptr = &rdptr->UserOptions;

   CGIVARNULL (cptr, "FORM_OPTION_SOY_SIGFILE_NAME");
   if (cptr)
   {
      while (*cptr && isspace(*cptr)) cptr++;
      if (*cptr)
      {
         strzcpy (uoptr->SigFileName, cptr, sizeof(uoptr->SigFileName));
         uoptr->SigFile = OPTIONS_SOY_SIGFILE_NAME;
      }
   }

   if (uoptr->SigFile == OPTIONS_SOY_SIGFILE_DEFAULT)
      fnptr = muptr->VmsMailSigFile;
   else
   if (uoptr->SigFile == OPTIONS_SOY_SIGFILE_SOYMAIL)
      fnptr = SOY_SIGFILE;
   else
   if (uoptr->SigFile == OPTIONS_SOY_SIGFILE_NAME &&
       isalnum(uoptr->SigFileName[0]))
   {
      zptr = (sptr = SigFileName) + sizeof(SigFileName)-1;
      for (cptr = SOYMAIL_SIGNATURE_NAME;
           *cptr && sptr < zptr;
           *sptr++ = *cptr++); 
      for (cptr = uoptr->SigFileName; *cptr && sptr < zptr; *sptr++ = *cptr++);
      for (cptr = ".TXT"; *cptr && sptr< zptr; *sptr++ = *cptr++);
      *sptr = '\0';
      fnptr = SigFileName;
   }
   else
      return;

   fnptr = CallMailFileIn (muptr, NULL, fnptr);

   status = SS$_NORMAL;

   CGIVARNULL (SigFileText, "FORM_OPTION_SIGFILE_TEXT");
   if (!SigFileText)
   {
      StatusMessage (FI_LI, SS$_BUGCHECK, LangFor("option_saved"));
      return;
   }

   /* reduce those pesky Windows <CR><LF> to <LF> */
   cptr = sptr = SigFileText;
   while (*cptr)
   {
      if (*(USHORTPTR)cptr == '\r\n') cptr++;
      *sptr++ = *cptr++;
   }
   *sptr = '\0';
   for (cptr = SigFileText; *cptr && isspace(*cptr); cptr++);

   if (*cptr)
   {
      fp = fopen (fnptr, "w");
      if (fp)
      {
         if (fputs (SigFileText, fp) < 0) status = vaxc$errno;
         fclose (fp);
         if (VMSok (status))
         {
            /* purge the versions back */
            strcat (fnptr, ";-1");
            while (!remove (fnptr));
         }
         else
         {
            /* remove this latest one */
            strcat (fnptr, ";0");
            remove (fnptr);
         }
      }
      else
         status = vaxc$errno;
   }
   else
   {
      /* empty content, just delete the file */
      if (remove (fnptr)) status = vaxc$errno;
   }

   if (VMSok (status))
      StatusMessage (FI_LI, 0, LangFor("option_saved"));
   else
      StatusMessage (FI_LI, 1, "%s: %s.",
                     LangFor("option_sigfile"), SysGetMsg(status));
}

/*****************************************************************************/
/*
For all files matching the supplied specification create an appropriate
<option> item for an enclosing </select> dialog.  If the searched-for file name
matches the supplied file name then make that the selected item.  Files with a
leading underscore have the visibility of that underscore changed to allow
soyMAIL distributions to avoid overwriting theme files, etc.  Just prefix local
ones with an underscore!
*/

int OptionsSigSelectFile
(
REQUEST_DATA *rdptr,
char *ThisSigFile
)
{
   int  FileCount = 0;
   char  *cptr, *sptr, *zptr;
   char  FileName [256];
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSigSelectFile()\n");

   muptr = &VmsMailUser;

   cptr = FileSpecSearch (1, muptr->VmsMailFullDirectory,
                             SOYMAIL_SIGNATURE_NAME "*.TXT");
   while (cptr)
   {
      FileCount++;
      cptr += SOYMAIL_SIGNATURE_SIZE;

      zptr = (sptr = FileName) + sizeof(FileName)-1;
      while (*cptr && *cptr != '.' && sptr < zptr)
      {
         if (*cptr == '_')
            *sptr++ = ' ';
         else
            *sptr++ = *cptr;
         cptr++;
      }
      *sptr = '\0';

      if (SoyMailVolumeStruct != 5)
      {
         /* capitalise all leading alphabetics while lower-casing all others */
         cptr = FileName;
         if (isalpha(*cptr)) *cptr = toupper(*cptr);
         for (cptr++; *cptr; cptr++)
            if (!isalnum(*(cptr-1)) && isalpha(*cptr))
               *cptr = toupper(*cptr);
            else
               *cptr = tolower(*cptr);
      }

      if (strsame (FileName, ThisSigFile, -1))
         cptr = " selected";
      else
         cptr = "";
      sptr = HTML_ESCAPE(FileName); 

      fprintf (stdout, "<option value=\"%s\"%s>%s\n", sptr, cptr, sptr);

      cptr = FileSpecSearch (1, NULL, NULL);
   }

   return (FileCount);
}

/*****************************************************************************/
/*
Load the user options file and parse it's contents (setting user options along
the way!)  soyMAIL administrator can override some of those options so check
for that and parse as necessary.
*/

void OptionsLoadSoy (REQUEST_DATA *rdptr)

{
   int  status,
        OptionsTextLength;
   char  *cptr, *fnptr, *sptr,
         *OptionsTextPtr,
         *NamePtr,
         *ValuePtr;
   USER_OPTIONS  *uoptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsLoadSoy()\n");

   muptr = &VmsMailUser;
   uoptr = &rdptr->UserOptions;

   memset (uoptr, 0, sizeof(USER_OPTIONS));

   uoptr->OptionsLoaded = TRUE;

   if (!muptr->UserName[0])
   {
      strcpy (muptr->UserName, rdptr->UserName);
      muptr->UserNameLength = strlen(muptr->UserName);
   }

   CallMailGetUserProfile (muptr);
   if (VMSnok (muptr->MailVmsStatus))
   {
      /* pretty fundamental error */
      if (WatchEnabled) WatchThis (FI_LI, "%X!8XL", muptr->MailVmsStatus);
      if (muptr->MailVmsStatus == MAIL$_NOSUCHUSER)
      {
         /* well before we've loaded our language file */
         CgiLibResponseError (FI_LI, 0, CallMailNoSuchUser);
         exit (SS$_NORMAL);
      }
      else
         ErrorExit (muptr->MailVmsStatus, FI_LI);
   }
   rdptr->NewMessages = muptr->VmsMailNewMessages;

   if (!muptr->VmsMailFullDirectoryLength) ErrorExit (SS$_BUGCHECK, FI_LI);

   /**************************/
   /* some up-front defaults */
   /**************************/

   if (muptr->MailFileList.ListLength && muptr->MailFileList.ListCount <= 1)
      uoptr->AllMailFiles = 0;

   uoptr->MassageRead = atoi(DEFAULT_WRAP_AT);
   uoptr->MessageOrder = 1;
   uoptr->PmdfImap = 0;
   uoptr->PreviewAfter = DEFAULT_PREVIEW_AFTER;
   uoptr->PreviewSize = DEFAULT_PREVIEW_SIZE;

   strcpy (uoptr->QuoteReply, OPTIONS_QUOTE_REPLY);
   strcpy (uoptr->QuoteForward, OPTIONS_QUOTE_FORWARD);

   if (SoyMailConfig.VmsOccluded)
      uoptr->SigFile == OPTIONS_SOY_SIGFILE_NONE;
   else
      uoptr->SigFile = OPTIONS_SOY_SIGFILE_DEFAULT;
   sprintf (uoptr->SigFileName, "(%d)", uoptr->SigFile);

   /*********************/
   /* load options file */
   /*********************/

   fnptr = CallMailFileIn (muptr, NULL, SOY_OPTIONS);

   if (WatchEnabled) WatchThis (FI_LI, "OPTION !AZ", fnptr);

   status = ReadFileIntoMemory (fnptr, &OptionsTextPtr, &OptionsTextLength);
   if (VMSnok (status) && status != RMS$_FNF) 
      StatusMessage (FI_LI, 1, "%s: %s.", SOY_MAIL, SysGetMsg(status));

   /*****************/
   /* parse options */
   /*****************/

   /* if the soyMAIL administrator wishes to default some options */
   if (SoyMailConfig.UserOptionsDefault)
      OptionsParse (uoptr, SoyMailConfig.UserOptionsDefault);

   OptionsParse (uoptr, OptionsTextPtr);

   /* make sure they are reasonable */
   OptionsMunge (uoptr);
}

/*****************************************************************************/
/*
Set up the 'personal configuration' options for public access.
*/

void OptionsPublicGet (REQUEST_DATA *rdptr)

{
   USER_OPTIONS  *uoptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsPublicGet()\n");

   uoptr = &rdptr->UserOptions;

   uoptr->MassageRead = atoi(DEFAULT_WRAP_AT);
   uoptr->AllMailFiles = 0;
   uoptr->PmdfImap = 0;

   /* if the soyMAIL administrator wishes to default some options */
   if (SoyMailConfig.PublicOptionsDefault)
      OptionsParse (uoptr, SoyMailConfig.PublicOptionsDefault);

   /* make sure they are reasonable */
   OptionsMunge (uoptr);
}

/*****************************************************************************/
/*
Make sure the options seem reasonable.
*/

void OptionsMunge (USER_OPTIONS *uoptr)

{
    char  *cptr, *sptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsMunge()\n");

   if (!uoptr->Theme[0]) strcpy (uoptr->Theme, OPTIONS_THEME);
   if (!uoptr->Language[0]) strcpy (uoptr->Language, OPTIONS_LANGUAGE);

   if (!uoptr->FontFamily[0])
      strcpy (uoptr->FontFamily, OptionsFontFamily[0]);
   if (strstr (uoptr->FontFamily, "monospace"))
      uoptr->FontIsMono = TRUE;
   else
      uoptr->FontIsMono = FALSE;

   if (!uoptr->FontSize) uoptr->FontSize = OPTIONS_FONT_SIZE;
   if (uoptr->FontSize < 6) uoptr->FontSize = 6;
   if (uoptr->FontSize > 20) uoptr->FontSize = 20;

   if (uoptr->CheckNewMailMins < 0) uoptr->CheckNewMailMins = 0;
   if (uoptr->CheckNewMailMins > 60) uoptr->CheckNewMailMins = 60;

   if (!uoptr->MessagesPerPage) uoptr->MessagesPerPage = OPTIONS_PER_PAGE;
   if (uoptr->MessagesPerPage < 1) uoptr->MessagesPerPage = 1;
   if (uoptr->MessagesPerPage > 100) uoptr->MessagesPerPage = 100;

   if (uoptr->ReadPreference != OPTIONS_READ_PLAIN1_HTML0 &&
       uoptr->ReadPreference != OPTIONS_READ_PLAIN1_HTML2 &&
       uoptr->ReadPreference != OPTIONS_READ_PLAIN2_HTML1)
      uoptr->ReadPreference = OPTIONS_READ_PLAIN1_HTML2;

   if (!strcmp (uoptr->FolderDraftItems, "MAIL") ||
       !strcmp (uoptr->FolderDraftItems, "NEWMAIL"))
      strzcpy (uoptr->FolderDraftItems, 
               LangFor("folder_draft_items"),
               sizeof(uoptr->FolderDraftItems));

   if (!strcmp (uoptr->FolderWasteItems, "MAIL") ||
       !strcmp (uoptr->FolderWasteItems, "NEWMAIL"))
      strzcpy (uoptr->FolderWasteItems, 
               LangFor("folder_waste_items"),
               sizeof(uoptr->FolderWasteItems));

   /* remove the (v1.2 and later) enclosing quotes */
   cptr = sptr = uoptr->QuoteForward;
   if (*cptr == '\"')
   {
      for (cptr++; *cptr; cptr++);
      if (cptr > sptr && *(cptr-1) == '\"')
      {
         for (cptr = sptr+1; *cptr; *sptr++ = *cptr++);
         *--sptr = '\0';
      }
   }
   cptr = sptr = uoptr->QuoteReply;
   if (*cptr == '\"')
   {
      for (cptr++; *cptr; cptr++);
      if (cptr > sptr && *(cptr-1) == '\"')
      {
         for (cptr = sptr+1; *cptr; *sptr++ = *cptr++);
         *--sptr = '\0';
      }
   }

   /* with backward compatibility to pre-v1.4 */
   cptr = uoptr->SigFileName;
   if (!strcmp (cptr, "(0)") ||
       !strcmp (cptr, "999"))
      uoptr->SigFile = OPTIONS_SOY_SIGFILE_NONE;
   else
   if (!strcmp (cptr, "(1)") ||
       !strcmp (cptr, "0"))
      uoptr->SigFile = OPTIONS_SOY_SIGFILE_DEFAULT;
   else
   if (!strcmp (cptr, "(2)") ||
       !strcmp (cptr, "1"))
      uoptr->SigFile = OPTIONS_SOY_SIGFILE_SOYMAIL;
   else
   {
      uoptr->SigFile = OPTIONS_SOY_SIGFILE_NAME;
      /* only basic characters allowed */
      for (cptr = sptr = uoptr->SigFileName; *cptr; cptr++)
         if (isalnum(*cptr) || isspace(*cptr) || *cptr == '_')
            *sptr++ = *cptr;
      *sptr = '\0';
   }

   /*
      An exclamation mark (or asterisk for backwards compatibility)
      creates an empty [smtp-from] (for user options override).
   */
   if (uoptr->SmtpFrom[0] == '!' || uoptr->SmtpFrom[0] == '*')
      uoptr->SmtpFrom[0] = '\0';

   /* PMDF IMAP processing has precedence */
   if (uoptr->PmdfImap) uoptr->AllMailFiles = 0;

   switch (uoptr->PreviewAfter)
   {
      /* milliseconds (JavaScript) */
      case 0 :
      case 800 :
      case 1000 :
      case 1200 :
      case 1400 :
      case 1600 :
      case 1800 :
      case 2000 :
      case 3000 :
      case 5000 :
         break;
      default :
         uoptr->PreviewAfter = 1000;
   }

   if (uoptr->PreviewSize < 256 ||
       uoptr->PreviewSize > 1024)
      uoptr->PreviewSize = DEFAULT_PREVIEW_SIZE;
}

/*****************************************************************************/
/*
Parse a collection of newline-delimited text with options directives setting
user options.
*/

void OptionsParse
(
USER_OPTIONS *uoptr,
char  *OptionsTextPtr
)
{
   char  *cptr, *NamePtr, *ValuePtr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsParse()\n");

   if (!OptionsTextPtr) return;

   while (*OptionsTextPtr)
   {
      cptr = ConfigTextParse (&OptionsTextPtr, &NamePtr, &ValuePtr);
      if (!cptr) break;

      if (strsame (NamePtr, "accessability-1", -1)) {
         if (isdigit(*ValuePtr)) uoptr->Accessability1 = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "charset-default", -1))
         strzcpy (uoptr->CharSetDefault, ValuePtr,
                  sizeof(uoptr->CharSetDefault));
      else
      if (strsame (NamePtr, "check-newmail-ajax", -1)) {
         if (isdigit(*ValuePtr)) uoptr->CheckNewMailAjax = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "check-new-mail", -1)) {
         if (isdigit(*ValuePtr)) uoptr->CheckNewMailMins = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "compose-charsets", -1))
         strzcpy (uoptr->ComposeCharSets, ValuePtr,
                  sizeof(uoptr->ComposeCharSets));
      else
      if (strsame (NamePtr, "compose-edit-cols", -1))
         strzcpy (uoptr->ComposeEditCols, ValuePtr,
                  sizeof(uoptr->ComposeEditCols));
      else
      if (strsame (NamePtr, "compose-edit-rows", -1))
         strzcpy (uoptr->ComposeEditRows, ValuePtr,
                  sizeof(uoptr->ComposeEditRows));
      else
      if (strsame (NamePtr, "compose-HTML", -1)) {
         if (isdigit(*ValuePtr)) uoptr->ComposeHTML = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "compose-wrap-at", -1))
         strzcpy (uoptr->ComposeWrapAt, ValuePtr,
                  sizeof(uoptr->ComposeWrapAt));
      else
      if (strsame (NamePtr, "draft-items", -1))
         strzcpy (uoptr->FolderDraftItems, ValuePtr,
                  sizeof(uoptr->FolderDraftItems));
      else
      if (strsame (NamePtr, "font-family", -1))
         strzcpy (uoptr->FontFamily, ValuePtr, sizeof(uoptr->FontFamily));
      else
      if (strsame (NamePtr, "font-size", -1)) {
         if (isdigit(*ValuePtr)) uoptr->FontSize = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "folder-buttons", -1)) {
         if (isdigit(*ValuePtr)) uoptr->FolderButtons = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "image-inline", -1)) {
         if (isdigit(*ValuePtr)) uoptr->ImageInline = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "language", -1))
         strzcpy (uoptr->Language, ValuePtr, sizeof(uoptr->Language));
      else
      if (strsame (NamePtr, "massage-read", -1)) {
         if (isdigit(*ValuePtr)) uoptr->MassageRead = atoi(ValuePtr);
         if (uoptr->MassageRead && uoptr->MassageRead < atoi(DEFAULT_WRAP_AT))
            uoptr->MassageRead = atoi(DEFAULT_WRAP_AT);
      }
      else
      if (strsame (NamePtr, "message-attachment-panel", -1)) {
         if (*ValuePtr) uoptr->MessageAttachmentPanel = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "message-order", -1)) {
         if (*ValuePtr) uoptr->MessageOrder = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "message-read-preference", -1)) {
         if (isdigit(*ValuePtr)) uoptr->ReadPreference= atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "messages-per-page", -1)) {
         if (isdigit(*ValuePtr)) uoptr->MessagesPerPage = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "VMS-newmsg", -1)) {
         if (isdigit(*ValuePtr) || *ValuePtr == '-')
            uoptr->VmsNewMsg = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "options-panel-expand", -1)) {
         if (isdigit(*ValuePtr)) uoptr->OptionsPanelExpand = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "personal-name", -1))
         strzcpy (uoptr->PersonalName, ValuePtr, sizeof(uoptr->PersonalName));
      else
      if (strsame (NamePtr, "PMDF-IMAP", -1)) {
         if (isdigit(*ValuePtr)) uoptr->PmdfImap = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "preview-after", -1)) {
         if (isdigit(*ValuePtr)) uoptr->PreviewAfter = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "preview-size", -1)) {
         if (isdigit(*ValuePtr)) uoptr->PreviewSize = atoi(ValuePtr);
      }
      else
      if (strsame (NamePtr, "quote-reply", -1) ||
          /* backward compatibility with v1.2 */
          strsame (NamePtr, "quote-char", -1))
         strzcpy (uoptr->QuoteReply, ValuePtr, sizeof(uoptr->QuoteReply));
      else
      if (strsame (NamePtr, "quote-forward", -1))
         strzcpy (uoptr->QuoteForward, ValuePtr, sizeof(uoptr->QuoteForward));
      else
      if (strsame (NamePtr, "sent-items", -1))
         strzcpy (uoptr->FolderSentItems, ValuePtr,
                  sizeof(uoptr->FolderSentItems));
      else
      if (strsame (NamePtr, "sig-file", -1))
         strzcpy (uoptr->SigFileName, ValuePtr, sizeof(uoptr->SigFileName));
      else
      if (strsame (NamePtr, "SMTP-from", -1))
         strzcpy (uoptr->SmtpFrom, ValuePtr, sizeof(uoptr->SmtpFrom));
      else
      if (strsame (NamePtr, "theme", -1))
         strzcpy (uoptr->Theme, ValuePtr, sizeof(uoptr->Theme));
      else
      if (strsame (NamePtr, "use-only-MAIL", -1))
      {
         if (atoi(ValuePtr))
            uoptr->AllMailFiles = 0;
         else
            uoptr->AllMailFiles = 1;
      }
      else
      if (strsame (NamePtr, "version", -1))
         cptr = NULL;
      else
      if (strsame (NamePtr, "you-got-mail", -1))
         strzcpy (uoptr->YouGotMail, ValuePtr, sizeof(uoptr->YouGotMail));
      else
      if (strsame (NamePtr, "you-got-mail-at", -1))
         strzcpy (uoptr->YouGotMailAt, ValuePtr, sizeof(uoptr->YouGotMailAt));
      else
      if (strsame (NamePtr, "waste-items", -1))
         strzcpy (uoptr->FolderWasteItems, ValuePtr,
                  sizeof(uoptr->FolderWasteItems));
      else
      if (WatchEnabled)
         WatchThis (FI_LI, "OPTION error [!AZ]", NamePtr);
   }
}

/*****************************************************************************/
/*
Return true if the specific option name is found in any [user-options-override]
configuration directive that might be set.  If not found return false.
*/

BOOL OptionsUserOverride (char *OptionName)

{
   char  *cptr, *sptr,
         *OptionsTextPtr,
         *NamePtr,
         *ValuePtr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsUserOverride()\n");

   if (!(cptr = SoyMailConfig.UserOptionsOverride)) return (FALSE);

   if (Debug) fprintf (stdout, "|%s|\n", cptr);

   /* duplicate because ConfigTextParse() munges the string */
   OptionsTextPtr = sptr =  CgiLibVeeMemCalloc (strlen(cptr)+1);
   if (!OptionsTextPtr) ErrorExit (vaxc$errno, FI_LI);
   strcpy (OptionsTextPtr, cptr);

   while (*OptionsTextPtr)
   {
      cptr = ConfigTextParse (&OptionsTextPtr, &NamePtr, &ValuePtr);
      if (!cptr) break;
      if (strsame (cptr, OptionName, -1))
      {
         CgiLibVeeMemFree (sptr);
         return (TRUE);
      }
   }
   CgiLibVeeMemFree (sptr);

   return (FALSE);
}

/*****************************************************************************/
/*
Display in the selector the [lang_name] string rather than the file name (just
a bit more friendly, eh Bill?)
*/

void OptionsSelectLanguage (USER_OPTIONS *uoptr)

{
   int  status,
        FileCount,
        LangTextLength;
   char  *cptr, *fnptr, *sptr, *zptr,
         *LangTextPtr;
   char  FileName [64],
         LangName [64];

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSelectLanguage()\n");

   fnptr = FileSpecSearch (0, SOY_LANG_DIR, "*.TXT");
   while (fnptr)
   {
      if (WatchEnabled) WatchThis (FI_LI, "!AZ", fnptr); 
      FileCount++;
      LangName[0] = '\0';

      for (cptr = fnptr; *cptr; cptr++);
      while (cptr > fnptr && *cptr != ']') cptr--;
      if (*cptr == ']') cptr++;
      zptr = (sptr = FileName) + sizeof(FileName)-1;
      while (*cptr && *cptr != '.' && sptr < zptr) *sptr++ = tolower(*cptr++);
      *sptr = '\0';

      status = ReadFileIntoMemory (fnptr, &LangTextPtr, &LangTextLength);
      if (VMSok (status))
      {
         if (cptr = strstr (LangTextPtr, "[lang_name]"))
         {
            for (cptr += 11; *cptr && isspace(*cptr); cptr++);
            if (*cptr != '[')
            {
               zptr = (sptr = LangName) + sizeof(LangName)-1;
               while (*cptr && !isspace(*cptr) && sptr < zptr)
                  *sptr++ = *cptr++;
               *sptr = '\0';
            }
         }
         CgiLibVeeMemFree (LangTextPtr);
      }
      else
      if (WatchEnabled) WatchThis (FI_LI, "!AZ %X!8XL", fnptr, status); 

      if (!LangName[0]) strcpy (LangName, FileName);

      fprintf (stdout, "<option value=\"%s\"%s>%s\n",
               FileName,
               strsame(uoptr->Language,FileName,-1) ? " selected" : "",
               LangName);

      fnptr = FileSpecSearch (0, NULL, NULL);
   }

   if (!FileCount)
      fprintf (stdout, "<option value=\"%s\">%s\n",
               LangFor("sanity_check"), LangFor("sanity_check"));
}

/*****************************************************************************/
/*
For all files matching the supplied specification create an appropriate
<option> item for an enclosing </select> dialog.  If the searched-for file name
matches the supplied file name then make that the selected item.  Files with a
leading underscore have the visibility of that underscore changed to allow
soyMAIL distributions to avoid overwriting theme files, etc.  Just prefix local
ones with an underscore!
*/

int OptionsSelectFile
(
char *DefaultDirectory,
char *FileSpec,
char *SelectFileName
)
{
   int  FileCount = 0;
   char  *cptr, *sptr, *zptr;
   char  FileName [256];

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsSelectFile()\n");

   cptr = FileSpecSearch (1, DefaultDirectory, FileSpec);
   while (cptr)
   {
      FileCount++;
      zptr = (sptr = FileName) + sizeof(FileName)-1;
      if (SoyMailVolumeStruct == 5)
         while (*cptr && *cptr != '.' && sptr < zptr) *sptr++ = *cptr++;
      else
         while (*cptr && *cptr != '.' && sptr < zptr)
            *sptr++ = tolower(*cptr++);
      *sptr = '\0';
      if (strsame (FileName, SelectFileName, -1))
         cptr = " selected";
      else
         cptr = "";
      sptr = HTML_ESCAPE(FileName); 
      /* suppress the visibility of a leading underscore */
      fprintf (stdout, "<option value=\"%s\"%s>%s\n",
               sptr, cptr, *sptr == '_' ? sptr+1 : sptr);
      cptr = FileSpecSearch (1, NULL, NULL);
   }
   return (FileCount);
}

/*****************************************************************************/
/*
Uploaded personal newmail audio file content.
*/

void OptionsPersonalYouGotMail (REQUEST_DATA *rdptr)

{
   /* this leading sequence identifies a .MP3 file content ("RIFF") */
   static char  WavFourId [] = { 0x52, 0x49, 0x46, 0x46 };

   int  retval, status,
        DataLength;
   char  *cptr, *fnptr, *DataPtr;
   FILE  *fp;
   USER_OPTIONS  *uoptr;
   VMS_MAIL_USER  *muptr;

   /*********/
   /* begin */
   /*********/

   if (Debug) fprintf (stdout, "OptionsPersonalYouGotMail()\n");

   muptr = &VmsMailUser;
   uoptr = &rdptr->UserOptions;

   DataPtr = CgiLibVar ("FORM_OPTION_SOY_FILE_YOUGOTMAIL");
   if (WatchEnabled)
      WatchThis (FI_LI, "CGIVAR !AZ=!AZ", "FORM_OPTION_SOY_FILE_YOUGOTMAIL", DataPtr); 
   if (CgiLibBodyIsMultipartFormData())
      DataLength = CgiLibHtmlDeEntify (DataPtr);
   else
      DataLength = strlen(DataPtr);

   if (DataLength / 1024 > SOY_YOUGOTMAIL_SIZE_KBYTES_MAX)
   {
      StatusMessage (FI_LI, 1, "%s %d kbytes.",
                     LangFor("file_too_large"),
                     SOY_YOUGOTMAIL_SIZE_KBYTES_MAX);
      return;
   }

   if (memcmp (DataPtr, WavFourId, 4))
   {
      StatusMessage (FI_LI, 1, "%s %s.",
                     LangFor("file_wrong_type"), ".MP3 (audio/mpeg)");
      return;
   }

   fnptr = CallMailFileIn (muptr, NULL, SOY_YOUGOTMAIL);
   if (WatchEnabled) WatchThis (FI_LI, "OPTIONS !AZ", fnptr);

   fp = fopen (fnptr, "w", "ctx=bin", "rfm=udf", "rat=none");
   if (!fp)
   {
      status = vaxc$errno;
      StatusMessage (FI_LI, 1, "%s: %s.", SOY_YOUGOTMAIL, SysGetMsg(status));
      return;
   }

   retval = write (fileno(fp), DataPtr, DataLength);
   fclose (fp);

   if (retval <= 0)
   {
      status = vaxc$errno;
      StatusMessage (FI_LI, 1, "%s: %s.", SOY_YOUGOTMAIL, SysGetMsg(status));
      /* remove remnants of failed write */
      while (!remove (fnptr));
      return;
   }

   /* purge the versions back */
   strcat (fnptr, ";-1");
   while (!remove (fnptr));

   strcpy (uoptr->YouGotMail, LangFor("option_soy_you_got_mail_personal"));
}

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

