Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes
nsMapiAddressBook Class Reference

#include <nsMapiAddressBook.h>

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

List of all members.

Public Member Functions

 nsMapiAddressBook (void)
virtual ~nsMapiAddressBook (void)
BOOL GetFolders (nsMapiEntryArray &aFolders)
BOOL GetCards (const nsMapiEntry &aParent, LPSRestriction aRestriction, nsMapiEntryArray &aCards)
BOOL GetNodes (const nsMapiEntry &aParent, nsMapiEntryArray &aNodes)
BOOL GetCardsCount (const nsMapiEntry &aParent, ULONG &aNbCards)
HRESULT LastError (void) const
BOOL GetPropertyString (const nsMapiEntry &aObject, ULONG aPropertyTag, nsCString &aValue)
BOOL GetPropertyUString (const nsMapiEntry &aObject, ULONG aPropertyTag, nsString &aValue)
BOOL GetPropertiesUString (const nsMapiEntry &aObject, const ULONG *aPropertiesTag, ULONG aNbProperties, nsStringArray &aValues)
BOOL GetPropertyDate (const nsMapiEntry &aObject, ULONG aPropertyTag, WORD &aYear, WORD &aMonth, WORD &aDay)
BOOL GetPropertyLong (const nsMapiEntry &aObject, ULONG aPropertyTag, ULONG &aValue)
BOOL GetPropertyBin (const nsMapiEntry &aObject, ULONG aPropertyTag, nsMapiEntry &aValue)
BOOL TestOpenEntry (const nsMapiEntry &aContainer, const nsMapiEntry &aEntry)
BOOL DeleteEntry (const nsMapiEntry &aContainer, const nsMapiEntry &aEntry)
BOOL SetPropertyUString (const nsMapiEntry &aObject, ULONG aPropertyTag, const PRUnichar *aValue)
BOOL SetPropertiesUString (const nsMapiEntry &aObject, const ULONG *aPropertiesTag, ULONG aNbProperties, nsXPIDLString *aValues)
BOOL SetPropertyDate (const nsMapiEntry &aObject, ULONG aPropertyTag, WORD aYear, WORD aMonth, WORD aDay)
BOOL CreateEntry (const nsMapiEntry &aParent, nsMapiEntry &aNewEntry)
BOOL CreateDistList (const nsMapiEntry &aParent, nsMapiEntry &aNewEntry)
BOOL CopyEntry (const nsMapiEntry &aContainer, const nsMapiEntry &aSource, nsMapiEntry &aTarget)
BOOL GetDefaultContainer (nsMapiEntry &aContainer)
BOOL IsOK (void) const

Protected Member Functions

BOOL Initialize (void)
virtual void AllocateBuffer (ULONG aByteCount, LPVOID *aBuffer)
virtual void FreeBuffer (LPVOID aBuffer)
BOOL GetContents (const nsMapiEntry &aParent, LPSRestriction aRestriction, nsMapiEntry **aList, ULONG &aNbElements, ULONG aMapiType)
BOOL GetMAPIProperties (const nsMapiEntry &aObject, const ULONG *aPropertyTags, ULONG aNbProperties, LPSPropValue &aValues, ULONG &aValueCount)
BOOL SetMAPIProperties (const nsMapiEntry &aObject, ULONG aNbProperties, const LPSPropValue &aValues)
void MyFreeProws (LPSRowSet aSet)

Static Protected Member Functions

static BOOL LoadMapiLibrary (void)
static void FreeMapiLibrary (void)

Protected Attributes

HRESULT mLastError
LPADRBOOK mAddressBook

Static Protected Attributes

static HMODULE mLibrary = NULL
static PRInt32 mLibUsage = 0
static LPMAPIINITIALIZE mMAPIInitialize = NULL
static LPMAPIUNINITIALIZE mMAPIUninitialize = NULL
static LPMAPIALLOCATEBUFFER mMAPIAllocateBuffer = NULL
static LPMAPIFREEBUFFER mMAPIFreeBuffer = NULL
static LPMAPILOGONEX mMAPILogonEx = NULL
static BOOL mInitialized = FALSE
static BOOL mLogonDone = FALSE
static LPMAPISESSION mRootSession = NULL
static LPADRBOOK mRootBook = NULL
static PRUint32 mEntryCounter = 0
static PRLockmMutex = PR_NewLock()

Detailed Description

Definition at line 43 of file nsMapiAddressBook.h.


Constructor & Destructor Documentation

Definition at line 144 of file nsMapiAddressBook.cpp.

: nsAbWinHelper()
{
    BOOL result = Initialize() ;

    NS_ASSERTION(result == TRUE, "Couldn't initialize Mapi Helper") ;
    MOZ_COUNT_CTOR(nsMapiAddressBook) ;
}

Here is the call graph for this function:

