/*
 * $Id: winvn.c 1.85 1997/04/05 00:26:27 dumoulin Exp $
 */

/*  WinVn.c
 *  This program is a visual Usenet news reader for Microsoft Windows.
 *  It bears a vague similarity to the Unix program "vn"; hence the
 *  name WINVN.
 *
 *  WinVN talks NNTP (Network News Transfer Protocol) to a news
 *  server, which must be running the NNTP program.
 *
 *  NNTP servers for many platforms are freely available.
 *
 *  For more information, see WINVN.WRI and WVDOC.C.
 *
 *  Mark Riordan    September - October 1989    riordanmr@clvax1.cl.msu.edu
 *  1100 Parker  Lansing, MI  48912
 *  
 *  Major modifications and additions were made by Sam Rushing and Jim Dumoulin
 *  of NASA/Kennedy Space Center.  WinVN is currently being maintained by Jim
 *  Dumoulin and a number of folks on the WinVN mailing list.  For more information
 *  send e-mail to "winvn@news.ksc.nasa.gov"   */

#include <windows.h>
#include <windowsx.h>
#pragma hdrstop
#define WINMAIN
#include "wvglob.h"
#include "winvn.h"
#include "ctype.h"
#include "defaults.h"                   // default profile settings
#include <stdlib.h>
#include <time.h>               // for TimeZone info
#include <io.h>                                 // for _access
#include <tchar.h>
#include <commctrl.h>
#ifdef USE_3D_CONTROLS
#include "ctl3d.h"
#endif

#ifdef _WIN32
#include <ole2.h>
#endif

#include "sha1.h" //TESTING
#include "wvimage.h" //KWIKDecode
#include "mdump.h" //MiniDump on crash

#ifndef _DEBUG
MiniDumper HailMary("WinVN"); //global dumper object
#endif


void ReadWinvnProfile ();

// (jsc) undefine this when pre v.90 is obsolete
#define PROFILE_PRE90_UPGRADE
void UpgradePre90Profile ();

// (jsc) undefine this when pre v.93 is obsolete
#define PROFILE_PRE93_UPGRADE
void UpgradePre93Profile ();

#ifndef _DEBUG
static int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep) 
{
    const TCHAR *pMsg = NULL;
    bool bUnknown = false;    
    switch (code)
    {
        case EXCEPTION_ACCESS_VIOLATION:
            pMsg = _T("Access Violation");
            break;    
        case EXCEPTION_DATATYPE_MISALIGNMENT:
            pMsg = _T("Datatype Mismatch");
            break;
        case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
            pMsg = _T("Array Bounds Exceeded");
            break;
        case EXCEPTION_FLT_DENORMAL_OPERAND:
            pMsg = _T("Floatingpoint operand denormal");
            break;
        case EXCEPTION_FLT_DIVIDE_BY_ZERO:
            pMsg = _T("Floatingpoint divide by 0");
            break;
        case EXCEPTION_FLT_INEXACT_RESULT:
            pMsg = _T("Floatingpoint inexact result");
            break;
        case EXCEPTION_FLT_INVALID_OPERATION:
            pMsg = _T("Floatingpoint invalid operation");
            break;
        case EXCEPTION_FLT_OVERFLOW:
            pMsg = _T("Floatingpoint overflow");
            break;
        case EXCEPTION_FLT_STACK_CHECK:
            pMsg = _T("Floatingpoint stack check");
            break;
        case EXCEPTION_FLT_UNDERFLOW:
            pMsg = _T("Floatingpoint underflow");
            break;
        case EXCEPTION_INT_DIVIDE_BY_ZERO:
            pMsg = _T("Integer divide by 0");
            break;
        case EXCEPTION_INT_OVERFLOW:
            pMsg = _T("Integer overflow");
            break;
        case EXCEPTION_PRIV_INSTRUCTION:
            pMsg = _T("Priviledge Instuction violation");
            break;
        case EXCEPTION_NONCONTINUABLE_EXCEPTION:
            pMsg = _T("Thread attempted to continue after noncontinuable exception occured");
            break;
        case EXCEPTION_BREAKPOINT:
            pMsg = _T("Breakpoint encountered");
            break;
        case EXCEPTION_SINGLE_STEP:
            pMsg = _T("Single Step indication");
            break;
        default:
            pMsg = _T("Unknown exception code");
            bUnknown = true;
            break;
    }

 
    
    if (ep->ExceptionRecord->ExceptionFlags == 0 && (code == EXCEPTION_BREAKPOINT || code == EXCEPTION_SINGLE_STEP || bUnknown) )
        return EXCEPTION_CONTINUE_SEARCH;

    TRACE(  _T("Caught exception:0x%08lX %s at 0x%08lX"), code, pMsg, ep->ExceptionRecord->ExceptionAddress);
    if (code == EXCEPTION_ACCESS_VIOLATION)
    {   //show address of exception
        TRACE(  _T("%s failure accessing address 0x%08lX"),           
            ep->ExceptionRecord->ExceptionInformation[0] == 0 ? _T("Read") : _T("Write"), ep->ExceptionRecord->ExceptionInformation[1]);
    }
    if (ep->ContextRecord->ContextFlags & CONTEXT_CONTROL)
    { // SS:SP, CS:IP, FLAGS, BP
        _CONTEXT* pRec = ep->ContextRecord;
#ifdef _WIN64
#else
        TRACE(  _T("SS:SP 0x%08lX:0x%08lX CS:IP 0x%08lX:0x%08lX\r\nFLAGS: 0x%08lX  BP: 0x%08lX"),
            pRec->SegSs, pRec->Esp, pRec->SegCs, pRec->Eip, pRec->EFlags, pRec->Ebp);
#endif
    }
    if (ep->ContextRecord->ContextFlags & CONTEXT_INTEGER)
    { // AX, BX, CX, DX, SI, DI
        _CONTEXT* pRec = ep->ContextRecord;
#ifdef _WIN64
#else
		TRACE(  _T("AX:0x%08lX  BX:0x%08lX  CX:0x%08lX\r\nDX:0x%08lX  SI:0x%08lX  DI:0x%08lX"),
            pRec->Eax, pRec->Ebx, pRec->Ecx, pRec->Edx, pRec->Esi, pRec->Edi);
#endif
	}
    if (ep->ContextRecord->ContextFlags & CONTEXT_SEGMENTS)
    { // DS, ES, FS, GS
        _CONTEXT* pRec = ep->ContextRecord;
#ifdef _WIN64
#else
		TRACE(  _T("DS:0x%08lX  ES:0x%08lX  FS:0x%08lX GS:0x%08lX"),
            pRec->SegDs, pRec->SegEs, pRec->SegFs, pRec->SegGs);    
#endif
	}

    return EXCEPTION_EXECUTE_HANDLER;

}
#endif

/*--- function WinMain -----------------------------------------------
 *
 *  Main program for WinVN.
 *  Initialize, then execute main loop.
 *
 *    Entry    hInstance      is a handle to this instance of execution
 *                            of this program.
 *             hPrevInstance  is a handle to a previous instance
 *                            of execution of this program (usually
 *                            0, i.e., none.  Few people would have
 *                            two copies of WinVN running simultaneously.)
 *             lpCmdLine      points to the command line--currently
 *                            not used.  (Not to useful for Windows programs.)
 *             nCmdShow       is a flag indicating that the main window
 *                            should be displayed.  (Fairly worthless.)
 */
#ifdef _WIN32
int system_codepage;
#endif

#ifdef JAPANESE // for test alpha level japanese patch
LONG __stdcall MyUnhandledExceptionFilter(EXCEPTION_POINTERS *xp)
{
  WVMessageLog("Exception");
  WVMessageBox( NULL, "Exception", "Handling", MB_OK | MB_ICONHAND);
  return EXCEPTION_CONTINUE_SEARCH;
}
#endif

int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  int x, y, width, height;
  char mybuf[MAXINTERNALLINE];

#ifdef _WIN32
  OSVERSIONINFO osv;
  STARTUPINFO sinfo; //S.Yoshida
  GetStartupInfo (&sinfo);
#endif

#ifdef USE_3D_CONTROLS
  Ctl3dRegister (hInstance);
  Ctl3dAutoSubclass (hInstance);
#endif

#ifdef COMMCTRL
  InitCommonControls();
#endif

#ifdef _WIN32
    //CoInitialize(NULL);
#endif

#ifdef JAPANESE
  SetUnhandledExceptionFilter( MyUnhandledExceptionFilter );
#endif

	SaveNewsrc = SaveConfig = TRUE;  

  //MDS parse cmdline for news: URL
  gURLinfo = (TypURL *) GlobalAllocPtr(GMEM_MOVEABLE, sizeof (TypURL));
  if (gURLinfo)
  {
      if ( !ParseURL( gURLinfo, lpCmdLine )) {
          GlobalFreePtr(gURLinfo);
          gURLinfo = NULL;
      }
      else
      {
          //if some random server or group don't save   our settings
          if ( *gURLinfo->URLServer || *gURLinfo->URLUser   || *gURLinfo->URLPassword )
              SaveNewsrc = SaveConfig = FALSE; 

      }
  }

#if NDEBUG
    __try 
#endif
    {

  if (!hPrevInstance)
        if (!WinVnInit (hInstance, lpCmdLine)) 
		{
#ifdef USE_3D_CONTROLS
          Ctl3dUnregister (hInstance);
#endif
        if (GroupFilter)
          GlobalFreePtr (GroupFilter);
        if (gURLinfo)
          GlobalFreePtr(gURLinfo);  
        return (0);
  }

/****************************************************************
* The new IntelliMouse uses a Registered message to transmit    *
* wheel rotation info. So register for it!                      *
*****************************************************************
*/
  uMSH_MOUSEWHEEL =
         RegisterWindowMessage(MSH_MOUSEWHEEL);
             if ( !uMSH_MOUSEWHEEL )    {
                  WVMessageBox(NULL,IDS_WINVN_REGISTERWHEEL,IDS_ERROR,MB_OK | MB_ICONINFORMATION);
                  return (0);
         } 
		 
  uRegMsg = RegisterWindowMessage( _T("WINVNMSG") );   

  hInst = hInstance;

#ifdef _WIN32
  system_codepage = GetACP();
#endif

  /* Initialize the document that will contain the list of          */
  /* newsgroups.  This will be the main window.                     */

  InitDoc (&NetDoc, (HWND) 0, (TypDoc *) NULL, DOCTYPE_NET);

  /* Create and display the main window.  At first, the window      */
  /* just has an initialization message in it.                      */

  /* Compute default window position and size. */
  x = 0;
  y = 0;
  width = (int) (xScreen * 1 / 2);
  height = (int) (yScreen * 9 / 10);

  /* If the window position and size have been saved, use that
   * info instead.
   */
  GetPrivateProfileString (GROUPLIST, "UsenetWindowPos", "!",
                                                   mybuf, MAXINTERNALLINE, szAppProFile);
  if (mybuf[0] != '!') {
        sscanf (mybuf, "%d,%d,%d,%d", &x, &y, &width, &height);
  }

#ifdef _WIN32
  if (sinfo.dwFlags & STARTF_USEPOSITION) {
    x = sinfo.dwX;
    y = sinfo.dwY;
  }
  if (sinfo.dwFlags & STARTF_USESIZE) {
    width = sinfo.dwXSize;
    height = sinfo.dwYSize;
  }
#endif
	{
        RECT r;
        r.top = y;
        r.left = x;
        r.right = r.left+width;
        r.bottom = r.top + height;
        MakeRectVisible(r);
        x=r.left;
        y=r.top;
        width = r.right-r.left;
        height=r.bottom-r.top;	
	}
	NetDoc.hWndFrame = CreateWindow ("WinVnFrame",
				   "WinVN -- Usenet News Reader",
				   WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
				   x,   /* Initial X position */
				   y,   /* Initial Y position */
				   width,       /* Initial X width */
				   height,      /* Initial Y height */
				   NULL,
				   NULL,
				   hInstance,
				   NULL);

  if (!NetDoc.hWndFrame) {
#ifdef USE_3D_CONTROLS
        Ctl3dUnregister (hInstance);
#endif
        if (GroupFilter)
          GlobalFreePtr (GroupFilter);
        if (gURLinfo)
          GlobalFreePtr(gURLinfo); 
        return (0);
  }
  
#ifdef _WIN32
    /* can't make toolbar work in Win32s, so lets not run */

    osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osv);
    if ( ((osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
          (osv.dwMajorVersion == 4) && 
          (osv.dwMinorVersion >= 10)) ||
         ((osv.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
          (osv.dwMajorVersion >= 4)) )
    {
          //if Win98+, NT4+
          SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &ucNumLines, 0);
		  if (ucNumLines == (UINT) -1)
		  {
			//system wants page at a time scroll
		  }
    }
    else if ((osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) ||
            ((osv.dwPlatformId == VER_PLATFORM_WIN32_NT) && 
             (osv.dwMajorVersion < 4) )   )

    {
        //Try Win95/NT3.51 registered message
        HWND hdlMSHWheel=NULL;
        UINT msgMSHWheelGetScrollLines=0;

        msgMSHWheelGetScrollLines = 
            RegisterWindowMessage(MSH_SCROLL_LINES);

        hdlMSHWheel = FindWindow(MSH_WHEELMODULE_CLASS, 
                                 MSH_WHEELMODULE_TITLE);
        
        if (hdlMSHWheel && msgMSHWheelGetScrollLines)
        {
                ucNumLines = 
                  (UINT)SendMessage(hdlMSHWheel,
                                    msgMSHWheelGetScrollLines,
                                    0, 
                                    0);
        }

    }


    if (AScrollMode == WHEELSCROLL_SYSTEM) AScrollByWheel[0] = (unsigned int) ucNumLines;
    if (GScrollMode == WHEELSCROLL_SYSTEM) GScrollByWheel[0] = (unsigned int) ucNumLines;
    if (UScrollMode == WHEELSCROLL_SYSTEM) UScrollByWheel[0] = (unsigned int) ucNumLines;

    if (osv.dwPlatformId == VER_PLATFORM_WIN32s) \
    {
        WVMessageBox(NetDoc.hWndFrame,IDS_WINVN_WIN32S,IDS_WINVN_WIN32S_T, MB_OK | MB_ICONSTOP);
        DestroyWindow (NetDoc.hWndFrame);
    }
    else 
    {
#endif

        InitStatBar (&StatbarPntData);
#ifdef _WIN32
        if (sinfo.dwFlags & STARTF_USESHOWWINDOW) 
        {
            ShowWindow (NetDoc.hWndFrame, sinfo.wShowWindow);
        } 
        else 
        {
            ShowWindow (NetDoc.hWndFrame, SW_SHOWDEFAULT);
        }
#else
        ShowWindow (NetDoc.hWndFrame, nCmdShow);
#endif

        SetHandleBkBrush (NetDoc.hDocWnd, hListBackgroundBrush);
        SetUserMenus (&NetDoc, DISABLE);        // menus disabled until connection made

//  hConfWnd = NetDoc.hDocWnd;
        //  NetDoc.hDocWnd = hWnd;   /* mrr */
        //  NetDoc.hWndFrame = hParentWnd;  /* jlg */

        if (gURLinfo)
        {
          if (*gURLinfo->URLServer)
            strncpy (NNTPHost, gURLinfo->URLServer, MAXNNTPSIZE);
          if (*gURLinfo->URLGroup)
          {}
          if (*gURLinfo->URLUser)
            strncpy(NNTPUserName, gURLinfo->URLUser, MAXNNTPSIZE);
          else
            NNTPUserName[0] = '\0';     
          if (*gURLinfo->URLPassword)
          {
            MRREncrypt ((unsigned char *)gURLinfo->URLPassword, strlen (gURLinfo->URLPassword) + 1,
                                  NNTPPasswordEncrypted);

          }
          else
            NNTPPasswordEncrypted[0] = '\0';

          if (*gURLinfo->URLPort)
            strncpy( NNTPService, gURLinfo->URLPort, MAXNNTPSIZE); 

        }
        /* Make sure we have a host name (JSC) */
        while (NNTPHost[0] == '\0' || !strcmp (NNTPHost, DEF_NNTPHost))
          if (!DialogBox (hInst, MAKEINTRESOURCE(IDD_WINVNCOMM), NetDoc.hWndFrame, (DLGPROC) lpfnWinVnCommDlg))
                break;


        /* Make sure we have a valid user name (JD) */
        while (UserName[0] == '\0' || !strcmp (UserName, DEF_UserName)
                   || !strcmp (UserName, "Unknown"))
          if (!DialogBox (hInst, (LPCSTR) MAKEINTRESOURCE(IDD_WINVNPERSONAL), NetDoc.hWndFrame, (DLGPROC) lpfnWinVnPersonalInfoDlg))
                break;

        MoreInit ();

        ShowWindow (NetDoc.hDocWnd, nCmdShow);

        UpdateWindow (NetDoc.hDocWnd);
        UpdateWindow (NetDoc.hWndFrame);
        SendMessage (NetDoc.hDocWnd, WM_SIZE, 0, 0L);

#ifdef USE_SPLASH
        if (ShowSplashScreen)
                DisplaySplashScreen(hInstance, NetDoc.hWndFrame, 3);
#endif

        /* Read the NEWSRC file and display its contents in the           */
        /* main window.                                                   */

        if (!ReadNewsrc ()) 
		{
          WVMessageBox(NetDoc.hDocWnd, IDS_WINVN_OPENNEWSRC, IDS_FATAL_ERROR, MB_OK | MB_ICONHAND);
          PostQuitMessage (0);
        }

        Initializing = INIT_NOT_CONNECTED;

        if (ConnectAtStartup || gURLinfo && gURLinfo->URLServer[0] != '\0') //MDS added URL override
          Connect ();

        InvalidateRect (NetDoc.hDocWnd, NULL, TRUE);
        UpdateWindow (NetDoc.hDocWnd);
        SetFocus (NetDoc.hDocWnd);

        /* And now for the main loop, which appears in all Windows programs. */
        hAccel = LoadAccelerators (hInstance, "WinVNAccel");

#ifdef _WIN32
  }                                                             /* end of if GetVersion != win32 */
#endif

  while (MainLoopPass ());

#ifdef USE_3D_CONTROLS
  Ctl3dUnregister (hInstance);
#endif

#ifdef _WIN32
    //CoUninitialize();
#endif

	}
#if NDEBUG	
    __except(filter(GetExceptionCode(), GetExceptionInformation()))
    {
		MessageBox(NULL, "WinVn had a fatal exception and has to close", "Sorry", MB_OK | MB_ICONSTOP);
		if (SaveNewsrc && NewsrcDirty) 
			WriteNewsrc ();

    }
#endif

  if (GroupFilter)
        GlobalFreePtr (GroupFilter);
  if (gURLinfo)
    GlobalFreePtr(gURLinfo);
#ifdef __GNUC__
  {
    extern void DynUnloadLibs( void );
    DynUnloadLibs();
  }
#endif
  return (MainMsg.wParam);
}

/* --- FUNCTION Connect ---------------------------------------------
 * Connect inits comm services and starts connection process
 */
