home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / femess.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  23.7 KB  |  898 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 "mmsystem.h"
  21. #include "apiapi.h"
  22. #ifdef MOZ_MAIL_NEWS
  23. #include "msgcom.h"
  24. #include "apimsg.h"
  25. #endif
  26.  
  27. #ifdef MOZ_MAIL_NEWS
  28. #include "msgcom.h"
  29. #endif
  30. #include "fe_proto.h"
  31. #include "hiddenfr.h"
  32. #ifdef MOZ_MAIL_NEWS
  33. #include "mailfrm.h"
  34. #include "mailmisc.h"
  35. #include "mnprefs.h"
  36. #include "compfrm.h"
  37. #endif
  38. #include "template.h"
  39. #include "prefapi.h"
  40. #ifdef MOZ_MAIL_NEWS
  41. #include "winbif.h"
  42. #endif
  43.  
  44. /* This function is defined in msgfrm.cpp
  45.    Declare here to avoid including the whole header file */
  46. #ifdef MOZ_MAIL_NEWS   
  47. MSG_Master *WFE_MSGGetMaster();
  48. #endif 
  49.  
  50. extern "C" MSG_Master* FE_GetMaster(){
  51. #ifdef MOZ_MAIL_NEWS 
  52.     return WFE_MSGGetMaster();
  53. #else
  54.    return(NULL);
  55. #endif /* MOZ_MAIL_NEWS */
  56. }
  57.  
  58. // prototypes
  59. BOOL SetBiffInfoNum(LPCSTR pKey, uint32 num);
  60.  
  61.  
  62.  
  63. //
  64. // I'm sure this already exists...
  65. //
  66. CGenericFrame *wfe_FrameFromXPContext(MWContext * pXPCX)
  67. {
  68.     if(!pXPCX)
  69.         return(NULL);
  70.  
  71.     CFrameGlue * pFrameGlue = GetFrame(pXPCX);
  72.     if(pFrameGlue) {
  73.         CFrameWnd * pFrame = pFrameGlue->GetFrameWnd();
  74.         if(pFrame && pFrame->IsKindOf(RUNTIME_CLASS(CGenericFrame)))
  75.             return((CGenericFrame*)pFrame);
  76.     }
  77.  
  78.     return(NULL);
  79. }
  80.  
  81. extern "C" int FE_GetURL(MWContext *pContext, URL_Struct *pUrl)    
  82. {
  83.     if(!pContext || !ABSTRACTCX(pContext))
  84.         return(-1);
  85. #ifdef EDITOR
  86.     // The only circumstance in which we load a URL
  87.     //   into Editor when called from XP code is during
  88.     //   Publishing: we have "files to post"
  89.     if( EDT_IS_EDITOR(pContext) && pUrl->files_to_post == NULL ){
  90.         // So switch to or create a Browser frame/context
  91.         // TODO: A possibly bad side effect is that changing
  92.         //   frames will obscure the last active frame 
  93.         //   (and  possibly a preference dialog)
  94.         CGenericFrame* pFrame = (CGenericFrame*)FEU_GetLastActiveFrame(MWContextBrowser);
  95.         pContext = NULL;
  96.         if( pFrame && pFrame->GetMainContext() ){
  97.             pContext = pFrame->GetMainContext()->GetContext();
  98.             if( pContext ){
  99.                 // Find previously-active Browser frame
  100.                 if ( pFrame->IsIconic() ){
  101.                     pFrame->ShowWindow(SW_RESTORE);
  102.                 }
  103.                 pFrame->SetActiveWindow();
  104.             }
  105.         } else {
  106.             // Create a new Browser frame
  107.             pContext = CFE_CreateNewDocWindow(NULL, NULL);
  108.         }
  109.         if( !pContext ){
  110.             return -1;
  111.         }
  112.     }
  113. #endif
  114.     return(ABSTRACTCX(pContext)->GetUrl(pUrl, FO_CACHE_AND_PRESENT));
  115. }
  116.  
  117. //
  118. // The must return a unix style path.
  119. //   We'll have to figure out how to convert Win9x "\\fuzzhead\d-drive\span\mail"
  120. //   into a unix path at some point.
  121. //
  122. extern "C" const char* FE_GetFolderDirectory(MWContext *pContext)    
  123. {
  124. #ifdef MOZ_MAIL_NEWS
  125.     static char pStr[_MAX_PATH];
  126.     pStr[0] = '\0';
  127.  
  128.     if (!g_MsgPrefs.m_csMailDir.IsEmpty())
  129.     {
  130.            sprintf(pStr, "/%s", (LPCTSTR) g_MsgPrefs.m_csMailDir);
  131.     
  132.         for(char * p = pStr; p && *p; p++)
  133.             if(*p == '\\')
  134.                 *p = '/';
  135.             else if(*p == ':')
  136.                 *p = '|'; 
  137.     }
  138.  
  139.     return(pStr);
  140. #else  // MOZ_MAIL_NEWS
  141.    return("");
  142. #endif // MOZ_MAIL_NEWS   
  143.        
  144. }
  145.  
  146. extern "C" uint32
  147. FE_DiskSpaceAvailable (MWContext *context, const char *lpszPath )
  148. {
  149.     char aDrive[_MAX_DRIVE];
  150.     _splitpath( lpszPath, aDrive, NULL, NULL, NULL);
  151.  
  152.     if(aDrive[0] == '\0')    {
  153.  
  154.         // The back end is always trying to pass us paths that look
  155.         //   like /c|/netscape/mail.  See if we've got one of them
  156.         if(strlen(lpszPath) > 2 && lpszPath[0] == '/' && lpszPath[2] == '|') {
  157.             aDrive[0] = lpszPath[1];
  158.             aDrive[1] = ':';
  159.             aDrive[2] = '\0';
  160.         }
  161.         else {
  162.             // Return bogus large number and hope for the best
  163.             TRACE("Unable to determine drive, can't check free disk space.\n");
  164.             return 1L<<30; 
  165.         }
  166.     }
  167.  
  168.     CString csDrive = aDrive;
  169.     csDrive += '\\';
  170.     TRACE("Checking drive %s disk space\n", (const char *)csDrive);
  171.  
  172.     DWORD dwSectorsPerCluster = 0;
  173.     DWORD dwBytesPerSector = 0;
  174.     DWORD dwFreeClusters = 0;
  175.     DWORD dwTotalClusters = 0;
  176.     if(GetDiskFreeSpace(csDrive, 
  177.                         &dwSectorsPerCluster, 
  178.                         &dwBytesPerSector, 
  179.                         &dwFreeClusters, 
  180.                         &dwTotalClusters) == FALSE)    {
  181.         TRACE("Couldn't get free disk space...\n");
  182.         return 1L<<30; // Return bogus large number and hope for the best
  183.     }
  184.  
  185.     //    We can now figure free disk space.
  186.     DWORD dwFreeSpace = dwFreeClusters * dwSectorsPerCluster * dwBytesPerSector;
  187.     TRACE("%lu free bytes\n", dwFreeSpace);
  188.  
  189.      return dwFreeSpace;
  190. }
  191.  
  192. //
  193. // Generate a temp file name for a file that can eventually maybe be renamed
  194. //   to pFileName.  We could do something more intelligent
  195. //   about putting it in the right directory and all that but not today
  196. //
  197. extern "C" char *FE_GetTempFileFor(MWContext *pContext, const char *pFileName, XP_FileType ftype, XP_FileType *rettype)    
  198. {
  199.     char * pString = WH_TempFileName(ftype, NULL, NULL);
  200.     if(!pString)
  201.         return(NULL);
  202.  
  203.     if(rettype)
  204.         *rettype = xpTemporary;
  205.  
  206.     return(pString);
  207. }
  208.  
  209. #ifdef MOZ_MAIL_NEWS
  210. extern "C" void FE_MsgShowHeaders(MSG_Pane *pPane, MSG_HEADER_SET mhsHeaders)    
  211. {
  212. }
  213.  
  214. extern "C" void FE_UpdateCompToolbar(MSG_Pane *pPane)    
  215. {
  216.   CComposeFrame * pCompose = (CComposeFrame *) MSG_GetFEData(pPane);
  217.   if ( pCompose && pCompose->GetMainContext() && !MSG_DeliveryInProgress(pPane))
  218.   {
  219.     // Stop animation in corner and (more importantly) kill the progress bar.
  220.     MWContext *pContext = pCompose->GetMainContext()->GetContext();
  221.     if (pContext && !XP_IsContextBusy(pContext))
  222.     {
  223.       pCompose->GetChrome()->StopAnimation();
  224.  
  225.       pCompose->UpdateComposeWindowForMAPI(); // rhp - for MAPI operations
  226.     }
  227.   }
  228. }
  229. #endif /* MOZ_MAIL_NEWS */
  230.  
  231. //
  232. // Prompt the user for a local file name
  233. //
  234. extern "C" int FE_PromptForFileName(MWContext *context,
  235.                                  const char *prompt_string,
  236.                                  const char *default_path,
  237.                                  XP_Bool file_must_exist_p,
  238.                                  XP_Bool directories_allowed_p,
  239.                                  ReadFileNameCallbackFunction fn,
  240.                                  void *closure)
  241. {
  242.     HWND hWnd = NULL;
  243.     CGenericFrame * pWnd = wfe_FrameFromXPContext(context);
  244.     if(pWnd)
  245.         hWnd = pWnd->m_hWnd;
  246.     else if (context) {    // XXX WHS Do what we really should have done
  247.         CWnd *pWnd2 = (ABSTRACTCX(context))->GetDialogOwner();
  248.         ASSERT(pWnd2 != CWnd::GetDesktopWindow());
  249.         if (pWnd2 && pWnd2 != CWnd::GetDesktopWindow())
  250.             hWnd = pWnd2->m_hWnd;
  251.     }
  252.     ASSERT(hWnd); // Bad!
  253.  
  254.     char * pFile = NULL;
  255.     if (file_must_exist_p)
  256.     {
  257.         // Doing a file open
  258.         // check for PKCS 12 files 
  259.         if(default_path && !strcmp(default_path, "*.p12")) {
  260.             default_path = NULL;
  261.             pFile = wfe_GetExistingFileName(hWnd, (char *)prompt_string, P12,
  262.                 file_must_exist_p, FALSE);
  263.         } else {
  264.             //  Changed to prompt for ALL, instead defaulting to first filter.
  265.             pFile = wfe_GetExistingFileName(hWnd , (char *)prompt_string, ALL,
  266.                 file_must_exist_p, FALSE);
  267.         }
  268.     }  /* end if */
  269.     else if (context->type == MWContextRDFSlave)
  270.     {
  271.         CString cs;
  272.         cs.LoadString(IDS_UNTITLED);
  273.         // Since someone undid my work for untyped title strings.
  274.         cs += ".rdf";
  275.         pFile = wfe_GetSaveFileName(hWnd, (char *)prompt_string, (char *) (LPCTSTR) cs, 0);
  276.     } 
  277.  
  278. #ifdef MOZ_MAIL_NEWS
  279.     else if (directories_allowed_p) {
  280.         CDirDialog directory(ABSTRACTCX(context)->GetDialogOwner(), default_path);
  281.         if (IDOK == directory.DoModal())
  282.         {
  283.             CString fileName = directory.GetPathName();
  284.             /* There is a reason for this k5bg bogusness */
  285.             /* Whatever well-meaning person coded CDirPicker in mnprefs.cpp did it wrong */
  286.             /* this is a hidden string we are getting rid of */
  287.             int nPos = fileName.GetLength() - strlen("\\k5bg");
  288.             CString pathName(fileName.Left(nPos));
  289.             pFile = XP_STRDUP(pathName);
  290.         }
  291.     }
  292.     else
  293.     {
  294.         CString cs;
  295.  
  296.         // Doing a file save
  297.         if ((context->type == MWContextMail) || 
  298.             (context->type == MWContextNews) ||
  299.             (context->type == MWContextMailMsg) ||
  300.             (context->type == MWContextNewsMsg) ) {
  301.             // Suggest an untyped file name
  302.             cs.LoadString(IDS_UNTITLED);
  303.             // Since someone undid my work for untyped title strings.
  304.             cs += ".txt";
  305.             pFile = wfe_GetSaveFileName(hWnd, (char *)prompt_string, (char *) (LPCTSTR) cs, 0);
  306.         } else if (context->type == MWContextBookmarks) {
  307.             // Suggest the default bookmarks file
  308.             pFile = wfe_GetSaveFileName(hWnd, (char *)prompt_string, (char *)(const char *)theApp.m_pBookmarkFile, 0);
  309.         } else if((default_path != NULL) && !strcmp(default_path, "*.p12")) {
  310.             int p12type = P12;
  311.             default_path = NULL;
  312.             pFile = wfe_GetSaveFileName(hWnd, (char *)prompt_string, (char *)default_path, &p12type);
  313.         } else {
  314.             pFile = wfe_GetSaveFileName(hWnd, (char *)prompt_string, (char *)default_path, 0);
  315.         }
  316.     }  /* end else */
  317. #endif
  318.  
  319.     if(!pFile)
  320.         return(-1);
  321.  
  322.     fn(context, pFile, closure);
  323.  
  324.     return(0);
  325. }
  326.  
  327. extern "C" int FE_PromptForNewsHost (MWContext *context,
  328.                                  const char *prompt_string,
  329.                                  ReadFileNameCallbackFunction fn,
  330.                                  void *closure)
  331. {
  332.  
  333.     char * pString = FE_Prompt(context, prompt_string, "");
  334.  
  335.     if(pString) {
  336.  
  337.         // make sure we have a correct looking news URL
  338.         if(strncmp(pString, "news://", 7) && strncmp(pString, "snews://", 8)) {
  339.             char * pNewString = (char *) XP_ALLOC(10 + XP_STRLEN(pString));
  340.             sprintf(pNewString, "news://%s", pString);
  341.             XP_FREE(pString);
  342.             pString = pNewString;
  343.         }
  344.  
  345.         fn(context, pString, closure);
  346.     }
  347.  
  348.     return(0);
  349. }
  350.  
  351. #ifdef MOZ_MAIL_NEWS
  352. extern "C" ABook * FE_GetAddressBook ( MSG_Pane *pPane)
  353. {
  354.     return theApp.m_pABook;
  355. }
  356.  
  357.  
  358. extern "C" XP_List * FE_GetDirServers ()
  359. {
  360.     return theApp.m_directories;
  361. }
  362.  
  363.  
  364. extern "C" MWContext * FE_GetAddressBookContext ( MSG_Pane *pPane, XP_Bool viewnow )
  365. {
  366.     return theApp.m_pAddressContext;
  367. }
  368. #endif
  369.  
  370. //
  371. // Send back the current user's email address
  372. //
  373. extern "C" const char *FE_UsersMailAddress()
  374. {
  375. #ifdef MOZ_MAIL_NEWS
  376.     const char * addr = g_MsgPrefs.m_csUsersEmailAddr;
  377.  
  378.     if(addr && *addr)
  379.         return(addr);
  380. #else
  381.    static char * prefStr = NULL;
  382.    XP_FREEIF(prefStr);   
  383.     PREF_CopyCharPref("mail.identity.useremail",&prefStr);
  384.    return(prefStr);
  385. #endif // MOZ_MAIL_NEWS        
  386.    return("");
  387. }
  388.  
  389.  
  390. //
  391. // Send back the fullname of the current user
  392. //
  393. extern "C" const char *FE_UsersFullName()
  394. {   
  395. #ifdef MOZ_MAIL_NEWS
  396.     const char * name = g_MsgPrefs.m_csUsersFullName;
  397.  
  398.     if(name && *name)
  399.         return(name);
  400.     else
  401.         return(NULL);
  402. #else        
  403.    static char * prefStr = NULL;
  404.    XP_FREEIF(prefStr);   
  405.     PREF_CopyCharPref("mail.identity.username", &prefStr);
  406.    return(prefStr);
  407. #endif
  408. }
  409.  
  410. //
  411. // Return the uesr's organization (if specified)
  412. //
  413. extern "C" const char *FE_UsersOrganization (void)
  414. {
  415. #ifdef MOZ_MAIL_NEWS
  416.     const char * org = g_MsgPrefs.m_csUsersOrganization;
  417.  
  418.     if(org && *org)
  419.         return(org);
  420.     else
  421.         return(NULL);
  422. #else        
  423.    static char * prefStr = NULL;
  424.    XP_FREEIF(prefStr);   
  425.    PREF_CopyCharPref("mail.identity.organization", &prefStr);
  426.    return(prefStr);
  427. #endif // MOZ_MAIL_NEWS        
  428. }
  429.  
  430. extern "C" const char *FE_UsersSignature(void)  
  431. {
  432. #ifdef MOZ_MAIL_NEWS
  433.     //  Just return the sig file that we read in on startup.
  434.     char * pszPref;
  435.     PREF_CopyCharPref("mail.signature_file", &pszPref);
  436.     if (pszPref) {
  437.         XP_FREEIF(g_MsgPrefs.m_pszUserSig);
  438.         g_MsgPrefs.m_pszUserSig = wfe_ReadUserSig(pszPref);
  439.     }
  440.     XP_FREEIF(pszPref);
  441.  
  442.     return(g_MsgPrefs.m_pszUserSig);
  443. #else
  444.    return("");
  445. #endif // MOZ_MAIL_NEWS   
  446.        
  447. }
  448.  
  449. // Read in a user's sig file
  450. // Return NULL on error
  451. // The string should be freed by the caller
  452. MODULE_PRIVATE char *wfe_ReadUserSig(const char * msg)
  453. {
  454. #ifdef MOZ_MAIL_NEWS
  455.     FILE * fp;
  456.     char * buffer;
  457.  
  458.     if(!msg || !msg[0])
  459.         return(NULL);
  460.  
  461. #ifdef XP_WIN32
  462.     fp = fopen(msg, "rb");
  463. #else
  464.     // Windows uses ANSI codepage, DOS uses OEM codepage, fopen takes OEM codepage
  465.     // That's why we need to do conversion here.
  466.     CString oembuff = msg;
  467.     oembuff.AnsiToOem();
  468.     fp = fopen(oembuff, "rb");
  469. #endif
  470.     if(!fp)
  471.         return(NULL);
  472.  
  473.     // go to the end
  474.     fseek(fp, 0L, SEEK_END);  
  475.     int32 len = ftell(fp);
  476.  
  477.     if(len < 1)
  478.         return(NULL);
  479.  
  480.     buffer = (char *) XP_ALLOC(len + 5);
  481.     if(!buffer)
  482.         return(NULL);
  483.  
  484.     fseek(fp, 0L, SEEK_SET);
  485.     len = fread(buffer, 1, CASTINT(len), fp);
  486.     buffer[len] = '\0';
  487.  
  488.     //  Strip whitespace from the end of the buffer.
  489.     len--;
  490.     while(len > 0 && (isspace(buffer[len])||buffer[len]==26))  {
  491.         buffer[len] = '\0';
  492.         len--;
  493.     }
  494.  
  495.     //  Add a new line to the end.
  496.     if(len > 0) {
  497.         strcat(buffer, "\r\n");
  498.     }
  499.  
  500.     fclose(fp);
  501.  
  502.     return(buffer);
  503. #else // MOZ_MAIL_NEWS
  504.    return("");
  505. #endif // MOZ_MAIL_NEWS
  506.        
  507. }
  508.  
  509. #ifdef MOZ_MAIL_NEWS
  510. // FE function that the back-end calls when it gets a new
  511. // IMAP highwater mark that needs to be communicated/stored
  512. // for the stand-alone biff
  513.  
  514. #ifdef _WIN32
  515. extern "C" uint32 FE_SetBiffInfo(MSG_BiffInfoType type, uint32 data)
  516. {
  517.     switch(type)
  518.     {
  519.         case MSG_IMAPHighWaterMark:
  520.         {
  521.             static const char szHighWaterKey[] = "IMAPHighWaterUID";
  522.             SetBiffInfoNum(szHighWaterKey, data);
  523.             break;
  524.         }
  525.         default:
  526.         {
  527.             break;
  528.         }
  529.     }
  530.     return(0);
  531. }
  532. #endif
  533. #endif
  534.  
  535. #ifdef MOZ_MAIL_NEWS
  536. //
  537. // A biff operation has just completed.
  538. //
  539.  
  540. extern "C" void FE_UpdateBiff(MSG_BIFF_STATE state)
  541. {
  542. #ifdef _WIN32
  543.     const char szNSNotifyWindowClassName[] = NSNotifyWindowClassName;        // do not localize this string
  544.     const char szNSNotifyRegisterMsgStr[] = NSMailNotifyMsg;        // do not localize this string
  545.     HWND nsNotifyHwnd = FindWindow(szNSNotifyWindowClassName, NULL);
  546.     static UINT WM_NSMailMsg = 0;
  547.     if (WM_NSMailMsg == 0)
  548.     {
  549.         WM_NSMailMsg = RegisterWindowMessage(szNSNotifyRegisterMsgStr);
  550.     }
  551.  
  552.     NOTIFYICONDATA nid;
  553.     if (sysInfo.m_bWin4) {
  554.         nid.cbSize = sizeof(NOTIFYICONDATA);
  555.         nid.hWnd = theApp.m_pHiddenFrame->GetSafeHwnd();
  556.         nid.uID = ID_TOOLS_INBOX;
  557.         nid.uFlags = 0;
  558.     }
  559.  
  560.     if (state == MSG_BIFF_NoMail) {
  561.         // tell the stand-alone biff there is no new mail anymore
  562.         // always do this, even if this is the same as the last state
  563.         if (nsNotifyHwnd) 
  564.             PostMessage(nsNotifyHwnd, WM_NSMailMsg, NSMAIL_GetMailCompleted, 0);
  565.     }
  566. #endif
  567.  
  568.     static MSG_BIFF_STATE stateOld = MSG_BIFF_Unknown;
  569.  
  570.     if ( stateOld != state ) {
  571.         switch ( state ) {
  572.         case MSG_BIFF_NoMail:
  573. #ifdef _WIN32
  574.             if (sysInfo.m_bWin4) {
  575.                 Shell_NotifyIcon( NIM_DELETE, &nid );
  576.             }
  577. #endif
  578.             theApp.GetTaskBarMgr().ReplaceTaskIcon( ID_TOOLS_INBOX, IDB_TASKBARL, IDB_TASKBARS, INBOX_ICON_INDEX);
  579.             break;
  580.         case MSG_BIFF_Unknown:
  581.             theApp.GetTaskBarMgr().ReplaceTaskIcon( ID_TOOLS_INBOX, IDB_TASKBARL, IDB_TASKBARS, UNKNOWN_MAIL_ICON_INDEX);
  582.             break;
  583.         case MSG_BIFF_NewMail:
  584.             XP_Bool prefBool = TRUE;
  585.             PREF_GetBoolPref("mail.play_sound",&prefBool);
  586.  
  587. #ifdef _WIN32
  588.             if (sysInfo.m_bWin4) {
  589.                 if (prefBool) {
  590.                     PlaySound( _T("MailBeep"), NULL, SND_ASYNC );
  591.                 }
  592.  
  593.                 // Add the biff icon only if we don't find a standalone biff
  594.                 if (!nsNotifyHwnd) {
  595.                     nid.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
  596.                     nid.uCallbackMessage = MSG_TASK_NOTIFY;
  597.                     nid.hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE( IDI_MAIL ));
  598.                     strcpy(nid.szTip, szLoadString(IDS_YOUHAVENEWMAIL));
  599.                     Shell_NotifyIcon( NIM_ADD, &nid );
  600.                     if (nid.hIcon)
  601.                         DestroyIcon(nid.hIcon);
  602.                 }
  603.                 else {
  604.                     if (sysInfo.m_bWin4) {
  605.                         Shell_NotifyIcon( NIM_DELETE, &nid );
  606.                     }
  607.                 }
  608.             }
  609.             else
  610. #endif
  611.             {
  612.                 if (prefBool) {
  613.                     sndPlaySound( "MailBeep", SND_ASYNC );
  614.                 }
  615.             }
  616.  
  617.             theApp.GetTaskBarMgr().ReplaceTaskIcon( ID_TOOLS_INBOX, IDB_TASKBARL, IDB_TASKBARS, NEW_MAIL_ICON_INDEX);
  618.             break;
  619.         }
  620.         stateOld = state;
  621.     }
  622. }
  623. #endif
  624.  
  625. //
  626. // Save the POP3 password in the encrypted form it was handed to us
  627. //
  628. extern "C" void FE_RememberPopPassword(MWContext * context, const char * password)
  629. {
  630. #ifdef MOZ_MAIL_NEWS
  631.     // if we aren't supposed to remember clear anything in the registry
  632.     XP_Bool prefBool;
  633.     PREF_GetBoolPref("mail.remember_password",&prefBool);
  634.  
  635.     if(prefBool)
  636.         PREF_SetCharPref("mail.pop_password",(char *)password);
  637.     else
  638.         PREF_SetCharPref("mail.pop_password","");
  639. #endif /* MOZ_MAIL_NEWS */
  640. }
  641.  
  642. #ifdef MOZ_MAIL_NEWS
  643. /////////////////////////////////////////////////////////////////////
  644. //
  645. // CNewsDownloadDialog
  646. //
  647.  
  648. class CNewsDownloadDialog: public CDialog {
  649.  
  650. protected:
  651.     enum { IDD = IDD_NEWSMAXHEADERS };
  652.  
  653.     virtual BOOL OnInitDialog( );
  654.     virtual void DoDataExchange(CDataExchange* pDX);
  655.  
  656. public:
  657.     int32 m_iNumMsg;
  658.     int m_iDownloadSome;
  659.     int32 m_iDownloadMax;
  660.     int m_iMarkRead;
  661.  
  662.     CNewsDownloadDialog( MWContext *pXPCX, int32 iNumMsg);
  663.  
  664. protected:
  665.     afx_msg void OnRadioClicked();
  666.     afx_msg void OnEditFocus();
  667.     DECLARE_MESSAGE_MAP();
  668. };
  669.  
  670. void CNewsDownloadDialog::DoDataExchange(CDataExchange* pDX)
  671. {
  672.     CDialog::DoDataExchange(pDX);
  673.  
  674.     DDX_Radio(pDX, IDC_RADIO1, m_iDownloadSome);
  675.     DDX_Text(pDX, IDC_EDIT1, m_iDownloadMax);
  676.     DDX_Check(pDX, IDC_CHECK1, m_iMarkRead);
  677. }
  678.  
  679. BOOL CNewsDownloadDialog::OnInitDialog()
  680. {
  681.     CDialog::OnInitDialog();
  682.  
  683.     CWnd *widget = GetDlgItem(IDC_STATIC1);
  684.  
  685.     CString cs;
  686.     cs.Format(szLoadString(IDS_MSGSTODOWNLOAD),
  687.               (long int) m_iNumMsg );
  688.     widget->SetWindowText(cs);
  689.  
  690.     widget = GetDlgItem( IDC_CHECK1 );
  691.     widget->EnableWindow( m_iDownloadSome );
  692.     return TRUE;
  693. }
  694.  
  695. CNewsDownloadDialog::CNewsDownloadDialog( MWContext *pXPCX, int32 iNumMsg ):
  696.     CDialog( IDD, ABSTRACTCX(pXPCX)->GetDialogOwner() )
  697. {
  698.     m_iNumMsg = iNumMsg;
  699.  
  700.     m_iDownloadMax = 0;
  701.     PREF_GetIntPref("news.max_articles", &m_iDownloadMax);
  702.  
  703.     m_iDownloadSome = 0;
  704.  
  705.     XP_Bool bMarkRead = FALSE;
  706.     PREF_GetBoolPref( "news.mark_old_read", &bMarkRead );
  707.     m_iMarkRead = bMarkRead ? 1 : 0;
  708. }
  709.  
  710. BEGIN_MESSAGE_MAP(CNewsDownloadDialog, CDialog)
  711.     ON_BN_CLICKED(IDC_RADIO1, OnRadioClicked)
  712.     ON_BN_CLICKED(IDC_RADIO2, OnRadioClicked)
  713.     ON_EN_SETFOCUS(IDC_EDIT1, OnEditFocus)
  714. END_MESSAGE_MAP()
  715.  
  716. void CNewsDownloadDialog::OnRadioClicked()
  717. {
  718.     UpdateData(TRUE);
  719.  
  720.     CWnd *widget = GetDlgItem( IDC_CHECK1 );
  721.     widget->EnableWindow( m_iDownloadSome );
  722. }
  723.  
  724. void CNewsDownloadDialog::OnEditFocus()
  725. {
  726.     CheckRadioButton(IDC_RADIO1, IDC_RADIO2, IDC_RADIO2);
  727.     OnRadioClicked();
  728. }
  729.  
  730. extern "C" XP_Bool FE_NewsDownloadPrompt( MWContext *context,
  731.                                           int32 numMessagesToDownload, 
  732.                                           XP_Bool *downloadAll)
  733. {
  734.     CNewsDownloadDialog dlg(context, numMessagesToDownload);
  735.  
  736.     if (dlg.DoModal() == IDOK ) {
  737.         if (dlg.m_iDownloadSome) {
  738.             *downloadAll = FALSE;
  739.             PREF_SetIntPref("news.max_articles", dlg.m_iDownloadMax);
  740.             PREF_SetBoolPref("news.mark_old_read", dlg.m_iMarkRead ? TRUE : FALSE);
  741.         } else {
  742.             *downloadAll = TRUE;
  743.         }
  744.         return TRUE;
  745.     } else {
  746.         return FALSE;
  747.     }
  748. }
  749.  
  750. extern "C" void FE_ListChangeStarting(MSG_Pane* pane, XP_Bool asynchronous,
  751.                                       MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  752.                                       int32 num)
  753. {
  754.     LPUNKNOWN pUnk = (LPUNKNOWN) MSG_GetFEData( pane );
  755.     if (pUnk) {
  756.         LPMSGLIST pInterface = NULL;
  757.         pUnk->QueryInterface( IID_IMsgList, (LPVOID *) &pInterface );
  758.         if ( pInterface ) {
  759.             pInterface->ListChangeStarting( pane, asynchronous, notify, where, num );
  760.             pInterface->Release();
  761.         }
  762.     }
  763. }
  764.  
  765. extern "C" void FE_ListChangeFinished(MSG_Pane* pane, XP_Bool asynchronous,
  766.                                       MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  767.                                       int32 num)
  768. {
  769.     LPUNKNOWN pUnk = (LPUNKNOWN) MSG_GetFEData( pane );
  770.     if (pUnk) {
  771.         LPMSGLIST pInterface = NULL;
  772.         pUnk->QueryInterface( IID_IMsgList, (LPVOID *) &pInterface );
  773.         if ( pInterface ) {
  774.             pInterface->ListChangeFinished( pane, asynchronous, notify, where, num );
  775.             pInterface->Release();
  776.         }
  777.     }
  778. }
  779.  
  780. extern "C" void FE_PaneChanged( MSG_Pane *pane, XP_Bool asynchronous, 
  781.                                 MSG_PANE_CHANGED_NOTIFY_CODE notify, int32 value)
  782. {
  783.     LPUNKNOWN pUnk = (LPUNKNOWN) MSG_GetFEData( pane );
  784.     if (pUnk) {
  785.         LPMAILFRAME pInterface = NULL;
  786.         pUnk->QueryInterface( IID_IMailFrame, (LPVOID *) &pInterface );
  787.         ASSERT( pInterface );
  788.         if ( pInterface ) {
  789.             pInterface->PaneChanged( pane, asynchronous, notify, value );
  790.             pInterface->Release();
  791.         }
  792.     }
  793. }
  794.  
  795. extern "C" XP_Bool FE_IsAltMailUsed(MWContext *pContext)
  796. {
  797.     return theApp.m_hPostalLib ? TRUE : FALSE;
  798. }
  799.  
  800. #endif // MOZ_MAIL_NEWS
  801.  
  802.  
  803. #ifdef _WIN32
  804.  
  805. // these are the registry functions that are used to communicate and store 
  806. // stuff in the registry for the stand-alone biff
  807. static const char szMasterKey[] = "Software\\Netscape\\Netscape Navigator\\%s";
  808. static const char szMasterKeyBiff[] = "Software\\Netscape\\Netscape Navigator\\biff";
  809. static const char szUserKey[] = "Software\\Netscape\\Netscape Navigator\\Users";
  810. static const char szCurrentUser[] = "CurrentUser";
  811.  
  812. BOOL GetConfigInfoStr(LPCSTR pSection, LPCSTR pKey, LPSTR pBuf, int lenBuf, HKEY hMasterKey);
  813. HKEY RegCreateParent(LPCSTR pSection, HKEY hMasterKey);
  814. BOOL SetConfigInfoNum(LPCSTR pSection, LPCSTR pKey, uint32 num, HKEY hMasterKey);
  815.  
  816. HKEY RegOpenParent(LPCSTR pSection, HKEY hRootKey)
  817. {
  818.     char buf[128];
  819.     HKEY hKey;
  820.     if (strchr(pSection, '\\'))
  821.     {
  822.         lstrcpy(buf, pSection);
  823.     }
  824.     else
  825.     {
  826.         wsprintf(buf, szMasterKey, pSection);
  827.     }
  828.     if (RegOpenKeyEx(hRootKey, buf, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  829.     {
  830.         return(NULL);
  831.     }
  832.     return(hKey);
  833. }
  834.  
  835. BOOL SetBiffInfoNum(LPCSTR pKey, uint32 num)
  836. {
  837.     char userName[512];
  838.     char temp[512];
  839.     if (GetConfigInfoStr(szUserKey, szCurrentUser, userName, sizeof(userName), HKEY_LOCAL_MACHINE))
  840.     {
  841.         wsprintf(temp, "%s\\%s\\biff", szUserKey, userName);
  842.         return(SetConfigInfoNum(temp, pKey, num, HKEY_LOCAL_MACHINE));
  843.     }
  844.     // if the user isn't there, then store it in the global biff location
  845.     return(SetConfigInfoNum(szMasterKeyBiff, pKey, num, HKEY_CURRENT_USER));
  846. }
  847.  
  848. BOOL GetConfigInfoStr(LPCSTR pSection, LPCSTR pKey, LPSTR pBuf, int lenBuf, HKEY hMasterKey)
  849. {
  850.     HKEY hKey;
  851.     hKey = RegOpenParent(pSection, hMasterKey);
  852.     if (!hKey)
  853.     {
  854.         return(FALSE);
  855.     }
  856.  
  857.     uint32 len = (uint32)lenBuf;
  858.     BOOL retVal = (RegQueryValueEx(hKey, pKey, NULL, NULL, (LPBYTE)pBuf, &len) == ERROR_SUCCESS);
  859.     RegCloseKey(hKey);
  860.     return(retVal);
  861. }
  862.  
  863. HKEY RegCreateParent(LPCSTR pSection, HKEY hMasterKey)
  864. {
  865.     char buf[128];
  866.     HKEY hKey;
  867.     if (strchr(pSection, '\\'))
  868.     {
  869.         lstrcpy(buf, pSection);
  870.     }
  871.     else
  872.     {
  873.         wsprintf(buf, szMasterKey, pSection);
  874.     }
  875.     if (RegCreateKey(hMasterKey, buf, &hKey) != ERROR_SUCCESS)
  876.     {
  877.         return(NULL);
  878.     }
  879.     return(hKey);
  880. }
  881.  
  882. BOOL SetConfigInfoNum(LPCSTR pSection, LPCSTR pKey, uint32 num, HKEY hMasterKey)
  883. {
  884.     HKEY hKey;
  885.     hKey = RegCreateParent(pSection, hMasterKey);
  886.     if (!hKey)
  887.     {
  888.         return(FALSE);
  889.     }
  890.  
  891.     BOOL retVal = (RegSetValueEx(hKey, pKey, 0, REG_DWORD, (LPBYTE)&num, sizeof(num)) == ERROR_SUCCESS);
  892.     RegCloseKey(hKey);
  893.     return(retVal);
  894. }
  895.  
  896. #endif        // _WIN32
  897.  
  898.