Definition at line 153 of file nsMapiAddressBook.cpp.

{
    nsAutoLock guard(mMutex) ;

    FreeMapiLibrary() ;
    MOZ_COUNT_DTOR(nsMapiAddressBook) ;
}

Here is the call graph for this function:


Member Function Documentation

void nsMapiAddressBook::AllocateBuffer ( ULONG  aByteCount,
LPVOID aBuffer 
) [protected, virtual]

Implements nsAbWinHelper.

Definition at line 174 of file nsMapiAddressBook.cpp.

{
    mMAPIAllocateBuffer(aByteCount, aBuffer) ;
}
BOOL nsAbWinHelper::CopyEntry ( const nsMapiEntry aContainer,
const nsMapiEntry aSource,
nsMapiEntry aTarget 
) [inherited]

Definition at line 770 of file nsAbWinHelper.cpp.

{
    nsMapiInterfaceWrapper<LPABCONT> container ;
    ULONG objType = 0 ;

    mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
                                         &IID_IABContainer, MAPI_MODIFY, &objType,
                                         container) ;
    if (HR_FAILED(mLastError)) { 
        PRINTF(("Cannot open container %08x.\n", mLastError)) ;
        return FALSE ;
    }
    nsMapiInterfaceWrapper<LPMAPIPROP> newEntry ;

    mLastError = container->CreateEntry(aSource.mByteCount, aSource.mEntryId,
                                        CREATE_CHECK_DUP_LOOSE, newEntry) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
        return FALSE ;
    }
    mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
        return FALSE ;
    }
    SPropTagArray property ;
    LPSPropValue value = NULL ;
    ULONG valueCount = 0 ;
    
    property.cValues = 1 ;
    property.aulPropTag [0] = PR_ENTRYID ;
    mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
    if (HR_FAILED(mLastError) || valueCount != 1) {
        PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
        return FALSE ;
    }
    aTarget.Assign(value->Value.bin.cb, 
                   NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
    FreeBuffer(value) ;
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::CreateDistList ( const nsMapiEntry aParent,
nsMapiEntry aNewEntry 
) [inherited]

Definition at line 706 of file nsAbWinHelper.cpp.

{
    nsMapiInterfaceWrapper<LPABCONT> container ;
    ULONG objType = 0 ;

    mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
                                         &IID_IABContainer, MAPI_MODIFY, &objType,
                                         container) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot open container %08x.\n", mLastError)) ;
        return FALSE ;
    }
    SPropTagArray property ;
    LPSPropValue value = NULL ;
    ULONG valueCount = 0 ;

    property.cValues = 1 ;
    property.aulPropTag [0] = PR_DEF_CREATE_DL ;
    mLastError = container->GetProps(&property, 0, &valueCount, &value) ;
    if (HR_FAILED(mLastError) || valueCount != 1) {
        PRINTF(("Cannot obtain template %08x.\n", mLastError)) ;
        return FALSE ;
    }
    nsMapiInterfaceWrapper<LPMAPIPROP> newEntry ;

    mLastError = container->CreateEntry(value->Value.bin.cb, 
                                        NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb),
                                        CREATE_CHECK_DUP_LOOSE,
                                        newEntry) ;
    FreeBuffer(value) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
        return FALSE ;
    }
    SPropValue displayName ;
    LPSPropProblemArray problems = NULL ;
    nsAutoString tempName ;

    displayName.ulPropTag = PR_DISPLAY_NAME_W ;
    tempName.AssignLiteral("__MailList__") ;
    tempName.AppendInt(mEntryCounter ++) ;
    displayName.Value.lpszW = NS_CONST_CAST(WCHAR *, tempName.get()) ;
    mLastError = newEntry->SetProps(1, &displayName, &problems) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot set temporary name %08x.\n", mLastError)) ;
        return FALSE ;
    }
    mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
        return FALSE ;
    }
    property.aulPropTag [0] = PR_ENTRYID ;
    mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
    if (HR_FAILED(mLastError) || valueCount != 1) {
        PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
        return FALSE ;
    }
    aNewEntry.Assign(value->Value.bin.cb, 
                     NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
    FreeBuffer(value) ;
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::CreateEntry ( const nsMapiEntry aParent,
nsMapiEntry aNewEntry 
) [inherited]

Definition at line 643 of file nsAbWinHelper.cpp.

{
    nsMapiInterfaceWrapper<LPABCONT> container ;
    ULONG objType = 0 ;

    mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
                                         &IID_IABContainer, MAPI_MODIFY, &objType,
                                         container) ;
    if (HR_FAILED(mLastError)) { 
        PRINTF(("Cannot open container %08x.\n", mLastError)) ;
        return FALSE ;
    }
    SPropTagArray property ;
    LPSPropValue value = NULL ;
    ULONG valueCount = 0 ;

    property.cValues = 1 ;
    property.aulPropTag [0] = PR_DEF_CREATE_MAILUSER ;
    mLastError = container->GetProps(&property, 0, &valueCount, &value) ;
    if (HR_FAILED(mLastError) || valueCount != 1) {
        PRINTF(("Cannot obtain template %08x.\n", mLastError)) ;
        return FALSE ;
    }
    nsMapiInterfaceWrapper<LPMAPIPROP> newEntry ;

    mLastError = container->CreateEntry(value->Value.bin.cb, 
                                        NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb),
                                        CREATE_CHECK_DUP_LOOSE,
                                        newEntry) ;
    FreeBuffer(value) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
        return FALSE ;
    }
    SPropValue displayName ;
    LPSPropProblemArray problems = NULL ;
    nsAutoString tempName ;

    displayName.ulPropTag = PR_DISPLAY_NAME_W ;
    tempName.AssignLiteral("__MailUser__") ;
    tempName.AppendInt(mEntryCounter ++) ;
    displayName.Value.lpszW = NS_CONST_CAST(WCHAR *, tempName.get()) ;
    mLastError = newEntry->SetProps(1, &displayName, &problems) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot set temporary name %08x.\n", mLastError)) ;
        return FALSE ;
    }
    mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
        return FALSE ;
    }
    property.aulPropTag [0] = PR_ENTRYID ;
    mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
    if (HR_FAILED(mLastError) || valueCount != 1) {
        PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
        return FALSE ;
    }
    aNewEntry.Assign(value->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
    FreeBuffer(value) ;
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::DeleteEntry ( const nsMapiEntry aContainer,
const nsMapiEntry aEntry 
) [inherited]

Definition at line 533 of file nsAbWinHelper.cpp.

{
    nsMapiInterfaceWrapper<LPABCONT> container ;
    ULONG objType = 0 ;
    SBinary entry ;
    SBinaryArray entryArray ;

    mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
                                         &IID_IABContainer, MAPI_MODIFY, &objType, 
                                         container) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot open container %08x.\n", mLastError)) ;
        return FALSE ;
    }
    entry.cb = aEntry.mByteCount ;
    entry.lpb = NS_REINTERPRET_CAST(LPBYTE, aEntry.mEntryId) ;
    entryArray.cValues = 1 ;
    entryArray.lpbin = &entry ;
    mLastError = container->DeleteEntries(&entryArray, 0) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot delete entry %08x.\n", mLastError)) ;
        return FALSE ;
    }
    return TRUE ;
}

