Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
CMapiImp Class Reference

#include <msgMapiImp.h>

Inheritance diagram for CMapiImp:
Inheritance graph
[legend]
Collaboration diagram for CMapiImp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

STDMETHODIMP QueryInterface (const IID &aIid, void **aPpv)
 STDMETHODIMP_ (ULONG) AddRef()
 STDMETHODIMP_ (ULONG) Release()
STDMETHODIMP Login (unsigned long aUIArg, LOGIN_PW_TYPE aLogin, LOGIN_PW_TYPE aPassWord, unsigned long aFlags, unsigned long *aSessionId)
STDMETHODIMP SendMail (unsigned long aSession, lpnsMapiMessage aMessage, short aRecipCount, lpnsMapiRecipDesc aRecips, short aFileCount, lpnsMapiFileDesc aFiles, unsigned long aFlags, unsigned long aReserved)
STDMETHODIMP SendDocuments (unsigned long aSession, LPTSTR aDelimChar, LPTSTR aFilePaths, LPTSTR aFileNames, ULONG aFlags)
STDMETHODIMP FindNext (unsigned long aSession, unsigned long ulUIParam, LPTSTR lpszMessageType, LPTSTR lpszSeedMessageID, unsigned long flFlags, unsigned long ulReserved, unsigned char lpszMessageID[64])
STDMETHODIMP ReadMail (unsigned long lhSession, unsigned long ulUIParam, LPTSTR lpszMessageID, unsigned long flFlags, unsigned long ulReserved, lpnsMapiMessage *lppMessage)
STDMETHODIMP DeleteMail (unsigned long lhSession, unsigned long ulUIParam, LPTSTR lpszMessageID, unsigned long flFlags, unsigned long ulReserved)
STDMETHODIMP SaveMail (unsigned long lhSession, unsigned long ulUIParam, lpnsMapiMessage lppMessage, unsigned long flFlags, unsigned long ulReserved, LPTSTR lpszMessageID)
STDMETHODIMP Initialize ()
STDMETHODIMP IsValid ()
STDMETHODIMP IsValidSession (unsigned long aSession)
STDMETHODIMP Logoff (unsigned long aSession)
STDMETHODIMP CleanUp ()
 CMapiImp ()
 ~CMapiImp ()
LONG InitContext (unsigned long session, MsgMapiListContext **listContext)
nsresult GetDefaultInbox (nsIMsgFolder **inboxFolder)
HRESULT FindNext ([in] unsigned long aSession,[in] ULONG ulUIParam,[in] LPTSTR lpszMessageType,[in] LPTSTR lpszSeedMessageID,[in] ULONG flFlags,[in] ULONG ulReserved,[in][out] char lpszMessageID[64])
HRESULT ReadMail ([in] unsigned long lhSession,[in] ULONG ulUIParam,[in] LPTSTR lpszMessageID,[in] ULONG flFlags,[in] ULONG ulReserved,[out] lpnsMapiMessage *lppMessage)
HRESULT DeleteMail ([in] unsigned long lhSession,[in] ULONG ulUIParam,[in] LPTSTR lpszMessageID,[in] ULONG flFlags,[in] ULONG ulReserved)
HRESULT SaveMail ([in] unsigned long lhSession,[in] ULONG ulUIParam,[in] lpnsMapiMessage lppMessage,[in] ULONG flFlags,[in] ULONG ulReserved,[in] LPTSTR lpszMessageID)
virtual long QueryInterface ()=0
virtual long AddRef ()=0
virtual long Release ()=0

Private Attributes

PRLockm_Lock
PRInt32 m_cRef

Detailed Description

Definition at line 54 of file msgMapiImp.h.


Constructor & Destructor Documentation

Definition at line 77 of file msgMapiImp.cpp.

: m_cRef(1)
{
    m_Lock = PR_NewLock();
  if (!MAPI)
    MAPI = PR_NewLogModule("MAPI");
}

Here is the call graph for this function:

Definition at line 85 of file msgMapiImp.cpp.

Here is the call graph for this function:


Member Function Documentation

virtual long IUnknown::AddRef ( ) [pure virtual, inherited]

Here is the caller graph for this function:

STDMETHODIMP CMapiImp::CleanUp ( void  )

Implements nsIMapi.

Definition at line 517 of file msgMapiImp.cpp.

