home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / compmapi.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.7 KB  |  253 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. #include "stdafx.h"
  19. #include "allxpstr.h"
  20. #include "xpgetstr.h"
  21.  
  22. typedef struct {
  23.     char * pszTo;
  24.     char * pszSubject;
  25.     char * pszOrganization;
  26. } MAPI_HEADER_INFO;
  27.  
  28. static MAPI_HEADER_INFO _temp;
  29.  
  30. #ifdef XP_WIN32
  31. extern "C" int FE_LoadExchangeInfo(
  32.    MWContext * context,
  33.    char * pszTo, char * pszCc, char * pszBcc,
  34.    char * pszOrganization,
  35.    char * pszNewsgroups,
  36.    char * pszSubject);
  37. #endif
  38.  
  39. #define MAX_MAIL_SIZE 300000
  40. extern "C" void FE_DoneMailTo(PrintSetup * print) 
  41. {
  42.     ASSERT(print);
  43.  
  44.     MWContext * context = (MWContext *) print->carg;
  45.     CGenericFrame * pFrame = wfe_FrameFromXPContext(context);
  46.     ASSERT(pFrame);
  47.     fclose(print->out);    
  48.  
  49.     char * buffer;
  50.     buffer = (char *) malloc(MAX_MAIL_SIZE + 5);
  51.     FILE * fp = fopen(print->filename, "r");
  52.     int len = fread(buffer, 1, MAX_MAIL_SIZE + 5, fp);
  53.     buffer[len] = '\0';
  54.     fclose(fp);                        
  55.  
  56.  
  57.     if(theApp.m_hPostalLib) {
  58.  
  59.         if(theApp.m_bInitMapi) {
  60.             if(theApp.m_fnOpenMailSession) {
  61.                 POSTCODE status = (*theApp.m_fnOpenMailSession) (NULL, NULL);
  62.                 if(status == POST_OK) {
  63.                     theApp.m_bInitMapi = FALSE;
  64.                 }
  65.             }
  66.         }
  67.  
  68.         // create mail window with no quoting
  69.         if(theApp.m_fnComposeMailMessage)
  70.             (*theApp.m_fnComposeMailMessage) ((const char *) _temp.pszTo,
  71.                                               (const char *) "",  /* no refs field.  BAD! BUG! */
  72.                                               (const char *) _temp.pszOrganization,
  73.                                               (const char *) "", /* no URL */
  74.                                               (const char *) _temp.pszSubject, 
  75.                                               buffer,
  76.                                               (const char *) "",                                              
  77.                                               (const char *) "");
  78.  
  79.         if (strlen(_temp.pszTo))
  80.             free(_temp.pszTo);
  81.         if (strlen(_temp.pszSubject))
  82.             free(_temp.pszSubject);
  83.         if (strlen(_temp.pszOrganization))
  84.             free(_temp.pszOrganization);
  85.  
  86.         // get rid of the file and free the memory  
  87.         remove(print->filename);
  88.  
  89.         // XP_FREE(print->filename);
  90.         // print->filename = NULL;
  91.         XP_FREE(buffer);
  92.  
  93.         return;
  94.  
  95.     }
  96. }
  97.  
  98. extern "C" int FE_LoadExchangeInfo(
  99.    MWContext * context,
  100.    char * pszTo, char * pszCc, char * pszBcc,
  101.    char * pszOrganization,
  102.    char * pszNewsgroups,
  103.    char * pszSubject)
  104. {
  105.     _temp.pszTo = _temp.pszSubject = _temp.pszOrganization = "";
  106.     if(!context)
  107.         return(FALSE);
  108.  
  109.     if(!theApp.m_hPostalLib)
  110.         return(FALSE);
  111.  
  112.     History_entry * hist_ent = NULL;
  113.     if(context)
  114.         hist_ent = SHIST_GetCurrent(&(context->hist));
  115.  
  116.     CString csURL;
  117.     if(hist_ent)
  118.         csURL = hist_ent->address;
  119.     else
  120.         csURL = "";
  121.  
  122.     if (!pszSubject || !strlen(pszSubject))
  123.         pszSubject = (char *)(const char *)csURL;
  124.  
  125.     //Set hist_ent to NULL if context->title is "Message Composition"
  126.     //This is a nasty way of determining if we're in here in response
  127.     //to "Mail Doc" or "New Mail Message".
  128.     //Also, if there's To: field info present(pBar->m_pszTo) then 
  129.     //we know that it's a Mailto: and set hist_ent to NULL 
  130.     //Without this differentiation the code always sends the contents
  131.     //of the previously mailed document even when someone chooses
  132.     //"New Mail Message" or "Mailto:"
  133.    
  134.     if(!strcmp(XP_GetString(MK_MSG_MSG_COMPOSITION), context->title) || strlen(pszTo) )
  135.         hist_ent = NULL;
  136.  
  137.     // make sure there was a document loaded
  138.     if(!hist_ent) {
  139.  
  140.         if(theApp.m_bInitMapi) {
  141.             if(theApp.m_fnOpenMailSession) {
  142.                 POSTCODE status = (*theApp.m_fnOpenMailSession) (NULL, NULL);
  143.                 if(status == POST_OK) {
  144.                     theApp.m_bInitMapi = FALSE;
  145.                 }
  146.                 else {
  147.                     return(FALSE);
  148.                 }
  149.             }
  150.         }
  151.  
  152.         // create mail window with no quoting
  153.         if(theApp.m_fnComposeMailMessage)
  154.             (*theApp.m_fnComposeMailMessage) (
  155.                                     (const char *)pszTo,
  156.                                     (const char *) "",  /* no refs field.  BAD! BUG! */
  157.                                                (const char *)pszOrganization,
  158.                                     (const char *) "", /* no URL */
  159.                                     (const char *)pszSubject,
  160.                                     "",
  161.                                                (const char *)pszCc,                                              
  162.                                                (const char *)pszBcc);
  163.         return(TRUE);
  164.     }
  165.  
  166.     URL_Struct * URL_s = SHIST_CreateURLStructFromHistoryEntry(context, hist_ent);
  167.  
  168.     // Zero out the saved data
  169.     memset(&URL_s->savedData, 0, sizeof(URL_s->savedData));
  170.  
  171.     PrintSetup print;                                
  172.  
  173.     XL_InitializeTextSetup(&print);
  174.     print.width = 68; 
  175.     print.prefix = "";
  176.     print.eol = "\r\n";
  177.  
  178.     char * name = WH_TempName(xpTemporary, NULL);
  179.     if(!name) {
  180.         return(FALSE);
  181.     }
  182.  
  183.     print.out  = fopen(name, "w");
  184.     print.completion = (XL_CompletionRoutine) FE_DoneMailTo;
  185.     print.carg = context;
  186.     print.filename = name;
  187.     print.url = URL_s;
  188.  
  189.     if (pszSubject && strlen(pszSubject))
  190.         _temp.pszSubject = strdup(pszSubject);
  191.     if (pszTo && strlen(pszTo))
  192.         _temp.pszTo = strdup(pszTo);
  193.     if (pszOrganization && strlen(pszOrganization))
  194.         _temp.pszOrganization = strdup(pszOrganization);
  195.  
  196.     // leave pCompose window alive until completion routine
  197.     XL_TranslateText(context, URL_s, &print); 
  198.  
  199.     return(TRUE);
  200. }
  201.  
  202. void InitializeMapi(void)
  203. {
  204.    
  205. }
  206.  
  207. extern "C" void DoAltMailComposition(MWContext *pContext)
  208. {
  209.     if ( pContext ) 
  210.     {
  211.         FE_LoadExchangeInfo(
  212.             pContext,
  213.             "",
  214.             "",
  215.             "",
  216.             (char *)FE_UsersOrganization(),
  217.             "",
  218.             "");
  219.     }
  220. }
  221.  
  222. extern "C" void FE_AlternateCompose(
  223.     char * from, char * reply_to, char * to, char * cc, char * bcc,
  224.     char * fcc, char * newsgroups, char * followup_to,
  225.     char * organization, char * subject, char * references,
  226.     char * other_random_headers, char * priority,
  227.     char * attachment, char * newspost_url, char * body)
  228. {
  229.     if(theApp.m_bInitMapi) {
  230.         if(theApp.m_fnOpenMailSession) {
  231.             POSTCODE status = (*theApp.m_fnOpenMailSession) (NULL, NULL);
  232.             if(status == POST_OK) {
  233.                 theApp.m_bInitMapi = FALSE;
  234.             }
  235.             else
  236.                 return;
  237.         }
  238.     }
  239.  
  240.     // create mail window with no quoting
  241.     if(theApp.m_fnComposeMailMessage)
  242.         (*theApp.m_fnComposeMailMessage) (
  243.             (const char *)to, 
  244.             (const char *)references, 
  245.             (const char *)(organization ? organization : FE_UsersOrganization()), 
  246.             (const char *)"", 
  247.             (const char *)subject, 
  248.             (const char *)body,
  249.             (const char *)cc, 
  250.             (const char *)bcc );
  251. }
  252.  
  253.