Here is the caller graph for this function:

void nsMapiAddressBook::FreeBuffer ( LPVOID  aBuffer) [protected, virtual]

Implements nsAbWinHelper.

Definition at line 179 of file nsMapiAddressBook.cpp.

{
    mMAPIFreeBuffer(aBuffer) ;
}
void nsMapiAddressBook::FreeMapiLibrary ( void  ) [static, protected]

Definition at line 118 of file nsMapiAddressBook.cpp.

{
    if (mLibrary) {
        if (-- mLibUsage == 0) {
            {
                if (mRootBook) { mRootBook->Release() ; }
                if (mRootSession) {
                    if (mLogonDone) { 
                        mRootSession->Logoff(NULL, 0, 0) ; 
                        mLogonDone = FALSE ;
                    }
                    mRootSession->Release() ;
                }
                if (mInitialized) { 
                    mMAPIUninitialize() ; 
                    mInitialized = FALSE ;
                }
            }  
            FreeLibrary(mLibrary) ;
            mLibrary = NULL ; 
        }
    }
}

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetCards ( const nsMapiEntry aParent,
LPSRestriction  aRestriction,
nsMapiEntryArray aCards 
) [inherited]

Definition at line 360 of file nsAbWinHelper.cpp.

{
    aCards.CleanUp() ;
    return GetContents(aParent, aRestriction, &aCards.mEntries, aCards.mNbEntries, 0) ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetCardsCount ( const nsMapiEntry aParent,
ULONG aNbCards 
) [inherited]

Definition at line 373 of file nsAbWinHelper.cpp.

{
    aNbCards = 0 ;
    return GetContents(aParent, NULL, NULL, aNbCards, 0) ;
}

Here is the call graph for this function:

BOOL nsAbWinHelper::GetContents ( const nsMapiEntry aParent,
LPSRestriction  aRestriction,
nsMapiEntry **  aList,
ULONG aNbElements,
ULONG  aMapiType 
) [protected, inherited]

Definition at line 844 of file nsAbWinHelper.cpp.

{
    if (aList != NULL) { *aList = NULL ; }
    aNbElements = 0 ;
    nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
    nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
    ULONG objType = 0 ;
    ULONG rowCount = 0 ;

    mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId, 
                                         &IID_IMAPIContainer, 0, &objType, 
                                         parent) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
        return FALSE ; 
    }
    // Here, flags for WAB and MAPI could be different, so this works
    // only as long as we don't want to use any flag in GetContentsTable
    mLastError = parent->GetContentsTable(0, contents) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
        return FALSE ; 
    }
    if (aRestriction != NULL) {
        mLastError = contents->Restrict(aRestriction, 0) ;
        if (HR_FAILED(mLastError)) {
            PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
            return FALSE ;
        }
    }
    mLastError = contents->SetColumns((LPSPropTagArray) &ContentsColumns, 0) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
        return FALSE ;
    }
    mLastError = contents->GetRowCount(0, &rowCount) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
        return FALSE ;
    }
    if (aList != NULL) { *aList = new nsMapiEntry [rowCount] ; }
    aNbElements = 0 ;
    do {
        LPSRowSet rowSet = NULL ;
        
        rowCount = 0 ;
        mLastError = contents->QueryRows(1, 0, &rowSet) ;
        if (HR_FAILED(mLastError)) {
            PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
            return FALSE ;
        }
        rowCount = rowSet->cRows ;
        if (rowCount > 0 &&
            (aMapiType == 0 ||
            rowSet->aRow->lpProps[ContentsColumnObjectType].Value.ul == aMapiType)) {
            if (aList != NULL) {
                nsMapiEntry& current = (*aList) [aNbElements] ;
                SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
                
                current.Assign(currentValue.Value.bin.cb,
                    NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
            }
            ++ aNbElements ;
        }
        MyFreeProws(rowSet) ;
    } while (rowCount > 0) ;
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetDefaultContainer ( nsMapiEntry aContainer) [inherited]

Definition at line 813 of file nsAbWinHelper.cpp.

{
    LPENTRYID entryId = NULL ; 
    ULONG byteCount = 0 ;

    mLastError = mAddressBook->GetPAB(&byteCount, &entryId) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot get PAB %08x.\n", mLastError)) ;
        return FALSE ;
    }
    aContainer.Assign(byteCount, entryId) ;
    FreeBuffer(entryId) ;
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetFolders ( nsMapiEntryArray aFolders) [inherited]

Definition at line 294 of file nsAbWinHelper.cpp.

{
    aFolders.CleanUp() ;
    nsMapiInterfaceWrapper<LPABCONT> rootFolder ;
    nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
    ULONG objType = 0 ;
    ULONG rowCount = 0 ;
    SRestriction restriction ;
    SPropTagArray folderColumns ;

    mLastError = mAddressBook->OpenEntry(0, NULL, NULL, 0, &objType, 
                                         rootFolder) ;
    if (HR_FAILED(mLastError)) { 
        PRINTF(("Cannot open root %08x.\n", mLastError)) ;
        return FALSE ; 
    }
    mLastError = rootFolder->GetHierarchyTable(0, folders) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot get hierarchy %08x.\n", mLastError)) ;
        return FALSE ; 
    }
    // We only take into account modifiable containers, 
    // otherwise, we end up with all the directory services...
    restriction.rt = RES_BITMASK ;
    restriction.res.resBitMask.ulPropTag = PR_CONTAINER_FLAGS ;
    restriction.res.resBitMask.relBMR = BMR_NEZ ;
    restriction.res.resBitMask.ulMask = AB_MODIFIABLE ;
    mLastError = folders->Restrict(&restriction, 0) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot restrict table %08x.\n", mLastError)) ;
    }
    folderColumns.cValues = 1 ;
    folderColumns.aulPropTag [0] = PR_ENTRYID ;
    mLastError = folders->SetColumns(&folderColumns, 0) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
        return FALSE ;
    }
    mLastError = folders->GetRowCount(0, &rowCount) ;
    if (HR_SUCCEEDED(mLastError)) {
        aFolders.mEntries = new nsMapiEntry [rowCount] ;
        aFolders.mNbEntries = 0 ;
        do {
            LPSRowSet rowSet = NULL ;

            rowCount = 0 ;
            mLastError = folders->QueryRows(1, 0, &rowSet) ;
            if (HR_SUCCEEDED(mLastError)) {
                rowCount = rowSet->cRows ;
                if (rowCount > 0) {
                    nsMapiEntry& current = aFolders.mEntries [aFolders.mNbEntries ++] ;
                    SPropValue& currentValue = rowSet->aRow->lpProps [0] ;
                    
                    current.Assign(currentValue.Value.bin.cb,
                                   NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
                }
                MyFreeProws(rowSet) ;
            }
            else {
                PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
            }
        } while (rowCount > 0) ;
    }
    return HR_SUCCEEDED(mLastError) ;
}

