home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / mnprefs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  42.3 KB  |  1,661 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20. #include "prefapi.h"
  21. #include "dialog.h"
  22. #include "msgcom.h"
  23. #include "nethelp.h"
  24. #include "xp_help.h"
  25. #include "mailpriv.h"
  26. #include "mnprefs.h"
  27. #ifdef XP_WIN16
  28. #include "mninterf.h"
  29. #else
  30. #include "winprefs/mninterf.h"
  31. #endif
  32. #include "subnews.h"
  33. #include "wfemsg.h"
  34.  
  35. #include "ldap.h"
  36.  
  37. extern "C" {
  38. #include "xpgetstr.h"
  39. #ifdef MOZ_MAIL_NEWS
  40. extern int MK_MSG_LOCAL_MAIL;
  41. #endif
  42. };
  43.  
  44. //also in mnpref\src\pages.h, brpref\src\advpages.cpp
  45. #define MNPREF_PrefIsLocked(pPrefName) PREF_PrefIsLocked(pPrefName)
  46.  
  47. static void ShowMapiError(UINT nId, LPCSTR pParam, CWnd* pWnd)
  48. {
  49.     char buffer[1024];
  50.     CString msg;
  51.     msg.LoadString(nId);
  52.     if (pParam)
  53.         sprintf(buffer, msg, pParam);
  54.     else
  55.         strcpy(buffer, msg);
  56.     if (pWnd)
  57.     {
  58.         pWnd->MessageBox(buffer, NULL, MB_OK | MB_ICONSTOP);
  59.     }
  60.     else
  61.     {
  62.         AfxMessageBox(buffer);
  63.     }
  64. }
  65.  
  66. static void ShowError(UINT nId, CWnd* pWnd)
  67. {
  68.     ShowMapiError(nId, NULL, pWnd);
  69. }
  70.  
  71.  
  72. #ifdef _WIN32
  73.  
  74. static const char szMapiDll[] = "Mapi32.dll";
  75.  
  76. static BOOL IsOurMapiInstalled(void)
  77. {
  78.     // see if our MAPI support is already installed
  79.     BOOL ourDLLInstalled = FALSE;
  80.     HINSTANCE hMAPIInst = LoadLibrary(szMapiDll);
  81.     if (hMAPIInst)
  82.     {
  83.         FARPROC funcPtr = GetProcAddress(hMAPIInst, "MAPIGetNetscapeVersion");
  84.         if (funcPtr)
  85.         {
  86.             ourDLLInstalled = TRUE;
  87.         }
  88.         FreeLibrary(hMAPIInst);
  89.     }
  90.     return(ourDLLInstalled);
  91. }
  92.  
  93. static BOOL UpdateMapiDll(BOOL prefUseMAPI, CWnd* pWnd)
  94. {
  95.     // get the two directories to copy between
  96.     const char szMapiBackupDll[] = "Mapi32bak.dll";
  97.     const char sznscpMapiDll[] = "nsmapi32.dll";
  98.  
  99.     CString nsMapiFile;
  100.     CString systemPath;
  101.     CString msMapiFile;
  102.     CString msMapiBackupFile;
  103.     CFileStatus status;
  104.     GetSystemDirectory(systemPath.GetBuffer(_MAX_PATH), _MAX_PATH);
  105.     systemPath.ReleaseBuffer();
  106.     if (systemPath.Right(1) != "\\")
  107.     {
  108.         systemPath += "\\";
  109.     }
  110.     GetModuleFileName(theApp.m_hInstance, nsMapiFile.GetBuffer(_MAX_PATH), _MAX_PATH);
  111.     nsMapiFile.ReleaseBuffer();
  112.     // strip off the netscape.exe from the end
  113.     int pos = nsMapiFile.ReverseFind('\\');
  114.     if (pos != -1)
  115.     {
  116.         nsMapiFile = nsMapiFile.Left(pos);
  117.     }
  118.     if (nsMapiFile.Right(1) != "\\")
  119.     {
  120.         nsMapiFile += "\\";
  121.     }
  122.     nsMapiFile += sznscpMapiDll;
  123.  
  124.     msMapiFile = systemPath + szMapiDll;
  125.     msMapiBackupFile = systemPath + szMapiBackupDll;
  126.  
  127.     BOOL ourDLLInstalled = IsOurMapiInstalled();
  128.  
  129.     if (prefUseMAPI)
  130.     {
  131.         // Before the Send option will show up in other applications, you must have
  132.         // [Mail]
  133.         // MAPIX=1
  134.         // MAPI=1
  135.         WriteProfileString("Mail", "MAPIX", "1");
  136.         WriteProfileString("Mail", "MAPI", "1");
  137.         if (ourDLLInstalled)
  138.         {
  139.             // if the nsmapi32.dll that we have is a newer date than the installed one
  140.             // copy it over anyway
  141.             CFileStatus installedFile, ourFile;
  142.             if (CFile::GetStatus(msMapiFile, installedFile))
  143.             {
  144.                 if (CFile::GetStatus(nsMapiFile, ourFile))
  145.                 {
  146.                     // if ours is newer, install it anyway
  147.                     if (ourFile.m_mtime > installedFile.m_mtime)
  148.                     {
  149.                         // don't need to do a backup because our file is already installed
  150.                         if (!CopyFile(nsMapiFile, msMapiFile, FALSE))
  151.                         {
  152.                             // can't install ours, tell the user
  153.                             ShowMapiError(IDS_NSMAPI32_COPY_FAILED, msMapiFile, pWnd);
  154.                             return(FALSE);
  155.                         }
  156.                     }
  157.                 }
  158.             }
  159.         }
  160.         else
  161.         {
  162.             // check for the existance of nsmapi32.dll
  163.             if (!CFile::GetStatus(nsMapiFile, status))
  164.             {
  165.                 // nsmapi32.dll doesn't exist, tell the user
  166.                 ShowMapiError(IDS_NO_NSMAPI32, nsMapiFile, pWnd);
  167.                 return(FALSE);
  168.             }
  169.             // check for the existance of mapi32.dll and only make the backup if it exists
  170.             if (CFile::GetStatus(msMapiFile, status))
  171.             {
  172.                 if (!CopyFile(msMapiFile, msMapiBackupFile, FALSE))
  173.                 {
  174.                     // can't make backup copy, refuse to install
  175.                     ShowMapiError(IDS_MAPI_BACKUP_FAILED, msMapiBackupFile, pWnd);
  176.                     return(FALSE);
  177.                 }
  178.             }
  179.             if (!CopyFile(nsMapiFile, msMapiFile, FALSE))
  180.             {
  181.                 // can't install ours, tell the user
  182.                 ShowMapiError(IDS_NSMAPI32_COPY_FAILED, msMapiFile, pWnd);
  183.                 return(FALSE);
  184.             }
  185.         }
  186.     }
  187.     else    // don't use our MAPI
  188.     {
  189.         if (ourDLLInstalled)
  190.         {
  191.             // restore the backup DLL
  192.             if (!CFile::GetStatus(msMapiBackupFile, status))
  193.             {
  194.                 // old mapi file doesn't exist, tell the user
  195.                 ShowMapiError(IDS_MAPI_BACKUP_MISSING, msMapiBackupFile, pWnd);
  196.                 return(FALSE);
  197.             }
  198.             if (!CopyFile(msMapiBackupFile, msMapiFile, FALSE))
  199.             {
  200.                 // copy failed, tell the user
  201.                 ShowMapiError(IDS_NSMAPI32_COPY_FAILED2, msMapiFile, pWnd);
  202.                 return(FALSE);
  203.             }
  204.             // remove the backup file
  205.             remove(msMapiBackupFile);
  206.         }
  207.     }
  208.     return(TRUE);
  209. }
  210.  
  211. static BOOL UpdateMapiDll(void)
  212. {
  213.     XP_Bool prefUseMAPI = FALSE;
  214.      PREF_GetBoolPref("mail.use_mapi_server", &prefUseMAPI);
  215.     return(UpdateMapiDll(prefUseMAPI, NULL));
  216. }
  217. #endif
  218.  
  219. extern "C" BOOL IsNumeric(char* pStr)
  220. {
  221.     
  222.     for (char* p = pStr; p && *p; p++)
  223.     {
  224.         if (0 == isdigit(*p))
  225.             return FALSE; 
  226.     }
  227.     return TRUE;
  228. }
  229.  
  230. #ifdef MOZ_MAIL_NEWS
  231.  
  232. extern "C" MSG_Host *DoAddNewsServer(CWnd* pParent, int nFromWhere)
  233. {                                
  234.     CNewsServerDialog addServerDialog(pParent, NULL, nFromWhere);
  235.     if (IDOK == addServerDialog.DoModal())
  236.     {
  237.         char* pName = addServerDialog.GetNewsHostName();
  238.         XP_Bool bSecure = addServerDialog.GetSecure();
  239.         XP_Bool bAuthentication = addServerDialog.GetAuthentication();
  240.         int32 nPort = addServerDialog.GetNewsHostPort();
  241.  
  242.         MSG_NewsHost *pNewHost = MSG_CreateNewsHost(WFE_MSGGetMaster(), pName, 
  243.                                                     bSecure, nPort);
  244.                      
  245.         if (pNewHost)
  246.         {
  247.             // tell the back-end to ask for name/pw without getting challenged
  248.             MSG_SetNewsHostPushAuth (pNewHost, bAuthentication);
  249.  
  250.             return MSG_GetMSGHostFromNewsHost(pNewHost);
  251.         }
  252.         else
  253.             return NULL;
  254.     }
  255.     else
  256.         return NULL;
  257. }
  258.  
  259. extern "C" MSG_Host *DoAddIMAPServer(CWnd* pParent, char* pServerName, BOOL bImap)
  260. {
  261.     CString title;
  262.     title.LoadString(IDS_ADD_MAIL_SERVER);
  263.     CMailServerPropertySheet addMailServer(pParent, title, pServerName, TYPE_IMAP, FALSE);
  264.     if (IDOK == addMailServer.DoModal())
  265.     {
  266.         return NULL;
  267.     }
  268.     else
  269.         return NULL;
  270. }
  271.  
  272. void UnixToDosString(char* pStr)
  273. {
  274.     if (!pStr || !strlen(pStr))
  275.         return;
  276.     for (char * p = pStr; p && *p; p++)
  277.     {
  278.         if(*p == '/')
  279.             *p = '\\';
  280.         else if (*p == '|')
  281.             *p = ':'; 
  282.     }
  283. }
  284.  
  285. void DosToUnixString(char* pStr)
  286. {
  287.     if (!pStr || !strlen(pStr))
  288.         return;
  289.     for (char * p = pStr; p && *p; p++)
  290.     {
  291.         if(*p == '\\')
  292.             *p = '/';
  293.         else if(*p == ':')
  294.             *p = '|'; 
  295.     }
  296. }
  297.  
  298. //Make sure caller function XP_FREE the return string
  299. extern "C" char* ConvertPathToURL(char* lpPath)
  300. {
  301.     static const char *formatString = "mailbox:/%s";
  302.  
  303.     if (!lpPath || !strlen(lpPath))
  304.         return NULL;
  305.  
  306.     DosToUnixString(lpPath);
  307.     char *urlString = (char*)XP_ALLOC(XP_STRLEN(formatString) + XP_STRLEN(lpPath));
  308.     if (urlString)
  309.         sprintf(urlString, formatString, lpPath);
  310.     UnixToDosString(lpPath);
  311.     return urlString;
  312. }
  313.  
  314. MSG_FolderInfo * GetFolderInfoFromPref(char* lpPref)
  315.     MSG_FolderInfo *pFolderInfo = NULL;
  316.  
  317.     int nLen = strlen(lpPref);
  318.     if (nLen)
  319.     {
  320.         MSG_Master *pMaster    = WFE_MSGGetMaster();
  321.         int nUrlType = NET_URL_Type(lpPref);
  322.         if (0 == nUrlType || MAILBOX_TYPE_URL == nUrlType)
  323.         {
  324.             if (0 == nUrlType)
  325.             {
  326.                 char* pURL = NULL;
  327.                 pURL = ConvertPathToURL(lpPref);
  328.                 if (pURL)
  329.                 {
  330.                     pFolderInfo = MSG_GetFolderInfoFromURL(pMaster, pURL);
  331.                     XP_FREE(pURL);
  332.                 }
  333.             }
  334.             else
  335.                 pFolderInfo = MSG_GetFolderInfoFromURL(pMaster, lpPref);
  336.         }
  337.         else if (IMAP_TYPE_URL == nUrlType)
  338.             pFolderInfo = MSG_GetFolderInfoFromURL(pMaster, lpPref);
  339.     }
  340.     return pFolderInfo;
  341. }
  342.  
  343. void SetFolderComboCurSel(HWND hControl, char* lpName, int nDefaultID)
  344.     int nFolderIndex = 0;
  345.     int nLen = strlen(lpName);
  346.  
  347.     if (nLen)
  348.     {
  349.         MSG_FolderInfo *pFolder = GetFolderInfoFromPref(lpName);
  350.  
  351.         int nCount = (int)SendMessage(hControl, CB_GETCOUNT, 0, 0);
  352.         for (int i = 0; i < nCount; i++ ) 
  353.         {
  354.             MSG_FolderInfo *pFolderInfo = (MSG_FolderInfo*)SendMessage(hControl, 
  355.                                                            CB_GETITEMDATA, i, 0);
  356.             if (pFolderInfo == pFolder)
  357.             {
  358.                 nFolderIndex = i;
  359.                 break;
  360.             }
  361.         }
  362.     }
  363.     SendMessage(hControl, CB_SETCURSEL, nFolderIndex, 0);
  364. }
  365.  
  366. BOOL SetServerComboCurSel(HWND hControl, char* lpName, int nDefaultID)
  367.     MSG_Master *pMaster = WFE_MSGGetMaster();
  368.     MSG_FolderInfo *pFolder = NULL;
  369.     int nLen = strlen(lpName);
  370.     int nUrlType = NET_URL_Type(lpName);
  371.     BOOL bLocalMail = FALSE;
  372.     BOOL bUseDefaultName = FALSE;
  373.     char* pLocal = NULL;
  374.     char* pDefaultName = XP_GetString(nDefaultID);
  375.     MSG_FolderLine folderLine;
  376.  
  377.     if (nLen)
  378.     {
  379.         pFolder = GetFolderInfoFromPref(lpName);
  380.         MSG_GetFolderLineById (pMaster, pFolder, &folderLine);
  381.         if (!XP_FILENAMECMP(pDefaultName, folderLine.name))
  382.         {
  383.             bUseDefaultName = TRUE;
  384.         }
  385.         if (0 == nUrlType || MAILBOX_TYPE_URL == nUrlType)
  386.             bLocalMail = TRUE;
  387.     }
  388.     else
  389.     {
  390.         bLocalMail = TRUE;
  391.         bUseDefaultName = TRUE;
  392.     }
  393.  
  394.     int nFolderIndex = 0;
  395.  
  396.     if (bLocalMail)
  397.         pLocal = XP_GetString(MK_MSG_LOCAL_MAIL);
  398.     MSG_FolderInfo*  pHostFolderInfo = GetHostFolderInfo(pFolder);
  399.     int nCount = (int)SendMessage(hControl, CB_GETCOUNT, 0, 0);
  400.     for (int i = 0; i < nCount; i++ ) 
  401.     {
  402.         MSG_FolderInfo *pFolderInfo = (MSG_FolderInfo*)SendMessage(hControl, 
  403.                                                        CB_GETITEMDATA, i, 0);
  404.         if (bLocalMail)
  405.         {
  406.             MSG_GetFolderLineById (pMaster, pFolderInfo, &folderLine);
  407.             if (!XP_FILENAMECMP(pLocal, folderLine.name))
  408.             {
  409.                 nFolderIndex = i;
  410.                 break;
  411.             }
  412.             nFolderIndex = (int)SendMessage(hControl, CB_FINDSTRING, (WPARAM)-1,
  413.                                             (LPARAM)(LPCSTR)pLocal);
  414.         }
  415.         else
  416.         {
  417.             if (pHostFolderInfo == pFolderInfo)
  418.             {
  419.                 nFolderIndex = i;
  420.                 break;
  421.             }
  422.         }
  423.     }
  424.     SendMessage(hControl, CB_SETCURSEL, nFolderIndex, 0);
  425.  
  426.     if (bUseDefaultName)
  427.         return TRUE;
  428.     else
  429.         return FALSE;
  430. }
  431.  
  432. extern "C" void GetFolderServerNames
  433. (char* lpName, int nDefaultID, CString& folder, CString& server)
  434.     MSG_FolderInfo *pFolderInfo = NULL;
  435.  
  436.     int nLen = strlen(lpName);
  437.     if (nLen)
  438.     {
  439.         pFolderInfo = GetFolderInfoFromPref(lpName);
  440.     }
  441.     else
  442.     {
  443.         char* pDefault = XP_GetString(nDefaultID);
  444.  
  445.         char defaultName[256];
  446.         int nLen = 255;
  447.  
  448.         if (PREF_NOERROR == PREF_GetCharPref("mail.directory", defaultName, &nLen))
  449.         {
  450.             defaultName[nLen] = '\0';
  451.             XP_STRCAT(defaultName, "\\");
  452.             XP_STRCAT(defaultName, pDefault);
  453.         }
  454.         pFolderInfo = GetFolderInfoFromPref(defaultName);
  455.     }
  456.  
  457.     if (pFolderInfo)
  458.     {
  459.         MSG_Master* pMaster = WFE_MSGGetMaster();
  460.         MSG_FolderLine folderLine;
  461.         if (MSG_GetFolderLineById(pMaster, pFolderInfo, &folderLine)) 
  462.             folder = folderLine.name;
  463.  
  464.         MSG_FolderInfo*  pHostFolderInfo = GetHostFolderInfo(pFolderInfo);
  465.         if (pHostFolderInfo)
  466.         {
  467.             if (MSG_GetFolderLineById(pMaster, pHostFolderInfo, &folderLine)) 
  468.                 server = folderLine.name;
  469.         }
  470.         else
  471.             server = XP_GetString(MK_MSG_LOCAL_MAIL);
  472.     }
  473. }
  474.  
  475. /////////////////////////////////////////////////////////////////////////////
  476. // CChooseFolderDialog    
  477. //       
  478. CChooseFolderDialog::CChooseFolderDialog(CWnd *pParent, char* pFolderPath, int nTypeID)
  479.     : CDialog(IDD, pParent)
  480. {
  481.     m_pFolderPath =  pFolderPath;
  482.     m_nDefaultID = nTypeID;
  483. }
  484.  
  485. BOOL CChooseFolderDialog::OnInitDialog()
  486. {
  487.     BOOL ret = CDialog::OnInitDialog();
  488.  
  489.     CString formatString, defaultTitle;
  490.     formatString.LoadString(IDS_SPECIAL_FOLDER);
  491.     defaultTitle.Format(LPCTSTR(formatString), XP_GetString(m_nDefaultID));
  492.     SetDlgItemText(IDC_RADIO_SENT, LPCTSTR(defaultTitle));
  493.  
  494.     if ( ret ) {
  495.         // Subclass Server combo
  496.         m_ServerCombo.SubclassDlgItem( IDC_COMBO_SERVERS, this );
  497.         m_ServerCombo.NoPrettyName();
  498.         m_ServerCombo.PopulateMailServer( WFE_MSGGetMaster() );
  499.         if (SetServerComboCurSel(m_ServerCombo.GetSafeHwnd(), 
  500.             m_pFolderPath, m_nDefaultID))
  501.             CheckDlgButton(IDC_RADIO_SENT, TRUE);
  502.         else
  503.             CheckDlgButton(IDC_RADIO_OTHER, TRUE);
  504.  
  505.         // Subclass folder combo
  506.         m_FolderCombo.SubclassDlgItem( IDC_COMBO_FOLDERS, this );
  507.         m_FolderCombo.PopulateMail( WFE_MSGGetMaster() );
  508.         SetFolderComboCurSel(m_FolderCombo.GetSafeHwnd(), 
  509.             m_pFolderPath, m_nDefaultID);
  510.     }
  511.     
  512.     return ret;
  513. }
  514.  
  515. void CChooseFolderDialog::OnOK() 
  516. {
  517.     MSG_FolderInfo *pFolder = NULL;
  518.     MSG_FolderLine folderLine;
  519.     MSG_Master* pMaster = WFE_MSGGetMaster();
  520.  
  521.     if (IsDlgButtonChecked(IDC_RADIO_SENT))
  522.     {
  523.         pFolder = (MSG_FolderInfo*)m_ServerCombo.GetItemData(m_ServerCombo.GetCurSel());
  524.         m_szFolder = XP_GetString(m_nDefaultID);
  525.         if (MSG_GetFolderLineById(pMaster, pFolder, &folderLine)) 
  526.             m_szServer = folderLine.name;
  527.         URL_Struct *url = MSG_ConstructUrlForFolder(NULL, pFolder);
  528.         m_szPrefUrl = url->address;
  529.     }
  530.     else if (IsDlgButtonChecked(IDC_RADIO_OTHER))
  531.     {
  532.         pFolder = (MSG_FolderInfo*)m_FolderCombo.GetItemData(m_FolderCombo.GetCurSel());
  533.  
  534.         if (MSG_GetFolderLineById(pMaster, pFolder, &folderLine)) 
  535.         {
  536.             m_szFolder = folderLine.name;
  537.             MSG_FolderInfo*  pHostFolderInfo = GetHostFolderInfo(pFolder);
  538.             if (pHostFolderInfo)
  539.             {
  540.                 if (MSG_GetFolderLineById(pMaster, pHostFolderInfo, &folderLine)) 
  541.                     m_szServer = folderLine.name;
  542.             }
  543.             else
  544.                 m_szServer = XP_GetString(MK_MSG_LOCAL_MAIL);
  545.  
  546.             URL_Struct *url = MSG_ConstructUrlForFolder(NULL, pFolder);
  547.             m_szPrefUrl = url->address;
  548.         }
  549.     }
  550.  
  551.     CDialog::OnOK();
  552. }
  553.  
  554. void CChooseFolderDialog::DoDataExchange(CDataExchange* pDX)
  555. {
  556.     CDialog::DoDataExchange(pDX);
  557. }
  558.  
  559. void CChooseFolderDialog::OnNewFolder()
  560. {   
  561.     CPrefNewFolderDialog newFolderDlg( this, NULL);
  562.     if (IDOK == newFolderDlg.DoModal())
  563.     {
  564.         MSG_FolderInfo *pNewFolder = newFolderDlg.GetNewFolder();
  565.         m_FolderCombo.PopulateMail(WFE_MSGGetMaster());
  566.  
  567.         for (int i = m_FolderCombo.GetCount(); i >= 0 ; i--)
  568.         {
  569.             MSG_FolderInfo *pFolderInfo = (MSG_FolderInfo*)m_FolderCombo.GetItemData(i);
  570.             if (pNewFolder == pFolderInfo)
  571.             {
  572.                 m_FolderCombo.SetCurSel(i);
  573.                 break;
  574.             }
  575.         }
  576.     }
  577. }                                     
  578.  
  579. BEGIN_MESSAGE_MAP(CChooseFolderDialog, CDialog)
  580.     ON_BN_CLICKED(IDC_NEW_FOLDER, OnNewFolder)
  581. END_MESSAGE_MAP()
  582.  
  583. /////////////////////////////////////////////////////////////////////////////
  584. // CNewsServerDialog    
  585. //       
  586. CNewsServerDialog::CNewsServerDialog(CWnd *pParent, const char* pName, int nFromWhere, MSG_NewsHost *pHost)
  587.     : CDialog(CNewsServerDialog::IDD, pParent)
  588. {
  589.     m_hostName[0] = '\0';
  590.     if (pName && strlen(pName))
  591.         XP_STRCAT(m_hostName, pName);
  592.     m_bIsSecure = FALSE;
  593.     m_bAuthentication = FALSE;
  594.     m_nFromWhere = nFromWhere;
  595.     m_lPort = NEWS_PORT;
  596.     m_pEditHost = pHost;
  597.     if (pHost)
  598.     {
  599.          m_bIsSecure = MSG_IsNewsHostSecure(pHost);
  600.          m_lPort = MSG_GetNewsHostPort(pHost);
  601.          m_bAuthentication = MSG_GetNewsHostPushAuth(pHost);
  602.     }
  603. }
  604.  
  605. BOOL CNewsServerDialog::OnInitDialog()
  606. {
  607.     CDialog::OnInitDialog();
  608.     CString title;
  609.     char port[16];
  610.  
  611.     sprintf(port, "%ld", m_lPort);
  612.     SetDlgItemText(IDC_EDIT_PORT, port);
  613.     if (m_pEditHost)
  614.     {
  615.         title.LoadString(IDS_NEWS_SERVER_PROPERTY);
  616.         SetWindowText(LPCTSTR(title));
  617.         SetDlgItemText(IDC_STATIC_HOST, MSG_GetNewsHostName(m_pEditHost));
  618.         GetDlgItem(IDC_EDIT_HOST)->ShowWindow(SW_HIDE);
  619.  
  620.         if (m_bAuthentication)    // Authentication
  621.             CheckDlgButton(IDC_USE_NAME, TRUE);
  622.         else
  623.             CheckDlgButton(IDC_USE_NAME, FALSE);
  624.         ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetFocus();
  625.     }
  626.     else
  627.     {
  628.         title.LoadString(IDS_ADD_NEWS_SERVER);
  629.         SetWindowText(LPCTSTR(title));
  630.         GetDlgItem(IDC_STATIC_HOST)->ShowWindow(SW_HIDE);
  631.     #ifdef _WIN32
  632.         ((CEdit*)GetDlgItem(IDC_EDIT_HOST))->SetLimitText(MAX_HOSTNAME_LEN - 1);
  633.     #else
  634.         ((CEdit*)GetDlgItem(IDC_EDIT_HOST))->LimitText(MAX_HOSTNAME_LEN - 1);
  635.     #endif
  636.         ((CEdit*)GetDlgItem(IDC_EDIT_HOST))->SetFocus();
  637.     }
  638.     return 0;
  639. }
  640.  
  641. void CNewsServerDialog::DoDataExchange(CDataExchange* pDX)
  642. {
  643.     CDialog::DoDataExchange(pDX);
  644. }
  645.  
  646. void CNewsServerDialog::OnOK() 
  647. {
  648.     char port[16];
  649.     BOOL bServerExist = FALSE;
  650.  
  651.     if (!m_pEditHost && 0 == GetDlgItemText(IDC_EDIT_HOST, m_hostName, MAX_HOSTNAME_LEN))
  652.     {
  653.         AfxMessageBox(IDS_EMPTY_STRING);
  654.         ((CEdit*)GetDlgItem(IDC_EDIT_HOST))->SetFocus();
  655.         return;
  656.     }
  657.     if (!m_pEditHost && NewsHostExists())
  658.     {
  659.         AfxMessageBox(IDS_SERVER_EXISTS);
  660.         ((CEdit*)GetDlgItem(IDC_EDIT_HOST))->SetFocus();
  661.         ((CEdit*)GetDlgItem(IDC_EDIT_HOST))->SetSel((DWORD)MAKELONG(0, -1));
  662.         return;
  663.     }  
  664.     if (GetDlgItemText(IDC_EDIT_PORT, port, 16))
  665.     {
  666.         int32 lPort = GetPortNumber();
  667.         if (lPort < 0 || lPort> MAX_PORT_NUMBER)
  668.         {
  669.             AfxMessageBox(IDS_PORT_RANGE);
  670.             ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetFocus();
  671.             ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetSel((DWORD)MAKELONG(0, -1));
  672.             return;        
  673.         }
  674.         if (!::IsNumeric(port))
  675.         {
  676.             AfxMessageBox(IDS_NUMBERS_ONLY);
  677.             ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetFocus();
  678.             ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetSel((DWORD)MAKELONG(0, -1));
  679.             return;
  680.         }
  681.         m_lPort = lPort;
  682.     }
  683.     else
  684.     {
  685.         if (m_bIsSecure)
  686.             m_lPort = SECURE_NEWS_PORT;
  687.         else
  688.             m_lPort = NEWS_PORT;
  689.     }
  690.     if (IsDlgButtonChecked(IDC_USE_NAME))    // Authentication
  691.         m_bAuthentication = TRUE;
  692.     else
  693.         m_bAuthentication = FALSE;
  694.     CDialog::OnOK();
  695. }
  696.  
  697. BOOL CNewsServerDialog::NewsHostExists()
  698. {    
  699.     if (m_nFromWhere == FROM_SUBSCRIBEUI)
  700.     {
  701.         CSubscribePropertySheet* pSheet;
  702.         CSubscribePropertyPage* pPage;
  703.  
  704.         pSheet = (CSubscribePropertySheet*)GetParent();
  705.         pPage = (CSubscribePropertyPage*)pSheet->GetCurrentPage();
  706.         CComboBox* pServerCombo = pPage->GetServerCombo();
  707.         int nTotal = pServerCombo->GetCount();
  708.         for (int i = 0; i < nTotal; i++)
  709.         {
  710.             MSG_Host *pNewsHost = (MSG_Host *)pServerCombo->GetItemDataPtr(i);
  711.             if (IsSameServer(pNewsHost))
  712.                 return TRUE;
  713.         }
  714.         return FALSE;
  715.     }
  716.     else 
  717.     {
  718.          MSG_Host** hNewsHost = NULL;
  719.         BOOL bSameHost = FALSE;
  720.         int32 nTotal = 0;
  721.  
  722.         MSG_Master* pMaster = WFE_MSGGetMaster();
  723.         if (m_nFromWhere == FROM_FOLDERPANE)
  724.             nTotal =  MSG_GetSubscribingHosts(pMaster, NULL, 0);
  725.         else
  726.             nTotal =  MSG_GetNewsHosts(pMaster, NULL, 0);
  727.         if (nTotal)
  728.         {
  729.             hNewsHost = new MSG_Host* [nTotal];
  730.             ASSERT(hNewsHost != NULL);
  731.             if (m_nFromWhere == FROM_FOLDERPANE)
  732.                 nTotal =  MSG_GetSubscribingHosts(pMaster, hNewsHost, nTotal);
  733.             else
  734.                 nTotal =  MSG_GetNewsHosts(pMaster, (MSG_NewsHost**)hNewsHost, nTotal);
  735.             for (int i = 0; i < nTotal; i++)
  736.             {
  737.                 if (bSameHost = IsSameServer(hNewsHost[i]))
  738.                     break;
  739.             }
  740.             if (hNewsHost)
  741.                 delete [] hNewsHost;
  742.         }
  743.         return bSameHost;
  744.     }    
  745. }
  746.  
  747. BOOL CNewsServerDialog::IsSameServer(MSG_Host *pHost)
  748. {    
  749.     XP_Bool bIsSecure = IsDlgButtonChecked(IDC_SECURE);
  750.     int32 lEditPort = GetPortNumber();
  751.     const char* pHostName = MSG_GetNewsHostName((MSG_NewsHost*)pHost);
  752.     if (0 == lstrcmp(m_hostName, pHostName))
  753.     {
  754.         XP_Bool bSecure = MSG_IsNewsHostSecure((MSG_NewsHost*)pHost);
  755.         int32 lPort = MSG_GetNewsHostPort((MSG_NewsHost*)pHost);
  756.         if (bIsSecure == bSecure && lEditPort == lPort)
  757.             return TRUE;
  758.     }  
  759.     return FALSE;
  760. }
  761.  
  762. int32 CNewsServerDialog::GetPortNumber()
  763. {
  764.     char szPort[16];
  765.  
  766.     if (GetDlgItemText(IDC_EDIT_PORT, szPort, 15) > 0)
  767.         return atol(szPort);
  768.     else
  769.         return -1;
  770. }
  771.  
  772. void CNewsServerDialog::OnCheckSecure() 
  773. {
  774.     char port[16];
  775.     if (IsDlgButtonChecked(IDC_SECURE))
  776.         m_bIsSecure = TRUE;
  777.     else
  778.         m_bIsSecure = FALSE;
  779.     if (GetDlgItemText(IDC_EDIT_PORT, port, 16) == 0)
  780.     {
  781.         if (m_bIsSecure)
  782.             SetDlgItemInt(IDC_EDIT_PORT, SECURE_NEWS_PORT);
  783.         else
  784.             SetDlgItemInt(IDC_EDIT_PORT, NEWS_PORT);
  785.     }
  786.     else
  787.     {
  788.         int32 lPort = GetPortNumber();
  789.         if (m_bIsSecure && lPort == NEWS_PORT)
  790.             SetDlgItemInt(IDC_EDIT_PORT, SECURE_NEWS_PORT);
  791.         else  if (!m_bIsSecure && lPort == SECURE_NEWS_PORT)
  792.             SetDlgItemInt(IDC_EDIT_PORT, NEWS_PORT);
  793.     }
  794. }
  795.  
  796. void CNewsServerDialog::OnHelp()
  797. {
  798.     NetHelp(HELP_ADD_SERVER);
  799. }
  800.  
  801. BEGIN_MESSAGE_MAP(CNewsServerDialog, CDialog)
  802.     ON_BN_CLICKED(IDOK, OnOK)
  803.     ON_BN_CLICKED(IDC_SECURE, OnCheckSecure)
  804.     ON_BN_CLICKED(ID_HELP, OnHelp)
  805. END_MESSAGE_MAP()
  806.  
  807. /////////////////////////////////////////////////////////////////////////////
  808. // IMAP pref stuff
  809.  
  810. typedef enum
  811. {
  812.   CHAR_USERNAME,
  813.   BOOL_REMEMBER_PASSWORD,
  814.   BOOL_CHECK_NEW_MAIL,
  815.   INT_CHECK_TIME,
  816.   BOOL_OFFLINE_DOWNLOAD,
  817.   BOOL_MOVE_TO_TRASH,
  818.   BOOL_IS_SECURE,
  819.   CHAR_PERAONAL_DIR,
  820.   CHAR_PUBLIC_DIR,
  821.   CHAR_OTHER_USER_DIR,
  822.   BOOL_OVERRIDE_NAMESPACES
  823.  
  824. }IMAP_PREF;
  825.  
  826.  
  827. static const char *kPrefTemplate = "mail.imap.server.%s.%s";
  828.  
  829. // Make sure XP_FREE() from the caller function;
  830. char* IMAP_GetPrefString(const char *pHostName, int nID)
  831. {
  832.     int        prefSize = XP_STRLEN(pHostName) + 60;
  833.     char    *pPrefName = (char *) XP_ALLOC(prefSize);
  834.  
  835.     if (!pPrefName)
  836.         return pPrefName;
  837.  
  838.     switch (nID)
  839.     {
  840.     case CHAR_USERNAME:
  841.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "userName");
  842.         break;
  843.  
  844.     case BOOL_REMEMBER_PASSWORD:
  845.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "remember_password");
  846.         break;
  847.  
  848.     case BOOL_CHECK_NEW_MAIL:
  849.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "check_new_mail");
  850.         break;
  851.  
  852.     case INT_CHECK_TIME:
  853.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "check_time");
  854.         break;
  855.  
  856.     case BOOL_OFFLINE_DOWNLOAD:
  857.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "offline_download");
  858.         break;
  859.  
  860.     case BOOL_MOVE_TO_TRASH:
  861.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "delete_is_move_to_trash");
  862.         break;
  863.  
  864.     case BOOL_IS_SECURE:
  865.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "isSecure");
  866.         break;
  867.  
  868.     case CHAR_PERAONAL_DIR:
  869.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "namespace.personal");
  870.         break;
  871.  
  872.     case CHAR_PUBLIC_DIR:
  873.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "namespace.public");
  874.         break;
  875.     
  876.     case CHAR_OTHER_USER_DIR:
  877.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "namespace.other_users");
  878.         break;
  879.  
  880.     case BOOL_OVERRIDE_NAMESPACES:
  881.         PR_snprintf(pPrefName, prefSize, kPrefTemplate, pHostName, "override_namespaces");
  882.         break;
  883.  
  884.     default:
  885.         ASSERT(0);
  886.         break;
  887.     }
  888.  
  889.     return pPrefName;
  890. }
  891.  
  892. BOOL IMAP_PrefIsLocked(const char *pHostName, int nID)
  893. {
  894.     BOOL    bResult = FALSE;
  895.     char*    pPrefName = NULL;
  896.  
  897.     pPrefName = IMAP_GetPrefString(pHostName, nID);
  898.     if (pPrefName)
  899.     {
  900.         bResult = PREF_PrefIsLocked(pPrefName);
  901.         XP_FREE(pPrefName);
  902.     }
  903.     return bResult;
  904. }
  905.  
  906. void IMAP_SetCharPref(const char *pHostName, int nID, const char* pValue)
  907. {
  908.     char*    pPrefName = NULL;
  909.  
  910.     pPrefName = IMAP_GetPrefString(pHostName, nID);
  911.     if (pPrefName)
  912.     {
  913.         PREF_SetCharPref(pPrefName, pValue);
  914.         XP_FREE(pPrefName);
  915.     }
  916. }
  917.  
  918. void IMAP_SetIntPref(const char *pHostName, int nID, int32 lValue)
  919. {
  920.     char*    pPrefName = NULL;
  921.  
  922.     pPrefName = IMAP_GetPrefString(pHostName, nID);
  923.     if (pPrefName)
  924.     {
  925.         PREF_SetIntPref(pPrefName, lValue);
  926.         XP_FREE(pPrefName);
  927.     }
  928. }
  929.  
  930. void IMAP_SetBoolPref(const char *pHostName, int nID, XP_Bool bValue) 
  931. {
  932.     char*    pPrefName = NULL;
  933.  
  934.     pPrefName = IMAP_GetPrefString(pHostName, nID);
  935.     if (pPrefName)
  936.     {
  937.         PREF_SetBoolPref(pPrefName, bValue);
  938.         XP_FREE(pPrefName);
  939.     }
  940. }
  941.  
  942. void IMAP_GetCharPref(const char *pHostName, int nID, char **hBuffer) 
  943. {
  944.     char*    pPrefName = NULL;
  945.  
  946.     pPrefName = IMAP_GetPrefString(pHostName, nID);
  947.     if (pPrefName)
  948.     {
  949.         PREF_CopyCharPref(pPrefName, hBuffer);
  950.         XP_FREE(pPrefName);
  951.     }
  952. }
  953.  
  954. void IMAP_GetIntPref(const char *pHostName, int nID, int32 *pInt)     
  955. {
  956.     char*    pPrefName = NULL;
  957.  
  958.     pPrefName = IMAP_GetPrefString(pHostName, nID);
  959.     if (pPrefName)
  960.     {
  961.         PREF_GetIntPref(pPrefName, pInt);
  962.         XP_FREE(pPrefName);
  963.     }
  964. }
  965.  
  966. void IMAP_GetBoolPref(const char *pHostName, int nID, XP_Bool *pBool)     
  967. {
  968.     char*    pPrefName = NULL;
  969.  
  970.     pPrefName = IMAP_GetPrefString(pHostName, nID);
  971.     if (pPrefName)
  972.     {
  973.         PREF_GetBoolPref(pPrefName, pBool);
  974.         XP_FREE(pPrefName);
  975.     }
  976. }
  977.  
  978. /////////////////////////////////////////////////////////////////////////////
  979. // CMailServerPropertySheet        
  980. //   
  981. CMailServerPropertySheet::CMailServerPropertySheet
  982. (CWnd *pParent, const char* pTitle, const char* pName, int nType, BOOL bEdit, BOOL bBothType)
  983.     : CPropertySheet(pTitle, pParent)
  984. {
  985.     m_hostName[0] = '\0';
  986.     if (pName && strlen(pName))
  987.         XP_STRCAT(m_hostName, pName);
  988.     if (nType == TYPE_IMAP)
  989.         m_bPop = FALSE;
  990.     else
  991.         m_bPop = TRUE;
  992.     m_bEdit = bEdit;
  993.     m_bBothType = bBothType;
  994.  
  995.     m_pGeneralPage = NULL;
  996.     m_pPopPage = NULL;
  997.     m_pIMAPPage = NULL;
  998.     m_pAdvancedPage = NULL;
  999.  
  1000.     if (m_bPop)
  1001.     {
  1002.         m_pGeneralPage = new CGeneralServerPage(this, pName);
  1003.         m_pPopPage = new CPopServerPage(this);
  1004.         AddPage(m_pGeneralPage);
  1005.         AddPage(m_pPopPage);
  1006.     }
  1007.     else
  1008.     {
  1009.         m_pGeneralPage = new CGeneralServerPage(this, pName);
  1010.         m_pIMAPPage = new CIMAPServerPage(this, pName);
  1011.         m_pAdvancedPage = new CIMAPAdvancedPage(this, pName);
  1012.         AddPage(m_pGeneralPage);
  1013.         AddPage(m_pIMAPPage);
  1014.         AddPage(m_pAdvancedPage);
  1015.     }
  1016. }
  1017.  
  1018. CMailServerPropertySheet::~CMailServerPropertySheet()
  1019. {
  1020.     if (m_pGeneralPage)
  1021.         delete m_pGeneralPage;
  1022.     if (m_pPopPage)
  1023.         delete m_pPopPage;
  1024.     if (m_pIMAPPage)
  1025.         delete m_pIMAPPage;   
  1026.     if (m_pAdvancedPage)
  1027.         delete m_pAdvancedPage;   
  1028. }
  1029.  
  1030. void CMailServerPropertySheet::SetMailHostName(char* pName)
  1031. {
  1032.     if (pName && strlen(pName))
  1033.         XP_STRCAT(m_hostName, pName);
  1034. }
  1035.  
  1036. XP_Bool CMailServerPropertySheet::GetIMAPUseSSL()
  1037. {
  1038.     if (m_pIMAPPage && IsWindow(m_pIMAPPage->GetSafeHwnd()))
  1039.         return m_pIMAPPage->GetUseSSL();
  1040.     else
  1041.         return FALSE;
  1042. }
  1043.  
  1044. void CMailServerPropertySheet::GetIMAPPersonalDir(char* pDir, int nLen)
  1045. {
  1046.     if (m_pAdvancedPage && IsWindow(m_pAdvancedPage->GetSafeHwnd()))
  1047.     {
  1048.         m_pAdvancedPage->GetPersonalDir(pDir, nLen);
  1049.     }
  1050.     else
  1051.         strcpy(pDir, "");
  1052. }
  1053.  
  1054. void CMailServerPropertySheet::GetIMAPPublicDir(char* pDir, int nLen)
  1055. {
  1056.     if (m_pAdvancedPage && IsWindow(m_pAdvancedPage->GetSafeHwnd()))
  1057.     {
  1058.         m_pAdvancedPage->GetPublicDir(pDir, nLen);
  1059.     }
  1060.     else
  1061.         strcpy(pDir, "");
  1062. }
  1063.  
  1064. void CMailServerPropertySheet::GetIMAPOthersDir(char* pDir, int nLen)
  1065. {
  1066.     if (m_pAdvancedPage && IsWindow(m_pAdvancedPage->GetSafeHwnd()))
  1067.     {
  1068.         m_pAdvancedPage->GetOthersDir(pDir, nLen);
  1069.     }
  1070.     else
  1071.         strcpy(pDir, "");
  1072. }
  1073.  
  1074. XP_Bool CMailServerPropertySheet::GetIMAPOverrideNameSpaces()
  1075. {
  1076.     if (m_pAdvancedPage && IsWindow(m_pAdvancedPage->GetSafeHwnd()))
  1077.         return m_pAdvancedPage->GetOverrideNameSpaces();
  1078.     else
  1079.         return FALSE;
  1080. }
  1081.  
  1082. void CMailServerPropertySheet::ShowHidePages(int nShowType) 
  1083. {
  1084.     if (nShowType == TYPE_POP)
  1085.     {
  1086.         m_bPop = TRUE;
  1087.         m_pPopPage = new CPopServerPage(this);
  1088.         AddPage(m_pPopPage);
  1089.         if (m_pIMAPPage)
  1090.         {
  1091.             RemovePage(m_pIMAPPage);
  1092.             m_pIMAPPage = NULL;
  1093.         }
  1094.         if (m_pAdvancedPage)
  1095.         {
  1096.             RemovePage(m_pAdvancedPage);
  1097.             m_pAdvancedPage = NULL;
  1098.         }
  1099.     }
  1100.     else
  1101.     {
  1102.         m_bPop = FALSE;
  1103.         m_pIMAPPage = new CIMAPServerPage(this, m_hostName);
  1104.         m_pAdvancedPage = new CIMAPAdvancedPage(this, m_hostName);
  1105.         AddPage(m_pIMAPPage);
  1106.         AddPage(m_pAdvancedPage);
  1107.         if (m_pPopPage)
  1108.         {
  1109.             RemovePage(m_pPopPage);
  1110.             m_pPopPage = NULL;
  1111.         }
  1112.     }
  1113. }
  1114.  
  1115. #ifdef _WIN32
  1116.  
  1117. BOOL CMailServerPropertySheet::OnInitDialog()
  1118. {
  1119.     BOOL ret = CPropertySheet::OnInitDialog();
  1120.  
  1121.     return ret;
  1122. }
  1123.  
  1124. #else
  1125.  
  1126. int CMailServerPropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
  1127. {
  1128.     int ret = CPropertySheet::OnCreate(lpCreateStruct);
  1129.     
  1130.     return ret;
  1131. }
  1132.  
  1133. #endif
  1134.  
  1135. BOOL CMailServerPropertySheet::IsPageValid(CPropertyPage* pPage)
  1136. {
  1137.     if (pPage && IsWindow(pPage->GetSafeHwnd()))
  1138.         return TRUE;
  1139.     else
  1140.         return FALSE;
  1141. }
  1142.  
  1143. void CMailServerPropertySheet::OnOK()
  1144. {
  1145.     ASSERT_VALID(this);
  1146.  
  1147.     if (GetActivePage()->OnKillActive())
  1148.     {
  1149.         if (m_bPop)
  1150.         {
  1151.             if (IsPageValid(m_pGeneralPage))
  1152.             {
  1153.                 if (!m_pGeneralPage->ProcessOK())
  1154.                 {    
  1155.                     SetActivePage(m_pGeneralPage);
  1156.                     return;
  1157.                 }
  1158.             }
  1159.             if (IsPageValid(m_pPopPage))
  1160.             {
  1161.                 if (!m_pPopPage->ProcessOK())
  1162.                 {    
  1163.                     SetActivePage(m_pPopPage);
  1164.                     return;
  1165.                 }
  1166.             }
  1167.         }
  1168.         else
  1169.         {
  1170.             if (IsPageValid(m_pGeneralPage))
  1171.             {
  1172.                 if (!m_pGeneralPage->ProcessOK())
  1173.                 {    
  1174.                     SetActivePage(m_pGeneralPage);
  1175.                     return;
  1176.                 }
  1177.             }
  1178.             if (IsPageValid(m_pIMAPPage))
  1179.             {
  1180.                 if (!m_pIMAPPage->ProcessOK())
  1181.                 {    
  1182.                     SetActivePage(m_pIMAPPage);
  1183.                     return;
  1184.                 }
  1185.             }
  1186.             if (IsPageValid(m_pAdvancedPage))
  1187.             {
  1188.                 if (!m_pAdvancedPage->ProcessOK())
  1189.                 {    
  1190.                     SetActivePage(m_pAdvancedPage);
  1191.                     return;
  1192.                 }
  1193.             }
  1194.         }
  1195.         EndDialog(IDOK);
  1196.     }
  1197.  
  1198. }
  1199.  
  1200. void CMailServerPropertySheet::OnHelp()
  1201. {
  1202. }
  1203.  
  1204. BEGIN_MESSAGE_MAP(CMailServerPropertySheet, CPropertySheet)
  1205. #ifndef _WIN32
  1206.     ON_WM_CREATE()
  1207. #endif
  1208.     ON_BN_CLICKED(IDOK, OnOK)
  1209. END_MESSAGE_MAP()
  1210.  
  1211. /////////////////////////////////////////////////////////////////////////////
  1212. // CGeneralServerPage
  1213. //
  1214. CGeneralServerPage::CGeneralServerPage(CWnd *pParent, const char* pName)
  1215.     : CPropertyPage(IDD)
  1216. {
  1217.     m_pParent = (CMailServerPropertySheet*)pParent;
  1218.     m_szServerName = pName;
  1219. }
  1220.  
  1221. BOOL CGeneralServerPage::OnInitDialog()
  1222. {
  1223.     BOOL ret = CPropertyPage::OnInitDialog();
  1224.  
  1225. #ifdef _WIN32
  1226.     ((CEdit*)GetDlgItem(IDC_EDIT_CHECK_MAIL))->SetLimitText(5);
  1227. #else
  1228.     ((CEdit*)GetDlgItem(IDC_EDIT_CHECK_MAIL))->LimitText(5);
  1229. #endif
  1230.  
  1231.     if (!m_szServerName.IsEmpty())
  1232.     {
  1233.         SetDlgItemText(IDC_STATIC_MAIL_SERVER, szLoadString(IDS_MAIL_SERVER));
  1234.         SetDlgItemText(IDC_STATIC_SERVER, LPCTSTR(m_szServerName));
  1235.         ((CEdit*)GetDlgItem(IDC_EDIT_SERVER))->ShowWindow(SW_HIDE);
  1236.     }
  1237.     else
  1238.     {
  1239.         GetDlgItem(IDC_STATIC_SERVER)->ShowWindow(SW_HIDE);
  1240.     #ifdef _WIN32
  1241.         ((CEdit*)GetDlgItem(IDC_EDIT_SERVER))->SetLimitText(MAX_HOSTNAME_LEN - 1);
  1242.     #else
  1243.         ((CEdit*)GetDlgItem(IDC_EDIT_SERVER))->LimitText(MAX_HOSTNAME_LEN - 1);
  1244.     #endif
  1245.     }
  1246.  
  1247.     CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_TYPE);
  1248.     if (m_pParent->AllowBothTypes())
  1249.     {
  1250.         int nImap = pCombo->AddString(szLoadString(IDS_SERVER_IMAP_STATIC));
  1251.         pCombo->SetItemData(nImap, TYPE_IMAP);
  1252.         int nPop = pCombo->AddString(szLoadString(IDS_SERVER_POP3_STATIC));
  1253.         pCombo->SetItemData(nPop, TYPE_POP);
  1254.         if (m_pParent->IsPopServer())
  1255.             pCombo->SetCurSel(nPop);
  1256.         else
  1257.             pCombo->SetCurSel(nImap);
  1258.     }
  1259.     else 
  1260.     {
  1261.         int nIndex;
  1262.         if (m_pParent->IsPopServer())
  1263.         {
  1264.             nIndex = pCombo->AddString(szLoadString(IDS_SERVER_POP3_STATIC));
  1265.             pCombo->SetItemData(nIndex, TYPE_POP);
  1266.         }
  1267.         else
  1268.         {
  1269.             nIndex = pCombo->AddString(szLoadString(IDS_SERVER_IMAP_STATIC));
  1270.             pCombo->SetItemData(nIndex, TYPE_IMAP);
  1271.         }
  1272.         pCombo->SetCurSel(nIndex);
  1273.     }
  1274.     char* pUserName = NULL;
  1275.     int32 lCheckTime = 0;
  1276.     char buffer[32];
  1277.     XP_Bool bRememberPassword = FALSE;
  1278.     XP_Bool bCheckMail = FALSE;
  1279.  
  1280.     if (m_pParent->IsPopServer())
  1281.     {
  1282.         PREF_CopyCharPref("mail.pop_name", &pUserName);
  1283.         PREF_GetBoolPref("mail.remember_password",&bRememberPassword);
  1284.         PREF_GetBoolPref("mail.check_new_mail", &bCheckMail);
  1285.         PREF_GetIntPref("mail.check_time", &lCheckTime);
  1286.     }
  1287.     else
  1288.     {
  1289.         if (m_pParent->EditServer())
  1290.         {
  1291.             IMAP_GetCharPref(LPCTSTR(m_szServerName), CHAR_USERNAME, &pUserName);
  1292.             IMAP_GetBoolPref(LPCTSTR(m_szServerName), BOOL_CHECK_NEW_MAIL, &bCheckMail);
  1293.             IMAP_GetIntPref(LPCTSTR(m_szServerName), INT_CHECK_TIME, &lCheckTime);
  1294.             IMAP_GetBoolPref(LPCTSTR(m_szServerName), BOOL_REMEMBER_PASSWORD, &bRememberPassword);
  1295.         }
  1296.     }
  1297.     if (pUserName)
  1298.     {
  1299.         SetDlgItemText(IDC_EDIT_USERNAME, pUserName);
  1300.         XP_FREE(pUserName);
  1301.     }
  1302.     CheckDlgButton(IDC_CHECK_PASSWORD, bRememberPassword);
  1303.     CheckDlgButton(IDC_CHECK_MAIL, bCheckMail);
  1304.  
  1305.     if (lCheckTime < 0) 
  1306.     {
  1307.         SetDlgItemText(IDC_EDIT_CHECK_MAIL, "");
  1308.     } 
  1309.     else 
  1310.     {
  1311.         sprintf(buffer, "%ld", lCheckTime);
  1312.         SetDlgItemText(IDC_EDIT_CHECK_MAIL, buffer);
  1313.     }
  1314.  
  1315.     if (m_pParent->IsPopServer())
  1316.     {
  1317.         if (PREF_PrefIsLocked("mail.pop_name")) 
  1318.             GetDlgItem(IDC_EDIT_USERNAME)->EnableWindow(FALSE);
  1319.         if (PREF_PrefIsLocked("mail.check_new_mail")) 
  1320.             GetDlgItem(IDC_CHECK_MAIL)->EnableWindow(FALSE);
  1321.         if (PREF_PrefIsLocked("mail.check_time")) 
  1322.             GetDlgItem(IDC_EDIT_CHECK_MAIL)->EnableWindow(FALSE);
  1323.         if (PREF_PrefIsLocked("mail.remember_password")) 
  1324.             GetDlgItem(IDC_CHECK_PASSWORD)->EnableWindow(FALSE);
  1325.     }
  1326.     else
  1327.     {
  1328.         if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), CHAR_USERNAME)) 
  1329.             GetDlgItem(IDC_EDIT_USERNAME)->EnableWindow(FALSE);
  1330.         if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), BOOL_CHECK_NEW_MAIL) || 
  1331.             IMAP_PrefIsLocked(LPCTSTR(m_szServerName), INT_CHECK_TIME)) 
  1332.         {
  1333.             GetDlgItem(IDC_CHECK_MAIL)->EnableWindow(FALSE);
  1334.             GetDlgItem(IDC_EDIT_CHECK_MAIL)->EnableWindow(FALSE);
  1335.         }
  1336.         if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), BOOL_REMEMBER_PASSWORD)) 
  1337.             GetDlgItem(IDC_CHECK_PASSWORD)->EnableWindow(FALSE);
  1338.     }
  1339.     return ret;
  1340. }
  1341.  
  1342. void CGeneralServerPage::DoDataExchange(CDataExchange* pDX)
  1343. {
  1344.     CDialog::DoDataExchange(pDX);
  1345. }
  1346.  
  1347. BOOL CGeneralServerPage::ProcessOK()
  1348. {
  1349.     char name[MAX_HOSTNAME_LEN];
  1350.     char userName[256];
  1351.     char text[MAX_DESCRIPTION_LEN];
  1352.  
  1353.     if (m_szServerName.IsEmpty() && 
  1354.         0 == GetDlgItemText(IDC_EDIT_SERVER, name, MAX_HOSTNAME_LEN))
  1355.     {
  1356.         AfxMessageBox(IDS_EMPTY_STRING);
  1357.         ((CEdit*)GetDlgItem(IDC_EDIT_SERVER))->SetFocus();
  1358.         return FALSE;
  1359.     }
  1360.  
  1361.     if (0 == GetDlgItemText(IDC_EDIT_USERNAME, userName, 255))
  1362.     {
  1363.         AfxMessageBox(IDS_EMPTY_STRING);
  1364.         ((CEdit*)GetDlgItem(IDC_EDIT_USERNAME))->SetFocus();
  1365.         return FALSE;
  1366.     }
  1367.  
  1368.     if (IsDlgButtonChecked(IDC_CHECK_MAIL) &&  
  1369.         GetDlgItemText(IDC_EDIT_CHECK_MAIL, text, MAX_DESCRIPTION_LEN))
  1370.     {
  1371.         if (!::IsNumeric(text))
  1372.         {
  1373.             ShowError(IDS_NUMBERS_ONLY, this);
  1374.             ((CEdit*)GetDlgItem(IDC_EDIT_CHECK_MAIL))->SetFocus();
  1375.             ((CEdit*)GetDlgItem(IDC_EDIT_CHECK_MAIL))->SetSel((DWORD)MAKELONG(0, -1));
  1376.             return FALSE;
  1377.         }
  1378.     }
  1379.     if (m_szServerName.IsEmpty())
  1380.         m_pParent->SetMailHostName(name);
  1381.     else
  1382.         strncpy(name, LPCTSTR(m_szServerName), m_szServerName.GetLength());
  1383.  
  1384.     int nCheckTime    = 0;
  1385.     XP_Bool bRememberPassword = IsDlgButtonChecked(IDC_CHECK_PASSWORD);
  1386.     XP_Bool bCheckMail = IsDlgButtonChecked(IDC_CHECK_MAIL);
  1387.     if (GetDlgItemText(IDC_EDIT_CHECK_MAIL, text, MAX_DESCRIPTION_LEN)) 
  1388.         nCheckTime = atoi(text);
  1389.  
  1390.     if (m_pParent->IsPopServer())
  1391.     {
  1392.         PREF_SetIntPref("mail.server_type", (int32)TYPE_POP);
  1393.         PREF_SetCharPref("network.hosts.pop_server", LPCTSTR(m_szServerName));
  1394.         PREF_SetCharPref("mail.pop_name", userName);
  1395.         PREF_SetBoolPref("mail.remember_password",bRememberPassword);
  1396.         PREF_SetBoolPref("mail.check_new_mail", bCheckMail);
  1397.         PREF_SetIntPref("mail.check_time", (int32)nCheckTime);
  1398.     }
  1399.     else
  1400.     {
  1401.         if (!m_pParent->EditServer())
  1402.         {
  1403.             XP_Bool bIsSecure = m_pParent->GetIMAPUseSSL();
  1404.             XP_Bool bOverrideNamespaces = m_pParent->GetIMAPOverrideNameSpaces();
  1405.             char personalDir[256];
  1406.             char publicDir[256];
  1407.             char othersDir[256];
  1408.             m_pParent->GetIMAPPersonalDir(personalDir, 255);
  1409.             m_pParent->GetIMAPPublicDir(publicDir, 255);
  1410.             m_pParent->GetIMAPOthersDir(othersDir, 255);
  1411.  
  1412.             MSG_IMAPHost* pHost = MSG_CreateIMAPHost(WFE_MSGGetMaster(),
  1413.                                             name,
  1414.                                             bIsSecure, 
  1415.                                             userName,
  1416.                                             bCheckMail,
  1417.                                             nCheckTime,
  1418.                                             bRememberPassword,
  1419.                                             FALSE,
  1420.                                             bOverrideNamespaces, 
  1421.                                             personalDir,
  1422.                                             publicDir, 
  1423.                                             othersDir 
  1424.                                             );
  1425.         }
  1426.  
  1427.         PREF_SetIntPref("mail.server_type", (int32)TYPE_IMAP);
  1428.         IMAP_SetCharPref(LPCTSTR(m_szServerName), CHAR_USERNAME, userName);
  1429.         IMAP_SetBoolPref(LPCTSTR(m_szServerName), BOOL_CHECK_NEW_MAIL, bCheckMail);
  1430.         IMAP_SetIntPref(LPCTSTR(m_szServerName), INT_CHECK_TIME, (int32)nCheckTime);
  1431.         IMAP_SetBoolPref(LPCTSTR(m_szServerName), BOOL_REMEMBER_PASSWORD, bRememberPassword);
  1432.     }
  1433.     return TRUE;
  1434. }
  1435.  
  1436. void CGeneralServerPage::OnChangeServerType()
  1437. {
  1438.     CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_TYPE);
  1439.     int nType = (int)pCombo->GetItemData(pCombo->GetCurSel());
  1440.     if ((m_pParent->IsPopServer() && nType == TYPE_POP) ||
  1441.         (!m_pParent->IsPopServer() && nType == TYPE_IMAP))
  1442.         return;
  1443.     m_pParent->ShowHidePages(nType);
  1444. }
  1445.  
  1446. BEGIN_MESSAGE_MAP(CGeneralServerPage, CPropertyPage)
  1447.     ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnChangeServerType)
  1448. END_MESSAGE_MAP()
  1449.  
  1450. /////////////////////////////////////////////////////////////////////////////
  1451. // CPopServerPage
  1452. //
  1453. CPopServerPage::CPopServerPage(CWnd *pParent)
  1454.     : CPropertyPage(IDD)
  1455. {
  1456. }
  1457.  
  1458. BOOL CPopServerPage::OnInitDialog()
  1459. {
  1460.     BOOL ret = CPropertyPage::OnInitDialog();
  1461.  
  1462.     XP_Bool prefBool = FALSE;
  1463.     PREF_GetBoolPref("mail.leave_on_server",&prefBool);
  1464.     if (prefBool)
  1465.         CheckDlgButton(IDC_CHECK_POP_REMOTE, TRUE);
  1466.     else 
  1467.         CheckDlgButton(IDC_CHECK_POP_REMOTE, FALSE);
  1468.  
  1469.     if (PREF_PrefIsLocked("mail.leave_on_server")) 
  1470.         GetDlgItem(IDC_CHECK_POP_REMOTE)->EnableWindow(FALSE);
  1471.  
  1472.     return ret;
  1473. }
  1474.  
  1475. void CPopServerPage::DoDataExchange(CDataExchange* pDX)
  1476. {
  1477.     CDialog::DoDataExchange(pDX);
  1478. }
  1479.  
  1480. BOOL CPopServerPage::ProcessOK()
  1481. {
  1482.     if (IsDlgButtonChecked(IDC_CHECK_POP_REMOTE))
  1483.         PREF_SetBoolPref("mail.leave_on_server", TRUE);
  1484.     else
  1485.         PREF_SetBoolPref("mail.leave_on_server", FALSE);
  1486.     return TRUE;
  1487. }
  1488.  
  1489. BEGIN_MESSAGE_MAP(CPopServerPage, CPropertyPage)
  1490. END_MESSAGE_MAP()
  1491.  
  1492. /////////////////////////////////////////////////////////////////////////////
  1493. // CIMAPServerPage
  1494. //
  1495. CIMAPServerPage::CIMAPServerPage(CWnd *pParent, const char* pName)
  1496.     : CPropertyPage(IDD)
  1497. {
  1498.     m_pParent = (CMailServerPropertySheet*)pParent;
  1499.     m_szServerName = pName;
  1500. }
  1501.  
  1502. BOOL CIMAPServerPage::OnInitDialog()
  1503. {
  1504.     BOOL ret = CPropertyPage::OnInitDialog();
  1505.  
  1506.     XP_Bool bOfflineDownload = FALSE;
  1507.     XP_Bool bMoveToTrash = FALSE;
  1508.     XP_Bool bUseSSL = FALSE;
  1509.  
  1510.     IMAP_GetBoolPref(LPCTSTR(m_szServerName), BOOL_OFFLINE_DOWNLOAD, &bOfflineDownload);
  1511.     IMAP_GetBoolPref(LPCTSTR(m_szServerName), BOOL_MOVE_TO_TRASH, &bMoveToTrash);
  1512.     IMAP_GetBoolPref(LPCTSTR(m_szServerName), BOOL_IS_SECURE, &bUseSSL);
  1513.     CheckDlgButton(IDC_CHECK_IMAP_LOCAL, bOfflineDownload);
  1514.     CheckDlgButton(IDC_CHECK_IMAP_TRASH, bMoveToTrash);
  1515.     CheckDlgButton(IDC_CHECK_IMAP_SSL, bUseSSL);
  1516.  
  1517.     if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), BOOL_OFFLINE_DOWNLOAD)) 
  1518.         GetDlgItem(IDC_CHECK_IMAP_LOCAL)->EnableWindow(FALSE);
  1519.     if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), BOOL_MOVE_TO_TRASH)) 
  1520.         GetDlgItem(IDC_CHECK_IMAP_TRASH)->EnableWindow(FALSE);
  1521.     if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), BOOL_IS_SECURE)) 
  1522.         GetDlgItem(IDC_CHECK_IMAP_SSL)->EnableWindow(FALSE);
  1523.  
  1524.     return ret;
  1525. }
  1526.  
  1527. XP_Bool CIMAPServerPage::GetUseSSL()
  1528. {
  1529.     return (IsDlgButtonChecked(IDC_CHECK_IMAP_SSL) == 0 ? FALSE : TRUE);
  1530. }
  1531.  
  1532. void CIMAPServerPage::DoDataExchange(CDataExchange* pDX)
  1533. {
  1534.     CDialog::DoDataExchange(pDX);
  1535. }
  1536.  
  1537. BOOL CIMAPServerPage::ProcessOK()
  1538. {
  1539.     XP_Bool bOfflineDownload = IsDlgButtonChecked(IDC_CHECK_IMAP_LOCAL);
  1540.     XP_Bool bMoveToTrash = IsDlgButtonChecked(IDC_CHECK_IMAP_TRASH);
  1541.     XP_Bool bUseSSL = IsDlgButtonChecked(IDC_CHECK_IMAP_SSL);
  1542.  
  1543.     IMAP_SetBoolPref(LPCTSTR(m_szServerName), BOOL_OFFLINE_DOWNLOAD, bOfflineDownload);
  1544.     IMAP_SetBoolPref(LPCTSTR(m_szServerName), BOOL_MOVE_TO_TRASH, bMoveToTrash);
  1545.     IMAP_SetBoolPref(LPCTSTR(m_szServerName), BOOL_IS_SECURE, bUseSSL);
  1546.     return TRUE;
  1547. }
  1548.  
  1549. BEGIN_MESSAGE_MAP(CIMAPServerPage, CPropertyPage)
  1550. END_MESSAGE_MAP()
  1551.  
  1552. /////////////////////////////////////////////////////////////////////////////
  1553. // CIMAPAdvancedPage
  1554. //
  1555. CIMAPAdvancedPage::CIMAPAdvancedPage(CWnd *pParent, const char* pName)
  1556.     : CPropertyPage(IDD)
  1557. {
  1558.     m_pParent = (CMailServerPropertySheet*)pParent;
  1559.     m_szServerName = pName;
  1560. }
  1561.  
  1562. BOOL CIMAPAdvancedPage::OnInitDialog()
  1563. {
  1564.     BOOL ret = CPropertyPage::OnInitDialog();
  1565.  
  1566.     XP_Bool bOverrideNamespaces = TRUE;
  1567.  
  1568.     char* pPersonalDir = NULL;
  1569.     char* pPublicDir = NULL;
  1570.     char* pOtherUserDir = NULL;
  1571.     IMAP_GetCharPref(LPCTSTR(m_szServerName), CHAR_PERAONAL_DIR, &pPersonalDir);
  1572.     if (pPersonalDir)
  1573.     {
  1574.         SetDlgItemText(IDC_EDIT_IMAP_DIR, pPersonalDir);
  1575.         XP_FREE(pPersonalDir);
  1576.     }
  1577.     IMAP_GetCharPref(LPCTSTR(m_szServerName), CHAR_PUBLIC_DIR, &pPublicDir);
  1578.     if (pPublicDir)
  1579.     {
  1580.         SetDlgItemText(IDC_EDIT_PUBLIC_DIR, pPublicDir);
  1581.         XP_FREE(pPublicDir);
  1582.     }
  1583.     IMAP_GetCharPref(LPCTSTR(m_szServerName), CHAR_OTHER_USER_DIR, &pOtherUserDir);
  1584.     if (pOtherUserDir)
  1585.     {
  1586.         SetDlgItemText(IDC_EDIT_OTHERS_DIR, pOtherUserDir);
  1587.         XP_FREE(pOtherUserDir);
  1588.     }
  1589.     IMAP_GetBoolPref(LPCTSTR(m_szServerName), BOOL_OVERRIDE_NAMESPACES, &bOverrideNamespaces);
  1590.     CheckDlgButton(IDC_CHECK_OVERRIDE, bOverrideNamespaces);
  1591.  
  1592.     if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), CHAR_PERAONAL_DIR)) 
  1593.         GetDlgItem(IDC_EDIT_IMAP_DIR)->EnableWindow(FALSE);
  1594.     if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), CHAR_PUBLIC_DIR)) 
  1595.         GetDlgItem(IDC_EDIT_PUBLIC_DIR)->EnableWindow(FALSE);
  1596.     if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), CHAR_OTHER_USER_DIR)) 
  1597.         GetDlgItem(IDC_EDIT_OTHERS_DIR)->EnableWindow(FALSE);
  1598.     if (IMAP_PrefIsLocked(LPCTSTR(m_szServerName), BOOL_OVERRIDE_NAMESPACES)) 
  1599.         GetDlgItem(IDC_CHECK_OVERRIDE)->EnableWindow(FALSE);
  1600.  
  1601.     return ret;
  1602. }
  1603.  
  1604. void CIMAPAdvancedPage::GetPersonalDir(char* pDir, int nLen)
  1605. {
  1606.     if (0 == GetDlgItemText(IDC_EDIT_IMAP_DIR, pDir, nLen))
  1607.         ;
  1608. }
  1609.  
  1610. void CIMAPAdvancedPage::GetPublicDir(char* pDir, int nLen)
  1611. {
  1612.     if (0 == GetDlgItemText(IDC_EDIT_PUBLIC_DIR, pDir, nLen))
  1613.         ;
  1614. }
  1615.  
  1616. void CIMAPAdvancedPage::GetOthersDir(char* pDir, int nLen)
  1617. {
  1618.     if (0 == GetDlgItemText(IDC_EDIT_OTHERS_DIR, pDir, nLen))
  1619.         ;
  1620. }
  1621.  
  1622. XP_Bool CIMAPAdvancedPage::GetOverrideNameSpaces()
  1623. {
  1624.     return (IsDlgButtonChecked(IDC_CHECK_OVERRIDE) == 0 ? FALSE : TRUE);
  1625. }
  1626.  
  1627. void CIMAPAdvancedPage::DoDataExchange(CDataExchange* pDX)
  1628. {
  1629.     CDialog::DoDataExchange(pDX);
  1630. }
  1631.  
  1632. BOOL CIMAPAdvancedPage::ProcessOK()
  1633. {
  1634.     char directory[256];
  1635.     if (0 == GetDlgItemText(IDC_EDIT_IMAP_DIR, directory, 255))
  1636.         IMAP_SetCharPref(LPCTSTR(m_szServerName), CHAR_PERAONAL_DIR, "");
  1637.     else
  1638.         IMAP_SetCharPref(LPCTSTR(m_szServerName), CHAR_PERAONAL_DIR, directory);
  1639.     if (0 == GetDlgItemText(IDC_EDIT_PUBLIC_DIR, directory, 255))
  1640.         IMAP_SetCharPref(LPCTSTR(m_szServerName), CHAR_PUBLIC_DIR, "");
  1641.     else
  1642.         IMAP_SetCharPref(LPCTSTR(m_szServerName), CHAR_PUBLIC_DIR, directory);
  1643.     if (0 == GetDlgItemText(IDC_EDIT_OTHERS_DIR, directory, 255))
  1644.         IMAP_SetCharPref(LPCTSTR(m_szServerName), CHAR_OTHER_USER_DIR, "");
  1645.     else
  1646.         IMAP_SetCharPref(LPCTSTR(m_szServerName), CHAR_OTHER_USER_DIR, directory);
  1647.  
  1648.     XP_Bool bOverrideNamespaces = IsDlgButtonChecked(IDC_CHECK_OVERRIDE);
  1649.     IMAP_SetBoolPref(LPCTSTR(m_szServerName), BOOL_OVERRIDE_NAMESPACES, bOverrideNamespaces);
  1650.     return TRUE;
  1651. }
  1652.  
  1653. BEGIN_MESSAGE_MAP(CIMAPAdvancedPage, CPropertyPage)
  1654. END_MESSAGE_MAP()
  1655.  
  1656. #endif /* MOZ_MAIL_NEWS */
  1657.