void Connect ()
{
  if (Initializing != INIT_NOT_CONNECTED)
        return;

	
  Initializing = INIT_ESTAB_CONN;

  /* disable the connect menu item during connect attempt */
  SetConnectMenuItems (&NetDoc, DISABLE);       // connect item has reverse attributes
  /* disable toolbar button during connect, SetUserMenus will enable */
  SendMessage (NetDoc.hWndTB, TB_ENABLEBUTTON, IDB_TOGGLE_CONNECT, FALSE);
  //   Keep reset Menu enabled (JD 3/8/97)
  SendMessage (NetDoc.hWndTB, TB_ENABLEBUTTON, IDM_RESET, TRUE);

  WVSetStatbarText (NetDoc.hWndFrame, IDS_STBAR_CONNECT, &NetDoc, TRUE, TRUE);

  InvalidateRect (NetDoc.hDocWnd, NULL, TRUE);
  UpdateWindow (NetDoc.hDocWnd);

  if (MRRInitComm () != 0) 
  {    /* Set up communications */
        if (Reconnecting)
        {
            Reconnecting = 0;
            Disconnect(); //close all doc windows
        }
        Initializing = INIT_NOT_CONNECTED;
        MRRCloseComm ();
        SetConnectMenuItems (&NetDoc, ENABLE);
        UpdateWindow (NetDoc.hDocWnd);
        return;
  }
  /* Set up the timer which will wake us up every so often
   * so we can check to see if new characters have arrived from
   * the server.
   */
  idTimer = SetTimer (NetDoc.hDocWnd, ID_TIMER, COMM_TIMER_INTERVAL, (TIMERPROC) NULL);

  if (!idTimer) 
  {
        WVMessageBox (NetDoc.hDocWnd, IDS_WINVN_TIMER, IDS_WINVN_FATAL, MB_OK | MB_ICONASTERISK);
        Initializing = INIT_NOT_CONNECTED;
        MRRCloseComm ();
        SetConnectMenuItems (&NetDoc, ENABLE);
        if (Reconnecting)
        {
            Reconnecting = 0;
            Disconnect(); //close all doc windows
        }

        return;
  }

  InternalTimeoutCounter = StallTimeout * 1000 / COMM_TIMER_INTERVAL;
  TimeoutCounter = CommTimeout * 1000 / COMM_TIMER_INTERVAL;

  CommDoc = &NetDoc;

  /* MRRInitComm causes CommState to be ST_ESTABLISH_COMM.  DoCommState 
   * begins processing when DoCommInput (started by the timer) sees data
   * from the server.  DoCommState will set Initializing back to 
   * INIT_NOT_CONNECTED if any error.
   * Initializing is INIT_DONE when we're connected and happy
   */
}

/*---  FUNCTION: AbortAllComm -------------------------------------------
 *
 *  Aborts and cleans up internal comm state
 *  jsc 9/12/94
 */
void AbortAllComm (BOOL bDontKill)
{
  if (Decoding && !bDontKill) 
  {

        if (CompleteThisDecode () != BUSY )
            DecodeDone ();
  }
  if (SendingPost)                              // don't abort if sending mail
        DoSend (ABORT);

  MRRCloseComm ();
  CommDoc = (TypDoc *) NULL;
  CommBusy = FALSE;
  CommState = ST_NONE;
  SetStatbarText (NetDoc.hWndFrame, "--Disconnected--", &NetDoc, TRUE, TRUE);
}

//Want to abort whatever comm & drop connection without closing doc.
void DropConnection()
{

	if (Decoding) 
	{
		if (CompleteThisDecode () != BUSY)
			DecodeDone ();
	}
	if (SendingPost)                              // don't abort if sending mail
		DoSend (ABORT);

	CommBusy = FALSE;
	CommState = ST_NONE;
	KillTimer (NetDoc.hDocWnd, ID_TIMER);
	Initializing = INIT_NOT_CONNECTED;
	MRRCloseComm(); //CommState = ST_CLOSED_COMM;
	SetStatbarText (NetDoc.hWndFrame, "--Disconnected--", &NetDoc, TRUE, TRUE);
}


/* --- FUNCTION Disconnect ------------------------------------------ --
 * This is kills all comm.  Does not send a QUIT, or check any state.
 * jsc 9/29/94
 */
void Disconnect ()
{
	char mybuf[MAXHEADERLINE];
	AbortAllComm (FALSE);

	KillTimer (NetDoc.hDocWnd, ID_TIMER);
	Initializing = INIT_NOT_CONNECTED;
	Reconnecting = 0;
	CloseArticleWnds ();
	CloseGroupWnds ();
	CloseStatusWnds ();

	SetUserMenus (&NetDoc, DISABLE);
	InvalidateRect (NetDoc.hDocWnd, NULL, TRUE);
	UpdateWindow (NetDoc.hDocWnd);

	//default is true, so delete it from .ini if it exists
	sprintf(mybuf, "N: %s", NNTPHost);
	if (g_bUseXHDR)
		WritePrivateProfileString (mybuf, "ActionUseXHDR", NULL, szAppProFile);
	else
		WritePrivateProfileInt (mybuf, "ActionUseXHDR", 0, szAppProFile);


	MRRCloseComm ();                              /* blammo */
}




/* --- FUNCTION Reconnect ------------------------------------------ --
 *  uh, reconnect.
 * jsc 11/12/94
 */
void 
Reconnect ()
{
        SendMessage (NetDoc.hWndTB, TB_ENABLEBUTTON, IDB_TOGGLE_CONNECT, TRUE);
        SendMessage (NetDoc.hWndTB, TB_CHECKBUTTON, IDB_TOGGLE_CONNECT, TRUE);
        Reconnecting = 0;
		Disconnect();
        Connect();
}

/* --- FUNCTION WinVnInit ---------------------------------------------

 *    Initialize the program (first stage).
 *    This routine does some initialization needed before the
 *    creation of the main window.
 *    I put off additional initialization until after the main
 *    window is created.
 *
 *    Entry    hInstance   is a handle to the current instance of
 *                         execution.
 *
 *    Exit     Window classes have been registered, and a small
 *             amount of other window- and comm-related initialization
 *             is done.
 */

BOOL WinVnInit (HINSTANCE hInstance, LPSTR lpCmdLine)
{
  WNDCLASS wndClass;
  HDC hDC;
  BOOL bSuccess;
  OSVERSIONINFO osv;

  Initializing = INIT_READING_NEWSRC;
  Reconnecting = 0;
  Autoconnect = 1;
  NewsrcDirty = FALSE;
  CommLineLWAp1 = CommLineIn + MAXCOMMLINE;
  LineHeight = 30;                              /* kludge so Net window doesn't get divide-by-zero */

  szAppName = "WinVN";
  MaxDBSize = TOOMANYARTS;
  

  osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  GetVersionEx(&osv);

	
	g_bIsXP = FALSE;
	g_bIsVista = FALSE;        
	if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT)
	{
		if (osv.dwMajorVersion >= 5)
			g_bIsXP = TRUE;
		if (osv.dwMajorVersion >= 6)
			g_bIsVista = TRUE;

	}


  // locate newsrc and winvn.ini
  if (fnLocateFiles (hInstance, lpCmdLine))
        return (0);

  /* ok we found the files... now make sure they're writeable */
  if (_access (szAppProFile, 2) == -1) {
        WVArgMessageBox(NULL, IDS_WINVN_STARTUP,IDS_READ_ONLY, MB_OK | MB_ICONSTOP, szAppProFile);
        return (0);
  }
  if (_access (szNewsSrc, 2) == -1) {
        WVArgMessageBox(NULL, IDS_WINVN_STARTUP,IDS_READ_ONLY, MB_OK | MB_ICONSTOP, szNewsSrc);
        return (0);
  }

  if ((GroupFilter = (char *) GlobalAllocPtr (GMEM_MOVEABLE, MAXGROUPFILTERSIZE)) == NULL) {
        EnableGroupFilter = FALSE;
  }

  ReadWinvnProfile ();

  // obtain point-to-logical-units conversion constants for screen and printer
  hDC = GetDC (NetDoc.hDocWnd);//there is no NetDoc.hDocWnd yet! 
  ScreenYPixels = GetDeviceCaps (hDC, LOGPIXELSY);
  LimitedColor = GetDeviceCaps (hDC, RASTERCAPS) & RC_PALETTE;
  ReleaseDC (NetDoc.hDocWnd, hDC);

  PrinterInit ();

  // initialize fonts
  InitAllFonts ();

  /* Create pointers to the dialog box functions, needed   */
  /* for routine processing of dialog boxes.               */
#ifdef WANTOLDACTION
  lpfnWinVnArticleActionDlg = &WinVnArticleActionDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnArticleActionDlg, hInstance);
#endif
  lpfnWinVnArticleAction = &WinVnArticleAction;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnArticleActionDlg, hInstance);
  lpfnWinVnCommDlg = &WinVnCommDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnCommDlg, hInstance);
  lpfnWinVnSaveArtDlg = &WinVnSaveArtDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnSaveArtDlg, hInstance);
  lpfnWinVnSaveArtsDlg = &WinVnSaveArtsDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnSaveArtsDlg, hInstance);
  lpfnWinVnFindDlg = &WinVnFindDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnFindDlg, hInstance);
  lpfnWinVnPersonalInfoDlg = &WinVnPersonalInfoDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnPersonalInfoDlg, hInstance);
  lpfnWinVnExecuteInfoDlg = &WinVnExecuteInfoDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnExecuteInfoDlg, hInstance);
  lpfnWinVnConfirmationDlg = &WinVnConfigConfirmationDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnConfigConfirmationDlg, hInstance);
  lpfnWinVnControlSubclass = &WinVnControlIntercept;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnControlIntercept, hInst);
  lpfnWinVnThresholdDlg = &WinVnThresholdDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnThresholdDlg, hInstance);
  lpfnWinVnLogOptDlg = &WinVnLogOptDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnLogOptDlg, hInstance);
  lpfnWinVnDecodeArtsDlg = &WinVnDecodeArtsDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnDecodeArtsDlg, hInstance);
  lpfnWinVnAttachDlg = &WinVnAttachDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnAttachDlg, hInstance);
  lpfnWinVnComposePrefsDlg = &WinVnComposePrefsDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnComposePrefsDlg, hInstance);
  lpfnWinVnAttachPrefsDlg = &WinVnAttachPrefsDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnAttachPrefsDlg, hInstance);
  lpfnWinVnEncodeDlg = &WinVnEncodeDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnEncodeDlg, hInstance);
  lpfnWinVnExitDlg = &WinVnExitDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnExitDlg, hInstance);
  lpfnWinVnMailDlg = &WinVnMailDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnMailDlg, hInstance);
  lpfnWinVnSmartFilerDlg = &WinVnSmartFilerDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnSmartFilerDlg, hInstance);
  lpfnWinVnSelectPathDlg = &WinVnSelectPathDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnSelectPathDlg, hInstance);

  lpfnWinVnArticleDlg = &WinVnConfigArticleDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnConfigArticleDlg, hInstance);
  lpfnWinVnCodingPrefsDlg = &WinVnConfigCodingPrefsDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnConfigCodingPrefsDlg, hInstance);
  lpfnWinVnArtListDlg = &WinVnConfigArticleListDlg; //(DLGPROC) MakeProcInstance ((FARPROC) WinVnConfigArticleListDlg, hInstance);
  lpfnWinVnGroupListDlg = &WinVnConfigGroupListDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnConfigGroupListDlg, hInstance);
  lpfnWinVnHeadersDlg = &WinVnHeadersDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnHeadersDlg, hInstance);      // shimomai
  lpfnWinVnSMTPDlg = &WinVnSMTPDlg;//(DLGPROC) MakeProcInstance ((FARPROC) WinVnSMTPDlg, hInstance);
  lpfnWinVnMergeDlg = &WinVnMergeDlg;
  lpfnWinVnAppendDlg = &WinVnAppendDlg;


  //xScreen = GetSystemMetrics (SM_CXVIRTUALSCREEN);
  //yScreen = GetSystemMetrics (SM_CYVIRTUALSCREEN);
  xScreen = GetSystemMetrics (SM_CXFULLSCREEN);
  yScreen = GetSystemMetrics (SM_CYFULLSCREEN);

  
  CaptionHeight = GetSystemMetrics (SM_CYCAPTION);

  CommDoc = &NetDoc;
  Authenticated = FALSE;

  hListBackgroundBrush = CreateSolidBrush (ListBackgroundColor);
  hArticleBackgroundBrush = CreateSolidBrush (ArticleBackgroundColor);
  hStatusBackgroundBrush = CreateSolidBrush (StatusBackgroundColor);

  memset (&wndClass, 0, sizeof (WNDCLASS));

  wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
  wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "winvn");
  wndClass.lpszMenuName = (LPSTR) "ConfMenu";
  wndClass.lpszClassName = (LPSTR) "WinVnFrame";
  wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
  wndClass.hInstance = hInstance;
  wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  wndClass.lpfnWndProc = WinVnConfFrameWndProc;
  bSuccess = RegisterClass (&wndClass);

  if (bSuccess) 
  {
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "winvn");
        wndClass.lpszMenuName = (LPSTR) "ConfMenu";
        wndClass.lpszClassName = (LPSTR) "WinVn";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
        wndClass.lpfnWndProc = WinVnConfWndProc;
        bSuccess = RegisterClass (&wndClass);
  }

  if (bSuccess) 
  {
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvgroup");
        wndClass.lpszMenuName = (LPSTR) "ViewMenu";
        wndClass.lpszClassName = (LPSTR) "WinVnViewFrame";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
        wndClass.lpfnWndProc = WinVnViewFrameWndProc;
        bSuccess = RegisterClass (&wndClass);
  }

  if (bSuccess) 
  {
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvgroup");
        wndClass.lpszMenuName = (LPSTR) "ViewMenu";
        wndClass.lpszClassName = (LPSTR) "WinVnView";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
        wndClass.lpfnWndProc = WinVnViewWndProc;
        bSuccess = RegisterClass (&wndClass);
  }

  if (bSuccess) 
  {
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvart");
        wndClass.lpszMenuName = (LPSTR) "ArtMenu";
        wndClass.lpszClassName = (LPSTR) "WinVnArtFrame";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
        wndClass.lpfnWndProc = WinVnArtFrameWndProc;

        bSuccess = RegisterClass (&wndClass);
  }

  if (bSuccess) 
  {
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvart");
        wndClass.lpszMenuName = (LPSTR) "ArtMenu";
        wndClass.lpszClassName = (LPSTR) "WinVnArt";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
        wndClass.lpfnWndProc = WinVnArtWndProc;

        bSuccess = RegisterClass (&wndClass);
  }

  if (bSuccess) 
  {                               /* identical to wvmail except for the icon */
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvpost");
        wndClass.lpszMenuName = (LPSTR) "ComposeMenu";
        wndClass.lpszClassName = (LPSTR) "WinVnPost";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW;
        wndClass.lpfnWndProc = WinVnComposeWndProc;

        bSuccess = RegisterClass (&wndClass);
  }

  if (bSuccess) 
  {                               /* identical to wvpost except for the icon */
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvmail");
        wndClass.lpszMenuName = (LPSTR) "ComposeMenu";
        wndClass.lpszClassName = (LPSTR) "WinVnMail";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW;
        wndClass.lpfnWndProc = WinVnComposeWndProc;

        bSuccess = RegisterClass (&wndClass);
  }

  if (bSuccess) 
  {
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvcstat2");
        wndClass.lpszMenuName = (LPSTR) NULL;//"StatMenu";
        wndClass.lpszClassName = (LPSTR) "WinVnCoding";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW;
        wndClass.lpfnWndProc = WinVnCodingWndProc;

        bSuccess = RegisterClass (&wndClass);
  }
  if (bSuccess) 
  {
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvcstat1");
        wndClass.lpszMenuName = NULL;
        wndClass.lpszClassName = (LPSTR) "WinVnBlockCoding";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW;
        wndClass.lpfnWndProc = WinVnCodedBlockWndProc;

        bSuccess = RegisterClass (&wndClass);
  }

  if (bSuccess) 
  {
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.hIcon = LoadIcon (hInstance, (LPSTR) "wvart");
        wndClass.lpszMenuName = (LPSTR) NULL;
        wndClass.lpszClassName = (LPSTR) "WinVnArtFace";
        wndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndClass.hInstance = hInstance;
        wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
        wndClass.lpfnWndProc = WinVnArtFaceWndProc;

        bSuccess = RegisterClass (&wndClass);
  }
  if (bSuccess)
  {
      // Get normal dialog class information
    bSuccess = GetClassInfo(NULL, MAKEINTRESOURCE(WC_DIALOG), &wndClass);
   
    if (bSuccess)
    {
        // modify normal dialog class info to suit our needs
        wndClass.lpszClassName = "WINVNDLG";
        wndClass.style ^= CS_GLOBALCLASS;
        wndClass.hIcon = LoadIcon(hInstance, (LPSTR) "WINVN");
        wndClass.hInstance = hInstance;
        
		bSuccess = RegisterClass(&wndClass);
    }

  }


  return (bSuccess);
}

/* --- Function MoreInit -----------------------------------------------

 *    Finish up initializing the program.
 *    I do as much initialization here as possible.  I'd rather
 *    have code run after the main window is created (in WinVNInit),
 *    so I have someplace to display error messages if necessary.
 *
 *    I read quite a few profile strings (from WIN.INI)
 *    here and act appropriately (usually means setting a global variable).
 *    I try to read as many as possible of the profile strings used by this
 *    program here.
 */
BOOL MoreInit ()
{
	register int j;
	//  extern char uuTable[CODINGTABLESIZE], xxTable[CODINGTABLESIZE], base64Table[CODINGTABLESIZE];
	//  CheckView (NetDoc.hDocWnd);     /* modify menu as necessary           */

	/* Initialize some document and article related globals */

	for (j = 0; j < 16; j++)              // set custom colors to white
	{
		char szEntry[20], buf[40];
		wsprintf( szEntry, "CustomColor%02d", j);
		GetPrivateProfileString (WVINTERFACE, szEntry, "255,255,255", buf, 32, szAppProFile);
		CustomColors[j] = StrToRGB (buf);

	}

#ifdef MULTIGROUP
		MultiGroupDoc	= (TypDoc *) NULL;
		GroupDocs[MAXGROUPWNDS].InUse = FALSE;
		GroupDocs[MAXGROUPWNDS].numArtsSaved = 0;
		GroupDocs[MAXGROUPWNDS].savingArtIndex = -1;
		GroupDocs[MAXGROUPWNDS].curSaveArtIndex = -1;
#endif

	ActiveGroupDoc = (TypDoc *) NULL;
	ActiveArticleDoc = (TypDoc *) NULL;
	for (j = 0; j < MAXGROUPWNDS; j++) 
	{
		GroupDocs[j].InUse = FALSE;
		GroupDocs[j].numArtsSaved = 0;
		GroupDocs[j].savingArtIndex = -1;
		GroupDocs[j].curSaveArtIndex = -1;
	}

	for (j = 0; j < MAXARTICLEWNDS; j++)
	{
		ArticleDocs[j].InUse = FALSE;
		ArticleDocs[j].numArtsSaved = 0;
		ArticleDocs[j].savingArtIndex = -1;      /* reset to non-saving state */
		ArticleDocs[j].curSaveArtIndex = -1;
	}

	for (j = 0; j < MAXPOSTWNDS; j++)
		memset (&WndPosts[j], 0, sizeof (WndEdit));

	for (j = 0; j < MAXMAILWNDS; j++)
		memset (&WndMails[j], 0, sizeof (WndEdit));

	ComposeWnd = (WndEdit *) NULL;

	*SaveArtFileName = '\0';

	CodingState = INACTIVE;
	CommDecoding = FALSE;
	AutoDecode = 0;
	AbortDownload = 0;
	SendingMail = SendingPost = FALSE;

	CreateCodingMap (uuMap, uuTable);
	uuMap[' '] = 0;                               // decode both quote and space to 0 in UU

	CodingMap[CODE_UU] = uuMap;
	CreateCodingMap (xxMap, xxTable);
	CodingMap[CODE_XX] = xxMap;
	CreateCodingMap (base64Map, base64Table);
	CodingMap[CODE_BASE64] = base64Map;
	// the custom map is just a pointer.  The map is defined if/when a
	// custom table is read in during decoding
	CodingMap[CODE_CUSTOM] = customMap;
	CodingMap[CODE_YENC] = customMap;  //never ever used




	Signature = InitTextBlock (NetDoc.hDocWnd);
	if (*SigFileName)
		if (ReadFileToTextBlock (NetDoc.hDocWnd, Signature, SigFileName) == FAIL) 
		{
			WVMessageBox(NetDoc.hDocWnd, IDS_WINVN_SIGNATURE_D, IDS_WINVN_SIGNATURE_T, MB_OK | MB_ICONINFORMATION);
			EnableSig = FALSE;
		}

	NumGroupWnds = NumArticleWnds = NumPostWnds = NumMailWnds = NumStatusTexts = 0;
	hCodedBlockWnd = NULL;
	for (j = 0; j < MAX_DECODE_THREADS; j++)
	{
		CodingStatusText[j] = NULL;
	}

	ClearLatestInfo();

	AutoDeleteList = NULL;

	return (TRUE);
}