{
    nsMapiHook::CleanUp();
    return S_OK;
}
STDMETHODIMP CMapiImp::DeleteMail ( unsigned long  lhSession,
unsigned long  ulUIParam,
LPTSTR  lpszMessageID,
unsigned long  flFlags,
unsigned long  ulReserved 
)

Definition at line 481 of file msgMapiImp.cpp.

{
  PRInt32 irv;
  nsCAutoString keyString((char *) lpszMessageID);
  nsMsgKey msgKey = keyString.ToInteger(&irv);
  if (irv)
    return SUCCESS_SUCCESS;
  MsgMapiListContext *listContext;
  LONG ret = InitContext(aSession, &listContext);
  if (ret != SUCCESS_SUCCESS)
    return ret;
  return (listContext->DeleteMessage(msgKey)) ? SUCCESS_SUCCESS : MAPI_E_INVALID_MESSAGE;
}

Here is the call graph for this function:

HRESULT nsIMapi::DeleteMail ( [in] unsigned long  lhSession,
[in] ULONG  ulUIParam,
[in] LPTSTR  lpszMessageID,
[in] ULONG  flFlags,
[in] ULONG  ulReserved 
) [inherited]

Here is the caller graph for this function:

STDMETHODIMP CMapiImp::FindNext ( unsigned long  aSession,
unsigned long  ulUIParam,
LPTSTR  lpszMessageType,
LPTSTR  lpszSeedMessageID,
unsigned long  flFlags,
unsigned long  ulReserved,
unsigned char  lpszMessageID[64] 
)

Definition at line 410 of file msgMapiImp.cpp.

{
  //
  // If this is true, then this is the first call to this FindNext function
  // and we should start the enumeration operation.
  //

  *lpszMessageID = '\0';
  nsMAPIConfiguration * pMapiConfig = nsMAPIConfiguration::GetMAPIConfiguration() ;
  if (!pMapiConfig) 
  {
    NS_ASSERTION(PR_FALSE, "failed to get config in findnext");
    return NS_ERROR_FAILURE ;  // get the singelton obj
  }
  MsgMapiListContext *listContext;
  LONG ret = InitContext(aSession, &listContext);
  if (ret != SUCCESS_SUCCESS)
  {
    NS_ASSERTION(PR_FALSE, "init context failed");
    return ret;
  }
  NS_ASSERTION(listContext, "initContext returned null context");
  if (listContext)
  {
//    NS_ASSERTION(PR_FALSE, "find next init context succeeded");
    nsMsgKey nextKey = listContext->GetNext();
    if (nextKey == nsMsgKey_None)
    {
      pMapiConfig->SetMapiListContext(aSession, NULL);
      delete listContext;
      return(MAPI_E_NO_MESSAGES);
    }

//    TRACE("MAPI: ProcessMAPIFindNext() Found message id = %d\n", nextKey);

    sprintf((char *) lpszMessageID, "%d", nextKey);
  }

  PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::FindNext returning key %s\n", (char *) lpszMessageID));
  return(SUCCESS_SUCCESS);
}

Here is the call graph for this function:

HRESULT nsIMapi::FindNext ( [in] unsigned long  aSession,
[in] ULONG  ulUIParam,
[in] LPTSTR  lpszMessageType,
[in] LPTSTR  lpszSeedMessageID,
[in] ULONG  flFlags,
[in] ULONG  ulReserved,
[out] char  lpszMessageID[64] 
) [inherited]

Here is the caller graph for this function:

Definition at line 299 of file msgMapiImp.cpp.