Here is the call graph for this function:

BOOL nsAbWinHelper::GetMAPIProperties ( const nsMapiEntry aObject,
const ULONG aPropertyTags,
ULONG  aNbProperties,
LPSPropValue &  aValues,
ULONG aValueCount 
) [protected, inherited]

Definition at line 914 of file nsAbWinHelper.cpp.

{
    nsMapiInterfaceWrapper<LPMAPIPROP> object ;
    ULONG objType = 0 ;
    LPSPropTagArray properties = NULL ;
    ULONG i = 0 ;
    
    mLastError = mAddressBook->OpenEntry(aObject.mByteCount, aObject.mEntryId,
                                         &IID_IMAPIProp, 0, &objType, 
                                         object) ;
    if (HR_FAILED(mLastError)) { 
        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
        return FALSE ; 
    }
    AllocateBuffer(CbNewSPropTagArray(aNbProperties), 
                   NS_REINTERPRET_CAST(void **, &properties)) ;
    properties->cValues = aNbProperties ;
    for (i = 0 ; i < aNbProperties ; ++ i) {
        properties->aulPropTag [i] = aPropertyTags [i] ;
    }
    mLastError = object->GetProps(properties, 0, &aValueCount, &aValue) ;
    FreeBuffer(properties) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot get props %08x.\n", mLastError)) ;
    }
    return HR_SUCCEEDED(mLastError) ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetNodes ( const nsMapiEntry aParent,
nsMapiEntryArray aNodes 
) [inherited]