// Read continuous words used in URLs
BOOL ReadURLString( char *dest, char **ptr, int limit)
{
	int len;
	register int i;
	char *str = *ptr;

	if (*str == '\0')
	return FALSE;

	len = strlen (str);

	if (len == 0)
	return FALSE;

	//copy continous words excluding '/' '\' ':' '@' <whitespace>

	for (i = 0; i < len; i++) 
	{
		if (   str[i] != ':' && str[i] != '\\' && str[i] != '/' 
			&& str[i] != '@' && !isspace((unsigned char) str[i]) ) 
		{
			if ( i < limit) 
			{
				dest[i] = str[i];
			}
		}
		else
			break;
	}
	if (i < limit-1)
		dest[i] = '\0';
	else
		dest[limit-1] = '\0';

	*ptr = str + i; // increment line ptr

	return TRUE;

}

BOOL ReadMessageIDString( char *dest, char **ptr, int limit)
{
	int len;
	register int i;
	char *str = *ptr;

	if (*str == '\0')
		return FALSE;

	len = strlen (str);

	if (len == 0)
		return FALSE;

	//copy continous words excluding '>' <whitespace>

	for (i = 0; i < len; i++) 
	{
		if (   str[i] != '>' && !isspace((unsigned char)str[i]) ) 
		{
			if ( i < limit) 
			{
				dest[i] = str[i];
			}
		}
		else
			break;
	}
	if (i < limit-1)
		dest[i] = '\0';
	else
		dest[limit-1] = '\0';

	*ptr = str + i; // increment line ptr

	return TRUE;

}

// Parse a string containing a URL into its components
//
// It handles the following URL arguments   news:, nntp:
//
// A news URL takes one of two forms: 
//
// news:<newsgroup-name>                 (dotted-no-space
// news:message-id               (<- has @ sign, no spaces or ">")
// news:*                        (all groups)
// news:<newsgroup>/<message-id>
// news://server/group
//
// The nntp URL scheme is an alternative method of referencing news articles, 
// useful for specifying news articles from NNTP servers (RFC 977).
//
// A nntp URL takes the form:
//
// nntp://<host>:<port>/<newsgroup-name>/<article-number>
// port default is 119
//
// The <newsgroup-name> is the name of the group, while the <article- number> 
// is the numeric id of the article within that newsgroup. 
//
// Basic URL syntax 
//  <user>:<password>@<host>:<port>/<url-path>
//
// My fully expanded version
//
// nntp://<user>:<password>@<host>:<port>/<newsgroup-name>/<article-number>
//
// message-id is: string not containing blank or ">"> and includes <unique@fulldomain>
//
// A <newsgroup-name> is a period-delimited hierarchical name, such as 
// "comp.infosystems.www.misc". A <message-id> corresponds to the Message-ID 
// of section 2.1.5 of RFC 1036, without the enclosing "<" and ">"; it takes 
// the form <unique>@<full_domain_name>. A message identifier may be distinguished 
// from a news group name by the presence of the commercial at "@" character. 
// No additional characters are reserved within the components of a news URL. 
//
// If <newsgroup-name> is "*" (as in <URL:news:*>), it is used to refer to 
// "all available news groups". 
//
BOOL ParseURL( TypURL *pURL, LPSTR lpCmdLine )
{

	char *p;
	char *pstart = NULL;
	char *pend;
	char line[_MAX_PATH];
	int  len;
	BOOL bNNTP = FALSE;

	if (!lpCmdLine || *lpCmdLine == '\0' || !pURL) 
	{
		return FALSE;
	}


	*pURL->URLServer = '\0';
	*pURL->URLGroup = '\0';
	*pURL->URLUser = '\0';
	*pURL->URLPassword = '\0';
	*pURL->URLPort = '\0';
	*pURL->URLMessageID = '\0';

	//make a copy to modify
	lstrcpyn(line, lpCmdLine, _MAX_PATH); 

	p = line;
	pend = line + strlen(line);

	while (*p && p + 5 < pend) 
	{
		if (_strnicmp(p, "news:", 5) == 0 ) 
		{ 
			pstart = p+5;
			break;
		}
		if (_strnicmp(p, "nntp:", 5) == 0 ) 
		{
			pstart = p+5;
			bNNTP = TRUE;
			break;
		}
		p++;
	}

	if (!pstart || pend - pstart < 2)
		return FALSE;

	//find end of URL string
	pend = pstart;
	while (*pend && !isspace((unsigned char)*pend))
		pend++;
	*pend = '\0'; //string now URL only, no other args


	if ( (*pstart == '/' && *(pstart+1) == '/') ||
		 (*pstart == '\\' && *(pstart+1) == '\\') ) 
	{
		pstart +=2;

		len = strcspn(pstart, ":@\\/");
		p = pstart + len;

		if (*p == ':') 
		{
			//differentiate between user:password@server, and server:port

			if (strchr(p, '@')) 
			{
				//look for user:passwd@server

				ReadURLString(pURL->URLUser, &pstart, MAXNNTPSIZE);
				if (*pstart != ':')
				  goto URLfail;
				pstart++; //skip ':'

				ReadURLString(pURL->URLPassword, &pstart, MAXNNTPSIZE);
				if (*pstart != '@')
					goto URLfail;
				pstart++; //skip '@'

			}
		}

		ReadURLString(pURL->URLServer, &pstart, MAXNNTPSIZE);

		if (*pstart == ':') 
		{
			pstart++;
			ReadURLString(pURL->URLPort, &pstart, MAXNNTPSIZE);
		}
	}
	else
	{
		if (!bNNTP)
		{
			//news:group, 
			//news:message-id
			//news:*

			if (strchr(p, '@')) 
			{
				ReadMessageIDString(pURL->URLMessageID, &pstart, MAXNNTPSIZE);
			}
			else 
			{
				ReadURLString(pURL->URLGroup, &pstart, MAXGROUPNAME);
			}
			return TRUE;
		}

	}

	if (*pstart == ':' || *pstart == '\\' || *pstart == '/') 
	{
		pstart++;
		ReadURLString(pURL->URLGroup, &pstart, MAXGROUPNAME);
	}
	if (*pstart == '/') 
	{
		pstart++;
		ReadMessageIDString(pURL->URLMessageID, &pstart, MAXNNTPSIZE);
	}

	if (pstart == pend)
		return TRUE;

URLfail:
	*pURL->URLServer = '\0';
	*pURL->URLGroup = '\0';
	*pURL->URLUser = '\0';
	*pURL->URLPassword = '\0';
	*pURL->URLPort = '\0';
	*pURL->URLMessageID = '\0';

	return FALSE;

}


/* --- InitFont Functions -----------------------------------------------
 *    Initialize global fonts and metrics
 * Be sure to delete any existing font objects before replacing them
 * Convert points representation to logical units for sizes
 * JSC 1/10/93
 */
#ifndef CLEARTYPE_QUALITY
#define CLEARTYPE_QUALITY       5
#define CLEARTYPE_NATURAL_QUALITY 6
#endif

void InitAllFonts ()
{
	hWinVnFont = hCompositionFont = hListFont = hFontArtNormal = 
		hFontArtQuote = hFontPrint = hFontPrintB = hFontPrintS = 
		hFontPrintI = hStatusFont = (HFONT) NULL;

	InitWinVnFonts ();
	InitCompositionFonts ();
	InitListFonts ();
	InitArticleFonts ();
	//  InitPrintFonts();
	InitStatusFonts ();
}

#define FontCharSet (DEFAULT_CHARSET)

void InitWinVnFonts ()
{
	TEXTMETRIC tmFontInfo;
	HFONT hOldFont;
	HDC hDC;
    int nQuality = UseClearType == 0 ? DEFAULT_QUALITY  :
				   UseClearType == 1 ? NONANTIALIASED_QUALITY :
				  (UseClearType == 2 || !g_bIsXP) ? ANTIALIASED_QUALITY : CLEARTYPE_QUALITY;
	/* Unless user specified the system font, create a font as per
	* the user's specifications.
	*/

	if (hWinVnFont)
		DeleteObject (hWinVnFont);

	hWinVnFont = (HFONT) NULL;
	if (WinVnFontSize) 
	{
		hWinVnFont = CreateFont
		  (-MulDiv (WinVnFontSize, ScreenYPixels, 72),
		   0,                                           /* width */
		   0,                                           /* escapement */
		   0,                                           /* orientation */
		   strstr (WinVnFontStyle, "Bold") ? FW_BOLD : FW_MEDIUM,
		   (BYTE) (strstr (WinVnFontStyle, "Italic") ? 1 : 0),
		   0,                                           /* no underline */
		   0,                                           /* no strikeout */
		   FontCharSet,
		   OUT_DEFAULT_PRECIS,
		   CLIP_DEFAULT_PRECIS,
		   nQuality,                                     //possibly antialiased
		   0,
		   WinVnFontFace);
	}

	if (!hWinVnFont)
		hWinVnFont = (HFONT)GetStockObject (OEM_FIXED_FONT);

	/*  Get information about the font.  LineHeight and CharWidth
	*  are pretty self-explanatory and the methods of determining these
	*  are standard.  TopSpace and SideSpace are the top and left margins
	*  in pixels; I compute them by a method I determined empirically.
	*/

	hDC = GetDC (NetDoc.hDocWnd);
	hOldFont = (HFONT) SelectObject (hDC, hWinVnFont);
	GetTextMetrics (hDC, (LPTEXTMETRIC) & tmFontInfo);
	WinVnLineHeight = tmFontInfo.tmExternalLeading + tmFontInfo.tmHeight;
	WinVnCharWidth = tmFontInfo.tmAveCharWidth;
	SelectObject (hDC, hOldFont);
	ReleaseDC (NetDoc.hDocWnd, hDC);
}

void InitCompositionFonts ()
{
	TEXTMETRIC tmFontInfo;
	HFONT hOldFont;
	HDC hDC;
    int nQuality = UseClearType == 0 ? DEFAULT_QUALITY  :
				   UseClearType == 1 ? NONANTIALIASED_QUALITY :
			  	  (UseClearType == 2 || !g_bIsXP) ? ANTIALIASED_QUALITY : CLEARTYPE_QUALITY;
	/* Unless user specified the system font, create a font as per
	* the user's specifications.
	*/

	if (hCompositionFont)
		DeleteObject (hCompositionFont);

	hCompositionFont = (HFONT) NULL;
	if (CompositionFontSize) {
		hCompositionFont = CreateFont
		  (-MulDiv (CompositionFontSize, ScreenYPixels, 72),
		   0,                                           /* width */
		   0,                                           /* escapement */
		   0,                                           /* orientation */
		   strstr (CompositionFontStyle, "Bold") ? FW_BOLD : FW_MEDIUM,
		   (BYTE) (strstr (CompositionFontStyle, "Italic") ? 1 : 0),
		   0,                                           /* no underline */
		   0,                                           /* no strikeout */
		   FontCharSet,
		   OUT_DEFAULT_PRECIS,
		   CLIP_DEFAULT_PRECIS,
		   nQuality,                                     //possibly antialiased
		   0,
		   CompositionFontFace);
	}

	if (!hCompositionFont)
		hCompositionFont = (HFONT) GetStockObject (OEM_FIXED_FONT);

	/*  Get information about the font.  LineHeight and CharWidth
	*  are pretty self-explanatory and the methods of determining these
	*  are standard.  TopSpace and SideSpace are the top and left margins
	*  in pixels; I compute them by a method I determined empirically.
	*/

	hDC = GetDC (NetDoc.hDocWnd);
	hOldFont = (HFONT) SelectObject (hDC, hCompositionFont);
	GetTextMetrics (hDC, (LPTEXTMETRIC) & tmFontInfo);
	CompositionLineHeight = tmFontInfo.tmExternalLeading + tmFontInfo.tmHeight;
	CompositionCharWidth = tmFontInfo.tmAveCharWidth;
	SelectObject (hDC, hOldFont);
	ReleaseDC (NetDoc.hDocWnd, hDC);
}

void InitListFonts ()
{
	TEXTMETRIC tmFontInfo;
	HFONT hOldFont;
	HDC hDC;
    int nQuality = UseClearType == 0 ? DEFAULT_QUALITY  :
				   UseClearType == 1 ? NONANTIALIASED_QUALITY :
				  (UseClearType == 2 || !g_bIsXP) ? ANTIALIASED_QUALITY : CLEARTYPE_QUALITY;
	/* Unless user specified the system font, create a font as per
	* the user's specifications.
	*/

	if (hListFont)
		DeleteObject (hListFont);

	hListFont = (HFONT) NULL;
	if (ListFontSize) {
		hListFont = CreateFont
		  (-MulDiv (ListFontSize, ScreenYPixels, 72),
		   0,                                           /* width */
		   0,                                           /* escapement */
		   0,                                           /* orientation */
		   strstr (ListFontStyle, "Bold") ? FW_BOLD : FW_MEDIUM,
		   (BYTE) (strstr (ListFontStyle, "Italic") ? 1 : 0),
		   0,                                           /* no underline */
		   0,                                           /* no strikeout */
		   FontCharSet,
		   OUT_DEFAULT_PRECIS,
		   CLIP_DEFAULT_PRECIS,
		   nQuality,                                     //possibly antialiased
		   0,
		   ListFontFace);
	}

	if (!hListFont)
		hListFont = hWinVnFont;

	/*  Get information about the font.  LineHeight and CharWidth
	*  are pretty self-explanatory and the methods of determining these
	*  are standard.  TopSpace and SideSpace are the top and left margins
	*  in pixels; I compute them by a method I determined empirically.
	*/

	hDC = GetDC (NetDoc.hDocWnd);
	hOldFont = (HFONT) SelectObject (hDC, hListFont);
	GetTextMetrics (hDC, (LPTEXTMETRIC) & tmFontInfo);

	LineHeight = tmFontInfo.tmExternalLeading + tmFontInfo.tmHeight;
	CharWidth = tmFontInfo.tmAveCharWidth;
	//TopSpace = tmFontInfo.tmExternalLeading;
	TopSpace = LineHeight >> 2;
	StartPen = TopSpace;
	SideSpace = CharWidth >> 1;
	SelectObject (hDC, hOldFont);
	ReleaseDC (NetDoc.hDocWnd, hDC);
	if (!CharWidth)
		CharWidth=1;
}

void
InitArticleFonts ()
{
  TEXTMETRIC tmFontInfo;
  HFONT hOldFont;
  HDC hDC;
  int nQuality = UseClearType == 0 ? DEFAULT_QUALITY  :
				 UseClearType == 1 ? NONANTIALIASED_QUALITY :
				(UseClearType == 2 || !g_bIsXP) ? ANTIALIASED_QUALITY : CLEARTYPE_QUALITY;
				    
  if (hFontArtNormal) {
        DeleteObject (hFontArtNormal);
        DeleteObject (hFontArtQuote);
  }
  hFontArtNormal = hFontArtQuote = (HFONT) NULL;

  if (ArticleFontSize) 
  {                /*  && !ArticleFixedFont */
        hFontArtNormal = CreateFont (
							-MulDiv (ArticleFontSize, ScreenYPixels, 72),
							0,    /* width */
							0,    /* escapement */
							0,    /* orientation */
							strstr (ArticleFontStyle, "Bold") ? FW_BOLD : FW_MEDIUM,
							(BYTE) (strstr (ArticleFontStyle, "Italic") ? 1 : 0),
							0,    /* no underline */
							0,    /* no strikeout */
							FontCharSet,
							OUT_DEFAULT_PRECIS,
							CLIP_DEFAULT_PRECIS,
							nQuality,                                     //possibly antialiased
							0,
							ArticleFontFace);

		hFontArtQuote = CreateFont (
							-MulDiv (ArticleFontSize, ScreenYPixels, 72),
							0,             /* width */
							0,             /* escapement */
							0,             /* orientation */
							strstr (ArticleFontStyle, "Bold") ? FW_BOLD : FW_MEDIUM,
							(BYTE) (strstr (ArticleFontStyle, "Italic") ? 0 : 1),        // opposite to above italics
							0,    /* no underline */
							0,             /* no strikeout */
							FontCharSet,
							OUT_DEFAULT_PRECIS,
							CLIP_DEFAULT_PRECIS,
							nQuality,                                     //possibly antialiased
							0,
							ArticleFontFace);
	}

	if (!hFontArtNormal)
		hFontArtNormal = hWinVnFont;

	if (!hFontArtQuote) 
		hFontArtQuote = hFontArtNormal;

	hDC = GetDC (NetDoc.hDocWnd);
	hOldFont = (HFONT) SelectObject (hDC, hFontArtNormal);
	GetTextMetrics (hDC, (LPTEXTMETRIC) & tmFontInfo);

	ArtLineHeight = tmFontInfo.tmExternalLeading + tmFontInfo.tmHeight;
	ArtCharWidth = tmFontInfo.tmAveCharWidth;
	if (!ArtCharWidth)
		ArtCharWidth = 1;

	SelectObject (hDC, hFontArtQuote);
	GetTextMetrics (hDC, (LPTEXTMETRIC) & tmFontInfo);

	ArtLineHeight = max (ArtLineHeight, (unsigned int)(tmFontInfo.tmExternalLeading + tmFontInfo.tmHeight));
	ArtCharWidth = max (ArtCharWidth, (unsigned int) (tmFontInfo.tmAveCharWidth));

	ArtTopSpace = ArtLineHeight / 4;
	ArtSideSpace = ArtCharWidth / 2;

	SelectObject (hDC, hOldFont);
	ReleaseDC (NetDoc.hDocWnd, hDC);
}

void InitStatusFonts ()
{
	TEXTMETRIC tmFontInfo;
	HDC hDC;
	HFONT hOldFont;
	int nQuality = UseClearType == 0 ? DEFAULT_QUALITY  :
				   UseClearType == 1 ? NONANTIALIASED_QUALITY :
				  (UseClearType == 2 || !g_bIsXP) ? ANTIALIASED_QUALITY : CLEARTYPE_QUALITY;
	if (hStatusFont)
		DeleteObject (hStatusFont);

	hStatusFont = (HFONT) NULL;
	if (StatusFontSize) {
		hStatusFont = CreateFont
		  (-MulDiv (StatusFontSize, ScreenYPixels, 72),
		   0,                                           /* width */
		   0,                                           /* escapement */
		   0,                                           /* orientation */
		   strstr (StatusFontStyle, "Bold") ? FW_BOLD : FW_MEDIUM,
		   (BYTE) (strstr (StatusFontStyle, "Italic") ? 1 : 0),
		   0,                                           /* no underline */
		   0,                                           /* no strikeout */
		   FontCharSet,
		   OUT_DEFAULT_PRECIS,
		   CLIP_DEFAULT_PRECIS,
		   nQuality,                                     //possibly antialiased
		   0,
		   StatusFontFace);
	}
	if (!hStatusFont)
		hStatusFont = hWinVnFont;

	/*  Get information about the font.  LineHeight and CharWidth
	*  are pretty self-explanatory and the methods of determining these
	*  are standard.  TopSpace and SideSpace are the top and left margins
	*  in pixels; I compute them by a method I determined empirically.
	*/

	hDC = GetDC (NetDoc.hDocWnd);
	hOldFont = (HFONT)SelectObject (hDC, hStatusFont);
	if (GetTextMetrics (hDC, (LPTEXTMETRIC) & tmFontInfo))
	{
		StatusLineHeight = tmFontInfo.tmExternalLeading + tmFontInfo.tmHeight;
		StatusCharWidth = tmFontInfo.tmAveCharWidth;
	}
	else
	{
		StatusLineHeight = 16;
		StatusCharWidth = 6;
	}
	SelectObject (hDC, hOldFont);
	ReleaseDC (NetDoc.hDocWnd, hDC);
}