{
  // get default account
  nsresult rv;
  nsCOMPtr <nsIMsgAccountManager> accountManager = 
    do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); 
  NS_ENSURE_SUCCESS(rv,rv);

  nsCOMPtr <nsIMsgAccount> account;
  rv = accountManager->GetDefaultAccount(getter_AddRefs(account));
  NS_ENSURE_SUCCESS(rv,rv);

  // get incoming server
  nsCOMPtr <nsIMsgIncomingServer> server;
  rv = account->GetIncomingServer(getter_AddRefs(server));
  NS_ENSURE_SUCCESS(rv,rv);

  nsXPIDLCString type;
  rv = server->GetType(getter_Copies(type));
  NS_ENSURE_SUCCESS(rv,rv);

  // we only care about imap and pop3
  if (!(nsCRT::strcmp(type.get(), "imap")) ||
      !(nsCRT::strcmp(type.get(), "pop3"))) 
  {
    // imap and pop3 account should have an Inbox
    nsCOMPtr<nsIMsgFolder> rootMsgFolder;
    rv = server->GetRootMsgFolder(getter_AddRefs(rootMsgFolder));
    NS_ENSURE_SUCCESS(rv,rv);
 
    if (!rootMsgFolder)
      return NS_ERROR_FAILURE;
 
    PRUint32 numFolders = 0;
    rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, inboxFolder);
    NS_ENSURE_SUCCESS(rv,rv);
 
    if (!*inboxFolder)
     return NS_ERROR_FAILURE;
 
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

LONG CMapiImp::InitContext ( unsigned long  session,
MsgMapiListContext **  listContext 
)

Definition at line 375 of file msgMapiImp.cpp.

{
  nsMAPIConfiguration * pMapiConfig = nsMAPIConfiguration::GetMAPIConfiguration() ;
  if (!pMapiConfig)
    return NS_ERROR_FAILURE ;  // get the singelton obj
  *listContext = (MsgMapiListContext *) pMapiConfig->GetMapiListContext(session);
  // This is the first message
  if (!*listContext)
  {
    nsCOMPtr <nsIMsgFolder> inboxFolder;
    nsresult rv = GetDefaultInbox(getter_AddRefs(inboxFolder));
    if (NS_FAILED(rv))
    {
      NS_ASSERTION(PR_FALSE, "in init context, no inbox");
      return(MAPI_E_NO_MESSAGES);
    }

    *listContext = new MsgMapiListContext;
    if (!*listContext)
      return MAPI_E_INSUFFICIENT_MEMORY;

    rv = (*listContext)->OpenDatabase(inboxFolder);
    if (NS_FAILED(rv))
    {
      pMapiConfig->SetMapiListContext(session, NULL);
      delete *listContext;
      NS_ASSERTION(PR_FALSE, "in init context, unable to open db");
      return MAPI_E_NO_MESSAGES;
    }
    else
      pMapiConfig->SetMapiListContext(session, *listContext);
  }
  return SUCCESS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

STDMETHODIMP CMapiImp::Initialize ( void  )

Implements nsIMapi.

Definition at line 143 of file msgMapiImp.cpp.

{
    HRESULT hr = E_FAIL;

    if (!m_Lock)
        return E_FAIL;

    PR_Lock(m_Lock);

    // Initialize MAPI Configuration

    nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
    if (pConfig != nsnull)
        if (nsMapiHook::Initialize())
            hr = S_OK;

    PR_Unlock(m_Lock);

    return hr;
}

Here is the call graph for this function:

STDMETHODIMP CMapiImp::IsValid ( )

Implements nsIMapi.

Definition at line 129 of file msgMapiImp.cpp.

{
    return S_OK;
}
STDMETHODIMP CMapiImp::IsValidSession ( unsigned long  aSession)

Implements nsIMapi.

Definition at line 134 of file msgMapiImp.cpp.

{
    nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
    if (pConfig && pConfig->IsSessionValid(aSession))
        return S_OK;

    return E_FAIL;
}

Here is the call graph for this function:

STDMETHODIMP CMapiImp::Login ( unsigned long  aUIArg,
LOGIN_PW_TYPE  aLogin,
LOGIN_PW_TYPE  aPassWord,
unsigned long  aFlags,
unsigned long aSessionId 
)

Implements nsIMapi.

Definition at line 164 of file msgMapiImp.cpp.

{
    HRESULT hr = E_FAIL;
     PRBool bNewSession = PR_FALSE;
    char *id_key = nsnull;

    PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::Login using flags %d\n", aFlags));
    if (aFlags & MAPI_NEW_SESSION)
        bNewSession = PR_TRUE;

    // Check For Profile Name
    if (aLogin != nsnull && aLogin[0] != '\0')
    {
        if (nsMapiHook::VerifyUserName(aLogin, &id_key) == PR_FALSE)
        {
            *aSessionId = MAPI_E_LOGIN_FAILURE;
            PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::Login failed for username %s\n", aLogin));
            NS_ASSERTION(PR_FALSE, "failed verifying user name");
            return hr;
        }
    }
    else
    {
      // get default account
      nsresult rv;
      nsCOMPtr <nsIMsgAccountManager> accountManager = 
        do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); 
      NS_ENSURE_SUCCESS(rv,MAPI_E_LOGIN_FAILURE);
      nsCOMPtr <nsIMsgAccount> account;
      nsCOMPtr <nsIMsgIdentity> identity;
       rv = accountManager->GetDefaultAccount(getter_AddRefs(account));
      NS_ENSURE_SUCCESS(rv,MAPI_E_LOGIN_FAILURE);
      account->GetDefaultIdentity(getter_AddRefs(identity));
      NS_ENSURE_SUCCESS(rv,MAPI_E_LOGIN_FAILURE);
      identity->GetKey(&id_key);

    }

    // finally register(create) the session.
    PRUint32 nSession_Id;
    PRInt16 nResult = 0;

    nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
    if (pConfig != nsnull)
        nResult = pConfig->RegisterSession(aUIArg, aLogin, aPassWord,
                                           (aFlags & MAPI_FORCE_DOWNLOAD), bNewSession,
                                           &nSession_Id, id_key);
    switch (nResult)
    {
        case -1 :
        {
            *aSessionId = MAPI_E_TOO_MANY_SESSIONS;
            return hr;
        }
        case 0 :
        {
            *aSessionId = MAPI_E_INSUFFICIENT_MEMORY;
            return hr;
        }
        default :
        {
            *aSessionId = nSession_Id;
            PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::Login succeeded\n"));
            break;
        }
    }

    return S_OK;
}