Definition at line 367 of file nsAbWinHelper.cpp.

{ 
    aNodes.CleanUp() ;
    return GetContents(aParent, NULL, &aNodes.mEntries, aNodes.mNbEntries, MAPI_DISTLIST) ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetPropertiesUString ( const nsMapiEntry aObject,
const ULONG aPropertiesTag,
ULONG  aNbProperties,
nsStringArray &  aValues 
) [inherited]

Definition at line 420 of file nsAbWinHelper.cpp.

{
    aNames.Clear() ;
    LPSPropValue values = NULL ;
    ULONG valueCount = 0 ;

    if (!GetMAPIProperties(aObject, aPropertyTags, aNbProperties, values, valueCount)) { 
        return FALSE ; 
    }
    if (valueCount == aNbProperties && values != NULL) {
        ULONG i = 0 ;

        for (i = 0 ; i < valueCount ; ++ i) {
            if (PROP_ID(values [i].ulPropTag) == PROP_ID(aPropertyTags [i])) {
                if (PROP_TYPE(values [i].ulPropTag) == PT_STRING8) {
                    nsAutoString temp ;

                    temp.AssignWithConversion (values [i].Value.lpszA) ;
                    aNames.AppendString(temp) ;
                }
                else if (PROP_TYPE(values [i].ulPropTag) == PT_UNICODE) {
                    aNames.AppendString(nsAutoString (values [i].Value.lpszW)) ;
                }
                else {
                    aNames.AppendString(nsAutoString((const PRUnichar *) "")) ;
                }
            }
            else {
                aNames.AppendString(nsAutoString((const PRUnichar *) "")) ;
            }
        }
        FreeBuffer(values) ;
    }
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetPropertyBin ( const nsMapiEntry aObject,
ULONG  aPropertyTag,
nsMapiEntry aValue 
) [inherited]

Definition at line 496 of file nsAbWinHelper.cpp.

{
    aValue.Assign(0, NULL) ;
    LPSPropValue values = NULL ;
    ULONG valueCount = 0 ;

    if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) { return FALSE ; }
    if (valueCount == 1 && values != NULL && PROP_TYPE(values->ulPropTag) == PT_BINARY) {
        aValue.Assign(values->Value.bin.cb, 
                      NS_REINTERPRET_CAST(LPENTRYID, values->Value.bin.lpb)) ;
    }
    FreeBuffer(values) ;
    return TRUE ;
}

Here is the call graph for this function:

BOOL nsAbWinHelper::GetPropertyDate ( const nsMapiEntry aObject,
ULONG  aPropertyTag,
WORD aYear,
WORD aMonth,
WORD aDay 
) [inherited]

Definition at line 457 of file nsAbWinHelper.cpp.

{
    aYear = 0 ; 
    aMonth = 0 ;
    aDay = 0 ;
    LPSPropValue values = NULL ;
    ULONG valueCount = 0 ;

    if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) { return FALSE ; }
    if (valueCount == 1 && values != NULL && PROP_TYPE(values->ulPropTag) == PT_SYSTIME) {
        SYSTEMTIME readableTime ;

        if (FileTimeToSystemTime(&values->Value.ft, &readableTime)) {
            aYear = readableTime.wYear ;
            aMonth = readableTime.wMonth ;
            aDay = readableTime.wDay ;
        }
    }
    FreeBuffer(values) ;
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetPropertyLong ( const nsMapiEntry aObject,
ULONG  aPropertyTag,
ULONG aValue 
) [inherited]

Definition at line 480 of file nsAbWinHelper.cpp.

{
    aValue = 0 ;
    LPSPropValue values = NULL ;
    ULONG valueCount = 0 ;

    if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) { return FALSE ; }
    if (valueCount == 1 && values != NULL && PROP_TYPE(values->ulPropTag) == PT_LONG) {
        aValue = values->Value.ul ;
    }
    FreeBuffer(values) ;
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::GetPropertyString ( const nsMapiEntry aObject,
ULONG  aPropertyTag,
nsCString aValue 
) [inherited]

Definition at line 379 of file nsAbWinHelper.cpp.

{
    aName.Truncate() ;
    LPSPropValue values = NULL ;
    ULONG valueCount = 0 ;

    if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) { return FALSE ; }
    if (valueCount == 1 && values != NULL) {
        if (PROP_TYPE(values->ulPropTag) == PT_STRING8) {
            aName = values->Value.lpszA ;
        }
        else if (PROP_TYPE(values->ulPropTag) == PT_UNICODE) {
            aName.AssignWithConversion(values->Value.lpszW) ;
        }
    }
    FreeBuffer(values) ;
    return TRUE ;
}