void InitPrintFonts ()
{
	HDC hDC;

	if (hFontPrint) {
		DeleteObject (hFontPrint);
		DeleteObject (hFontPrintB);
		DeleteObject (hFontPrintI);
		DeleteObject (hFontPrintS);
	}

	hFontPrint = hFontPrintB = hFontPrintI = hFontPrintS = (HFONT) NULL;

	hDC = (pd.hDC) ? pd.hDC : GetPrinterDC (NULL);
	PrinterYPixels = GetDeviceCaps (hDC, LOGPIXELSY);
	if (!pd.hDC)
		DeletePrinterDC (hDC);

	if (PrintFontSize) 
	{
		hFontPrint = CreateFont (
						-MulDiv (PrintFontSize, PrinterYPixels, 72),
						0,    /* width */
						0,    /* escapement */
						0,    /* orientation */
						FW_MEDIUM,
						0,    /* no italics */
						0,    /* no underline */
						0,    /* no strikeout */
						FontCharSet,
						OUT_DEFAULT_PRECIS,
						CLIP_DEFAULT_PRECIS,
						0,    /* no PROOF_QUALITY */
						0,
						PrintFontFace);

		hFontPrintB = CreateFont (
						-MulDiv (PrintFontSize, PrinterYPixels, 72),
						0,   /* width */
						0,   /* escapement */
						0,   /* orientation */
						FW_BOLD,
						0,   /* no italics */
						0,   /* no underline */
						0,   /* no strikeout */
						FontCharSet,
						OUT_DEFAULT_PRECIS,
						CLIP_DEFAULT_PRECIS,
						0,   /* no PROOF_QUALITY */
						0,
						PrintFontFace);

		hFontPrintI = CreateFont (
						-MulDiv ((int) (0.9 * PrintFontSize), PrinterYPixels, 72),
						0,   /* width */
						0,   /* escapement */
						0,   /* orientation */
						FW_LIGHT,
						1,   /* italics */
						0,   /* no underline */
						0,   /* no strikeout */
						FontCharSet,
						OUT_DEFAULT_PRECIS,
						CLIP_DEFAULT_PRECIS,
						0,   /* no PROOF_QUALITY */
						0,
						PrintFontFace);

		hFontPrintS = CreateFont (
						-MulDiv ((int) (1.5 * PrintFontSize), PrinterYPixels, 72),
						0,   /* width */
						0,   /* escapement */
						0,   /* orientation */
						FW_EXTRABOLD,
						0,   /* no italics */
						1,   /* underline */
						0,   /* no strikeout */
						FontCharSet,
						OUT_DEFAULT_PRECIS,
						CLIP_DEFAULT_PRECIS,
						0,   /* no PROOF_QUALITY */
						0,
						PrintFontFace);
	}
	else 
	{
		hFontPrint = CreateFont (
						-MulDiv (8, PrinterYPixels, 72),
						//    40,    /* default Font Size */
						0,    /* width */
						0,    /* escapement */
						0,    /* orientation */
						FW_MEDIUM,
						0,    /* no italics */
						0,    /* no underline */
						0,    /* no strikeout */
						FontCharSet,
						OUT_DEFAULT_PRECIS,
						CLIP_DEFAULT_PRECIS,
						0,    /* no PROOF_QUALITY */
						0,
						0);   /* Default Font Face */

		hFontPrintB = CreateFont (
						-MulDiv (8, PrinterYPixels, 72),
						//    40,    /* default font size */
						0,   /* width */
						0,   /* escapement */
						0,   /* orientation */
						FW_BOLD,
						0,   /* no italics */
						0,   /* no underline */
						0,   /* no strikeout */
						FontCharSet,
						OUT_DEFAULT_PRECIS,
						CLIP_DEFAULT_PRECIS,
						0,   /* no PROOF_QUALITY */
						0,
						0);  /* default font face */

		hFontPrintI = CreateFont (
						-MulDiv ((int) (0.9 * 8), PrinterYPixels, 72),
						//    36,    /* default font size */
						0,   /* width */
						0,   /* escapement */
						0,   /* orientation */
						FW_LIGHT,
						1,   /* italics */
						0,   /* no underline */
						0,   /* no strikeout */
						FontCharSet,
						OUT_DEFAULT_PRECIS,
						CLIP_DEFAULT_PRECIS,
						0,   /* no PROOF_QUALITY */
						0,
						0);  /* default font face */

		hFontPrintS = CreateFont (
						-MulDiv (8, PrinterYPixels, 72),
						//    60,
						0,   /* width */
						0,   /* escapement */
						0,   /* orientation */
						FW_EXTRABOLD,
						0,   /* no italics */
						1,   /* underline */
						0,   /* no strikeout */
						FontCharSet,
						OUT_DEFAULT_PRECIS,
						CLIP_DEFAULT_PRECIS,
						0,   /* no PROOF_QUALITY */
						0,
						"Arial");
	}
	if (!hFontPrint)
		hFontPrint = hWinVnFont;

	if (!hFontPrintB)
		hFontPrintB = hWinVnFont;

	if (!hFontPrintI)
		hFontPrintI = hWinVnFont;

	if (!hFontPrintS)
		hFontPrintS = hWinVnFont;
}

void DestroyFonts ()
{
	HDC hDC = GetDC (NetDoc.hDocWnd);

	/* at this point, NetDoc.hDocWnd should be the only open window */
	SelectObject (hDC, GetStockObject (SYSTEM_FONT));
	ReleaseDC (NetDoc.hDocWnd, hDC);

	if (hWinVnFont)
		DeleteObject (hWinVnFont);
	if (hCompositionFont)
		DeleteObject (hCompositionFont);
	if (hListFont)
		DeleteObject (hListFont);
	if (hFontArtNormal)
		DeleteObject (hFontArtNormal);
	if (hFontArtQuote)
		DeleteObject (hFontArtQuote);
	if (hStatusFont)
		DeleteObject (hStatusFont);
	if (hFontPrint)
		DeleteObject (hFontPrint);
	if (hFontPrintB)
		DeleteObject (hFontPrintB);
	if (hFontPrintS)
		DeleteObject (hFontPrintS);
	if (hFontPrintI)
		DeleteObject (hFontPrintI);
}

/*-------------------------------------------------------------
 *
 *  Bitmap resource handlers
 *  jsc 9/10/94
 */
void  InitBitmaps ()
{
	register int i;

	// Load drive and folder bitmaps
	for (i = IDB_DRIVEMIN; i <= IDB_DRIVEMAX; i++)
		DiskBitmaps[i - IDB_DRIVEMIN] = LoadBitmap (hInst, MAKEINTRESOURCE (i));

	for (i = IDB_FOLDERMIN; i <= IDB_FOLDERMAX; i++)
		FolderBitmaps[i - IDB_FOLDERMIN] = LoadBitmap (hInst, MAKEINTRESOURCE (i));

}

void DestroyBitmaps ()
{
	register int i;
	for (i = IDB_DRIVEMIN; i <= IDB_DRIVEMAX; i++)
		if (DiskBitmaps[i - IDB_DRIVEMIN])
		  DeleteObject (DiskBitmaps[i - IDB_DRIVEMIN]);

	for (i = IDB_FOLDERMIN; i <= IDB_FOLDERMAX; i++)
		if (FolderBitmaps[i - IDB_FOLDERMIN])
		  DeleteObject (FolderBitmaps[i - IDB_FOLDERMIN]);
}

/*--- function MainLoopPass ---------------------------------------------
 *
 *    Do one pass of the main loop.
 *
 *    Entry
 *
 *    Exit     returns result of GetMessage()
 */
BOOL MainLoopPass ()
{
	BOOL NoQuit, next;
	register int i;

	if (NoQuit = GetMessage (&MainMsg, (HWND) NULL, 0, 0)) 
	{
		if (!TranslateAccelerator (MainMsg.hwnd, hAccel, &MainMsg)) 
		{
			next = FALSE;
			if (NumPostWnds) 
			{
				for (i = 0; !next && i < MAXPOSTWNDS; i++) 
				{
					if (GetFocus() != WndPosts[i].hWndEdit &&
							WndPosts[i].hWnd != NULL &&
							IsDialogMessage(WndPosts[i].hWnd, &MainMsg)) 
					{
						next = TRUE;
					}
				}
			}
			if (!next && NumMailWnds) 
			{
				for (i = 0; !next && i < MAXMAILWNDS; i++) 
				{
					if (GetFocus() != WndMails[i].hWndEdit &&
							WndMails[i].hWndEdit != NULL && 
							IsDialogMessage(WndMails[i].hWnd, &MainMsg)) 
					{
						next = TRUE;
					}
				}
			}
			if (!next) 
			{
				TranslateMessage (&MainMsg);
				DispatchMessage (&MainMsg);
			}
		}
	}
	return (NoQuit);
}

#ifndef __OS2_PROFILE__

void fakeHostname(char * MyOwnHost)
{
    char * ptr;
    
    /* fake one a own hostname */
    strncpy(MyOwnHost,UserName,MAXNNTPSIZE-1);
    strcat(MyOwnHost,".");
    strncat(MyOwnHost,NNTPHost,MAXNNTPSIZE-strlen(MyOwnHost));
    /* check most of syntax as defined in RFC 1034 */
    for (ptr=MyOwnHost; *ptr ; ptr++) 
	{
        if ((*ptr < 'a') || (*ptr >'z'))
           if ((*ptr < 'A') || (*ptr > 'Z')) 
             if ((*ptr < '0') || (*ptr >'9'))
               if ((*ptr != '.') && ( *ptr !='-'))
                  *ptr = '-'; /* replace blanks etc. with hyphen */
    }
    while (ptr = strstr(MyOwnHost,".."))
            *ptr = 'x';
    while (ptr = strstr(MyOwnHost,"--"))
            *ptr = 'x';
    while (ptr = strstr(MyOwnHost,"-."))
            *ptr = 'x';
    while (ptr = strstr(MyOwnHost,".-")) 
	{
            ptr ++;
            *ptr = 'x';
    }
    ptr = MyOwnHost;
    while (*ptr) {
         if ((*ptr >= '0') && (*ptr <= '9'))
             *ptr = 'x';
         while (*ptr && (*ptr != '.'))
             ptr++;
         if (*ptr == '.')
            ptr++;
    } 
}




/*--- function ReadWinvnProfile -----------------------------------------
 *
 *    Read the profile values into global vars 
 *    (JSC 1/8/94)
 */
void ReadWinvnProfile ()
{
	char buf[8192];
	char buff2[MAXDIALOGSTRING];
	char *ptr;
#ifndef _WIN32 
	char TimeZoneBuf[MAXTZONESIZE+5];
#endif
	int j;

	/* mail address list */
	MailList = InitTextBlock (NetDoc.hDocWnd);
	for (j = 1;; j++) {
		sprintf (str, "Address%d", j);
		GetPrivateProfileString (MAIL_ADDRESSES, str, "", buf, MAILLEN, szAppProFile);
		if (!strcmp (buf, ""))
		  break;
		AddLineToTextBlock (MailList, buf);
	}
	MailListOrigNum = (int) MailList->numLines;

	/* smart filer extension list  -- jsc 9/10/94 */
	ExtMapSourceList = InitTextBlock (NetDoc.hDocWnd);
	ExtMapDosList = InitTextBlock (NetDoc.hDocWnd);
	for (j = 1;; j++) {
		sprintf (str, "ExtConvert%d", j);
		GetPrivateProfileString (SMARTFILER, str, "", buf, MAXINTERNALLINE, szAppProFile);
		if (!buf[0])
		  break;
		if ((ptr = strchr (buf, ',')) != NULL) {
		  *ptr = '\0';                          /* replace comma with null */
	  strcpy(buff2, ".");
	  strcat(buff2, ('.' == buf[0]) ? &buf[1] : &buf[0]);
		  ptr++;                                        /* skip comma, and any whitespace */
		  while (*ptr && isspace ((unsigned char)*ptr))
				++ptr;
	  if('.' != *ptr)
		--ptr;
	  *ptr = '.';
		  /* only add entries to lists if we had two tokens, comma-separated  */
		  if (*ptr) {
				AddLineToTextBlock (ExtMapSourceList, buff2);
				AddLineToTextBlock (ExtMapDosList, ptr);
		  }
		}
	}
	ExtListOrigNum = (int) ExtMapSourceList->numLines;

#ifdef PROFILE_PRE90_UPGRADE
	/* test for existence of Comm section in ini file
	* if doesn't exist but they do have a [WinVn] section, then we need to 
	* upgrade their INI file
	*/
	if (GetPrivateProfileString (COMM, NULL, "", buf, MAXINTERNALLINE, szAppProFile) == 0) {
		if (GetPrivateProfileString (OLD, NULL, "", buf, MAXINTERNALLINE, szAppProFile) != 0) {
		  UpgradePre90Profile ();
		  return;
		}
	}
#endif

	GetPrivateProfileString (PERSONAL, "UserName", DEF_UserName, UserName, MAILLEN, szAppProFile);
	GetPrivateProfileString (PERSONAL, "MailAddress", DEF_MailAddr, MailAddress, MAILLEN, szAppProFile);
	GetPrivateProfileString (PERSONAL, "Organization", DEF_Organization, Organization, MAILLEN, szAppProFile);
	GetPrivateProfileString (PERSONAL, "ReplyTo", DEF_ReplyTo, ReplyTo, MAILLEN, szAppProFile);

	GetPrivateProfileString (COMM, "NNTPHost", DEF_NNTPHost, NNTPHost, MAXNNTPSIZE, szAppProFile);
	GetPrivateProfileString (COMM, "SMTPHost", DEF_SMTPHost, SMTPHost, MAXNNTPSIZE, szAppProFile);
	GetPrivateProfileString (COMM, "NNTPService", DEF_NNTPService, NNTPService, MAXNNTPSIZE, szAppProFile);
	GetPrivateProfileString (COMM, "SMTPService", DEF_SMTPService, SMTPService, MAXNNTPSIZE, szAppProFile);
	ConnectAtStartup =
		GetPrivateProfileInt (COMM, "ConnectAtStartup", DEF_ConnectAtStartup, szAppProFile);
	UseSSL = 
		GetPrivateProfileInt (COMM, "UseSSL", DEF_UseSSL, szAppProFile);
	SMTPUseSSL = 
		GetPrivateProfileInt (COMM, "SMTPSSL", DEF_SMTPUseSSL, szAppProFile);
	SMTPIP_Family =
		GetPrivateProfileInt (COMM, "SMTP_IPFamily", DEF_SMTPIP_Family, szAppProFile);
	force_xhdr =
		GetPrivateProfileInt (COMM, "ForceXhdr", DEF_ForceXhdr, szAppProFile);
	use_zhdr = 
		GetPrivateProfileInt (COMM, "UseCompressedHdr", DEF_UseCompressHdr, szAppProFile);
	ip_family =
			GetPrivateProfileInt (COMM, "IPFamily", DEF_IPFamily, szAppProFile);
	MailDemandLogon =
		GetPrivateProfileInt (COMM, "MailDemandLogon", DEF_MailDemandLogon, szAppProFile);
	MailForceType =
		GetPrivateProfileInt (COMM, "MailForceType", DEF_MailForceType, szAppProFile);

	StallTimeout = GetPrivateProfileInt (COMM, "StallTimeout", DEF_StallTime, szAppProFile);
	CommTimeout = GetPrivateProfileInt (COMM, "CommTimeout", DEF_CommTimeout, szAppProFile);
	Autoconnect = GetPrivateProfileInt (COMM, "Autoconnect", 1, szAppProFile) == 0 ? 0 : 1;

	GetPrivateProfileString (COMM, "GenSockDLL", DEF_GenSockDLL, GenSockDLL, MAXFILENAME, szAppProFile);
	NntpdBugWait =
		GetPrivateProfileInt (COMM, "NntpdBugWait", 0, szAppProFile);

	GetNewsgroupsViaNNTP =
		GetPrivateProfileInt (COMM, "GetNewsgroupsViaNNTP", DEF_GetNewsgroupsViaNNTP, szAppProFile);
	GetPrivateProfileString (COMM, "MyOwnHost", DEF_MyOwnHost, MyOwnHost, MAXNNTPSIZE, szAppProFile);
	if (*MyOwnHost == '\0')
	 fakeHostname(MyOwnHost);

	GetPrivateProfileString (COMM, "MAPIPrefix", DEF_MAPIPrefix, MAPIPrefix, MAXPREFIXSIZE,szAppProFile);
    
#ifdef _WIN32                                 /* get values from NT control panel */
	//  GetPrivateProfileString (COMM, "TimeZone", NULL,TimeZone, MAXTZONESIZE,szAppProFile);
	//  if (TimeZone[0] == 0) {
	//     _tzset();
	//       ptr = getenv("TZ");
	//       if (ptr) strncpy(TimeZone,ptr,MAXTZONESIZE);
	//  }
	//  else 
	//    {
	//        strcpy(TimeZoneBuf,"TZ=");
	//        strcat(TimeZoneBuf,TimeZone);
	//        _putenv(TimeZoneBuf);
	//      } 
                                            
#else     
	GetPrivateProfileString (COMM, "TimeZone", (getenv("TZ")!=NULL) ? getenv("TZ"):DEF_TimeZone,
								 TimeZone, MAXTZONESIZE,szAppProFile);
	if (TimeZone[0] != 0) {
	 strcpy(TimeZoneBuf,"TZ=");
		 strcat(TimeZoneBuf,TimeZone);
		 _putenv(TimeZoneBuf);
	 _tzset();
	}
#endif

	GetPrivateProfileString (AUTH, "NNTPUserName", DEF_NNTPUserName, NNTPUserName, MAXNNTPSIZE, szAppProFile);
	GetPrivateProfileString (AUTH, "NNTPPassword", DEF_NNTPPassword, NNTPPasswordEncrypted, 2 * MAXNNTPSIZE, szAppProFile);
	NNTPSavePassword =
		GetPrivateProfileInt (AUTH, "NNTPSavePassword", DEF_NNTPSavePassword, szAppProFile);

	GetPrivateProfileString (AUTH, "SMTPUserName", DEF_SMTPUserName, SMTPUserName, MAXNNTPSIZE, szAppProFile);
	GetPrivateProfileString (AUTH, "SMTPPassword", DEF_SMTPPassword, SMTPPasswordEncrypted, 2 * MAXNNTPSIZE, szAppProFile);
	SMTPSavePassword =
		GetPrivateProfileInt (AUTH, "SMTPSavePassword", DEF_SMTPSavePassword, szAppProFile);


	AuthReqPost = GetPrivateProfileInt (AUTH, "AuthReqPost", DEF_AuthReqPost, szAppProFile);
	AuthReqMail = GetPrivateProfileInt (AUTH, "AuthReqMail", DEF_AuthReqMail, szAppProFile);

	MailLog =
		GetPrivateProfileInt (LOGGING, "MailLog", DEF_MailLog, szAppProFile);
	GetPrivateProfileString (LOGGING, "MailLogFile", DEF_MailLogFile, MailLogFile, MAXFILENAME, szAppProFile);
	PostLog =
		GetPrivateProfileInt (LOGGING, "PostLog", DEF_PostLog, szAppProFile);
	GetPrivateProfileString (LOGGING, "PostLogFile", DEF_PostLogFile, PostLogFile, MAXFILENAME, szAppProFile);
	/* MDS 2000 03 07 */
	MailLogAttach =
		GetPrivateProfileInt (LOGGING, "LogMailAttach", DEF_MailLogAttach, szAppProFile);
	PostLogAttach =
		GetPrivateProfileInt (LOGGING, "LogPostAttach", DEF_PostLogAttach, szAppProFile);

	ConfirmBatchOps =
		GetPrivateProfileInt (CONFIRM, "ConfirmBatchOps", DEF_ConfirmBatchOps, szAppProFile);
	ConfirmDisconnect =
		GetPrivateProfileInt (CONFIRM, "ConfirmDisconnect", DEF_ConfirmDisconnect, szAppProFile);
	ConfirmSaveOnExit =
		GetPrivateProfileInt (CONFIRM, "ConfirmSaveOnExit", DEF_ConfirmSaveOnExit, szAppProFile);

	ConfirmExitActive =
		 GetPrivateProfileInt (CONFIRM, "ConfirmExitWhenActive", DEF_ConfirmExitActive, szAppProFile);

	/* Ray Dunn:99/10 */
	ConfirmXPosting =
		GetPrivateProfileInt (CONFIRM, "ConfirmCrossPosting", DEF_ConfirmXPosting, szAppProFile);
	/* Ray Dunn:99/10:End */
	ConfirmReplyTo =
		GetPrivateProfileInt (CONFIRM, "ConfirmReplyTo", DEF_ConfirmReplyTo, szAppProFile);
#ifdef OFFLINE  // TANAKA Goh
	ConfirmDeleteArticle =
		GetPrivateProfileInt (CONFIRM, "ConfirmDeleteArticle", DEF_ConfirmDeleteArticle, szAppProFile);
#endif

	DoList =
		GetPrivateProfileInt (GROUPLIST, "DoList", DEF_DoList, szAppProFile);
	GroupListMultiSelect =
		GetPrivateProfileInt (GROUPLIST, "GroupListMultiSelect", DEF_GroupListMultiSelect, szAppProFile);
	ShowUnsubscribed =
		GetPrivateProfileInt (GROUPLIST, "ShowUnsubscribed", DEF_ShowUnsubscribed, szAppProFile);
	SortGroupList =
		GetPrivateProfileInt (GROUPLIST, "SortGroupList", DEF_SortGroupList, szAppProFile);
	GroupListSeparator =
		GetPrivateProfileInt (GROUPLIST, "GroupListSeparator", 0, szAppProFile);
	ShowDescription =
		GetPrivateProfileInt (GROUPLIST, "ShowDescription", DEF_ShowDescription, szAppProFile);
	ShowUnreadCount =
	    GetPrivateProfileInt (GROUPLIST, "ShowUnreadCount", DEF_ShowUnreadCount, szAppProFile);

#ifdef _WIN32  
	MaxDBSize = 
		GetPrivateProfileInt (GROUPLIST, "LimitGroupSize", TOOMANYARTS, szAppProFile);
#endif
	if (GroupFilter) 
	{
		GetPrivateProfileString (GROUPLIST, "GroupFilter", DEF_GroupFilter, GroupFilter, MAXGROUPFILTERSIZE - 1, szAppProFile);
		EnableGroupFilter =
		  GetPrivateProfileInt (GROUPLIST, "EnableGroupFilter", DEF_EnableGroupFilter, szAppProFile);
	}
	UScrollMode =
		GetPrivateProfileInt (GROUPLIST, "ScrollMode", DEF_UScrollMode, szAppProFile);
	for (j = 0 ; j < MAX_WHEEL_ENTRIES ; j++)
	  UScrollByWheel[j] = 0;
  
	UScrollByWheel[0] =
		GetPrivateProfileInt (GROUPLIST, "ScrollByWheel", DEF_UScrollByWheel, szAppProFile);

	for (j = 1 ; j < MAX_WHEEL_ENTRIES ; j++) {
	   sprintf(buf, "ScrollByWheel%d", j);
	   UScrollByWheel[j] = GetPrivateProfileInt (GROUPLIST, buf , 0 , szAppProFile);
	   if (UScrollByWheel[j] == 0)
		   break;
	}            
	article_threshold =
		GetPrivateProfileLong (ARTLIST, "ArticleThreshold", DEF_ArticleThreshold, szAppProFile);
	min_to_retrieve =
		GetPrivateProfileLong (ARTLIST, "MinArticlesToRetrieve", DEF_MinToRetrieve, szAppProFile);
	FullNameFrom =
		GetPrivateProfileInt (ARTLIST, "FullNameFrom", DEF_FullNameFrom, szAppProFile);
	threadp =
		GetPrivateProfileInt (ARTLIST, "EnableThreading", DEF_EnableThreading, szAppProFile);
	//deprecated
	ShowUnreadOnly =
		GetPrivateProfileInt (ARTLIST, "ShowUnreadOnly", DEF_ShowUnreadOnly, szAppProFile);
	if (ShowUnreadOnly)
	{
		article_threshold = DEF_ShowUnreadOnlyReplacement;
		//remove this preference
		WritePrivateProfileString (ARTLIST, "ShowUnreadOnly", NULL, szAppProFile);
	}

	SaveArtAppend =
		GetPrivateProfileInt (ARTLIST, "SaveArtAppend", DEF_SaveArtAppend, szAppProFile);
	SaveNewsrcOnClose =
		GetPrivateProfileInt (ARTLIST, "SaveNewsrcOnClose", DEF_SaveNewsrcOnClose, szAppProFile);
	//  ShowReadArticles = 
	//     GetPrivateProfileInt (ARTLIST,"ShowReadArticles", DEF_ShowReadArticles, szAppProFile);
	ViewNew =
		GetPrivateProfileInt (ARTLIST, "NewWndGroup", DEF_NewWndGroup, szAppProFile);
	ThreadFullSubject =
		GetPrivateProfileInt (ARTLIST, "ThreadFullSubject", DEF_ThreadFullSubject, szAppProFile);
	GetPrivateProfileString (ARTLIST, "ThreadDepthIndicator", DEF_ThreadDepthIndicator, ThreadDepthIndicator, 2, szAppProFile);
	ThreadDepthIndicator[1] = '\0';
	bEnableArticleAction =
		GetPrivateProfileInt (ARTLIST, "EnableArticleAction", DEF_EnableArticleAction, szAppProFile);

	/* Ray Dunn:99/10 */
	SortWithAlphaOnly =
		GetPrivateProfileInt (ARTLIST, "SortWithAlphaOnly", DEF_SortWithAlphaOnly, szAppProFile);
	/* Ray Dunn:99/10:End */
	ArtListMultiSelect =
		GetPrivateProfileInt (ARTLIST, "ArtListMultiSelect", DEF_ArtListMultiSelect, szAppProFile);

	for (j = 0 ; j < MAX_WHEEL_ENTRIES ; j++)
	  GScrollByWheel[j] = 0;
  
	GScrollByWheel[0] =
		GetPrivateProfileInt (ARTLIST, "ScrollByWheel", DEF_GScrollByWheel, szAppProFile);

	for (j = 1 ; j < MAX_WHEEL_ENTRIES ; j++) {
	   sprintf(buf, "ScrollByWheel%d", j);
	   GScrollByWheel[j] = GetPrivateProfileInt (ARTLIST, buf , 0 , szAppProFile);
	   if (GScrollByWheel[j] == 0)
		   break;
	}        
	GScrollMode =
		GetPrivateProfileInt (ARTLIST, "ScrollMode", DEF_GScrollMode, szAppProFile);
    
	for (j = 0 ; j < MAX_WHEEL_ENTRIES ; j++)
	  AScrollByWheel[j] = 0;
  
	AScrollByWheel[0] =
		GetPrivateProfileInt (ARTICLE, "ScrollByWheel", DEF_AScrollByWheel, szAppProFile);

	for (j = 1 ; j < MAX_WHEEL_ENTRIES ; j++) {
	   sprintf(buf, "ScrollByWheel%d", j);
	   AScrollByWheel[j] = GetPrivateProfileInt (ARTICLE, buf , 0 , szAppProFile);
	   if (AScrollByWheel[j] == 0)
		   break;
	}
	AScrollMode =
		GetPrivateProfileInt (ARTICLE, "ScrollMode", DEF_AScrollMode, szAppProFile);

	TrimHeaders =
		GetPrivateProfileInt (ARTICLE, "TrimHeaders", DEF_TrimHeaders, szAppProFile);
#ifdef RFC1522
	UseRFC1522 =
		GetPrivateProfileInt (ARTICLE, "UseRFC1522", DEF_UseRFC1522, szAppProFile);   
#endif
#ifdef VISUAL1521
	UseVISUAL1521 =
		GetPrivateProfileInt (ARTICLE, "UseVISUAL1521", DEF_UseVISUAL1521, szAppProFile);
#endif        
	TruncateSignatures =
		GetPrivateProfileInt (ARTICLE, "TruncateSignatures", DEF_TruncateSignatures, szAppProFile);
	TruncateSignatureFollowup =
		GetPrivateProfileInt (ARTICLE, "TruncateSignatureFollowup", DEF_TruncateSignatureFollowup, szAppProFile);

	WrapIncomingArticleText =
		GetPrivateProfileInt (ARTICLE, "WrapIncomingArticleText", DEF_WrapIncomingArticleText, szAppProFile);
	WrapIncomingArticleTextLength =
		GetPrivateProfileInt (ARTICLE, "WrapIncomingArticleTextLength", DEF_WrapIncomingArticleTextLength, szAppProFile);
	NewArticleWindow =
		GetPrivateProfileInt (ARTICLE, "NewWndArticle", DEF_NewWndArticle, szAppProFile);
	ScrollPastHeaders =
		GetPrivateProfileInt (ARTICLE, "ScrollPastHeaders", DEF_ScrollPastHeaders, szAppProFile);
	/* Ray Dunn:99/10 */
	ShowAuthorName =
		GetPrivateProfileInt (ARTICLE, "ShowAuthorName", DEF_ShowAuthorName, szAppProFile);
	/* Ray Dunn:99/10:End */
	ShowXFace =
		GetPrivateProfileInt (ARTICLE, "ShowXFace", DEF_ShowXFace, szAppProFile);

	GetPrivateProfileString(ARTICLE, "XFacePosition", "526,34", buf, sizeof(buf), szAppProFile);
	sscanf (buf, "%d,%d", &ptXFaceCoord.x, &ptXFaceCoord.y);

	RMDeselectOnMark =
	GetPrivateProfileInt (ARTICLE, "DeselectOnMarkRead", DEF_RMDeselectOnMark, szAppProFile); 


	ItalicizeQuotes =
		GetPrivateProfileInt (ARTICLE, "ItalicizeQuotes", DEF_ItalicizeQuotes, szAppProFile);
	ConfigJumpGroup = 
		GetPrivateProfileInt (ARTICLE, "SearchUnreadGroup", DEF_ConfigJumpGroup, szAppProFile);
	FlagJumpGroup = 0;

	TrackSubscribedCrossposts =
		GetPrivateProfileInt (ARTLIST, "TrackSubscribedCrossposts", DEF_TrackSubscribedCrossposts, szAppProFile);
	TrackUnsubscribedCrossposts =
		GetPrivateProfileInt (ARTLIST, "TrackUnsubscribedCrossposts", DEF_TrackUnsubscribedCrossposts, szAppProFile);
	ArtListSeparator1 =
		GetPrivateProfileInt (ARTLIST, "ArtListSeparator1", 0, szAppProFile);
	ArtListSeparator2 =
		GetPrivateProfileInt (ARTLIST, "ArtListSeparator2", 0, szAppProFile);
	ArtListSeparator3 =
		GetPrivateProfileInt (ARTLIST, "ArtListSeparator3", 0, szAppProFile);

	for (j = 0 ; j < MAX_WHEEL_ENTRIES ; j++)
	  CScrollByWheel[j] = 0;
  
	CScrollByWheel[0] =
		GetPrivateProfileInt (COMPOSE, "ScrollByWheel", DEF_CScrollByWheel, szAppProFile);

	for (j = 1 ; j < MAX_WHEEL_ENTRIES ; j++) {
	   sprintf(buf, "ScrollByWheel%d", j);
	   CScrollByWheel[j] = GetPrivateProfileInt (COMPOSE, buf , 0 , szAppProFile);
	   if (CScrollByWheel[j] == 0)
		   break;
	}        
	CScrollMode =
		GetPrivateProfileInt (COMPOSE, "ScrollMode", DEF_CScrollMode, szAppProFile);

#ifdef RFC1522
	EncodeRFC1522 =
		GetPrivateProfileInt (COMPOSE, "EncodeRFC1522", DEF_EncodeRFC1522, szAppProFile);
#endif
	WordWrap =
		GetPrivateProfileInt (COMPOSE, "WordWrap", DEF_WordWrap, szAppProFile);
	PrefillCcAddress =
		GetPrivateProfileInt (COMPOSE, "PrefillCcAddress", DEF_PrefillCcAddress, szAppProFile);
	ShowOrgHdr =
		GetPrivateProfileInt (COMPOSE, "ShowOrgHdr", DEF_ShowOrgHdr, szAppProFile);
	ShowReplyToHdr =
		GetPrivateProfileInt (COMPOSE, "ShowReplyToHdr", DEF_ShowReplyToHdr, szAppProFile);
	ShowFollowupToHdr =
		GetPrivateProfileInt (COMPOSE, "ShowFollowupToHdr", DEF_ShowFollowupToHdr, szAppProFile);
	ShowKeywordsHdr =
		GetPrivateProfileInt (COMPOSE, "ShowKeywordsHdr", DEF_ShowKeywordsHdr, szAppProFile);
	ShowSummaryHdr =
		GetPrivateProfileInt (COMPOSE, "ShowSummaryHdr", DEF_ShowSummaryHdr, szAppProFile);
	ShowDistributionHdr =
		GetPrivateProfileInt (COMPOSE, "ShowDistributionHdr", DEF_ShowDistributionHdr, szAppProFile);
	ShowFromHdr =
		GetPrivateProfileInt (COMPOSE, "ShowFromHdr", DEF_ShowFromHdr, szAppProFile);
	GetPrivateProfileString (COMPOSE, "FollowupSaysTemplate", DEF_FollowupSaysTemplate, FollowupSaysTemplate, MAXINTERNALLINE, szAppProFile);
	GetPrivateProfileString (COMPOSE, "ReplySaysTemplate", DEF_ReplySaysTemplate, ReplySaysTemplate, MAXINTERNALLINE, szAppProFile);
	GetPrivateProfileString (COMPOSE, "MessageIDToken", "" , IDToken, MAXINTERNALLINE, szAppProFile);
	GetPrivateProfileString (COMPOSE, "CancelKey", "" , CancelKey, MAXINTERNALLINE, szAppProFile);
	UseCancelKey = 
	GetPrivateProfileInt (COMPOSE, "UseCancelKey", DEF_UseCancelKey, szAppProFile);
	NoXNewsreader = 
	GetPrivateProfileInt (COMPOSE, "StripXNewsreader", DEF_NoXNewsreader, szAppProFile);

	GetPrivateProfileString (COMPOSE, "SignatureFile", DEF_SignatureFile, SigFileName, MAXFILENAME, szAppProFile);
	EnableSig =
		GetPrivateProfileInt (COMPOSE, "EnableSignature", DEF_EnableSignature, szAppProFile);
	XNoArchive =
		GetPrivateProfileInt (COMPOSE, "XNoArchive", DEF_XNoArchive, szAppProFile);  //MDS 20000401
	GetPrivateProfileString (CODING, "DecodePath", DEF_DecodePath, DecodePathName, MAXFILENAME, szAppProFile);
	GetPrivateProfileString (CODING, "AttachPath", DEF_DecodePath, AttachPath, MAXFILENAME, szAppProFile);
	CodingStatusVerbose =
		GetPrivateProfileInt (CODING, "CodingStatusVerbose", DEF_CodingStatusVerbose, szAppProFile);
	DumbDecode =
		GetPrivateProfileInt (CODING, "DumbDecode", DEF_DumbDecode, szAppProFile);
	AlsoDecodeOpenArticles =
		GetPrivateProfileInt (CODING, "AlsoDecodeOpenArticles", DEF_AlsoDecodeOpenArticles, szAppProFile);
	ExecuteDecodedFiles =
		GetPrivateProfileInt (CODING, "ExecuteDecodedFiles", DEF_ExecuteDecodedFiles, szAppProFile);
	NeverExeWarnFiles =
		GetPrivateProfileInt (CODING, "NeverEXEWarnFiles", DEF_NeverEXEWarnFiles, szAppProFile);
	KeepArticleHeaderVisible =
		GetPrivateProfileInt (CODING, "KeepArticleHeaderVisible", DEF_KeepArticleHeaderVisible, szAppProFile);
	BlockCodingStatusAlwaysOnTop =
		GetPrivateProfileInt (CODING, "BlockCodingStatusAlwaysOnTop", DEF_BlockCodingStatusAlwaysOnTop, szAppProFile);
	MinimizeStatusWindows =
		GetPrivateProfileInt (CODING, "MinimizeStatusWindows", DEF_MinimizeStatusWindows, szAppProFile);

	EnableDownloadSnd =
		GetPrivateProfileInt (CODING, "EnableDownloadSnd", 0, szAppProFile);
	GetPrivateProfileString (CODING, "DownloadSndPath", "", szDownloadSnd, MAXFILENAME, szAppProFile);

	DefaultAttachInNewArt =
		GetPrivateProfileInt (ATTACH, "DefaultAttachInNewArt", DEF_DefaultAttachInNewArt, szAppProFile);
	DefaultAttachInNewArt = 0;
	DefaultNewArtForAttach = 
		GetPrivateProfileInt (ATTACH, "DefaultNewArtForAttach", DEF_DefaultNewArtForAttach, szAppProFile);
	ArticleSplitLength =
		GetPrivateProfileLong (ATTACH, "ArticleSplitLength", DEF_ArticleSplitLength, szAppProFile);
	GetPrivateProfileString (ATTACH, "SubjectTemplate", DEF_SubjectTemplate, SubjectTemplate, CODINGTABLESIZE + 1, szAppProFile);
	GenerateMIME =
		GetPrivateProfileInt (ATTACH, "GenerateMIME", DEF_GenerateMIME, szAppProFile);
	MIMEUsageSuggestions =
		GetPrivateProfileInt (ATTACH, "MIMEUsageSuggestions", DEF_MIMEUsageSuggestions, szAppProFile);
	GetPrivateProfileString (ATTACH, "MIMEUUType", DEF_MIMEUUType, MIMEUUType, MAXENCODINGTYPELEN, szAppProFile);
	GetPrivateProfileString (ATTACH, "MIMEXXType", DEF_MIMEXXType, MIMEXXType, MAXENCODINGTYPELEN, szAppProFile);
	GetPrivateProfileString (ATTACH, "MIMECustomType", DEF_MIMECustomType, MIMECustomType, MAXENCODINGTYPELEN, szAppProFile);
	GetPrivateProfileString (ATTACH, "MIMECharset", DEF_MIMECharset, MIMECharset, 80, szAppProFile);
	GetPrivateProfileString (ATTACH, "DefaultEncodingType", DEF_DefaultEncodingType, DefaultEncodingTypeStr, MAXENCODINGTYPELEN, szAppProFile);
	DefaultEncodingType = EncodingStrToType (DefaultEncodingTypeStr);
	GetPrivateProfileString (ATTACH, "DefaultContentType", DEF_DefaultContentType, DefaultContentType, MAXCONTENTTYPELEN, szAppProFile);
	GetPrivateProfileString (ATTACH, "EncodingTable", DEF_EncodingTable, UserCodingTable, CODINGTABLESIZE + 1, szAppProFile);

	UseClearType = GetPrivateProfileInt (WVINTERFACE, "UseClearType", DEF_UseClearType, szAppProFile);
	GetPrivateProfileString (WVINTERFACE, "WinVnFontFace", DEF_WinVnFontFace, WinVnFontFace, 32, szAppProFile);
	WinVnFontSize =
		GetPrivateProfileInt (WVINTERFACE, "WinVnFontSize", DEF_WinVnFontSize, szAppProFile);
	if (WinVnFontSize < 0 || WinVnFontSize > MAXFONTSIZE) WinVnFontSize = DEF_WinVnFontSize;
	GetPrivateProfileString (WVINTERFACE, "WinVnFontStyle", DEF_WinVnFontStyle, WinVnFontStyle, 32, szAppProFile);
	GetPrivateProfileString (WVINTERFACE, "CompositionFontFace", DEF_CompositionFontFace, CompositionFontFace, 32, szAppProFile);
	CompositionFontSize =
		GetPrivateProfileInt (WVINTERFACE, "CompositionFontSize", DEF_CompositionFontSize, szAppProFile);
	if (CompositionFontSize < 0 || CompositionFontSize > MAXFONTSIZE) CompositionFontSize = DEF_CompositionFontSize;
	GetPrivateProfileString (WVINTERFACE, "CompositionFontStyle", DEF_CompositionFontStyle, CompositionFontStyle, 32, szAppProFile);
	GetPrivateProfileString (WVINTERFACE, "ListFontFace", DEF_ListFontFace, ListFontFace, 32, szAppProFile);
	ListFontSize =
		GetPrivateProfileInt (WVINTERFACE, "ListFontSize", DEF_ListFontSize, szAppProFile);
	if (ListFontSize < 0 || ListFontSize > MAXFONTSIZE) ListFontSize = DEF_ListFontSize;
	GetPrivateProfileString (WVINTERFACE, "ListFontStyle", DEF_ListFontStyle, ListFontStyle, 32, szAppProFile);
	//  FontBold = 
	//     GetPrivateProfileInt (WVINTERFACE, "FontBold", TRUE, szAppProFile);
	GetPrivateProfileString (WVINTERFACE, "ArticleFontFace", DEF_ArticleFontFace, ArticleFontFace, 32, szAppProFile);
	ArticleFontSize =
		GetPrivateProfileInt (WVINTERFACE, "ArticleFontSize", DEF_ArticleFontSize, szAppProFile);
	if (ArticleFontSize < 0 || ArticleFontSize > MAXFONTSIZE) ArticleFontSize = DEF_ArticleFontSize;
	GetPrivateProfileString (WVINTERFACE, "ArticleFontStyle", DEF_ArticleFontStyle, ArticleFontStyle, 32, szAppProFile);
	GetPrivateProfileString (WVINTERFACE, "StatusFontFace", DEF_StatusFontFace, StatusFontFace, 32, szAppProFile);
	StatusFontSize =
		GetPrivateProfileInt (WVINTERFACE, "StatusFontSize", DEF_StatusFontSize, szAppProFile);
	if (StatusFontSize < 0 || StatusFontSize > MAXFONTSIZE) StatusFontSize = DEF_StatusFontSize;
	GetPrivateProfileString (WVINTERFACE, "StatusFontStyle", DEF_StatusFontStyle, StatusFontStyle, 32, szAppProFile);
	GetPrivateProfileString (WVINTERFACE, "PrintFontFace", DEF_PrintFontFace, PrintFontFace, 32, szAppProFile);
	PrintFontSize =
		GetPrivateProfileInt (WVINTERFACE, "PrintFontSize", DEF_PrintFontSize, szAppProFile);
	if (PrintFontSize < 0 || PrintFontSize > MAXFONTSIZE) PrintFontSize = DEF_PrintFontSize;
	//  ArticleFixedFont = 
	//     GetPrivateProfileInt (WVINTERFACE, "ArticleFixedFont", FALSE, szAppProFile);
	ArticleFixedFont = 0;
	GetPrivateProfileString (WVINTERFACE, "NetUnSubscribedColor", DEF_NetUnSubscribedColor, buf, 32, szAppProFile);
	NetUnSubscribedColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "NetSubscribedColor", DEF_NetSubscribedColor, buf, 32, szAppProFile);
	NetSubscribedColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "ArticleUnSeenColor", DEF_ArticleUnSeenColor, buf, 32, szAppProFile);
	ArticleUnSeenColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "ArticleSeenColor", DEF_ArticleSeenColor, buf, 32, szAppProFile);
	ArticleSeenColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "ArticleKilledColor", DEF_ArticleKilledColor, buf, 32, szAppProFile);
	ArticleKilledColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "ArticleTextColor", DEF_ArticleTextColor, buf, 32, szAppProFile);
	ArticleTextColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "StatusTextColor", DEF_StatusTextColor, buf, 32, szAppProFile);
	StatusTextColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "ArticleBackgroundColor", DEF_ArticleBackgroundColor, buf, 32, szAppProFile);
	ArticleBackgroundColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "ListBackgroundColor", DEF_ListBackgroundColor, buf, 32, szAppProFile);
	ListBackgroundColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "StatusBackgroundColor", DEF_StatusBackgroundColor, buf, 32, szAppProFile);
	StatusBackgroundColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "ArticleErrorColor", DEF_ArticleErrorColor, buf, 32, szAppProFile);
	ArticleErrorColor = StrToRGB (buf);
	GetPrivateProfileString (WVINTERFACE, "ArticlePreviewColor", DEF_ArticlePreviewColor, buf, 32, szAppProFile);
	ArticlePreviewColor = StrToRGB (buf);
	UseInverseSelections =
		GetPrivateProfileInt (WVINTERFACE, "UseInverseSelections", DEF_UseInverseSelections, szAppProFile);
	ThumbTrack =
		GetPrivateProfileInt (WVINTERFACE, "ThumbTrack", DEF_ThumbTrack, szAppProFile);