Here is the call graph for this function:

STDMETHODIMP CMapiImp::Logoff ( unsigned long  aSession)

Implements nsIMapi.

Definition at line 507 of file msgMapiImp.cpp.

{
    nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();

    if (pConfig->UnRegisterSession((PRUint32)aSession))
        return S_OK;

    return E_FAIL;
}

Here is the call graph for this function:

virtual long IUnknown::QueryInterface ( ) [pure virtual, inherited]

Here is the caller graph for this function:

STDMETHODIMP CMapiImp::QueryInterface ( const IID &  aIid,
void **  aPpv 
)

Definition at line 91 of file msgMapiImp.cpp.

{    
    if (aIid == IID_IUnknown)
    {
        *aPpv = static_cast<nsIMapi*>(this); 
    }
    else if (aIid == IID_nsIMapi)
    {
        *aPpv = static_cast<nsIMapi*>(this);
    }
    else
    {
        *aPpv = nsnull;
        return E_NOINTERFACE;
    }

    reinterpret_cast<IUnknown*>(*aPpv)->AddRef();
    return S_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

STDMETHODIMP CMapiImp::ReadMail ( unsigned long  lhSession,
unsigned long  ulUIParam,
LPTSTR  lpszMessageID,
unsigned long  flFlags,
unsigned long  ulReserved,
lpnsMapiMessage lppMessage 
)

Definition at line 455 of file msgMapiImp.cpp.

{
  PRInt32 irv;
  nsCAutoString keyString((char *) lpszMessageID);
  PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::ReadMail asking for key %s\n", (char *) lpszMessageID));
  nsMsgKey msgKey = keyString.ToInteger(&irv);
  if (irv)
  {
    NS_ASSERTION(PR_FALSE, "invalid lpszMessageID");
    return MAPI_E_INVALID_MESSAGE;
  }
  MsgMapiListContext *listContext;
  LONG ret = InitContext(aSession, &listContext);
  if (ret != SUCCESS_SUCCESS)
  {
    NS_ASSERTION(PR_FALSE, "init context failed in ReadMail");
    return ret;
  }
  *lppMessage = listContext->GetMessage (msgKey, flFlags);
  NS_ASSERTION(*lppMessage, "get message failed");

  return (*lppMessage) ? SUCCESS_SUCCESS : E_FAIL;
}

Here is the call graph for this function:

HRESULT nsIMapi::ReadMail ( [in] unsigned long  lhSession,
[in] ULONG  ulUIParam,
[in] LPTSTR  lpszMessageID,
[in] ULONG  flFlags,
[in] ULONG  ulReserved,
[out] lpnsMapiMessage lppMessage 
) [inherited]

Here is the caller graph for this function:

virtual long IUnknown::Release ( ) [pure virtual, inherited]

Here is the caller graph for this function:

STDMETHODIMP CMapiImp::SaveMail ( unsigned long  lhSession,
unsigned long  ulUIParam,
lpnsMapiMessage  lppMessage,
unsigned long  flFlags,
unsigned long  ulReserved,
LPTSTR  lpszMessageID 
)

Definition at line 496 of file msgMapiImp.cpp.

{
  MsgMapiListContext *listContext;
  LONG ret = InitContext(aSession, &listContext);
  if (ret != SUCCESS_SUCCESS)
    return ret;
  return S_OK;
}

Here is the call graph for this function:

HRESULT nsIMapi::SaveMail ( [in] unsigned long  lhSession,
[in] ULONG  ulUIParam,
[in] lpnsMapiMessage  lppMessage,
[in] ULONG  flFlags,
[in] ULONG  ulReserved,
[in] LPTSTR  lpszMessageID 
) [inherited]
STDMETHODIMP CMapiImp::SendDocuments ( unsigned long  aSession,
LPTSTR  aDelimChar,
LPTSTR  aFilePaths,
LPTSTR  aFileNames,
ULONG  aFlags 
)

create nsIMsgCompFields obj and populate it

Implements nsIMapi.

Definition at line 276 of file msgMapiImp.cpp.

{
    nsresult rv = NS_OK ;

    PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::SendDocument using flags %d\n", aFlags));
    nsCOMPtr<nsIMsgCompFields> pCompFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv) ;
    if (NS_FAILED(rv) || (!pCompFields) ) return MAPI_E_INSUFFICIENT_MEMORY ;

    if (aFilePaths)
    {
        rv = nsMapiHook::PopulateCompFieldsForSendDocs(pCompFields, aFlags, aDelimChar, aFilePaths) ;
    }

    if (NS_SUCCEEDED (rv)) 
        rv = nsMapiHook::ShowComposerWindow(aSession, pCompFields);
    else
      PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::SendDocument error rv = %lx, paths = %s names = %s\n", rv, aFilePaths, aFileNames));

    return nsMAPIConfiguration::GetMAPIErrorFromNSError (rv) ;
}