Here is the call graph for this function:

BOOL nsAbWinHelper::GetPropertyUString ( const nsMapiEntry aObject,
ULONG  aPropertyTag,
nsString aValue 
) [inherited]

Definition at line 400 of file nsAbWinHelper.cpp.

{
    aName.Truncate() ;
    LPSPropValue values = NULL ;
    ULONG valueCount = 0 ;

    if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) { return FALSE ; }
    if (valueCount == 1 && values != NULL) {
        if (PROP_TYPE(values->ulPropTag) == PT_UNICODE) {
            aName = values->Value.lpszW ;
        }
        else if (PROP_TYPE(values->ulPropTag) == PT_STRING8) {
            aName.AssignWithConversion(values->Value.lpszA) ;
        }
    }
    FreeBuffer(values) ;
    return TRUE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 161 of file nsMapiAddressBook.cpp.

{
    if (mAddressBook) { return TRUE ; }
    nsAutoLock guard(mMutex) ;

    if (!LoadMapiLibrary()) {
        PRINTF(("Cannot load library.\n")) ;
        return FALSE ;
    }
    mAddressBook = mRootBook ; 
    return TRUE ;
}

Here is the call graph for this function:

BOOL nsAbWinHelper::IsOK ( void  ) const [inline, inherited]

Definition at line 128 of file nsAbWinHelper.h.

{ return mAddressBook != NULL ; }

Here is the caller graph for this function:

HRESULT nsAbWinHelper::LastError ( void  ) const [inline, inherited]

Definition at line 91 of file nsAbWinHelper.h.

{ return mLastError ; }
BOOL nsMapiAddressBook::LoadMapiLibrary ( void  ) [static, protected]

Definition at line 64 of file nsMapiAddressBook.cpp.

{
    if (mLibrary) { ++ mLibUsage ; return TRUE ; }
    HMODULE libraryHandle = LoadLibrary("MAPI32.DLL") ;

    if (!libraryHandle) { return FALSE ; }
    FARPROC entryPoint = GetProcAddress(libraryHandle, "MAPIGetNetscapeVersion") ;

    if (entryPoint) {
        FreeLibrary(libraryHandle) ;
        libraryHandle = LoadLibrary("MAPI32BAK.DLL") ;
        if (!libraryHandle) { return FALSE ; }
    }
    mLibrary = libraryHandle ;
    ++ mLibUsage ;
    mMAPIInitialize = NS_REINTERPRET_CAST(LPMAPIINITIALIZE, 
        GetProcAddress(mLibrary, "MAPIInitialize")) ;
    if (!mMAPIInitialize) { return FALSE ; }
    mMAPIUninitialize = NS_REINTERPRET_CAST(LPMAPIUNINITIALIZE, 
        GetProcAddress(mLibrary, "MAPIUninitialize")) ;
    if (!mMAPIUninitialize) { return FALSE ; }
    mMAPIAllocateBuffer = NS_REINTERPRET_CAST(LPMAPIALLOCATEBUFFER, 
        GetProcAddress(mLibrary, "MAPIAllocateBuffer")) ;
    if (!mMAPIAllocateBuffer) { return FALSE ; }
    mMAPIFreeBuffer = NS_REINTERPRET_CAST(LPMAPIFREEBUFFER, 
        GetProcAddress(mLibrary, "MAPIFreeBuffer")) ;
    if (!mMAPIFreeBuffer) { return FALSE ; }
    mMAPILogonEx = NS_REINTERPRET_CAST(LPMAPILOGONEX, 
        GetProcAddress(mLibrary, "MAPILogonEx")) ;
    if (!mMAPILogonEx) { return FALSE ; }
    MAPIINIT_0 mapiInit = { MAPI_INIT_VERSION, MAPI_MULTITHREAD_NOTIFICATIONS } ;
    HRESULT retCode = mMAPIInitialize(&mapiInit) ;

    if (HR_FAILED(retCode)) { 
        PRINTF(("Cannot initialize MAPI %08x.\n", retCode)) ; return FALSE ;
    }
    mInitialized = TRUE ;
    retCode = mMAPILogonEx(0, NULL, NULL,
                           MAPI_NO_MAIL | 
                           MAPI_USE_DEFAULT | 
                           MAPI_EXTENDED | 
                           MAPI_NEW_SESSION,
                           &mRootSession) ;
    if (HR_FAILED(retCode)) { 
        PRINTF(("Cannot logon to MAPI %08x.\n", retCode)) ; return FALSE ;
    }
    mLogonDone = TRUE ;
    retCode = mRootSession->OpenAddressBook(0, NULL, 0, &mRootBook) ;
    if (HR_FAILED(retCode)) { 
        PRINTF(("Cannot open MAPI address book %08x.\n", retCode)) ;
    }
    return HR_SUCCEEDED(retCode) ;
}