#ifdef USE_SPLASH
	ShowSplashScreen =
		GetPrivateProfileInt (WVINTERFACE, "ShowSplashScreen", DEF_ShowSplashScreen, szAppProFile);
#endif

	nToolbarMain = GetPrivateProfileInt (GROUPLIST, "ToolbarSize", 1, szAppProFile);
	nToolbarArt = GetPrivateProfileInt (ARTLIST, "ToolbarSize", 1, szAppProFile); 
	nToolbarView = GetPrivateProfileInt (ARTICLE, "ToolbarSize", 1, szAppProFile);

	GetPrivateProfileString (SEARCHES, "LastArticleTextFind", "", LastArticleTextFind, MAXFINDSTRING, szAppProFile);
	GetPrivateProfileString (SEARCHES, "LastArticleHeaderFind", "", LastArticleHeaderFind, MAXFINDSTRING, szAppProFile);
	GetPrivateProfileString (SEARCHES, "LastGroupNameFind", "", LastGroupNameFind, MAXFINDSTRING, szAppProFile);

	PageNumberAlwaysWithSubject =
		GetPrivateProfileInt (PRINTING, "PageNumberAlwaysWithSubject", DEF_PageNumberAlwaysWithSubject, szAppProFile);

	OnDupeName =
		GetPrivateProfileInt (SMARTFILER, "OnDupeName", DEF_OnDupeName, szAppProFile);
	OnNameTooLong =
		GetPrivateProfileInt (SMARTFILER, "OnNameTooLong", DEF_OnNameTooLong, szAppProFile);
	MaxFileNameLen =
		GetPrivateProfileInt (SMARTFILER, "MaxFileNameLen", DEF_MaxFileNameLen, szAppProFile);
	MaxFileExtLen =
		GetPrivateProfileInt (SMARTFILER, "MaxFileExtLen", DEF_MaxFileExtLen, szAppProFile);
	EnableExtensionConversion =
		GetPrivateProfileInt (SMARTFILER, "EnableExtensionConversion", DEF_EnableExtensionConversion, szAppProFile);
	SpaceProcessing = 
		GetPrivateProfileInt (SMARTFILER, "RemoveSpaces", DEF_SpaceProcessing, szAppProFile);

	// from Mitsuo Shimomai - Kagoshima University, Japan
	// Support for WWW access.   User interface, WAIS and GOPHER
	// support added by Jim Dumoulin, NASA/Kennedy Space Center
	{
	//read the real default path from the registry
	//these keys are now pretty much "standard" for browsers on win16, win32
	//MDS 2000407
	char szDefaultPath[MAXFILENAME];
	if (GetRegDefaultCommand("http", szDefaultPath, MAXFILENAME-3) )
	  strcat(szDefaultPath, " %u");
	else
	  strcpy(szDefaultPath, DEF_HttpClient); 

	GetPrivateProfileString (EXECUTE, "HttpClient", szDefaultPath, HttpClient,MAXFILENAME,szAppProFile);
	if (!strcmp(HttpClient, DEF_HttpClient) && *szDefaultPath )
	  strcpy(HttpClient, szDefaultPath); //update old unused(?) paths 
	

	if (GetRegDefaultCommand("ftp", szDefaultPath, MAXFILENAME-5) )
	  strcat(szDefaultPath, " %h:%f");
	else
	  strcpy(szDefaultPath, " %u");

	GetPrivateProfileString (EXECUTE, "FtpClient", szDefaultPath, FtpClient,MAXFILENAME,szAppProFile);
	if (!strcmp(FtpClient, DEF_FtpClient) && *szDefaultPath )
	  strcpy(FtpClient, szDefaultPath); //update old unused(?) paths 

	if (GetRegDefaultCommand("gopher", szDefaultPath, MAXFILENAME-3) )
	  strcat(szDefaultPath, " %u");
	else
	  strcpy(szDefaultPath, DEF_GopherClient);
	GetPrivateProfileString (EXECUTE, "GopherClient", szDefaultPath, GopherClient,MAXFILENAME,szAppProFile);
	if (*GopherClient == '\0')
	  strcpy(GopherClient, szDefaultPath); //update old unused(?) paths 

	GetPrivateProfileString (EXECUTE, "WaisClient", DEF_WaisClient, WaisClient,MAXFILENAME,szAppProFile);
	UsingDDE =
			GetPrivateProfileInt (EXECUTE, "UsingDDE", DEF_UsingDDE, szAppProFile);
	DdeServID = 
			GetPrivateProfileInt (EXECUTE, "DdeServID", DEF_DdeServID, szAppProFile); 
	GetPrivateProfileString (EXECUTE, "DdeServName", DEF_DdeServName, DdeServName,MAXFILENAME,szAppProFile);
	}     

#ifdef OFFLINE  // TANAKA Goh
	SaveNewsrcGNUSFormat =
		GetPrivateProfileInt ("Offline", "SaveNewsrcGNUSFormat", DEF_SaveNewsrcGNUSFormat, szAppProFile);
	SaveSOUPOnClose =
		GetPrivateProfileInt ("Offline", "SaveSOUPOnClose", DEF_SaveSOUPOnClose, szAppProFile);
#endif

#ifdef PROFILE_PRE93_UPGRADE
	/* kludgey upgrade ability
	* if the Compose section doesn't exist, read in from the pre.93.0 sections
	*/
	if (GetPrivateProfileString (COMPOSE, NULL, "", buf, MAXINTERNALLINE, szAppProFile) == 0) {
		UpgradePre93Profile ();
	}
#endif

	// The following is in WIN.INI (??)
	GetProfileString (INTERNATIONAL, "sDate", ".", fmtDateDelim, 2);
	//  fmtDateDelim[1]=0 ;
	fmtDaysB4Mth = (1 == GetProfileInt (INTERNATIONAL, "iDate", 0 /* US Date Format */ ));


}

/*--- function WriteWinvnProfile -----------------------------------------
 *
 *    Write the values modifiable in WinVn menus to the profile 
 *    (JSC 1/8/94)
 */
#ifndef _WIN32