Here is the call graph for this function:

STDMETHODIMP CMapiImp::SendMail ( unsigned long  aSession,
lpnsMapiMessage  aMessage,
short  aRecipCount,
lpnsMapiRecipDesc  aRecips,
short  aFileCount,
lpnsMapiFileDesc  aFiles,
unsigned long  aFlags,
unsigned long  aReserved 
)

create nsIMsgCompFields obj and populate it

Implements nsIMapi.

Definition at line 235 of file msgMapiImp.cpp.

{
    nsresult rv = NS_OK ;

    PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::SendMail using flags %d\n", aFlags));
    // Assign the pointers in the aMessage struct to the array of Recips and Files
    // recieved here from MS COM. These are used in BlindSendMail and ShowCompWin fns 
    aMessage->lpRecips = aRecips ;
    aMessage->lpFiles = aFiles ;

    PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::SendMail flags=%x subject: %s sender: %s\n", 
      aFlags, (char *) aMessage->lpszSubject, (aMessage->lpOriginator) ? aMessage->lpOriginator->lpszAddress : ""));

    nsCOMPtr<nsIMsgCompFields> pCompFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv) ;
    if (NS_FAILED(rv) || (!pCompFields) ) return MAPI_E_INSUFFICIENT_MEMORY ;

    if (aFlags & MAPI_UNICODE)
        rv = nsMapiHook::PopulateCompFields(aMessage, pCompFields) ;
    else
        rv = nsMapiHook::PopulateCompFieldsWithConversion(aMessage, pCompFields) ;
    
    if (NS_SUCCEEDED (rv))
    {
        // see flag to see if UI needs to be brought up
        if (!(aFlags & MAPI_DIALOG))
        {
            rv = nsMapiHook::BlindSendMail(aSession, pCompFields);
        }
        else
        {
            rv = nsMapiHook::ShowComposerWindow(aSession, pCompFields);
        }
    }
    
    return nsMAPIConfiguration::GetMAPIErrorFromNSError (rv) ;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 106 of file msgMapiImp.h.

Definition at line 105 of file msgMapiImp.h.


The documentation for this class was generated from the following files: