Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
MapiDll.cpp File Reference
#include <windows.h>
#include <tchar.h>
#include <mapidefs.h>
#include <mapi.h>
#include "msgMapi.h"
#include "msgMapiMain.h"

Go to the source code of this file.

Classes

struct  memTrackerType

Defines

#define MAX_RECIPS   100
#define MAX_FILES   100
#define MAX_NAME_LEN   256
#define MAX_PW_LEN   256
#define MAX_MSGINFO_LEN   512
#define MAX_POINTERS   32
#define MAPI_MESSAGE_TYPE   0
#define MAPI_RECIPIENT_TYPE   1

Functions

void SetPointerArray (LPVOID ptr, BYTE type)
BOOL WINAPI DllMain (HINSTANCE aInstance, DWORD aReason, LPVOID aReserved)
BOOL InitMozillaReference (nsIMapi **aRetValue)
ULONG FAR PASCAL MAPILogon (ULONG aUIParam, LPTSTR aProfileName, LPTSTR aPassword, FLAGS aFlags, ULONG aReserved, LPLHANDLE aSession)
ULONG FAR PASCAL MAPILogoff (LHANDLE aSession, ULONG aUIParam, FLAGS aFlags, ULONG aReserved)
ULONG FAR PASCAL MAPISendMail (LHANDLE lhSession, ULONG ulUIParam, nsMapiMessage *lpMessage, FLAGS flFlags, ULONG ulReserved)
ULONG FAR PASCAL MAPISendDocuments (ULONG ulUIParam, LPTSTR lpszDelimChar, LPTSTR lpszFilePaths, LPTSTR lpszFileNames, ULONG ulReserved)
ULONG FAR PASCAL MAPIFindNext (LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageType, LPTSTR lpszSeedMessageID, FLAGS flFlags, ULONG ulReserved, unsigned char lpszMessageID[64])
ULONG FAR PASCAL MAPIReadMail (LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID, FLAGS flFlags, ULONG ulReserved, nsMapiMessage **lppMessage)
ULONG FAR PASCAL MAPISaveMail (LHANDLE lhSession, ULONG ulUIParam, lpnsMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved, LPTSTR lpszMessageID)
ULONG FAR PASCAL MAPIDeleteMail (LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID, FLAGS flFlags, ULONG ulReserved)
ULONG FAR PASCAL MAPIAddress (LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszCaption, ULONG nEditFields, LPTSTR lpszLabels, ULONG nRecips, lpMapiRecipDesc lpRecips, FLAGS flFlags, ULONG ulReserved, LPULONG lpnNewRecips, lpMapiRecipDesc FAR *lppNewRecips)
ULONG FAR PASCAL MAPIDetails (LHANDLE lhSession, ULONG ulUIParam, lpMapiRecipDesc lpRecip, FLAGS flFlags, ULONG ulReserved)
ULONG FAR PASCAL MAPIResolveName (LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszName, FLAGS flFlags, ULONG ulReserved, lpMapiRecipDesc FAR *lppRecip)
void FreeMAPIRecipient (lpMapiRecipDesc pv)
void FreeMAPIMessage (lpMapiMessage pv)
ULONG FAR PASCAL MAPIFreeBuffer (LPVOID pv)
ULONG FAR PASCAL GetMapiDllVersion ()
void FreeMAPIFile (lpMapiFileDesc pv)

Variables

const CLSID CLSID_CMapiImp
const IID IID_nsIMapi
DWORD tId = 0
memTrackerType memArray [MAX_POINTERS]

Class Documentation

struct memTrackerType

Definition at line 66 of file MapiDll.cpp.

Class Members
LPVOID lpMem
UCHAR memType

Define Documentation

Definition at line 63 of file MapiDll.cpp.

Definition at line 64 of file MapiDll.cpp.

#define MAX_FILES   100

Definition at line 48 of file MapiDll.cpp.

Definition at line 53 of file MapiDll.cpp.

#define MAX_NAME_LEN   256

Definition at line 51 of file MapiDll.cpp.

#define MAX_POINTERS   32

Definition at line 54 of file MapiDll.cpp.

#define MAX_PW_LEN   256

Definition at line 52 of file MapiDll.cpp.