void WINAPI	WriteWinvnProfile ()
{
  char buf[MAXINTERNALLINE];
  register int j;


  WritePrivateProfileString (ADMIN, "Version", WINVN_VERSION, szAppProFile);

  WritePrivateProfileString (PERSONAL, "UserName", UserName, szAppProFile);
  WritePrivateProfileString (PERSONAL, "MailAddress", MailAddress, szAppProFile);
  WritePrivateProfileString (PERSONAL, "Organization", Organization, szAppProFile);
  WritePrivateProfileString (PERSONAL, "ReplyTo", ReplyTo, szAppProFile);

  if (!gURLinfo)
  {
    //settings not saved when using command line URL
    WritePrivateProfileString (COMM, "NNTPHost", NNTPHost, szAppProFile);
    WritePrivateProfileString (COMM, "NNTPService", NNTPService, szAppProFile);
    WritePrivateProfileString (AUTH, "NNTPUserName", NNTPUserName, szAppProFile);
    WritePrivateProfileInt    (AUTH, "NNTPSavePassword", NNTPSavePassword, szAppProFile);

    if (NNTPSavePassword)
         WritePrivateProfileString (AUTH, "NNTPPassword", NNTPPasswordEncrypted, szAppProFile);
    else
         WritePrivateProfileString (AUTH, "NNTPPassword", DEF_NNTPPassword, szAppProFile);
  }
  WritePrivateProfileString (COMM, "SMTPHost", SMTPHost, szAppProFile);
  WritePrivateProfileInt (COMM, "ConnectAtStartup", ConnectAtStartup, szAppProFile);
  WritePrivateProfileInt (COMM, "ForceXhdr", force_xhdr, szAppProFile);
  WritePrivateProfileInt (COMM, "UseCompressedHdr", use_zhdr, szAppProFile);

  WritePrivateProfileInt (COMM, "MailDemandLogon", MailDemandLogon, szAppProFile);
  WritePrivateProfileInt (COMM, "MailForceType", MailForceType, szAppProFile);
  //WritePrivateProfileString (COMM, "GenSockDLL", GenSockDLL, szAppProFile);

  if (TimeZone[0] != 0)
     WritePrivateProfileString (COMM, "TimeZone", TimeZone, szAppProFile);
  WritePrivateProfileString (COMM, "MAPIPrefix", MAPIPrefix, szAppProFile);

  WritePrivateProfileInt (LOGGING, "MailLog", MailLog, szAppProFile);
  WritePrivateProfileString (LOGGING, "MailLogFile", MailLogFile, szAppProFile);
  WritePrivateProfileInt (LOGGING, "PostLog", PostLog, szAppProFile);
  WritePrivateProfileString (LOGGING, "PostLogFile", PostLogFile, szAppProFile);
  /* MDS 2000 03 07 */
  WritePrivateProfileInt (LOGGING, "LogMailAttach", MailLogAttach, szAppProFile);
  WritePrivateProfileInt (LOGGING, "LogPostAttach", PostLogAttach, szAppProFile);


  WritePrivateProfileInt (CONFIRM, "ConfirmBatchOps", ConfirmBatchOps, szAppProFile);
  WritePrivateProfileInt (CONFIRM, "ConfirmDisconnect", ConfirmDisconnect, szAppProFile);
  WritePrivateProfileInt (CONFIRM, "ConfirmSaveOnExit", ConfirmSaveOnExit, szAppProFile);
  WritePrivateProfileInt (CONFIRM, "ConfirmExitWhenActive", ConfirmExitActive, szAppProFile);

  /* Ray Dunn:99/10 */
  WritePrivateProfileInt (CONFIRM, "ConfirmCrossPosting", ConfirmXPosting, szAppProFile);
  /* Ray Dunn:99/10:End */
  WritePrivateProfileInt (CONFIRM, "ConfirmReplyTo", ConfirmReplyTo, szAppProFile);
#ifdef OFFLINE  // TANAKA Goh
  WritePrivateProfileInt (CONFIRM, "ConfirmDeleteArticle", ConfirmDeleteArticle, szAppProFile);
#endif

  WritePrivateProfileInt (GROUPLIST, "DoList", DoList, szAppProFile);
  WritePrivateProfileInt (GROUPLIST, "ShowUnsubscribed", ShowUnsubscribed, szAppProFile);
  WritePrivateProfileInt (GROUPLIST, "SortGroupList", SortGroupList, szAppProFile);
  WritePrivateProfileInt (GROUPLIST, "GroupListMultiSelect", GroupListMultiSelect, szAppProFile);
  WritePrivateProfileInt (GROUPLIST, "GroupListSeparator", GroupListSeparator, szAppProFile);
  //WritePrivateProfileInt (GROUPLIST, "SortGroupList",SortGroupList,szAppProFile);

// these aren't changeable from within winvn yet
  //  WritePrivateProfileString (GROUPLIST, "GroupFilter", GroupFilter, szAppProFile);
  //  WritePrivateProfileInt    (GROUPLIST, "EnableGroupFilter", EnableGroupFilter, szAppProFile);
  if (UScrollMode > WHEELSCROLL_SYSTEM ) {
    WritePrivateProfileInt (GROUPLIST, "ScrollByWheel", UScrollByWheel[0], szAppProFile);
    for (j = 1 ; ((j < MAX_WHEEL_ENTRIES)  && (UScrollByWheel[j] != 0)) ; j++) {
            sprintf(buf, "ScrollByWheel%d", j);
            WritePrivateProfileInt (GROUPLIST, buf , UScrollByWheel[j], szAppProFile);
    }
  }
  
  WritePrivateProfileLong (ARTLIST, "ArticleThreshold", article_threshold, szAppProFile);
  WritePrivateProfileLong (ARTLIST, "MinArticlesToRetrieve", min_to_retrieve, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "FullNameFrom", FullNameFrom, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "EnableThreading", threadp, szAppProFile);
  //deprecated WritePrivateProfileInt (ARTLIST, "ShowUnreadOnly", ShowUnreadOnly, szAppProFile);
  
  WritePrivateProfileInt (ARTLIST, "NewWndGroup", ViewNew, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "ThreadFullSubject", ThreadFullSubject, szAppProFile);
  WritePrivateProfileString (ARTLIST, "ThreadDepthIndicator", ThreadDepthIndicator, szAppProFile);

  WritePrivateProfileInt (ARTLIST, "SaveArtAppend", SaveArtAppend, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "SaveNewsrcOnClose", SaveNewsrcOnClose, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "ArtListMultiSelect", ArtListMultiSelect, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "TrackSubscribedCrossposts", TrackSubscribedCrossposts, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "TrackUnsubscribedCrossposts", TrackUnsubscribedCrossposts, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "ArtListSeparator1", ArtListSeparator1, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "ArtListSeparator2", ArtListSeparator2, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "ArtListSeparator3", ArtListSeparator3, szAppProFile);
  WritePrivateProfileInt (ARTLIST, "EnableArticleAction", bEnableArticleAction, szAppProFile);
  /* Ray Dunn:99/10 */
  WritePrivateProfileInt (ARTLIST, "SortWithAlphaOnly", SortWithAlphaOnly, szAppProFile);
  /* Ray Dunn:99/10:End */
  if (GScrollMode > WHEELSCROLL_SYSTEM) {
    WritePrivateProfileInt (ARTLIST, "ScrollByWheel", GScrollByWheel[0], szAppProFile);
    for (j = 1 ; ((j < MAX_WHEEL_ENTRIES)  && (GScrollByWheel[j] != 0)) ; j++) {
            sprintf(buf, "ScrollByWheel%d", j);
            WritePrivateProfileInt (ARTLIST, buf , GScrollByWheel[j], szAppProFile);
    }
  }
  

  if (AScrollMode > WHEELSCROLL_SYSTEM) {
    WritePrivateProfileInt (ARTICLE, "ScrollByWheel", AScrollByWheel[0], szAppProFile);
    for (j = 1 ; ((j < MAX_WHEEL_ENTRIES)  && (AScrollByWheel[j] != 0)) ; j++) {
            sprintf(buf, "ScrollByWheel%d", j);
            WritePrivateProfileInt (ARTICLE, buf , AScrollByWheel[j], szAppProFile);
    }
  }
  
  WritePrivateProfileInt (ARTICLE, "NewWndArticle", NewArticleWindow, szAppProFile);
  WritePrivateProfileInt (ARTICLE, "WrapIncomingArticleText", WrapIncomingArticleText, szAppProFile);
  WritePrivateProfileInt (ARTICLE, "WrapIncomingArticleTextLength", WrapIncomingArticleTextLength, szAppProFile);
  WritePrivateProfileInt (ARTICLE, "TrimHeaders", TrimHeaders, szAppProFile);
#ifdef RFC1522
  WritePrivateProfileInt (ARTICLE, "UseRFC1522", UseRFC1522, szAppProFile);
#endif
#ifdef VISUAL1521
  WritePrivateProfileInt (ARTICLE, "UseVISUAL1521", UseVISUAL1521, szAppProFile);  
#endif
  WritePrivateProfileInt (ARTICLE, "TruncateSignatures", TruncateSignatures, szAppProFile);
  WritePrivateProfileInt (ARTICLE, "ScrollPastHeaders", ScrollPastHeaders, szAppProFile);
  /* Ray Dunn:99/10 */
  WritePrivateProfileInt (ARTICLE, "ShowAuthorName", ShowAuthorName, szAppProFile);
  /* Ray Dunn:99/10:End */
  WritePrivateProfileInt (ARTICLE, "ItalicizeQuotes", ItalicizeQuotes, szAppProFile);
  WritePrivateProfileInt (ARTICLE, "SearchUnreadGroup", ConfigJumpGroup, szAppProFile);
  
#ifdef RFC1522
  WritePrivateProfileInt (COMPOSE, "EncodeRFC1522", EncodeRFC1522, szAppProFile);
#endif  
  WritePrivateProfileInt (COMPOSE, "WordWrap", WordWrap, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "PrefillCcAddress", PrefillCcAddress, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "ShowOrgHdr", ShowOrgHdr, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "ShowReplyToHdr", ShowReplyToHdr, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "ShowFollowupToHdr", ShowFollowupToHdr, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "ShowKeywordsHdr", ShowKeywordsHdr, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "ShowSummaryHdr", ShowSummaryHdr, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "ShowDistributionHdr", ShowDistributionHdr, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "ShowFromHdr", ShowFromHdr, szAppProFile);
  WritePrivateProfileString (COMPOSE, "FollowupSaysTemplate", FollowupSaysTemplate, szAppProFile);
  WritePrivateProfileString (COMPOSE, "ReplySaysTemplate", ReplySaysTemplate, szAppProFile);
  if (*IDToken)
	WritePrivateProfileString (COMPOSE, "MessageIDToken", IDToken, szAppProFile);
  else
	WritePrivateProfileString (COMPOSE, "MessageIDToken", NULL, szAppProFile);




  WritePrivateProfileString (COMPOSE, "SignatureFile", SigFileName, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "EnableSignature", EnableSig, szAppProFile);
  WritePrivateProfileInt (COMPOSE, "XNoArchive", XNoArchive, szAppProFile);   //MDS 20000401

  if (CScrollMode > WHEELSCROLL_SYSTEM) {
    WritePrivateProfileInt (COMPOSE, "ScrollByWheel", CScrollByWheel[0], szAppProFile);
    for (j = 1 ; ((j < MAX_WHEEL_ENTRIES)  && (CScrollByWheel[j] != 0)) ; j++) {
            sprintf(buf, "ScrollByWheel%d", j);
            WritePrivateProfileInt (COMPOSE, buf , CScrollByWheel[j], szAppProFile);
    }
  }

  WritePrivateProfileString (CODING, "DecodePath", DecodePathName, szAppProFile);
  WritePrivateProfileString (CODING, "AttachPath", AttachPath, szAppProFile);
  WritePrivateProfileInt (CODING, "CodingStatusVerbose", CodingStatusVerbose, szAppProFile);
  WritePrivateProfileInt (CODING, "AlsoDecodeOpenArticles", AlsoDecodeOpenArticles, szAppProFile);
  WritePrivateProfileInt (CODING, "DumbDecode", DumbDecode, szAppProFile);
  WritePrivateProfileInt (CODING, "BlockCodingStatusAlwaysOnTop", BlockCodingStatusAlwaysOnTop, szAppProFile);
  WritePrivateProfileInt (CODING, "MinimizeStatusWindows", MinimizeStatusWindows, szAppProFile);
  WritePrivateProfileInt (CODING, "ExecuteDecodedFiles", ExecuteDecodedFiles, szAppProFile);
  WritePrivateProfileInt (CODING, "NeverEXEWarnFiles", NeverExeWarnFiles, szAppProFile);
  WritePrivateProfileInt (CODING, "KeepArticleHeaderVisible", KeepArticleHeaderVisible, szAppProFile);

  WritePrivateProfileInt (CODING, "EnableDownloadSnd", EnableDownloadSnd, szAppProFile);
  WritePrivateProfileString (CODING, "DownloadSndPath",  szDownloadSnd, szAppProFile);

  WritePrivateProfileInt    (ATTACH, "DefaultAttachInNewArt", DefaultAttachInNewArt, szAppProFile);
  WritePrivateProfileInt    (ATTACH, "DefaultNewArtForAttach", DefaultNewArtForAttach, szAppProFile);
  WritePrivateProfileLong   (ATTACH, "ArticleSplitLength", ArticleSplitLength, szAppProFile);
  WritePrivateProfileString (ATTACH, "SubjectTemplate", SubjectTemplate, szAppProFile);
  WritePrivateProfileInt    (ATTACH, "GenerateMIME", GenerateMIME, szAppProFile);
  WritePrivateProfileInt    (ATTACH, "MIMEUsageSuggestions", MIMEUsageSuggestions, szAppProFile);
  WritePrivateProfileString (ATTACH, "MIMEUUType", MIMEUUType, szAppProFile);
  WritePrivateProfileString (ATTACH, "MIMEXXType", MIMEXXType, szAppProFile);
  WritePrivateProfileString (ATTACH, "MIMECustomType", MIMECustomType, szAppProFile);
  WritePrivateProfileString (ATTACH, "MIMECharset", MIMECharset, szAppProFile);
  WritePrivateProfileString (ATTACH, "DefaultEncodingType", EncodingTypeToStr (DefaultEncodingType), szAppProFile);
  WritePrivateProfileString (ATTACH, "DefaultContentType", DefaultContentType, szAppProFile);
  WritePrivateProfileString (ATTACH, "EncodingTable", UserCodingTable, szAppProFile);

  WritePrivateProfileString (WVINTERFACE, "WinVnFontFace", WinVnFontFace, szAppProFile);
  WritePrivateProfileInt    (WVINTERFACE, "WinVnFontSize", WinVnFontSize, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "WinVnFontStyle", WinVnFontStyle, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "CompositionFontFace", CompositionFontFace, szAppProFile);
  WritePrivateProfileInt    (WVINTERFACE, "CompositionFontSize", CompositionFontSize, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "CompositionFontStyle", CompositionFontStyle, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ListFontFace", ListFontFace, szAppProFile);
  WritePrivateProfileInt    (WVINTERFACE, "ListFontSize", ListFontSize, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ListFontStyle", ListFontStyle, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticleFontFace", ArticleFontFace, szAppProFile);
  WritePrivateProfileInt    (WVINTERFACE, "ArticleFontSize", ArticleFontSize, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticleFontStyle", ArticleFontStyle, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "StatusFontFace", StatusFontFace, szAppProFile);
  WritePrivateProfileInt    (WVINTERFACE, "StatusFontSize", StatusFontSize, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "StatusFontStyle", StatusFontStyle, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "PrintFontFace", PrintFontFace, szAppProFile);
  WritePrivateProfileInt    (WVINTERFACE, "PrintFontSize", PrintFontSize, szAppProFile);
//  WritePrivateProfileInt    (WVINTERFACE, "FontBold", FontBold, szAppProFile);
//  WritePrivateProfileInt    (WVINTERFACE, "ArticleFixedFont", ArticleFixedFont, szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "NetUnSubscribedColor", RGBToStr (str, NetUnSubscribedColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "NetSubscribedColor", RGBToStr (str, NetSubscribedColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticleUnSeenColor", RGBToStr (str, ArticleUnSeenColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticleSeenColor", RGBToStr (str, ArticleSeenColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticleKilledColor", RGBToStr (str, ArticleKilledColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticleTextColor", RGBToStr (str, ArticleTextColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "StatusTextColor", RGBToStr (str, StatusTextColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticleBackgroundColor", RGBToStr (str, ArticleBackgroundColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ListBackgroundColor", RGBToStr (str, ListBackgroundColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "StatusBackgroundColor", RGBToStr (str, StatusBackgroundColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticleErrorColor", RGBToStr (str, ArticleErrorColor), szAppProFile);
  WritePrivateProfileString (WVINTERFACE, "ArticlePreviewColor", RGBToStr (str, ArticlePreviewColor), szAppProFile);
  WritePrivateProfileInt (WVINTERFACE, "UseInverseSelections", UseInverseSelections, szAppProFile);
  WritePrivateProfileInt (WVINTERFACE, "ThumbTrack", ThumbTrack, szAppProFile);
#ifdef USE_SPLASH
  WritePrivateProfileInt (WVINTERFACE, "ShowSplashScreen", ShowSplashScreen, szAppProFile);
#endif
  WritePrivateProfileString (SEARCHES, "LastArticleTextFind", LastArticleTextFind, szAppProFile);
  WritePrivateProfileString (SEARCHES, "LastArticleHeaderFind", LastArticleHeaderFind, szAppProFile);
  WritePrivateProfileString (SEARCHES, "LastGroupNameFind", LastGroupNameFind, szAppProFile);

// from Mitsuo Shimomai - Kagoshima University, Japan
  WritePrivateProfileString (EXECUTE, "HttpClient", HttpClient, szAppProFile);
  WritePrivateProfileString (EXECUTE, "FtpClient", FtpClient, szAppProFile);
  
  WritePrivateProfileString (EXECUTE, "GopherClient", GopherClient, szAppProFile);
  WritePrivateProfileString (EXECUTE, "WaisClient", WaisClient, szAppProFile);
  WritePrivateProfileInt (EXECUTE, "UsingDDE", UsingDDE,szAppProFile);
  WritePrivateProfileInt (EXECUTE, "DdeServID", DdeServID,szAppProFile);
  WritePrivateProfileString (EXECUTE, "DdeServName", DdeServName,szAppProFile);

  WritePrivateProfileInt (SMARTFILER, "OnDupeName", OnDupeName, szAppProFile);
  WritePrivateProfileInt (SMARTFILER, "OnNameTooLong", OnNameTooLong, szAppProFile);
  WritePrivateProfileInt (SMARTFILER, "MaxFileNameLen", MaxFileNameLen, szAppProFile);
  WritePrivateProfileInt (SMARTFILER, "MaxFileExtLen", MaxFileExtLen, szAppProFile);
  WritePrivateProfileInt (SMARTFILER, "EnableExtensionConversion", EnableExtensionConversion, szAppProFile);
  WritePrivateProfileInt (SMARTFILER, "RemoveSpaces", SpaceProcessing, szAppProFile);

    WritePrivateProfileInt (GROUPLIST, "ToolbarSize", nToolbarMain, szAppProFile);
    WritePrivateProfileInt (ARTLIST, "ToolbarSize", nToolbarArt, szAppProFile); 
    WritePrivateProfileInt (ARTICLE, "ToolbarSize", nToolbarView, szAppProFile);


  if (MailList) {
        for (j = 0; j < max (MailListOrigNum, (int) MailList->numLines); j++) {
          sprintf (str, "Address%d", j + 1);
          WritePrivateProfileString (MAIL_ADDRESSES, str,
            (j >= (int) MailList->numLines) ? "" : TextBlockLine (MailList, j), szAppProFile);
        }
  }

  if (ExtMapSourceList && ExtMapDosList) {
        for (j = 0; j < max (ExtListOrigNum, (int) ExtMapSourceList->numLines); j++) {
          sprintf (str, "ExtConvert%d", j + 1);
          if (j >= (int) ExtMapSourceList->numLines)
                *buf = '\0';
          else
                _snprintf (buf, MAXINTERNALLINE - 1, "%s,%s",
                   TextBlockLine (ExtMapSourceList, j), TextBlockLine (ExtMapDosList, j));

          WritePrivateProfileString (SMARTFILER, str, buf, szAppProFile);
        }
  }
}
#endif //!WIN32

void SaveWindowPositions ()
{
  char mybuf[MAXINTERNALLINE];
  BOOL found;
  int idoc;
  WINDOWPLACEMENT wpl = {sizeof(WINDOWPLACEMENT)};

  /* Save position and size of Usenet window. */
  if  (GetWindowPlacement(NetDoc.hWndFrame, &wpl))
  {
          sprintf (mybuf, "%d,%d,%d,%d", wpl.rcNormalPosition.left, wpl.rcNormalPosition.top,
                           RectWidth (wpl.rcNormalPosition), RectHeight (wpl.rcNormalPosition));
          WritePrivateProfileString (GROUPLIST, "UsenetWindowPos", mybuf, szAppProFile);
  }

  /* Save position and size of first Group window */
  for (found = FALSE, idoc = 0; !found && idoc < MAXGROUPWNDS; idoc++) 
  {
        if (GroupDocs[idoc].InUse && GetWindowPlacement(GroupDocs[idoc].hWndFrame, &wpl)) 
		{
          found = TRUE;
          sprintf (mybuf, "%d,%d,%d,%d", wpl.rcNormalPosition.left, wpl.rcNormalPosition.top,
                           RectWidth (wpl.rcNormalPosition), RectHeight (wpl.rcNormalPosition));
          WritePrivateProfileString (ARTLIST, "GroupWindowPos", mybuf, szAppProFile);
        }
  }

  /* Save position and size of first Article window */
  for (found = FALSE, idoc = 0; !found && idoc < MAXARTICLEWNDS; idoc++) 
  {
        if (ArticleDocs[idoc].InUse && GetWindowPlacement(ArticleDocs[idoc].hWndFrame, &wpl)) 
		{
          found = TRUE;
          sprintf (mybuf, "%d,%d,%d,%d", wpl.rcNormalPosition.left, wpl.rcNormalPosition.top,
                           RectWidth (wpl.rcNormalPosition), RectHeight (wpl.rcNormalPosition));
          WritePrivateProfileString (ARTICLE, "ArticleWindowPos", mybuf, szAppProFile);
        }
  }

  /* Save position and size of first post/mail window */
  for (found = FALSE, idoc = 0; !found && idoc < MAXPOSTWNDS; idoc++) 
  {
        if (WndPosts[idoc].hWnd && GetWindowPlacement(WndPosts[idoc].hWnd, &wpl)) 
		{
          found = TRUE;
          sprintf (mybuf, "%d,%d,%d,%d", wpl.rcNormalPosition.left, wpl.rcNormalPosition.top,
                           RectWidth (wpl.rcNormalPosition), RectHeight (wpl.rcNormalPosition));
          WritePrivateProfileString (COMPOSE, "PostWindowPos", mybuf, szAppProFile);
        }
  }
  for (found = FALSE, idoc = 0; !found && idoc < MAXMAILWNDS; idoc++) 
  {
        if (WndMails[idoc].hWnd && GetWindowPlacement(WndMails[idoc].hWnd, &wpl)) 
		{

          found = TRUE;
          sprintf (mybuf, "%d,%d,%d,%d", wpl.rcNormalPosition.left, wpl.rcNormalPosition.top,
                           RectWidth (wpl.rcNormalPosition), RectHeight (wpl.rcNormalPosition));
          WritePrivateProfileString (COMPOSE, "MailWindowPos", mybuf, szAppProFile);
        }
  }

  /* save position of first decoding thread status window */
  for (found = FALSE, idoc = 0; !found && idoc < NumStatusTexts; idoc++) 
  {
        if (CodingStatusText[idoc]->hTextWnd && GetWindowPlacement(CodingStatusText[idoc]->hTextWnd, &wpl) ) 
        {
          
          found = TRUE;
          sprintf (mybuf, "%d,%d,%d,%d", wpl.rcNormalPosition.left, wpl.rcNormalPosition.top,
                           RectWidth (wpl.rcNormalPosition), RectHeight (wpl.rcNormalPosition));
          WritePrivateProfileString (CODING, "DecodeStatusWindowPos", mybuf, szAppProFile);
        }
  }

  /* save the position of the block status window */
  if (hCodedBlockWnd) 
  {
  		
		if  (GetWindowPlacement(hCodedBlockWnd, &wpl))
		{
          sprintf (mybuf, "%d,%d", wpl.rcNormalPosition.left, wpl.rcNormalPosition.top);
          WritePrivateProfileString (CODING, "BlockStatusWindowPos", mybuf, szAppProFile);
        }
  }
}

#ifdef PROFILE_PRE90_UPGRADE
/*--- function UpgradePre90Profile -----------------------------------------
 *
 *    Upgrades a user's old (pre v.90) style of WinVn.ini to the new style
 *    (JSC 1/8/94)
 */
void UpgradePre90Profile ()
{
  char buf[512];



  GetPrivateProfileString (OLD, "UserName", DEF_UserName, UserName, MAILLEN, szAppProFile);
  GetPrivateProfileString (OLD, "MailAddress", DEF_MailAddr, MailAddress, MAILLEN, szAppProFile);
  GetPrivateProfileString (OLD, "Organization", DEF_Organization, Organization, MAILLEN, szAppProFile);
  GetPrivateProfileString (OLD, "ReplyTo", DEF_ReplyTo, ReplyTo, MAILLEN, szAppProFile);

  GetPrivateProfileString (OLD, "NNTPHost", DEF_NNTPHost, NNTPHost, MAXNNTPSIZE, szAppProFile);
  GetPrivateProfileString (OLD, "SMTPHost", DEF_SMTPHost, SMTPHost, MAXNNTPSIZE, szAppProFile);
  GetPrivateProfileString (OLD, "NNTPService", DEF_NNTPService, NNTPService, MAXNNTPSIZE, szAppProFile);
  NNTPSavePassword =
        GetPrivateProfileInt (OLD, "NNTPSavePassword", DEF_NNTPSavePassword, szAppProFile);
  MailDemandLogon =
        GetPrivateProfileInt (OLD, "MailDemandLogon", DEF_MailDemandLogon, szAppProFile);
  MailForceType =
        GetPrivateProfileInt (OLD, "MailForceType", DEF_MailForceType, szAppProFile);
  GetPrivateProfileString (OLD, "NNTPUserName", DEF_NNTPUserName, NNTPUserName, MAXNNTPSIZE, szAppProFile);
  GetPrivateProfileString (OLD, "NNTPPassword", DEF_NNTPPassword, NNTPPasswordEncrypted, 2 * MAXNNTPSIZE, szAppProFile);

  threadp =
        GetPrivateProfileInt (OLD, "EnableThreading", DEF_EnableThreading, szAppProFile);
  GetPrivateProfileString (OLD, "SignatureFile", DEF_SignatureFile, SigFileName, MAXFILENAME + 1, szAppProFile);
//  GetPrivateProfileString (OLD, "MailListFile", DEF_MailFileName, MailFileName, MAXFILENAME+1,szAppProFile);
  EnableSig =
        GetPrivateProfileInt (OLD, "EnableSignature", DEF_EnableSignature, szAppProFile);

  MailLog =
        GetPrivateProfileInt (OLD, "MailLog", DEF_MailLog, szAppProFile);
  GetPrivateProfileString (OLD, "MailLogFile", DEF_MailLogFile, MailLogFile, MAXFILENAME, szAppProFile);
  PostLog =
        GetPrivateProfileInt (OLD, "PostLog", DEF_PostLog, szAppProFile);
  GetPrivateProfileString (OLD, "PostLogFile", DEF_PostLogFile, PostLogFile, MAXFILENAME, szAppProFile);

  ConnectAtStartup =
        GetPrivateProfileInt (OLD, "ConnectAtStartup", DEF_ConnectAtStartup, szAppProFile);
  FullNameFrom =
        GetPrivateProfileInt (OLD, "FullNameFrom", DEF_FullNameFrom, szAppProFile);
  article_threshold =
        GetPrivateProfileLong (OLD, "ArticleThreshold", DEF_ArticleThreshold, szAppProFile);
  min_to_retrieve =
        GetPrivateProfileLong (OLD, "MinArticlesToRetrieve", DEF_MinToRetrieve, szAppProFile);
  ShowUnsubscribed =
        GetPrivateProfileInt (OLD, "ShowUnsubscribed", DEF_ShowUnsubscribed, szAppProFile);
  SortGroupList =
        GetPrivateProfileInt (OLD, "SortGroupList", DEF_SortGroupList, szAppProFile);

//  ShowReadArticles = 
  //     GetPrivateProfileInt (OLD,"ShowReadArticles", DEF_ShowReadArticles, szAppProFile);
  GetPrivateProfileString (OLD, "GroupFilter", DEF_GroupFilter, GroupFilter, MAXGROUPFILTERSIZE - 1, szAppProFile);
  EnableGroupFilter =
        GetPrivateProfileInt (OLD, "EnableGroupFilter", DEF_EnableGroupFilter, szAppProFile);
  ConfirmBatchOps =
        GetPrivateProfileInt (OLD, "ConfirmBatchOps", DEF_ConfirmBatchOps, szAppProFile);
  ConfirmDisconnect =
        GetPrivateProfileInt (OLD, "ConfirmDisconnect", DEF_ConfirmDisconnect, szAppProFile);
  ConfirmSaveOnExit =
        GetPrivateProfileInt (OLD, "ConfirmSaveOnExit", DEF_ConfirmSaveOnExit, szAppProFile);
  ConfirmReplyTo =
        GetPrivateProfileInt (OLD, "ConfirmReplyTo", DEF_ConfirmReplyTo, szAppProFile);
#ifdef OFFLINE  // TANAKA Goh
  ConfirmDeleteArticle =
        GetPrivateProfileInt (OLD, "ConfirmDeleteArticle", DEF_ConfirmDeleteArticle, szAppProFile);
#endif
  ThreadFullSubject =
        GetPrivateProfileInt (OLD, "ThreadFullSubject", DEF_ThreadFullSubject, szAppProFile);
  GetPrivateProfileString (OLD, "ThreadDepthIndicator", DEF_ThreadDepthIndicator, ThreadDepthIndicator, 2, szAppProFile);
  ThreadDepthIndicator[1] = '\0';
  ViewNew =
        GetPrivateProfileInt (OLD, "NewWndGroup", DEF_NewWndGroup, szAppProFile);
  NewArticleWindow =
        GetPrivateProfileInt (OLD, "NewWndArticle", DEF_NewWndArticle, szAppProFile);
  SaveArtAppend =
        GetPrivateProfileInt (OLD, "SaveArtAppend", DEF_SaveArtAppend, szAppProFile);
  ShowUnreadOnly =
        GetPrivateProfileInt (OLD, "ShowUnreadOnly", DEF_ShowUnreadOnly, szAppProFile);
  ArtListMultiSelect =
        GetPrivateProfileInt (OLD, "ArtListMultiSelect", DEF_ArtListMultiSelect, szAppProFile);
  GroupListMultiSelect =
        GetPrivateProfileInt (OLD, "GroupListMultiSelect", DEF_GroupListMultiSelect, szAppProFile);
  TrimHeaders =
        GetPrivateProfileInt (OLD, "TrimHeaders", DEF_TrimHeaders, szAppProFile);
  WordWrap =
        GetPrivateProfileInt (OLD, "WordWrap", DEF_WordWrap, szAppProFile);
  ShowOrgHdr =
        GetPrivateProfileInt (OLD, "ShowOrgHdr", DEF_ShowOrgHdr, szAppProFile);
  ShowReplyToHdr =
        GetPrivateProfileInt (OLD, "ShowReplyToHdr", DEF_ShowReplyToHdr, szAppProFile);
  ShowFollowupToHdr =
        GetPrivateProfileInt (OLD, "ShowFollowupToHdr", DEF_ShowFollowupToHdr, szAppProFile);
  ShowKeywordsHdr =
        GetPrivateProfileInt (OLD, "ShowKeywordsHdr", DEF_ShowKeywordsHdr, szAppProFile);
  ShowSummaryHdr =
        GetPrivateProfileInt (OLD, "ShowSummaryHdr", DEF_ShowSummaryHdr, szAppProFile);
  ShowDistributionHdr =
        GetPrivateProfileInt (OLD, "ShowDistributionHdr", DEF_ShowDistributionHdr, szAppProFile);
  TrackSubscribedCrossposts =
        GetPrivateProfileInt (OLD, "TrackSubscribedCrossposts", DEF_TrackSubscribedCrossposts, szAppProFile);
  TrackUnsubscribedCrossposts =
        GetPrivateProfileInt (OLD, "TrackUnsubscribedCrossposts", DEF_TrackUnsubscribedCrossposts, szAppProFile);
  MinimizeStatusWindows =
        GetPrivateProfileInt (OLD, "MinimizeStatusWindows", DEF_MinimizeStatusWindows, szAppProFile);
  ScrollPastHeaders =
        GetPrivateProfileInt (OLD, "ScrollPastHeaders", DEF_ScrollPastHeaders, szAppProFile);
  ItalicizeQuotes =
        GetPrivateProfileInt (OLD, "ItalicizeQuotes", DEF_ItalicizeQuotes, szAppProFile);
  WrapIncomingArticleText =
        GetPrivateProfileInt (OLD, "WrapIncomingArticleText", DEF_WrapIncomingArticleText, szAppProFile);
  WrapIncomingArticleTextLength =
        GetPrivateProfileInt (OLD, "WrapIncomingArticleTextLength", DEF_WrapIncomingArticleTextLength, szAppProFile);

  GetPrivateProfileString (OLD, "DecodePath", DEF_DecodePath, DecodePathName, MAXFILENAME, szAppProFile);
  CodingStatusVerbose =
        GetPrivateProfileInt (OLD, "CodingStatusVerbose", DEF_CodingStatusVerbose, szAppProFile);
  BlockCodingStatusAlwaysOnTop =
        GetPrivateProfileInt (OLD, "BlockCodingStatusAlwaysOnTop", DEF_BlockCodingStatusAlwaysOnTop, szAppProFile);
  AlsoDecodeOpenArticles =
        GetPrivateProfileInt (OLD, "AlsoDecodeOpenArticles", DEF_AlsoDecodeOpenArticles, szAppProFile);
  DumbDecode =
        GetPrivateProfileInt (OLD, "DumbDecode", DEF_DumbDecode, szAppProFile);
//  ReviewAttach = 
  //     GetPrivateProfileInt (OLD, "ReviewAttach", DEF_ReviewAttach, szAppProFile);
  GenerateMIME =
        GetPrivateProfileInt (OLD, "GenerateMIME", DEF_GenerateMIME, szAppProFile);
  MIMEUsageSuggestions =
        GetPrivateProfileInt (OLD, "MIMEUsageSuggestions", DEF_MIMEUsageSuggestions, szAppProFile);

  GetPrivateProfileString (OLD, "DefaultEncodingType", DEF_DefaultEncodingType, DefaultEncodingTypeStr, MAXENCODINGTYPELEN, szAppProFile);
  DefaultEncodingType = EncodingStrToType (DefaultEncodingTypeStr);
  GetPrivateProfileString (OLD, "MIMEUUType", DEF_MIMEUUType, MIMEUUType, MAXENCODINGTYPELEN, szAppProFile);
  GetPrivateProfileString (OLD, "MIMEXXType", DEF_MIMEXXType, MIMEXXType, MAXENCODINGTYPELEN, szAppProFile);
  GetPrivateProfileString (OLD, "MIMECustomType", DEF_MIMECustomType, MIMECustomType, MAXENCODINGTYPELEN, szAppProFile);
  GetPrivateProfileString (OLD, "MIMECharset", DEF_MIMECharset, MIMECharset, 80, szAppProFile);

  GetPrivateProfileString (OLD, "DefaultContentType", DEF_DefaultContentType, DefaultContentType, MAXCONTENTTYPELEN, szAppProFile);

  DefaultAttachInNewArt =
        GetPrivateProfileInt (OLD, "DefaultAttachInNewArt", DEF_DefaultAttachInNewArt, szAppProFile);
  ExecuteDecodedFiles =
        GetPrivateProfileInt (OLD, "ExecuteDecodedFiles", DEF_ExecuteDecodedFiles, szAppProFile);
  KeepArticleHeaderVisible =
        GetPrivateProfileInt (OLD, "KeepArticleHeaderVisible", DEF_KeepArticleHeaderVisible, szAppProFile);

  ArticleSplitLength =
        GetPrivateProfileLong (OLD, "ArticleSplitLength", DEF_ArticleSplitLength, szAppProFile);
  GetPrivateProfileString (OLD, "EncodingTable", DEF_EncodingTable, UserCodingTable, CODINGTABLESIZE + 1, szAppProFile);
  GetPrivateProfileString (OLD, "SubjectTemplate", DEF_SubjectTemplate, SubjectTemplate, CODINGTABLESIZE + 1, szAppProFile);
  GetPrivateProfileString (OLD, "FollowupSaysTemplate", DEF_FollowupSaysTemplate, FollowupSaysTemplate, MAXINTERNALLINE, szAppProFile);
  GetPrivateProfileString (OLD, "ReplySaysTemplate", DEF_ReplySaysTemplate, ReplySaysTemplate, MAXINTERNALLINE, szAppProFile);

  GetPrivateProfileString (OLD, "WinVnFontFace", DEF_WinVnFontFace, WinVnFontFace, 32, szAppProFile);
  WinVnFontSize =
        GetPrivateProfileInt (OLD, "WinVnFontSize", DEF_WinVnFontSize, szAppProFile);
  GetPrivateProfileString (OLD, "WinVnFontStyle", DEF_WinVnFontStyle, WinVnFontStyle, 32, szAppProFile);
  GetPrivateProfileString (OLD, "CompositionFontFace", DEF_CompositionFontFace, CompositionFontFace, 32, szAppProFile);
  CompositionFontSize =
        GetPrivateProfileInt (OLD, "CompositionFontSize", DEF_CompositionFontSize, szAppProFile);
  GetPrivateProfileString (OLD, "CompositionFontStyle", DEF_CompositionFontStyle, CompositionFontStyle, 32, szAppProFile);
  GetPrivateProfileString (OLD, "ListFontFace", DEF_ListFontFace, ListFontFace, 32, szAppProFile);
  ListFontSize =
        GetPrivateProfileInt (OLD, "ListFontSize", DEF_ListFontSize, szAppProFile);
  GetPrivateProfileString (OLD, "ListFontStyle", DEF_ListFontStyle, ListFontStyle, 32, szAppProFile);
//  FontBold = 
  //     GetPrivateProfileInt (OLD, "FontBold", TRUE, szAppProFile);
  GetPrivateProfileString (OLD, "ArticleFontFace", DEF_ArticleFontFace, ArticleFontFace, 32, szAppProFile);
  ArticleFontSize =
        GetPrivateProfileInt (OLD, "ArticleFontSize", DEF_ArticleFontSize, szAppProFile);
  GetPrivateProfileString (OLD, "ArticleFontStyle", DEF_ArticleFontStyle, ArticleFontStyle, 32, szAppProFile);
  GetPrivateProfileString (OLD, "StatusFontFace", DEF_StatusFontFace, StatusFontFace, 32, szAppProFile);
  StatusFontSize =
        GetPrivateProfileInt (OLD, "StatusFontSize", DEF_StatusFontSize, szAppProFile);
  GetPrivateProfileString (OLD, "StatusFontStyle", DEF_StatusFontStyle, StatusFontStyle, 32, szAppProFile);
  GetPrivateProfileString (OLD, "PrintFontFace", DEF_PrintFontFace, PrintFontFace, 32, szAppProFile);
  PrintFontSize =
        GetPrivateProfileInt (OLD, "PrintFontSize", DEF_PrintFontSize, szAppProFile);
//
  // Previous versions of WINVN.INI stored fonts in Device dependent units
  // instead of Device Independent font sizes.  Since we can't safely 
  // convert, set font to something reasonable.   (JD 4/22/94)
  //
  if (ArticleFontSize && (ArticleFontSize == 0 || ArticleFontSize > 16))
        ArticleFontSize = 10;
  if (ListFontSize && (ListFontSize == 0 || ListFontSize > 16))
        ListFontSize = 10;
  if (StatusFontSize && (StatusFontSize == 0 || StatusFontSize > 16))
        StatusFontSize = 11;
  if (PrintFontSize && (PrintFontSize == 0 || PrintFontSize > 16))
        PrintFontSize = 10;

  ArticleFixedFont = 0;
  GetPrivateProfileString (OLD, "NetUnSubscribedColor", DEF_NetUnSubscribedColor, buf, 32, szAppProFile);
  NetUnSubscribedColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "NetSubscribedColor", DEF_NetSubscribedColor, buf, 32, szAppProFile);
  NetSubscribedColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "ArticleUnSeenColor", DEF_ArticleUnSeenColor, buf, 32, szAppProFile);
  ArticleUnSeenColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "ArticleSeenColor", DEF_ArticleSeenColor, buf, 32, szAppProFile);
  ArticleSeenColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "ArticleKilledColor", DEF_ArticleKilledColor, buf, 32, szAppProFile);
  ArticleKilledColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "ArticleTextColor", DEF_ArticleTextColor, buf, 32, szAppProFile);
  ArticleTextColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "StatusTextColor", DEF_StatusTextColor, buf, 32, szAppProFile);
  StatusTextColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "ArticleBackgroundColor", DEF_ArticleBackgroundColor, buf, 32, szAppProFile);
  ArticleBackgroundColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "ListBackgroundColor", DEF_ListBackgroundColor, buf, 32, szAppProFile);
  ListBackgroundColor = StrToRGB (buf);
  GetPrivateProfileString (OLD, "StatusBackgroundColor", DEF_StatusBackgroundColor, buf, 32, szAppProFile);
  UseInverseSelections =
        GetPrivateProfileInt (OLD, "UseInverseSelections", DEF_UseInverseSelections, szAppProFile);

  StatusBackgroundColor = StrToRGB (buf);
  ThumbTrack =
        GetPrivateProfileInt (OLD, "ThumbTrack", DEF_ThumbTrack, szAppProFile);