Here is the caller graph for this function:

void nsAbWinHelper::MyFreeProws ( LPSRowSet  aSet) [protected, inherited]

Definition at line 977 of file nsAbWinHelper.cpp.

{
    if (aRowset == NULL) { return ; }
    ULONG i = 0 ; 

    for (i = 0 ; i < aRowset->cRows ; ++ i) {
        FreeBuffer(aRowset->aRow [i].lpProps) ;
    }
    FreeBuffer(aRowset) ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::SetMAPIProperties ( const nsMapiEntry aObject,
ULONG  aNbProperties,
const LPSPropValue &  aValues 
) [protected, inherited]

Definition at line 944 of file nsAbWinHelper.cpp.

{
    nsMapiInterfaceWrapper<LPMAPIPROP> object ;
    ULONG objType = 0 ;
    LPSPropProblemArray problems = NULL ;

    mLastError = mAddressBook->OpenEntry(aObject.mByteCount, aObject.mEntryId,
                                         &IID_IMAPIProp, MAPI_MODIFY, &objType, 
                                         object) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
        return FALSE ;
    }
    mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
        return FALSE ;
    }
    if (problems != NULL) {
        for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
            PRINTF(("Problem %d: index %d code %08x.\n", i, 
                problems->aProblem [i].ulIndex, 
                problems->aProblem [i].scode)) ;
        }
    }
    mLastError = object->SaveChanges(0) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot commit changes %08x.\n", mLastError)) ;
    }
    return HR_SUCCEEDED(mLastError) ;
}

Here is the caller graph for this function:

BOOL nsAbWinHelper::SetPropertiesUString ( const nsMapiEntry aObject,
const ULONG aPropertiesTag,
ULONG  aNbProperties,
nsXPIDLString aValues 
) [inherited]

Definition at line 580 of file nsAbWinHelper.cpp.

