home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / compfe.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  20.8 KB  |  630 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.  
  20. #include "stdafx.h"
  21. #include "template.h"
  22. #include "msgcom.h"
  23. #include "wfemsg.h"
  24. #include "compstd.h"
  25. #include "compbar.h"
  26. #include "compmisc.h"
  27. #include "compfrm.h"
  28. #include "edt.h"
  29. #include "edview.h"
  30. #include "intl_csi.h"
  31. #include "prefapi.h"
  32. #include "apiaddr.h"
  33. #include "postal.h"
  34. #include "mailmisc.h"
  35. #include "dlghtmrp.h"
  36. #include "dlghtmmq.h"
  37.  
  38. extern "C" {
  39. #include "xpgetstr.h"
  40. extern int MK_MSG_MSG_COMPOSITION;
  41. };
  42.  
  43.  
  44. extern "C" int FE_LoadExchangeInfo(MWContext * context);
  45. extern "C" MSG_Pane * DoAltMailComposition(MWContext *pOldContext, MSG_CompositionFields* fields); 
  46.  
  47. int WFE_InsertMessage(void *closure, const char * data);
  48.  
  49. extern "C" void FE_DestroyMailCompositionContext(MWContext *pContext)    
  50. {
  51.    CGenericFrame * pFrame = wfe_FrameFromXPContext(pContext);
  52.    if ( pFrame ) {
  53.        CComposeFrame * pCompose = (CComposeFrame *) pFrame;
  54.        if (pCompose->UseHtml())
  55.            EDT_SetDirtyFlag(pContext,FALSE);
  56.        else
  57.            pCompose->GetEditorParent()->m_bModified = FALSE;
  58.        pCompose->SetMsgPane(NULL);
  59.        if(pCompose) {
  60.             pCompose->PostMessage ( WM_CLOSE );
  61.        }
  62.    }
  63. }
  64.  
  65. extern "C" int FE_GetMessageBody(MSG_Pane *pPane, char **ppBody, uint32 *ulBodySize, MSG_FontCode **ppFontChanges)    
  66. {
  67.     ASSERT(pPane);
  68.    CComposeFrame * pCompose = (CComposeFrame *) MSG_GetFEData(pPane);
  69.     ASSERT(pCompose);
  70.     MWContext *pContext = pCompose->GetMainContext()->GetContext();
  71.     ASSERT(pContext);
  72.  
  73.     if (pCompose->UseHtml())
  74.     {
  75.         MSG_SetHTMLMarkup(pPane,TRUE);
  76.         *ppBody = NULL;
  77.         *ulBodySize = 0;
  78.  
  79.         if ( pCompose )
  80.         {                                
  81.             // Danger!!! This is not legal!!! We must change this to be a real XP_HUGE for win16.
  82.             // see bug #39756
  83.             EDT_SaveToBuffer(pContext,(XP_HUGE_CHAR_PTR*) ppBody);
  84.  
  85.             if ( !*ppBody)
  86.                 return 1;
  87.             else {
  88.                 size_t lsize;
  89.                 lsize = strlen(*ppBody);
  90.                 *ulBodySize = lsize;
  91.                 return lsize;
  92.             }
  93.         }
  94.         return 0;
  95.     }
  96.  
  97.         // new compose window code          
  98.         size_t lsize = 0; 
  99. #ifdef XP_WIN16        
  100.         unsigned int   textLength;    // Cannot use uint32/int32; the compiler won't
  101.                                           // generate the correct code. Use unsigned int, at least
  102.                                           // we could get over with the 32767 boundary. 
  103.         
  104.         // Although 16-bit CEdit::GetWindowTextLength returns int casting it to
  105.         // unsigned int we can still get the correct text length if the text length is
  106.         // greater than 32767        
  107.         textLength = (unsigned int) pCompose->GetEditor()->GetWindowTextLength();  
  108. #else
  109.         int32    textLength;
  110.         textLength = pCompose->GetEditor()->GetWindowTextLength();
  111. #endif                
  112.         if ( textLength >= 0 )
  113.         {    
  114.             char * tmp = (char *)XP_CALLOC(1,textLength+1);
  115.              ASSERT ( tmp );
  116.          pCompose->GetEditor()->GetWindowText(tmp, textLength+1);
  117.             if (pCompose->GetWrapLongLines())
  118.          {
  119.             int32 lineWidth = 72;
  120.  
  121.             PREF_GetIntPref("mailnews.wraplength", &lineWidth);
  122.             if (lineWidth < 10) lineWidth = 10;
  123.             if (lineWidth > 30000) lineWidth = 30000;
  124.  
  125.             *ppBody = (char *) XP_WordWrap(INTL_DefaultWinCharSetID(pContext), 
  126.                  (unsigned char *)tmp, lineWidth, 1 /* look for '>' */);
  127.             free(tmp);                                         
  128.            }
  129.            else
  130.            {
  131.                 /* Else, don't wrap it at all. */
  132.                 *ppBody = tmp;
  133.            }
  134.          if (ppBody && *ppBody)
  135.             for (const char *ptr = *ppBody; ptr && *ptr; ptr++)
  136.                 lsize++;
  137.         }
  138.    *ulBodySize = lsize;
  139.    return 0;
  140. }
  141.  
  142. //
  143. // Create a composition window
  144. //
  145. extern "C" void FE_InitializeMailCompositionContext(MSG_Pane *pComposePane,
  146.     const char *pFrom,
  147.     const char *pReplyTo,
  148.     const char *pTo,
  149.     const char *pCc,
  150.     const char *pBcc,
  151.     const char *pFcc,
  152.     const char *pNewsgroups,
  153.     const char *pFollowupTo,
  154.     const char *pSubject,
  155.     const char *pAttachment)
  156. {
  157.  
  158.     MSG_SetCompHeader(pComposePane, MSG_TO_HEADER_MASK, pTo);
  159.     MSG_SetCompHeader(pComposePane, MSG_FROM_HEADER_MASK, pFrom);
  160.     MSG_SetCompHeader(pComposePane, MSG_SUBJECT_HEADER_MASK, pSubject);
  161.     MSG_SetCompHeader(pComposePane, MSG_CC_HEADER_MASK, pCc);
  162.     MSG_SetCompHeader(pComposePane, MSG_BCC_HEADER_MASK, pBcc);
  163.     MSG_SetCompHeader(pComposePane, MSG_FCC_HEADER_MASK, pFcc);
  164.     MSG_SetCompHeader(pComposePane, MSG_REPLY_TO_HEADER_MASK, pReplyTo);
  165.     MSG_SetCompHeader(pComposePane, MSG_FOLLOWUP_TO_HEADER_MASK, pFollowupTo);
  166.     MSG_SetCompHeader(pComposePane, MSG_NEWSGROUPS_HEADER_MASK, pNewsgroups);
  167. }
  168.  
  169. MWContext * g_NastyContextSavingHack = NULL;
  170.  
  171. // create a new xpContext with type == MWContextMessageComposition
  172. extern "C" MSG_Pane *FE_CreateCompositionPane(MWContext *pOldContext,
  173.                                               MSG_CompositionFields* fields,
  174.                                               const char *pInitialText,
  175.                                               MSG_EditorType editorType)
  176. {   
  177.     if(!theApp.m_hPostalLib) { 
  178.     CGenericDoc * pDocument;
  179.  
  180.     // Don't allow a compose window to be created if the user hasn't 
  181.     // specified an email address
  182.     const char *real_addr = FE_UsersMailAddress();
  183.     if (MISC_ValidateReturnAddress(pOldContext, real_addr) < 0)
  184.         return NULL;
  185.  
  186.     XP_Bool htmlCompose;
  187.     PREF_GetBoolPref("mail.html_compose",&htmlCompose);
  188.  
  189.     if (editorType == MSG_HTML_EDITOR)
  190.       htmlCompose = TRUE;
  191.     else if (editorType == MSG_PLAINTEXT_EDITOR)
  192.       htmlCompose = FALSE;
  193.  
  194.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(pOldContext);
  195.     int16 win_csid = INTL_GetCSIWinCSID(csi);
  196.     if (!MSG_GetForcePlainText(fields) && htmlCompose)
  197.         pDocument = (CGenericDoc*)theApp.m_ComposeTemplate->OpenDocumentFile(NULL, win_csid);
  198.     else
  199.         pDocument = (CGenericDoc*)theApp.m_TextComposeTemplate->OpenDocumentFile(NULL, win_csid);
  200.     
  201.     g_NastyContextSavingHack = pOldContext;
  202.  
  203.     if ( pDocument )
  204.     {
  205.         CWinCX * pContext = (CWinCX*) pDocument->GetContext();
  206.         if ( pContext ) {
  207.  
  208.             MSG_CompositionPaneCallbacks Callbacks;
  209.             Callbacks.CreateRecipientsDialog= CreateRecipientsDialog;
  210.             Callbacks.CreateAskHTMLDialog= CreateAskHTMLDialog;
  211.  
  212.             MWContext *context = pContext->GetContext();
  213.             CComposeFrame *pCompose = (CComposeFrame *) pContext->GetFrame()->GetFrameWnd();
  214.             pCompose->SetComposeStuff(pOldContext,fields); // squirl away stuff for post-create
  215.             // This needs to be set TRUE if using the old non-HTML text frame
  216.             //   to prevent dropping dragged URLs
  217.             pContext->m_bDragging = !pCompose->UseHtml();
  218.             if (!pCompose->UseHtml()) 
  219.             {
  220.                 pCompose->SetMsgPane(MSG_CreateCompositionPane(
  221.                     pContext->GetContext(), 
  222.                     pOldContext, g_MsgPrefs.m_pMsgPrefs, fields,
  223.                     WFE_MSGGetMaster()));
  224.             }
  225.             else                
  226.             {
  227.                 pCompose->SetMsgPane(MSG_CreateCompositionPaneNoInit(
  228.                     pContext->GetContext(), 
  229.                     g_MsgPrefs.m_pMsgPrefs,
  230.                 WFE_MSGGetMaster()));
  231.                 //set the callbacks for askHTML and Recipients dialogs
  232.                 MSG_SetCompositionPaneCallbacks( pCompose->GetMsgPane(),
  233.                                             &Callbacks,
  234.                                             0);
  235.  
  236.                 if (pCompose->GetMsgPane())
  237.                     MSG_SetHTMLMarkup(pCompose->GetMsgPane(), TRUE);
  238.             }
  239.             ASSERT(pCompose->GetMsgPane());
  240.             MSG_SetFEData(pCompose->GetMsgPane(),(void *)pCompose);
  241.             pCompose->UpdateAttachmentInfo();
  242.  
  243.             // Pass doccsid and win_csid info to new context for MailToWin conversion
  244.             INTL_CharSetInfo    old_csi = LO_GetDocumentCharacterSetInfo(pOldContext);
  245.             INTL_CharSetInfo    new_csi = LO_GetDocumentCharacterSetInfo(context);
  246.             int16 doccsid = INTL_GetCSIDocCSID(old_csi);
  247.  
  248.             INTL_SetCSIDocCSID(new_csi, 
  249.                 (doccsid ? doccsid : INTL_DefaultDocCharSetID(pOldContext)));
  250.  
  251.             INTL_SetCSIWinCSID(new_csi, 
  252.                 (win_csid ? win_csid : INTL_DocToWinCharSetID(INTL_GetCSIDocCSID(new_csi))));
  253.  
  254.             pCompose->DisplayHeaders(NULL);
  255.  
  256.          CComposeBar * pBar = pCompose->GetComposeBar();
  257.          ASSERT(pBar);
  258.          LPADDRESSCONTROL pIAddressList = pBar->GetAddressWidgetInterface();
  259.             
  260.             if (!pIAddressList->IsCreated()) 
  261.             {
  262.                 pBar->CreateAddressingBlock();
  263.             }
  264.  
  265.             if (!pCompose->UseHtml())
  266.             {
  267.                 pCompose->CompleteComposeInitialization();
  268.                 const char * pBody = pInitialText ? pInitialText : MSG_GetCompBody(pCompose->GetMsgPane());
  269.                 if (pBody)
  270.                 {
  271.                     FE_InsertMessageCompositionText(context,pBody,TRUE);
  272.                     // We don't want to quote the original if open as draft
  273.                     // Check for the editorType before we do the quoting
  274.                     // Since only draft code will specify what editor to
  275.                     // use, checking for editorType == MSG_DEFAULT will do
  276.                     // the work.
  277.                     if (MSG_ShouldAutoQuote(pCompose->GetMsgPane()) &&
  278.                                             editorType == MSG_DEFAULT)
  279.                     {
  280.                         pCompose->SetQuoteSelection();
  281.                         MSG_QuoteMessage(
  282.                             pCompose->GetMsgPane(),
  283.                                 WFE_InsertMessage,
  284.                                 (void*)pCompose->GetMainContext()->GetContext());
  285.                     }
  286.                 }
  287.             }
  288.             else
  289.             {
  290.                 pCompose->SetInitialText (pInitialText);
  291.                 URL_Struct * pUrl = NET_CreateURLStruct(EDT_NEW_DOC_URL,NET_DONT_RELOAD);
  292.                 if (pUrl != NULL)
  293.                 {
  294. //                    pUrl->pre_exit_fn = wfe_GoldDoneLoading;
  295.                     pContext->GetUrl(pUrl, FO_CACHE_AND_PRESENT);
  296.                     pContext->GetContext()->bIsComposeWindow = TRUE;
  297.                 }
  298.             }
  299.  
  300.          if (MSG_GetAttachmentList(pCompose->GetMsgPane()))
  301.             pCompose->SetModified(TRUE);
  302.          else
  303.             pCompose->SetModified(FALSE);
  304.  
  305.             // Post message to compose window to set the initial focus.
  306.             pCompose->PostMessage(WM_COMP_SET_INITIAL_FOCUS);
  307.             return pCompose->GetMsgPane();
  308.         }
  309.     }
  310.     return NULL;
  311.     } 
  312.     else 
  313.         return DoAltMailComposition(pOldContext, fields);
  314. }
  315.  
  316. extern "C" void FE_RaiseMailCompositionWindow(MSG_Pane *pPane)    
  317. {
  318.     CComposeFrame * pCompose = (CComposeFrame *) MSG_GetFEData(pPane);
  319.  
  320. #ifdef XP_WIN32
  321.     if(!theApp.m_hPostalLib) {
  322. #endif
  323.         pCompose->SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
  324.         pCompose->ShowWindow(SW_SHOW);
  325.         // Make Sure OnInitialUpdate gets called for the view.
  326.         pCompose->DisplayHeaders(pCompose->GetSavedHeaders());
  327. #ifdef XP_WIN32
  328.     }
  329.     else {
  330.         FE_LoadExchangeInfo(pCompose->GetMainContext()->GetContext());
  331.     }
  332. #endif
  333. }
  334.  
  335. extern "C" void FE_InsertMessageCompositionText(MWContext * context,
  336.                                     const char* text,
  337.                                     XP_Bool leaveCursorAtBeginning)
  338. {
  339.     if (context) {
  340.         if (ABSTRACTCX(context)->IsDestroyed())
  341.             return;
  342.            CGenericFrame * pFrame = wfe_FrameFromXPContext(context);
  343.         if (pFrame) 
  344.         {
  345.             CComposeFrame * pCompose = (CComposeFrame *) pFrame;
  346.             if ( pCompose )
  347.             {
  348.                 int nStartChar, nEndChar;
  349.                 if (!pCompose->UseHtml())
  350.                 {
  351.                     if ( leaveCursorAtBeginning ) 
  352.                         pCompose->GetEditor()->GetSel(nStartChar, nEndChar);
  353.                     pCompose->GetEditor()->ReplaceSel ( text );
  354.                     if ( leaveCursorAtBeginning ) 
  355.                         pCompose->GetEditor()->SetSel (nStartChar, nEndChar, TRUE );
  356.                 }
  357.                 else
  358.                 {
  359.                     ED_BufferOffset ins = -1;
  360.                     if ( leaveCursorAtBeginning ){
  361.                         ins = EDT_GetInsertPointOffset( context );
  362.                     }
  363.  
  364.                     EDT_PasteQuote( context, (char*) text );
  365.  
  366.                     if ( leaveCursorAtBeginning && ins != -1 ) {
  367.                         EDT_SetInsertPointToOffset( context, ins, 0 );
  368.                     }
  369.  
  370.                 }
  371.                 pCompose->GetChrome()->StopAnimation();
  372.             }
  373.         }
  374.     }
  375. }
  376.  
  377. extern "C" void FE_DoneWithMessageBody(MSG_Pane *pPane, char* body,
  378.                                    uint32 body_size)
  379. {
  380.     XP_FREE(body);
  381. }
  382.  
  383. extern "C" char * FE_PromptMessageSubject (MWContext * pContext)
  384. {
  385.     HWND hWnd = GetFocus();
  386.     CString csText;
  387.     CString csDefault;
  388.     csText.LoadString(IDS_COMPOSE_NOSUBJECT);
  389.     csDefault.LoadString(IDS_COMPOSE_DEFAULTNOSUBJECT);
  390.     char * ptr = CFE_Prompt(pContext, csText, csDefault );
  391.     SetFocus(hWnd);
  392.     if (!ptr)
  393.     {
  394.        CGenericFrame * pFrame = wfe_FrameFromXPContext(pContext);
  395.        CComposeFrame * pCompose = (CComposeFrame *) pFrame;
  396.        pCompose->GetChrome()->StopAnimation();
  397.     }
  398.     return ptr;
  399. }
  400.  
  401. #ifdef XP_WIN32
  402.  
  403. extern void FE_UpdateComposeWindowRecipients(MWContext *pContext,
  404.                                     char *pTo, char *pCc, char *pBcc)
  405. {
  406.    CGenericFrame * pFrame = wfe_FrameFromXPContext(pContext);
  407.    CComposeFrame * pCompose = (CComposeFrame *) pFrame;
  408.    if ( pCompose )
  409.    {
  410.       CComposeBar * pBar = pCompose->GetComposeBar();
  411.       ASSERT(pBar);
  412.       pBar->UpdateRecipientInfo (pTo, pCc, pBcc);
  413.    }
  414. }
  415.  
  416. #endif 
  417.  
  418.  
  419. extern "C" MSG_Pane * DoAltMailComposition(MWContext *pOldContext, MSG_CompositionFields* fields)
  420. {
  421.     CGenericDoc * pDocument;
  422.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(pOldContext);
  423.     pDocument = (CGenericDoc*)theApp.m_TextComposeTemplate->OpenDocumentFile(NULL, INTL_GetCSIWinCSID(csi));
  424.  
  425.     g_NastyContextSavingHack = pOldContext;
  426.  
  427.     if ( pDocument )
  428.     {
  429.         CWinCX * pContext = (CWinCX*) pDocument->GetContext();
  430.         if ( pContext ) 
  431.         {
  432.             MWContext *context = pContext->GetContext();
  433.             CComposeFrame *pCompose = (CComposeFrame *) pContext->GetFrame()->GetFrameWnd();
  434.             pCompose->SetComposeStuff(pOldContext,fields); // squirl away stuff for post-create
  435.  
  436.             pCompose->SetMsgPane(MSG_CreateCompositionPane(
  437.                 pContext->GetContext(), 
  438.                 pOldContext, g_MsgPrefs.m_pMsgPrefs, fields,
  439.                   WFE_MSGGetMaster()));
  440.             ASSERT(pCompose->GetMsgPane());
  441.             MSG_SetFEData(pCompose->GetMsgPane(),(void *)pCompose);
  442.  
  443.             pCompose->DisplayHeaders(NULL); 
  444.  
  445.             FE_LoadExchangeInfo(context);
  446.  
  447.             return pCompose->GetMsgPane();
  448.         }
  449.     }
  450.     return NULL;
  451. }
  452.  
  453. #define MAX_MAIL_SIZE 300000
  454. extern "C" void FE_DoneMailTo(PrintSetup * print) 
  455. {
  456.     ASSERT(print);
  457.  
  458.     MWContext * context = (MWContext *) print->carg;
  459.     
  460.     CGenericFrame * pFrame = wfe_FrameFromXPContext(context);
  461.     ASSERT(pFrame);
  462.  
  463.     CComposeFrame *  pCompose;
  464.     pCompose = (CComposeFrame *) pFrame;
  465.     ASSERT(pFrame);
  466.     
  467.     MSG_Pane * pMsgPane = pCompose->GetMsgPane();
  468.     ASSERT(pMsgPane);
  469.  
  470.     fclose(print->out);    
  471.  
  472.     //
  473.     // No no no, get the size the right way
  474.     //                            
  475.     char * buffer;
  476.     buffer = (char *) malloc(MAX_MAIL_SIZE + 5);
  477.     FILE * fp = fopen(print->filename, "r");
  478.     int len = fread(buffer, 1, MAX_MAIL_SIZE + 5, fp);
  479.     buffer[len] = '\0';
  480.     fclose(fp);                        
  481.  
  482.  
  483.     if(theApp.m_hPostalLib) {
  484.  
  485.         if(theApp.m_bInitMapi) {
  486.             if(theApp.m_fnOpenMailSession) {
  487.                 POSTCODE status = (*theApp.m_fnOpenMailSession) (NULL, NULL);
  488.                 if(status == POST_OK) {
  489.                     theApp.m_bInitMapi = FALSE;
  490.                 }
  491.                 else {
  492.                     FE_DestroyMailCompositionContext(context);
  493.                     return;
  494.                 }
  495.             }
  496.         }
  497.  
  498.         // create mail window with no quoting
  499.         if(theApp.m_fnComposeMailMessage)
  500.             (*theApp.m_fnComposeMailMessage) ((const char *) (const char *) MSG_GetCompHeader(pMsgPane, MSG_TO_HEADER_MASK),
  501.                                               (const char *) "",  /* no refs field.  BAD! BUG! */
  502.                                               (const char *) MSG_GetCompHeader(pMsgPane, MSG_ORGANIZATION_HEADER_MASK),
  503.                                               (const char *) "", /* no URL */
  504.                                               (const char *) MSG_GetCompHeader(pMsgPane, MSG_SUBJECT_HEADER_MASK), 
  505.                                               buffer,
  506.                                               (const char *) MSG_GetCompHeader(pMsgPane, MSG_CC_HEADER_MASK),                                              
  507.                                               (const char *) MSG_GetCompHeader(pMsgPane, MSG_BCC_HEADER_MASK));
  508.  
  509.         // get rid of the file and free the memory  
  510.         remove(print->filename);
  511.         // XP_FREE(print->filename);
  512.         // print->filename = NULL;
  513.         XP_FREE(buffer);
  514.  
  515.         FE_DestroyMailCompositionContext(context);
  516.         return;
  517.  
  518.     }
  519. }
  520.  
  521. extern "C" int FE_LoadExchangeInfo(MWContext * context)
  522. {
  523.     if(!context)
  524.         return(FALSE);
  525.  
  526.     if(!theApp.m_hPostalLib)
  527.         return(FALSE);
  528.  
  529.     CGenericFrame * pFrame = wfe_FrameFromXPContext(context);
  530.     ASSERT(pFrame);
  531.  
  532.     CComposeFrame *  pCompose;
  533.     pCompose = (CComposeFrame *) pFrame;
  534.     ASSERT(pFrame);
  535.     
  536.     MSG_Pane * pMsgPane = pCompose->GetMsgPane();
  537.     ASSERT(pMsgPane);
  538.  
  539.     History_entry * hist_ent = NULL;
  540.     if(g_NastyContextSavingHack)
  541.         hist_ent = SHIST_GetCurrent(&(g_NastyContextSavingHack->hist));
  542.  
  543.     CString csURL;
  544.     if(hist_ent)
  545.         csURL = hist_ent->address;
  546.     else
  547.         csURL = "";
  548.  
  549.     //Set hist_ent to NULL if context->title is "Message Composition"
  550.     //This is a nasty way of determining if we're in here in response
  551.     //to "Mail Doc" or "New Mail Message".
  552.     //Also, if there's To: field info present(pBar->m_pszTo) then 
  553.     //we know that it's a Mailto: and set hist_ent to NULL 
  554.     //Without this differentiation the code always sends the contents
  555.     //of the previously mailed document even when someone chooses
  556.     //"New Mail Message" or "Mailto:"
  557.     const char * pszTo = MSG_GetCompHeader(pMsgPane, MSG_TO_HEADER_MASK);
  558.     if(!strcmp(XP_GetString(MK_MSG_MSG_COMPOSITION), context->title) || strlen(pszTo) )
  559.         hist_ent = NULL;
  560.  
  561.     // make sure there was a document loaded
  562.     if(!hist_ent) {
  563.  
  564.         if(theApp.m_bInitMapi) {
  565.             if(theApp.m_fnOpenMailSession) {
  566.                 POSTCODE status = (*theApp.m_fnOpenMailSession) (NULL, NULL);
  567.                 if(status == POST_OK) {
  568.                     theApp.m_bInitMapi = FALSE;
  569.                 }
  570.                 else {
  571.                     FE_DestroyMailCompositionContext(context);
  572.                     return(FALSE);
  573.                 }
  574.             }
  575.         }
  576.  
  577.         // create mail window with no quoting
  578.         if(theApp.m_fnComposeMailMessage)
  579.             (*theApp.m_fnComposeMailMessage) ((const char *) MSG_GetCompHeader(pMsgPane, MSG_TO_HEADER_MASK),
  580.                                               (const char *) "",  /* no refs field.  BAD! BUG! */
  581.                                               (const char *) MSG_GetCompHeader(pMsgPane, MSG_ORGANIZATION_HEADER_MASK),
  582.                                               (const char *) "", /* no URL */
  583.                                               (const char *) MSG_GetCompHeader(pMsgPane, MSG_SUBJECT_HEADER_MASK),
  584.                                               "",
  585.                                               (const char *) MSG_GetCompHeader(pMsgPane, MSG_CC_HEADER_MASK),                                              
  586.                                               (const char *) MSG_GetCompHeader(pMsgPane, MSG_BCC_HEADER_MASK));
  587.  
  588.         FE_DestroyMailCompositionContext(context);
  589.         return(TRUE);
  590.     }
  591.  
  592.     URL_Struct * URL_s = SHIST_CreateURLStructFromHistoryEntry(g_NastyContextSavingHack, hist_ent);
  593.  
  594.     // Zero out the saved data
  595.     memset(&URL_s->savedData, 0, sizeof(URL_s->savedData));
  596.  
  597.     PrintSetup print;                                
  598.  
  599.     XL_InitializeTextSetup(&print);
  600.     print.width = 68; 
  601.     print.prefix = "";
  602.     print.eol = "\r\n";
  603.  
  604.     char * name = WH_TempName(xpTemporary, NULL);
  605.     if(!name) {
  606.         FE_DestroyMailCompositionContext(context);
  607.         return(FALSE);
  608.     }
  609.  
  610.     print.out  = fopen(name, "w");
  611.     print.completion = (XL_CompletionRoutine) FE_DoneMailTo;
  612.     print.carg = context;
  613.     print.filename = name;
  614.     print.url = URL_s;
  615.  
  616.     // leave pCompose window alive until completion routine
  617.     XL_TranslateText(g_NastyContextSavingHack, URL_s, &print); 
  618.  
  619.     return(TRUE);
  620. }
  621.  
  622. extern "C" void FE_SecurityOptionsChanged(MWContext * pContext)
  623. {
  624.    CGenericFrame * pFrame = wfe_FrameFromXPContext(pContext);
  625.    if ( pFrame ) {
  626.        CComposeFrame * pCompose = (CComposeFrame *) pFrame;
  627.        pCompose->UpdateSecurityOptions();
  628.    }
  629. }
  630.