#ifdef USE_SPLASH
  ShowSplashScreen =
        GetPrivateProfileInt (OLD, "ShowSplashScreen", DEF_ShowSplashScreen, szAppProFile);
#endif

  GetPrivateProfileString (OLD, "LastArticleTextFind", "", LastArticleTextFind, MAXFINDSTRING, szAppProFile);
  GetPrivateProfileString (OLD, "LastArticleHeaderFind", "", LastArticleHeaderFind, MAXFINDSTRING, szAppProFile);
  GetPrivateProfileString (OLD, "LastGroupNameFind", "", LastGroupNameFind, MAXFINDSTRING, szAppProFile);

  OnDupeName =
        GetPrivateProfileInt (OLD, "OnDupeName", DEF_OnDupeName, szAppProFile);
  OnNameTooLong =
        GetPrivateProfileInt (OLD, "OnNameTooLong", DEF_OnNameTooLong, szAppProFile);
  MaxFileNameLen =
        GetPrivateProfileInt (OLD, "MaxFileNameLen", DEF_MaxFileNameLen, szAppProFile);
  MaxFileExtLen =
        GetPrivateProfileInt (OLD, "MaxFileExtLen", DEF_MaxFileExtLen, szAppProFile);
  EnableExtensionConversion =
        GetPrivateProfileInt (OLD, "EnableExtensionConversion", DEF_EnableExtensionConversion, szAppProFile);

  GetPrivateProfileString (COMM, "GenSockDLL", DEF_GenSockDLL, GenSockDLL, MAXFILENAME + 1, szAppProFile);
  if (!GenSockDLL) {
        WritePrivateProfileString (COMM, "GenSockDLL", "gensock.dll", szAppProFile);
        strcpy (GenSockDLL, "gensock.dll");
  }
  WriteWinvnProfile ();
  WritePrivateProfileString (OLD, "Notice1", "**** The [winvn] section is no longer needed unless    ****", szAppProFile);
  WritePrivateProfileString (OLD, "Notice2", "**** you want compatibility with old versions of WinVn ****", szAppProFile);

  _strlwr (szAppProFile);
  WVArgMessageBox(NetDoc.hDocWnd,IDS_WINVN_UPGRADE, IDS_WINVN_CONFIG1, MB_OK | MB_ICONINFORMATION, szAppProFile);
}
#endif

#ifdef PROFILE_PRE93_UPGRADE
/*--- function UpgradePre93Profile -----------------------------------------
 *
 *    Upgrades a user's pre v.93 style of WinVn.ini to the new style
 *    This is used if the ini appears newer the v.90 but older than v.93
 *    (jsc 11/3/94)
 */

#define PREF "Preferences"

void UpgradePre93Profile ()
{
  // used to bundle all this stuff under Preferences
  threadp =
        GetPrivateProfileInt (PREF, "EnableThreading", DEF_EnableThreading, szAppProFile);
  GetPrivateProfileString (PREF, "SignatureFile", DEF_SignatureFile, SigFileName, MAXFILENAME + 1, szAppProFile);

  EnableSig =
        GetPrivateProfileInt (PREF, "EnableSignature", DEF_EnableSignature, szAppProFile);

  MailLog =
        GetPrivateProfileInt (PREF, "MailLog", DEF_MailLog, szAppProFile);
  GetPrivateProfileString (PREF, "MailLogFile", DEF_MailLogFile, MailLogFile, MAXFILENAME, szAppProFile);
  PostLog =
        GetPrivateProfileInt (PREF, "PostLog", DEF_PostLog, szAppProFile);
  GetPrivateProfileString (PREF, "PostLogFile", DEF_PostLogFile, PostLogFile, MAXFILENAME, szAppProFile);

  DoList =
        GetPrivateProfileInt (PREF, "DoList", DEF_DoList, szAppProFile);
  ConnectAtStartup =
        GetPrivateProfileInt (PREF, "ConnectAtStartup", DEF_ConnectAtStartup, szAppProFile);
  FullNameFrom =
        GetPrivateProfileInt (PREF, "FullNameFrom", DEF_FullNameFrom, szAppProFile);
  article_threshold =
        GetPrivateProfileLong (PREF, "ArticleThreshold", DEF_ArticleThreshold, szAppProFile);
  ShowUnsubscribed =
        GetPrivateProfileInt (PREF, "ShowUnsubscribed", DEF_ShowUnsubscribed, szAppProFile);
  SortGroupList =
        GetPrivateProfileInt (PREF, "SortGroupList", DEF_SortGroupList, szAppProFile);
//  ShowReadArticles =
//      GetPrivateProfileInt (PREF, "ShowReadArticles", DEF_ShowReadArticles, szAppProFile);
  ConfirmBatchOps =
        GetPrivateProfileInt (PREF, "ConfirmBatchOps", DEF_ConfirmBatchOps, szAppProFile);
  ConfirmSaveOnExit =
        GetPrivateProfileInt (PREF, "ConfirmExit", DEF_ConfirmSaveOnExit, szAppProFile);
  ConfirmReplyTo =
        GetPrivateProfileInt (PREF, "ConfirmReplyTo", DEF_ConfirmReplyTo, szAppProFile);
  ViewNew =
        GetPrivateProfileInt (PREF, "NewWndGroup", DEF_NewWndGroup, szAppProFile);
  NewArticleWindow =
        GetPrivateProfileInt (PREF, "NewWndArticle", DEF_NewWndArticle, szAppProFile);
  SaveArtAppend =
        GetPrivateProfileInt (PREF, "SaveArtAppend", DEF_SaveArtAppend, szAppProFile);
  ShowUnreadOnly =
        GetPrivateProfileInt (PREF, "ShowUnreadOnly", DEF_ShowUnreadOnly, szAppProFile);

  ThreadFullSubject =
        GetPrivateProfileInt (PREF, "ThreadFullSubject", DEF_ThreadFullSubject, szAppProFile);

  GroupListMultiSelect =
        GetPrivateProfileInt (PREF, "GroupMultiSelect", DEF_GroupListMultiSelect, szAppProFile);

  // these items got moves to Attachments
  ArticleSplitLength =
        GetPrivateProfileUInt (CODING, "ArticleSplitLength", (unsigned int) DEF_ArticleSplitLength, szAppProFile);
  GetPrivateProfileString (CODING, "EncodingTable", DEF_EncodingTable, UserCodingTable, CODINGTABLESIZE + 1, szAppProFile);
  GetPrivateProfileString (CODING, "SubjectTemplate", DEF_SubjectTemplate, SubjectTemplate, CODINGTABLESIZE + 1, szAppProFile);
  GenerateMIME =
        GetPrivateProfileInt (CODING, "GenerateMIME", DEF_GenerateMIME, szAppProFile);
  MIMEUsageSuggestions =
        GetPrivateProfileInt (CODING, "MIMEUsageSuggestions", DEF_MIMEUsageSuggestions, szAppProFile);
  GetPrivateProfileString (CODING, "EncodingType", DEF_DefaultEncodingType, DefaultEncodingTypeStr, MAXENCODINGTYPELEN, szAppProFile);
  DefaultEncodingType = EncodingStrToType (DefaultEncodingTypeStr);
  GetPrivateProfileString (CODING, "MIMEUUType", DEF_MIMEUUType, MIMEUUType, MAXENCODINGTYPELEN, szAppProFile);
  GetPrivateProfileString (CODING, "MIMEXXType", DEF_MIMEXXType, MIMEXXType, MAXENCODINGTYPELEN, szAppProFile);
  GetPrivateProfileString (CODING, "MIMECustomType", DEF_MIMECustomType, MIMECustomType, MAXENCODINGTYPELEN, szAppProFile);
  GetPrivateProfileString (CODING, "DefaultContentType", DEF_DefaultContentType, DefaultContentType, MAXINTERNALLINE, szAppProFile);
}

#endif
#endif // #ifdef __OS2_PROFILE__

/*
 * Local Variables:
 * tab-width: 2
 * end:
 */