{
    LPSPropValue values = new SPropValue [aNbProperties] ;
    if (!values)
        return FALSE ;

    ULONG i = 0 ;
    ULONG currentValue = 0 ;
    nsCAutoString alternativeValue ;
    BOOL retCode = TRUE ;

    for (i = 0 ; i < aNbProperties ; ++ i) {
        values [currentValue].ulPropTag = aPropertiesTag [i] ;
        if (PROP_TYPE(aPropertiesTag [i]) == PT_UNICODE) {
            values [currentValue ++].Value.lpszW = NS_CONST_CAST(WCHAR *, aValues [i].get()) ;
        }
        else if (PROP_TYPE(aPropertiesTag [i]) == PT_STRING8) {
            alternativeValue.AssignWithConversion(aValues [i].get()) ;
            char *av = nsCRT::strdup(alternativeValue.get()) ;
            if (!av) {
                retCode = FALSE ;
                break ;
            }
            values [currentValue ++].Value.lpszA = av ;
        }
    }
    if (retCode)
        retCode = SetMAPIProperties(aObject, currentValue, values) ;
    for (i = 0 ; i < currentValue ; ++ i) {
        if (PROP_TYPE(aPropertiesTag [i]) == PT_STRING8) {
            nsCRT::free(values [i].Value.lpszA) ;
        }
    }
    delete [] values ;
    return retCode ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::SetPropertyDate ( const nsMapiEntry aObject,
ULONG  aPropertyTag,
WORD  aYear,
WORD  aMonth,
WORD  aDay 
) [inherited]

Definition at line 618 of file nsAbWinHelper.cpp.

{
    SPropValue value ;
    
    value.ulPropTag = aPropertyTag ;
    if (PROP_TYPE(aPropertyTag) == PT_SYSTIME) {
        SYSTEMTIME readableTime ;

        readableTime.wYear = aYear ;
        readableTime.wMonth = aMonth ;
        readableTime.wDay = aDay ;
        readableTime.wDayOfWeek = 0 ;
        readableTime.wHour = 0 ;
        readableTime.wMinute = 0 ;
        readableTime.wSecond = 0 ;
        readableTime.wMilliseconds = 0 ;
        if (SystemTimeToFileTime(&readableTime, &value.Value.ft)) {
            return SetMAPIProperties(aObject, 1, &value) ;
        }
        return TRUE ;
    }
    return FALSE ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::SetPropertyUString ( const nsMapiEntry aObject,
ULONG  aPropertyTag,
const PRUnichar aValue 
) [inherited]

Definition at line 559 of file nsAbWinHelper.cpp.

{
    SPropValue value ;
    nsCAutoString alternativeValue ;

    value.ulPropTag = aPropertyTag ;
    if (PROP_TYPE(aPropertyTag) == PT_UNICODE) {
        value.Value.lpszW = NS_CONST_CAST(WCHAR *, aValue) ;
    }
    else if (PROP_TYPE(aPropertyTag) == PT_STRING8) {
        alternativeValue.AssignWithConversion(aValue) ;
        value.Value.lpszA = NS_CONST_CAST(char *, alternativeValue.get()) ;
    }
    else {
        PRINTF(("Property %08x is not a string.\n", aPropertyTag)) ;
        return TRUE ;
    }
    return SetMAPIProperties(aObject, 1, &value) ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL nsAbWinHelper::TestOpenEntry ( const nsMapiEntry aContainer,
const nsMapiEntry aEntry 
) [inherited]

Definition at line 515 of file nsAbWinHelper.cpp.

{
    nsMapiInterfaceWrapper<LPMAPICONTAINER> container ;
    nsMapiInterfaceWrapper<LPMAPIPROP> subObject ;
    ULONG objType = 0 ;
    
    mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
                                         &IID_IMAPIContainer, 0, &objType, 
                                         container) ;
    if (HR_FAILED(mLastError)) {
        PRINTF(("Cannot open container %08x.\n", mLastError)) ;
        return FALSE ;
    }
    mLastError = container->OpenEntry(aEntry.mByteCount, aEntry.mEntryId,
                                      NULL, 0, &objType, subObject) ;
    return HR_SUCCEEDED(mLastError) ;
}

Member Data Documentation

LPADRBOOK nsAbWinHelper::mAddressBook [protected, inherited]

Definition at line 132 of file nsAbWinHelper.h.

PRUint32 nsAbWinHelper::mEntryCounter = 0 [static, protected, inherited]

Definition at line 133 of file nsAbWinHelper.h.

Definition at line 67 of file nsMapiAddressBook.h.

HRESULT nsAbWinHelper::mLastError [protected, inherited]

Definition at line 131 of file nsAbWinHelper.h.

HMODULE nsMapiAddressBook::mLibrary = NULL [static, protected]

Definition at line 51 of file nsMapiAddressBook.h.

PRInt32 nsMapiAddressBook::mLibUsage = 0 [static, protected]

Definition at line 52 of file nsMapiAddressBook.h.

BOOL nsMapiAddressBook::mLogonDone = FALSE [static, protected]

Definition at line 68 of file nsMapiAddressBook.h.

LPMAPIALLOCATEBUFFER nsMapiAddressBook::mMAPIAllocateBuffer = NULL [static, protected]

Definition at line 55 of file nsMapiAddressBook.h.

LPMAPIFREEBUFFER nsMapiAddressBook::mMAPIFreeBuffer = NULL [static, protected]

Definition at line 56 of file nsMapiAddressBook.h.

LPMAPIINITIALIZE nsMapiAddressBook::mMAPIInitialize = NULL [static, protected]

Definition at line 53 of file nsMapiAddressBook.h.

LPMAPILOGONEX nsMapiAddressBook::mMAPILogonEx = NULL [static, protected]

Definition at line 57 of file nsMapiAddressBook.h.

LPMAPIUNINITIALIZE nsMapiAddressBook::mMAPIUninitialize = NULL [static, protected]

Definition at line 54 of file nsMapiAddressBook.h.

PRLock * nsAbWinHelper::mMutex = PR_NewLock() [static, protected, inherited]

Definition at line 134 of file nsAbWinHelper.h.

LPADRBOOK nsMapiAddressBook::mRootBook = NULL [static, protected]

Definition at line 70 of file nsMapiAddressBook.h.

LPMAPISESSION nsMapiAddressBook::mRootSession = NULL [static, protected]

Definition at line 69 of file nsMapiAddressBook.h.


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