#define MAX_RECIPS   100

Definition at line 47 of file MapiDll.cpp.


Function Documentation

BOOL WINAPI DllMain ( HINSTANCE  aInstance,
DWORD  aReason,
LPVOID  aReserved 
)

Definition at line 95 of file MapiDll.cpp.

{
    switch (aReason)
    {
        case DLL_PROCESS_ATTACH : tId = TlsAlloc();
                                  if (tId == 0xFFFFFFFF)
                                      return FALSE;
                                  break;

        case DLL_PROCESS_DETACH : TlsFree(tId);
                                  break;
    }
    return TRUE;
}
void FreeMAPIFile ( lpMapiFileDesc  pv)

Definition at line 446 of file MapiDll.cpp.

{
  if (!pv)
    return;

  if (pv->lpszPathName != NULL)   
    free(pv->lpszPathName);

  if (pv->lpszFileName != NULL)   
    free(pv->lpszFileName);
}

Here is the caller graph for this function:

void FreeMAPIMessage ( lpMapiMessage  pv)

Definition at line 460 of file MapiDll.cpp.

{
  ULONG i;

  if (!pv)
    return;

  if (pv->lpszSubject != NULL)
    free(pv->lpszSubject);

  if (pv->lpszNoteText)
      free(pv->lpszNoteText);
  
  if (pv->lpszMessageType)
    free(pv->lpszMessageType);
  
  if (pv->lpszDateReceived)
    free(pv->lpszDateReceived);
  
  if (pv->lpszConversationID)
    free(pv->lpszConversationID);
  
  if (pv->lpOriginator)
    FreeMAPIRecipient(pv->lpOriginator);
  
  for (i=0; i<pv->nRecipCount; i++)
  {
    if (&(pv->lpRecips[i]) != NULL)
    {
      FreeMAPIRecipient(&(pv->lpRecips[i]));
    }
  }

  if (pv->lpRecips != NULL)
  {
    free(pv->lpRecips);
  }

  for (i=0; i<pv->nFileCount; i++)
  {
    if (&(pv->lpFiles[i]) != NULL)
    {
      FreeMAPIFile(&(pv->lpFiles[i]));
    }
  }

  if (pv->lpFiles != NULL)
  {
    free(pv->lpFiles);
  }
  
  free(pv);
  pv = NULL;
}

Here is the caller graph for this function:

void FreeMAPIRecipient ( lpMapiRecipDesc  pv)

Definition at line 516 of file MapiDll.cpp.

{
  if (!pv)
    return;

  if (pv->lpszName != NULL)   
    free(pv->lpszName);

  if (pv->lpszAddress != NULL)
    free(pv->lpszAddress);

  if (pv->lpEntryID != NULL)
    free(pv->lpEntryID);  
}

Here is the caller graph for this function:

Definition at line 440 of file MapiDll.cpp.

{
    return 94;
}

Here is the caller graph for this function:

BOOL InitMozillaReference ( nsIMapi **  aRetValue)

Definition at line 110 of file MapiDll.cpp.

{
    // Check whether this thread has a valid Interface
    // by looking into thread-specific-data variable

    *aRetValue = (nsIMapi *)TlsGetValue(tId);

    // Check whether the pointer actually resolves to
    // a valid method call; otherwise mozilla is not running

    if ((*aRetValue) && (*aRetValue)->IsValid() == S_OK)
         return TRUE;

    HRESULT hRes = ::CoInitialize(nsnull) ;

    hRes = ::CoCreateInstance(CLSID_CMapiImp, NULL, CLSCTX_LOCAL_SERVER,
                                         IID_nsIMapi, (LPVOID *)aRetValue);

    if (hRes == S_OK && (*aRetValue)->Initialize() == S_OK)
        if (TlsSetValue(tId, (LPVOID)(*aRetValue)))
            return TRUE;

    // Either CoCreate or TlsSetValue failed; so return FALSE

    if ((*aRetValue))
        (*aRetValue)->Release();

    ::CoUninitialize();
    return FALSE;
}

Here is the caller graph for this function:

ULONG FAR PASCAL MAPIAddress ( LHANDLE  lhSession,
ULONG  ulUIParam,
LPTSTR  lpszCaption,
ULONG  nEditFields,
LPTSTR  lpszLabels,
ULONG  nRecips,
lpMapiRecipDesc  lpRecips,
FLAGS  flFlags,
ULONG  ulReserved,
LPULONG  lpnNewRecips,
lpMapiRecipDesc FAR lppNewRecips 
)

Definition at line 388 of file MapiDll.cpp.

{
    return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPIDeleteMail ( LHANDLE  lhSession,
ULONG  ulUIParam,
LPTSTR  lpszMessageID,
FLAGS  flFlags,
ULONG  ulReserved 
)

Definition at line 373 of file MapiDll.cpp.

{
  nsIMapi *pNsMapi = NULL;

  if (lhSession == 0)
    return(MAPI_E_INVALID_SESSION);

  if (!InitMozillaReference(&pNsMapi))
      return MAPI_E_FAILURE;

  return pNsMapi->DeleteMail(lhSession, ulUIParam,
                              lpszMessageID, flFlags, ulReserved) ;
}

Here is the call graph for this function:

ULONG FAR PASCAL MAPIDetails ( LHANDLE  lhSession,
ULONG  ulUIParam,
lpMapiRecipDesc  lpRecip,
FLAGS  flFlags,
ULONG  ulReserved 
)

Definition at line 397 of file MapiDll.cpp.

{
    return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPIFindNext ( LHANDLE  lhSession,
ULONG  ulUIParam,
LPTSTR  lpszMessageType,
LPTSTR  lpszSeedMessageID,
FLAGS  flFlags,
ULONG  ulReserved,
unsigned char  lpszMessageID[64] 
)

Definition at line 316 of file MapiDll.cpp.

{
  nsIMapi *pNsMapi = NULL;

  if (!InitMozillaReference(&pNsMapi))
    return MAPI_E_FAILURE;

  if (lhSession == 0)
    return(MAPI_E_INVALID_SESSION);

  if (!lpszMessageType)
    lpszMessageType = L"";

  if (!lpszSeedMessageID)
    lpszSeedMessageID = L"";

  return pNsMapi->FindNext(lhSession, ulUIParam, lpszMessageType,
                              lpszSeedMessageID, flFlags, ulReserved,
                              lpszMessageID) ;


}

Here is the call graph for this function:

Definition at line 412 of file MapiDll.cpp.

{
  int   i;

  if (!pv)
       return(S_OK);

  for (i=0; i<MAX_POINTERS; i++)
  {
    if (pv == memArray[i].lpMem)
    {
      if (memArray[i].memType == MAPI_MESSAGE_TYPE)
      {
        FreeMAPIMessage((MapiMessage *)pv);
        memArray[i].lpMem = NULL;
      }
      else if (memArray[i].memType == MAPI_RECIPIENT_TYPE)
      {
        FreeMAPIRecipient((MapiRecipDesc *)pv);
        memArray[i].lpMem = NULL;
      }
    }
  }

  pv = NULL;
  return(S_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ULONG FAR PASCAL MAPILogoff ( LHANDLE  aSession,
ULONG  aUIParam,
FLAGS  aFlags,
ULONG  aReserved 
)

Definition at line 195 of file MapiDll.cpp.

{
    nsIMapi *pNsMapi = (nsIMapi *)TlsGetValue(tId);
    if (pNsMapi != NULL)
    {
        if (pNsMapi->Logoff((ULONG) aSession) == S_OK)
            pNsMapi->Release();
        pNsMapi = NULL;
    }

    TlsSetValue(tId, NULL);

    ::CoUninitialize();

    return SUCCESS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ULONG FAR PASCAL MAPILogon ( ULONG  aUIParam,
LPTSTR  aProfileName,
LPTSTR  aPassword,
FLAGS  aFlags,
ULONG  aReserved,
LPLHANDLE  aSession 
)

Definition at line 146 of file MapiDll.cpp.

{
    HRESULT hr = 0;
    ULONG nSessionId = 0;
    nsIMapi *pNsMapi = NULL;

    if (!InitMozillaReference(&pNsMapi))
        return MAPI_E_FAILURE;

    if (!(aFlags & MAPI_UNICODE))
    {
        // Need to convert the parameters to Unicode.

        char *pUserName = (char *) aProfileName;
        char *pPassWord = (char *) aPassword;

        TCHAR ProfileName[MAX_NAME_LEN] = {0};
        TCHAR PassWord[MAX_PW_LEN] = {0};

        if (pUserName != NULL)
        {
            if (!MultiByteToWideChar(CP_ACP, 0, pUserName, -1, ProfileName,
                                                            MAX_NAME_LEN))
                return MAPI_E_FAILURE;
        }

        if (pPassWord != NULL)
        {
            if (!MultiByteToWideChar(CP_ACP, 0, pPassWord, -1, PassWord,
                                                            MAX_NAME_LEN))
                return MAPI_E_FAILURE;
        }

        hr = pNsMapi->Login(aUIParam, ProfileName, PassWord, aFlags,
                                                        &nSessionId);
    }
    else
        hr = pNsMapi->Login(aUIParam, aProfileName, aPassword,
                                                aFlags, &nSessionId);
    if (hr == S_OK)
        (*aSession) = (LHANDLE) nSessionId;
    else
        return nSessionId;

    return SUCCESS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ULONG FAR PASCAL MAPIReadMail ( LHANDLE  lhSession,
ULONG  ulUIParam,
LPTSTR  lpszMessageID,
FLAGS  flFlags,
ULONG  ulReserved,
nsMapiMessage **  lppMessage 
)

Definition at line 342 of file MapiDll.cpp.

{
  nsIMapi *pNsMapi = NULL;

  if (!InitMozillaReference(&pNsMapi))
    return MAPI_E_FAILURE;

  if (lhSession == 0)
    return(MAPI_E_INVALID_SESSION);

  return pNsMapi->ReadMail(lhSession, ulUIParam,
                              lpszMessageID, flFlags, ulReserved,
                              lppMessage) ;

}

Here is the call graph for this function:

ULONG FAR PASCAL MAPIResolveName ( LHANDLE  lhSession,
ULONG  ulUIParam,
LPTSTR  lpszName,
FLAGS  flFlags,
ULONG  ulReserved,
lpMapiRecipDesc FAR lppRecip 
)

Definition at line 403 of file MapiDll.cpp.

{
    return MAPI_E_FAILURE;
}
ULONG FAR PASCAL MAPISaveMail ( LHANDLE  lhSession,
ULONG  ulUIParam,
lpnsMapiMessage  lpMessage,
FLAGS  flFlags,
ULONG  ulReserved,
LPTSTR  lpszMessageID 
)

Definition at line 359 of file MapiDll.cpp.

{
    nsIMapi *pNsMapi = NULL;

  if (lhSession == 0)
    return(MAPI_E_INVALID_SESSION);

  if (!InitMozillaReference(&pNsMapi))
      return MAPI_E_FAILURE;

  return MAPI_E_FAILURE;
}

Here is the call graph for this function:

ULONG FAR PASCAL MAPISendDocuments ( ULONG  ulUIParam,
LPTSTR  lpszDelimChar,
LPTSTR  lpszFilePaths,
LPTSTR  lpszFileNames,
ULONG  ulReserved 
)

Definition at line 293 of file MapiDll.cpp.

{
    LHANDLE lhSession ;
    nsIMapi *pNsMapi = NULL;

    if (!InitMozillaReference(&pNsMapi))
        return MAPI_E_FAILURE;

    unsigned long result = MAPILogon (ulUIParam, (LPTSTR) NULL, (LPTSTR) NULL, MAPI_LOGON_UI, 0, &lhSession) ;
    if (result != SUCCESS_SUCCESS)
        return MAPI_E_LOGIN_FAILURE ;

    HRESULT hr;

    hr = pNsMapi->SendDocuments(lhSession, (LPTSTR) lpszDelimChar, (LPTSTR) lpszFilePaths, 
                                    (LPTSTR) lpszFileNames, ulReserved) ;

    MAPILogoff (lhSession, ulUIParam, 0,0) ;

    return hr ;
}

Here is the call graph for this function:

ULONG FAR PASCAL MAPISendMail ( LHANDLE  lhSession,
ULONG  ulUIParam,
nsMapiMessage lpMessage,
FLAGS  flFlags,
ULONG  ulReserved 
)

Definition at line 213 of file MapiDll.cpp.

{
    HRESULT hr = 0;
    BOOL bTempSession = FALSE ;
    nsIMapi *pNsMapi = NULL;

    if (!InitMozillaReference(&pNsMapi))
        return MAPI_E_FAILURE;

    if (lpMessage->nRecipCount > MAX_RECIPS)
        return MAPI_E_TOO_MANY_RECIPIENTS ;

    if (lpMessage->nFileCount > MAX_FILES)
        return MAPI_E_TOO_MANY_FILES ;

    if ( (!(flFlags & MAPI_DIALOG)) && (lpMessage->lpRecips == NULL) )
        return MAPI_E_UNKNOWN_RECIPIENT ;

    if (!lhSession || pNsMapi->IsValidSession(lhSession) != S_OK)
    {
        FLAGS LoginFlag ;
        if ( (flFlags & MAPI_LOGON_UI) && (flFlags & MAPI_NEW_SESSION) )
            LoginFlag = MAPI_LOGON_UI | MAPI_NEW_SESSION ;
        else if (flFlags & MAPI_LOGON_UI) 
            LoginFlag = MAPI_LOGON_UI ;

        hr = MAPILogon (ulUIParam, (LPTSTR) NULL, (LPTSTR) NULL, LoginFlag, 0, &lhSession) ;
        if (hr != SUCCESS_SUCCESS)
            return MAPI_E_LOGIN_FAILURE ;
        bTempSession = TRUE ;
    }

    // we need to deal with null data passed in by MAPI clients, specially when MAPI_DIALOG is set.
    // The MS COM type lib code generated by MIDL for the MS COM interfaces checks for these parameters
    // to be non null, although null is a valid value for them here. 
    nsMapiRecipDesc * lpRecips ;
    nsMapiFileDesc * lpFiles ;

    nsMapiMessage Message ;
    memset (&Message, 0, sizeof (nsMapiMessage) ) ;
    nsMapiRecipDesc Recipient ;
    memset (&Recipient, 0, sizeof (nsMapiRecipDesc) );
    nsMapiFileDesc Files ;
    memset (&Files, 0, sizeof (nsMapiFileDesc) ) ;

    if(!lpMessage)
    {
       lpMessage = &Message ;
    }
    if(!lpMessage->lpRecips)
    {
        lpRecips = &Recipient ;
    }
    else
        lpRecips = lpMessage->lpRecips ;
    if(!lpMessage->lpFiles)
    {
        lpFiles = &Files ;
    }
    else
        lpFiles = lpMessage->lpFiles ;

    hr = pNsMapi->SendMail (lhSession, lpMessage, 
                            (short) lpMessage->nRecipCount, lpRecips,
                            (short) lpMessage->nFileCount, lpFiles,
                            flFlags, ulReserved);

    // we are seeing a problem when using Word, although we return success from the MAPI support
    // MS COM interface in mozilla, we are getting this error here. This is a temporary hack !!
    if (hr == 0x800703e6)
        hr = SUCCESS_SUCCESS;
    
    if (bTempSession)
        MAPILogoff (lhSession, ulUIParam, 0,0) ;

    return hr ; 
}

Here is the call graph for this function:

void SetPointerArray ( LPVOID  ptr,
BYTE  type 
)

Definition at line 79 of file MapiDll.cpp.

{
int i;
  
  for (i=0; i<MAX_POINTERS; i++)
  {
    if (memArray[i].lpMem == NULL)
    {
      memArray[i].lpMem = ptr;
      memArray[i].memType = type;
      break;
    }
  }
}

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {0x29f458be, 0x8866, 0x11d5,
                              {0xa3, 0xdd, 0x0, 0xb0, 0xd0, 0xf3, 0xba, 0xa7}}

Definition at line 56 of file MapiDll.cpp.

Initial value:
 {0x6EDCD38E,0x8861,0x11d5,
                        {0xA3,0xDD,0x00,0xB0,0xD0,0xF3,0xBA,0xA7}}

Definition at line 58 of file MapiDll.cpp.

Definition at line 73 of file MapiDll.cpp.

DWORD tId = 0

Definition at line 61 of file MapiDll.cpp.