Allow Outlook (MAPI) and Outlook Express (WAB) addressbooks to be accessed from Mozilla (bug 83103). Patch from Cyrille.Moureaux@ireland.sun.com and John.Marmion@ireland.sun.com. r=chuang@netscape.com; sr=mscott@netscape.com

This commit is contained in:
dmose%netscape.com 2001-08-10 20:31:41 +00:00
parent e3c127fac5
commit 64d4399050
12 changed files with 1840 additions and 1354 deletions

View File

@ -111,6 +111,8 @@ CPP_OBJS= \
.\$(OBJDIR)\nsAbBooleanExpression.obj \ .\$(OBJDIR)\nsAbBooleanExpression.obj \
.\$(OBJDIR)\nsAbDirectoryRDFResource.obj \ .\$(OBJDIR)\nsAbDirectoryRDFResource.obj \
.\$(OBJDIR)\nsAbQueryStringToExpression.obj \ .\$(OBJDIR)\nsAbQueryStringToExpression.obj \
.\$(OBJDIR)\nsAbWinHelper.obj \
.\$(OBJDIR)\nsWabAddressBook.obj \
$(NULL) $(NULL)
include <$(DEPTH)\config\rules.mak> include <$(DEPTH)\config\rules.mak>

View File

@ -22,7 +22,7 @@
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com> * Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
*/ */
#include "nsAbOutlookCard.h" #include "nsAbOutlookCard.h"
#include "nsMapiAddressBook.h" #include "nsAbWinHelper.h"
#include "nslog.h" #include "nslog.h"
@ -35,7 +35,7 @@ extern const char *kOutlookDirectoryScheme ;
extern const char *kOutlookCardScheme ; extern const char *kOutlookCardScheme ;
nsAbOutlookCard::nsAbOutlookCard(void) nsAbOutlookCard::nsAbOutlookCard(void)
: nsRDFResource(), nsAbCardProperty(), mMapiData(nsnull) : nsRDFResource(), nsAbCardProperty(), mAbWinType(nsAbWinType_Unknown), mMapiData(nsnull)
{ {
mMapiData = new nsMapiEntry ; mMapiData = new nsMapiEntry ;
} }
@ -132,23 +132,22 @@ nsresult nsAbOutlookCard::Init(const char *aUri)
nsresult retCode = nsRDFResource::Init(aUri) ; nsresult retCode = nsRDFResource::Init(aUri) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
nsMapiAddressBook mapiAddBook ; nsCAutoString entry ;
nsCAutoString subUri ; nsCAutoString stub ;
PRInt32 schemeLength = nsCRT::strlen(kOutlookCardScheme) ;
mAbWinType = getAbWinType(kOutlookCardScheme, mURI, stub, entry) ;
if (nsCRT::strncmp(mURI, kOutlookCardScheme, schemeLength) != 0) { if (mAbWinType == nsAbWinType_Unknown) {
PRINTF("Huge problem URI=%s.\n", mURI) ; PRINTF("Huge problem URI=%s.\n", mURI) ;
return NS_ERROR_INVALID_ARG ; return NS_ERROR_INVALID_ARG ;
} }
subUri = mURI + schemeLength ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
if (!mapiAddBook.StringToEntry(subUri, *mMapiData)) {
PRINTF("Cannot parse string %s.\n", subUri.get()) ; if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
return NS_ERROR_INVALID_ARG ; mMapiData->Assign(entry) ;
}
nsStringArray unichars ; nsStringArray unichars ;
ULONG i = 0 ; ULONG i = 0 ;
if (mapiAddBook.GetPropertiesUString(*mMapiData, OutlookCardMAPIProps, index_LastProp, unichars)) { if (mapiAddBook->GetPropertiesUString(*mMapiData, OutlookCardMAPIProps, index_LastProp, unichars)) {
SetFirstName(unichars [index_FirstName]->get()) ; SetFirstName(unichars [index_FirstName]->get()) ;
SetLastName(unichars [index_LastName]->get()) ; SetLastName(unichars [index_LastName]->get()) ;
SetDisplayName(unichars [index_DisplayName]->get()) ; SetDisplayName(unichars [index_DisplayName]->get()) ;
@ -177,23 +176,23 @@ nsresult nsAbOutlookCard::Init(const char *aUri)
ULONG cardType = 0 ; ULONG cardType = 0 ;
nsCAutoString normalChars ; nsCAutoString normalChars ;
if (mapiAddBook.GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, cardType)) { if (mapiAddBook->GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, cardType)) {
SetIsMailList(cardType == MAPI_DISTLIST) ; SetIsMailList(cardType == MAPI_DISTLIST) ;
if (cardType == MAPI_DISTLIST) { if (cardType == MAPI_DISTLIST) {
normalChars = kOutlookDirectoryScheme ; buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, normalChars) ;
normalChars.Append(subUri) ; normalChars.Append(entry) ;
SetMailListURI(normalChars) ; SetMailListURI(normalChars) ;
} }
} }
nsAutoString unichar ; nsAutoString unichar ;
nsAutoString unicharBis ; nsAutoString unicharBis ;
if (mapiAddBook.GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET, unichar)) { if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET, unichar)) {
splitString(unichar, unicharBis) ; splitString(unichar, unicharBis) ;
SetHomeAddress(unichar.get()) ; SetHomeAddress(unichar.get()) ;
SetHomeAddress2(unicharBis.get()) ; SetHomeAddress2(unicharBis.get()) ;
} }
if (mapiAddBook.GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET, unichar)) { if (mapiAddBook->GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET, unichar)) {
splitString(unichar, unicharBis) ; splitString(unichar, unicharBis) ;
SetWorkAddress(unichar.get()) ; SetWorkAddress(unichar.get()) ;
SetWorkAddress2(unicharBis.get()) ; SetWorkAddress2(unicharBis.get()) ;
@ -201,8 +200,8 @@ nsresult nsAbOutlookCard::Init(const char *aUri)
WORD year = 0 ; WORD year = 0 ;
WORD month = 0 ; WORD month = 0 ;
WORD day = 0 ; WORD day = 0 ;
if (mapiAddBook.GetPropertyDate(*mMapiData, PR_BIRTHDAY, year, month, day)) { if (mapiAddBook->GetPropertyDate(*mMapiData, PR_BIRTHDAY, year, month, day)) {
wordToUnicode(year, unichar) ; wordToUnicode(year, unichar) ;
SetBirthYear(unichar.get()) ; SetBirthYear(unichar.get()) ;
wordToUnicode(month, unichar) ; wordToUnicode(month, unichar) ;
@ -219,7 +218,7 @@ static void UnicodeToWord(const PRUnichar *aUnicode, WORD& aWord)
if (aUnicode == nsnull || *aUnicode == 0) { return ; } if (aUnicode == nsnull || *aUnicode == 0) { return ; }
PRInt32 errorCode = 0 ; PRInt32 errorCode = 0 ;
nsAutoString unichar (aUnicode) ; nsAutoString unichar (aUnicode) ;
aWord = NS_STATIC_CAST(WORD, unichar.ToInteger(&errorCode)) ; aWord = NS_STATIC_CAST(WORD, unichar.ToInteger(&errorCode)) ;
if (errorCode != 0) { if (errorCode != 0) {
PRINTF("Error conversion string %S: %08x.\n", unichar.get(), errorCode) ; PRINTF("Error conversion string %S: %08x.\n", unichar.get(), errorCode) ;
@ -230,12 +229,13 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
{ {
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsXPIDLString *properties = nsnull ; nsXPIDLString *properties = nsnull ;
nsMapiAddressBook mapiAddBook ;
nsAutoString utility ; nsAutoString utility ;
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
// First, all the standard properties in one go // First, all the standard properties in one go
properties = new nsXPIDLString [index_LastProp] ; properties = new nsXPIDLString [index_LastProp] ;
if (properties == nsnull) { if (!properties) {
return NS_ERROR_OUT_OF_MEMORY ; return NS_ERROR_OUT_OF_MEMORY ;
} }
GetFirstName(getter_Copies(properties [index_FirstName])) ; GetFirstName(getter_Copies(properties [index_FirstName])) ;
@ -274,7 +274,7 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
GetWebPage1(getter_Copies(properties [index_WorkWebPage])) ; GetWebPage1(getter_Copies(properties [index_WorkWebPage])) ;
GetWebPage2(getter_Copies(properties [index_HomeWebPage])) ; GetWebPage2(getter_Copies(properties [index_HomeWebPage])) ;
GetNotes(getter_Copies(properties [index_Comments])) ; GetNotes(getter_Copies(properties [index_Comments])) ;
if (!mapiAddBook.SetPropertiesUString(*mMapiData, OutlookCardMAPIProps, if (!mapiAddBook->SetPropertiesUString(*mMapiData, OutlookCardMAPIProps,
index_LastProp, properties)) { index_LastProp, properties)) {
PRINTF("Cannot set general properties.\n") ; PRINTF("Cannot set general properties.\n") ;
} }
@ -290,7 +290,7 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
utility.Assign(unichar.get()) ; utility.Assign(unichar.get()) ;
if (utility.Length() > 0) { utility.AppendWithConversion(CRLF) ; } if (utility.Length() > 0) { utility.AppendWithConversion(CRLF) ; }
utility.Append(unichar2.get()) ; utility.Append(unichar2.get()) ;
if (!mapiAddBook.SetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_W, utility.get())) { if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_W, utility.get())) {
PRINTF("Cannot set home address.\n") ; PRINTF("Cannot set home address.\n") ;
} }
GetWorkAddress(getter_Copies(unichar)) ; GetWorkAddress(getter_Copies(unichar)) ;
@ -298,7 +298,7 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
utility.Assign(unichar.get()) ; utility.Assign(unichar.get()) ;
if (utility.Length() > 0) { utility.AppendWithConversion(CRLF) ; } if (utility.Length() > 0) { utility.AppendWithConversion(CRLF) ; }
utility.Append(unichar2.get()) ; utility.Append(unichar2.get()) ;
if (!mapiAddBook.SetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_W, utility.get())) { if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_W, utility.get())) {
PRINTF("Cannot set work address.\n") ; PRINTF("Cannot set work address.\n") ;
} }
GetBirthYear(getter_Copies(unichar)) ; GetBirthYear(getter_Copies(unichar)) ;
@ -307,7 +307,7 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
UnicodeToWord(unichar.get(), month) ; UnicodeToWord(unichar.get(), month) ;
GetBirthDay(getter_Copies(unichar)) ; GetBirthDay(getter_Copies(unichar)) ;
UnicodeToWord(unichar.get(), day) ; UnicodeToWord(unichar.get(), day) ;
if (!mapiAddBook.SetPropertyDate(*mMapiData, PR_BIRTHDAY, year, month, day)) { if (!mapiAddBook->SetPropertyDate(*mMapiData, PR_BIRTHDAY, year, month, day)) {
PRINTF("Cannot set date.\n") ; PRINTF("Cannot set date.\n") ;
} }
return retCode ; return retCode ;

View File

@ -45,7 +45,8 @@ public:
protected: protected:
nsMapiEntry *mMapiData ; nsMapiEntry *mMapiData ;
PRUint32 mAbWinType ;
private: private:
}; };

View File

@ -22,7 +22,7 @@
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com> * Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
*/ */
#include "nsAbOutlookDirFactory.h" #include "nsAbOutlookDirFactory.h"
#include "nsMapiAddressBook.h" #include "nsAbWinHelper.h"
#include "nsIAbDirectory.h" #include "nsIAbDirectory.h"
#include "nsIRDFService.h" #include "nsIRDFService.h"
@ -63,41 +63,69 @@ nsAbOutlookDirFactory::~nsAbOutlookDirFactory(void)
} }
extern const char *kOutlookDirectoryScheme ; extern const char *kOutlookDirectoryScheme ;
extern const char *kURIPropertyName ;
static void parseProperties(PRUint32 aNbProperties, const char **aPropertyNames,
const PRUnichar **aPropertyValues, nsAbWinType& aWinType)
{
aWinType = nsAbWinType_Unknown ;
PRUint32 i = 0 ;
for (i = 0 ; i < aNbProperties ; ++ i) {
if (nsCRT::strcmp(aPropertyNames [i], kURIPropertyName) == 0) {
nsCAutoString uri ;
nsCString stub ;
nsCString entry ;
uri.AssignWithConversion(aPropertyValues [i]) ;
aWinType = getAbWinType(kOutlookDirectoryScheme, uri.get(), stub, entry) ;
break ;
}
}
}
NS_IMETHODIMP nsAbOutlookDirFactory::CreateDirectory(PRUint32 aNbProperties, NS_IMETHODIMP nsAbOutlookDirFactory::CreateDirectory(PRUint32 aNbProperties,
const char **aPropertyNames, const char **aPropertyNames,
const PRUnichar **aPropertyValues, const PRUnichar **aPropertyValues,
nsISimpleEnumerator **aDirectories) nsISimpleEnumerator **aDirectories)
{ {
if (aPropertyNames == nsnull || if (!aPropertyNames || !aPropertyValues || !aDirectories) {
aPropertyValues == nsnull || return NS_ERROR_NULL_POINTER ;
aDirectories == nsnull) { return NS_ERROR_NULL_POINTER ; } }
*aDirectories = nsnull ; *aDirectories = nsnull ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsMapiAddressBook mapiAddBook ; nsAbWinType abType = nsAbWinType_Unknown ;
parseProperties(aNbProperties, aPropertyNames, aPropertyValues, abType) ;
if (abType == nsAbWinType_Unknown) {
return NS_ERROR_FAILURE ;
}
nsAbWinHelperGuard mapiAddBook (abType) ;
nsMapiEntryArray folders ; nsMapiEntryArray folders ;
ULONG nbFolders = 0 ; ULONG nbFolders = 0 ;
nsCOMPtr<nsISupportsArray> directories ; nsCOMPtr<nsISupportsArray> directories ;
retCode = NS_NewISupportsArray(getter_AddRefs(directories)) ; retCode = NS_NewISupportsArray(getter_AddRefs(directories)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
if (!mapiAddBook.GetFolders(folders)) { if (!mapiAddBook->IsOK() || !mapiAddBook->GetFolders(folders)) {
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
nsCOMPtr<nsIRDFService> rdf = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &retCode); nsCOMPtr<nsIRDFService> rdf = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &retCode);
NS_ENSURE_SUCCESS(retCode, retCode); NS_ENSURE_SUCCESS(retCode, retCode) ;
nsCAutoString entryId ; nsCAutoString entryId ;
nsCAutoString uri ; nsCAutoString uri ;
nsCOMPtr<nsIRDFResource> resource ; nsCOMPtr<nsIRDFResource> resource ;
for (ULONG i = 0 ; i < folders.mNbEntries ; ++ i) { for (ULONG i = 0 ; i < folders.mNbEntries ; ++ i) {
if (mapiAddBook.EntryToString(folders.mEntries [i], entryId)) { folders.mEntries [i].ToString(entryId) ;
uri.Assign(kOutlookDirectoryScheme) ; buildAbWinUri(kOutlookDirectoryScheme, abType, uri) ;
uri.Append(entryId) ; uri.Append(entryId) ;
retCode = rdf->GetResource(uri, getter_AddRefs(resource)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; retCode = rdf->GetResource(uri, getter_AddRefs(resource)) ;
directories->AppendElement(resource) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
} directories->AppendElement(resource) ;
} }
return NS_NewArrayEnumerator(aDirectories, directories) ; return NS_NewArrayEnumerator(aDirectories, directories) ;
} }

View File

@ -22,7 +22,7 @@
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com> * Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
*/ */
#include "nsAbOutlookDirectory.h" #include "nsAbOutlookDirectory.h"
#include "nsMapiAddressBook.h" #include "nsAbWinHelper.h"
#include "nsIRDFService.h" #include "nsIRDFService.h"
@ -70,7 +70,8 @@ private:
nsAbOutlookDirectory::nsAbOutlookDirectory(void) nsAbOutlookDirectory::nsAbOutlookDirectory(void)
: nsAbDirectoryRDFResource(), nsAbDirProperty(), nsAbDirSearchListenerContext(), : nsAbDirectoryRDFResource(), nsAbDirProperty(), nsAbDirSearchListenerContext(),
mQueryThreads(16, PR_TRUE), mCurrentQueryId(0), mSearchContext(-1), mMapiData(nsnull) mQueryThreads(16, PR_TRUE), mCurrentQueryId(0), mSearchContext(-1),
mAbWinType(nsAbWinType_Unknown), mMapiData(nsnull)
{ {
mMapiData = new nsMapiEntry ; mMapiData = new nsMapiEntry ;
mProtector = PR_NewLock() ; mProtector = PR_NewLock() ;
@ -84,9 +85,6 @@ nsAbOutlookDirectory::~nsAbOutlookDirectory(void)
NS_IMPL_ISUPPORTS_INHERITED3(nsAbOutlookDirectory, nsAbDirectoryRDFResource, NS_IMPL_ISUPPORTS_INHERITED3(nsAbOutlookDirectory, nsAbDirectoryRDFResource,
nsIAbDirectory, nsIAbDirectoryQuery, nsIAbDirectorySearch) nsIAbDirectory, nsIAbDirectoryQuery, nsIAbDirectorySearch)
const char *kOutlookCardScheme = "moz-aboutlookcard://" ;
const char *kOutlookDirectoryScheme = "moz-aboutlookdirectory://" ;
// nsIRDFResource method // nsIRDFResource method
NS_IMETHODIMP nsAbOutlookDirectory::Init(const char *aUri) NS_IMETHODIMP nsAbOutlookDirectory::Init(const char *aUri)
@ -94,30 +92,33 @@ NS_IMETHODIMP nsAbOutlookDirectory::Init(const char *aUri)
nsresult retCode = nsAbDirectoryRDFResource::Init(aUri) ; nsresult retCode = nsAbDirectoryRDFResource::Init(aUri) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
nsMapiAddressBook mapiAddBook ; nsCAutoString entry ;
nsAutoString unichars ; nsCAutoString stub ;
ULONG objectType = 0 ;
nsCAutoString subUri ; mAbWinType = getAbWinType(kOutlookDirectoryScheme, mURINoQuery, stub, entry) ;
PRInt32 schemeLength = nsCRT::strlen(kOutlookDirectoryScheme) ; if (mAbWinType == nsAbWinType_Unknown) {
if (nsCRT::strncmp(mURINoQuery, kOutlookDirectoryScheme, schemeLength) != 0) {
PRINTF("Huge problem URI=%s.\n", mURINoQuery) ; PRINTF("Huge problem URI=%s.\n", mURINoQuery) ;
return NS_ERROR_INVALID_ARG ; return NS_ERROR_INVALID_ARG ;
} }
subUri = mURINoQuery + schemeLength ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
if (!mapiAddBook.StringToEntry(subUri, *mMapiData)) { nsString prefix ;
PRINTF("Cannot parse string %s.\n", subUri.get()) ; nsAutoString unichars ;
return NS_ERROR_INVALID_ARG ; ULONG objectType = 0 ;
}
if (!mapiAddBook.GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, objectType)) { if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
mMapiData->Assign(entry) ;
if (!mapiAddBook->GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, objectType)) {
PRINTF("Cannot get type.\n") ; PRINTF("Cannot get type.\n") ;
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
if (!mapiAddBook.GetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, unichars)) { if (!mapiAddBook->GetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, unichars)) {
PRINTF("Cannot get name.\n") ; PRINTF("Cannot get name.\n") ;
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
SetDirName(unichars.get()) ; if (mAbWinType == nsAbWinType_Outlook) { prefix.AssignWithConversion("OP ") ; }
else { prefix.AssignWithConversion("OE ") ; }
prefix.Append(unichars) ;
SetDirName(prefix.get()) ;
if (objectType == MAPI_DISTLIST) { if (objectType == MAPI_DISTLIST) {
SetListName(unichars.get()) ; SetListName(unichars.get()) ;
SetIsMailList(PR_TRUE) ; SetIsMailList(PR_TRUE) ;
@ -131,7 +132,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::Init(const char *aUri)
// nsIAbDirectory methods // nsIAbDirectory methods
NS_IMETHODIMP nsAbOutlookDirectory::GetChildNodes(nsIEnumerator **aNodes) NS_IMETHODIMP nsAbOutlookDirectory::GetChildNodes(nsIEnumerator **aNodes)
{ {
if (aNodes == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aNodes) { return NS_ERROR_NULL_POINTER ; }
*aNodes = nsnull ; *aNodes = nsnull ;
nsCOMPtr<nsISupportsArray> nodeList ; nsCOMPtr<nsISupportsArray> nodeList ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
@ -148,7 +149,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildNodes(nsIEnumerator **aNodes)
NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards) NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
{ {
if (aCards == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aCards) { return NS_ERROR_NULL_POINTER ; }
*aCards = nsnull ; *aCards = nsnull ;
nsCOMPtr<nsISupportsArray> cardList ; nsCOMPtr<nsISupportsArray> cardList ;
nsresult retCode ; nsresult retCode ;
@ -163,6 +164,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
} }
if (NS_SUCCEEDED(retCode)) { if (NS_SUCCEEDED(retCode)) {
// Fill the results array and update the card list // Fill the results array and update the card list
// Also update the address list and notify any changes.
PRUint32 nbCards = 0 ; PRUint32 nbCards = 0 ;
nsCOMPtr<nsISupports> element ; nsCOMPtr<nsISupports> element ;
@ -171,25 +173,77 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
for (PRUint32 i = 0 ; i < nbCards ; ++ i) { for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
cardList->GetElementAt(i, getter_AddRefs(element)) ; cardList->GetElementAt(i, getter_AddRefs(element)) ;
nsVoidKey newKey (NS_STATIC_CAST(void *, element)) ; nsVoidKey newKey (NS_STATIC_CAST(void *, element)) ;
nsCOMPtr<nsISupports> oldElement = mCardList.Get(&newKey) ;
mCardList.Put(&newKey, element) ;
if (!oldElement) {
// We are dealing with a new element (probably directly
// added from Outlook), we may need to sync m_AddressList
mCardList.Put(&newKey, element) ;
nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
PRBool isMailList = PR_FALSE ;
retCode = card->GetIsMailList(&isMailList) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
if (isMailList) {
// We can have mailing lists only in folder,
// we must add the directory to m_AddressList
nsXPIDLCString mailListUri ;
retCode = card->GetMailListURI(getter_Copies(mailListUri)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
nsCOMPtr<nsIRDFResource> resource ;
retCode = gRDFService->GetResource(mailListUri, getter_AddRefs(resource)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
nsCOMPtr<nsIAbDirectory> mailList(do_QueryInterface(resource, &retCode)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
m_AddressList->AppendElement(mailList) ;
NotifyItemAddition(mailList) ;
}
else if (m_bIsMailList) {
m_AddressList->AppendElement(card) ;
NotifyItemAddition(card) ;
}
}
else {
NS_ASSERTION(oldElement == element, "Different card stored") ;
}
} }
} }
return retCode ; return retCode ;
} }
NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
{
if (!aCard || !aHasCard) { return NS_ERROR_NULL_POINTER ; }
nsVoidKey key (NS_STATIC_CAST(void *, aCard)) ;
*aHasCard = mCardList.Exists(&key) ;
return NS_OK ;
}
NS_IMETHODIMP nsAbOutlookDirectory::HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory)
{
if (!aDirectory || !aHasDirectory ) { return NS_ERROR_NULL_POINTER ; }
*aHasDirectory = (m_AddressList->IndexOf(aDirectory) >= 0) ;
return NS_OK ;
}
static nsresult ExtractEntryFromUri(nsIRDFResource *aResource, nsCString &aEntry, static nsresult ExtractEntryFromUri(nsIRDFResource *aResource, nsCString &aEntry,
const char *aPrefix, PRUint32 aPrefixSize) const char *aPrefix)
{ {
aEntry.Truncate() ; aEntry.Truncate() ;
if (aPrefix == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aPrefix ) { return NS_ERROR_NULL_POINTER ; }
nsXPIDLCString uri ; nsXPIDLCString uri ;
nsresult retCode = aResource->GetValue(getter_Copies(uri)) ; nsresult retCode = aResource->GetValue(getter_Copies(uri)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
if (nsCRT::strncmp(uri.get(), aPrefix, aPrefixSize) == 0) { nsCAutoString stub ;
aEntry = uri.get() + aPrefixSize ; nsAbWinType objType = getAbWinType(aPrefix, uri.get(), stub, aEntry) ;
}
return NS_OK ; return NS_OK ;
} }
@ -201,8 +255,7 @@ static nsresult ExtractCardEntry(nsIAbCard *aCard, nsCString& aEntry)
// Receiving a non-RDF card is accepted // Receiving a non-RDF card is accepted
if (NS_FAILED(retCode)) { return NS_OK ; } if (NS_FAILED(retCode)) { return NS_OK ; }
return ExtractEntryFromUri(resource, aEntry, kOutlookCardScheme, return ExtractEntryFromUri(resource, aEntry, kOutlookCardScheme) ;
nsCRT::strlen(kOutlookCardScheme)) ;
} }
static nsresult ExtractDirectoryEntry(nsIAbDirectory *aDirectory, nsCString& aEntry) static nsresult ExtractDirectoryEntry(nsIAbDirectory *aDirectory, nsCString& aEntry)
@ -213,35 +266,18 @@ static nsresult ExtractDirectoryEntry(nsIAbDirectory *aDirectory, nsCString& aEn
// Receiving a non-RDF directory is accepted // Receiving a non-RDF directory is accepted
if (NS_FAILED(retCode)) { return NS_OK ; } if (NS_FAILED(retCode)) { return NS_OK ; }
return ExtractEntryFromUri(resource, aEntry, kOutlookDirectoryScheme, return ExtractEntryFromUri(resource, aEntry, kOutlookDirectoryScheme) ;
nsCRT::strlen(kOutlookDirectoryScheme)) ;
}
NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
{
if (aCard == nsnull ||
aHasCard == nsnull) { return NS_ERROR_NULL_POINTER ; }
nsVoidKey key (NS_STATIC_CAST(void *, aCard)) ;
*aHasCard = mCardList.Exists(&key) ;
return NS_OK ;
}
NS_IMETHODIMP nsAbOutlookDirectory::HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory)
{
if (aDirectory == nsnull ||
aHasDirectory == nsnull) { return NS_ERROR_NULL_POINTER ; }
*aHasDirectory = (m_AddressList->IndexOf(aDirectory) >= 0) ;
return NS_OK ;
} }
NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList) NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
{ {
if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; } if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
if (aCardList == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aCardList) { return NS_ERROR_NULL_POINTER ; }
PRUint32 nbCards = 0 ; PRUint32 nbCards = 0 ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsMapiAddressBook mapiAddBook ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
retCode = aCardList->Count(&nbCards) ; retCode = aCardList->Count(&nbCards) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
@ -249,30 +285,28 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
nsCOMPtr<nsISupports> element ; nsCOMPtr<nsISupports> element ;
nsCAutoString entryString ; nsCAutoString entryString ;
nsMapiEntry cardEntry ; nsMapiEntry cardEntry ;
for (i = 0 ; i < nbCards ; ++ i) { for (i = 0 ; i < nbCards ; ++ i) {
retCode = aCardList->GetElementAt(i, getter_AddRefs(element)) ; retCode = aCardList->GetElementAt(i, getter_AddRefs(element)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ; nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
retCode = ExtractCardEntry(card, entryString) ; retCode = ExtractCardEntry(card, entryString) ;
if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) { if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) {
if (!mapiAddBook.StringToEntry(entryString, cardEntry)) {
PRINTF("Cannot manage uri %s.\n", entryString.get()) ; cardEntry.Assign(entryString) ;
if (!mapiAddBook->DeleteEntry(*mMapiData, cardEntry)) {
PRINTF("Cannot delete card %s.\n", entryString.get()) ;
} }
else { else {
if (!mapiAddBook.DeleteEntry(*mMapiData, cardEntry)) { nsVoidKey key (NS_STATIC_CAST(void *, element)) ;
PRINTF("Cannot delete card %s.\n", entryString.get()) ;
} mCardList.Remove(&key) ;
else { if (m_bIsMailList) { m_AddressList->RemoveElement(element) ; }
nsVoidKey key (NS_STATIC_CAST(void *, element)) ; retCode = NotifyItemDeletion(element) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
mCardList.Remove(&key) ;
if (m_bIsMailList) { m_AddressList->RemoveElement(element) ; }
retCode = NotifyItemDeletion(element) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
}
} }
} }
else { else {
@ -285,27 +319,24 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
NS_IMETHODIMP nsAbOutlookDirectory::DeleteDirectory(nsIAbDirectory *aDirectory) NS_IMETHODIMP nsAbOutlookDirectory::DeleteDirectory(nsIAbDirectory *aDirectory)
{ {
if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; } if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
if (aDirectory == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aDirectory) { return NS_ERROR_NULL_POINTER ; }
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsMapiAddressBook mapiAddBook ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
nsCAutoString entryString ; nsCAutoString entryString ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
retCode = ExtractDirectoryEntry(aDirectory, entryString) ; retCode = ExtractDirectoryEntry(aDirectory, entryString) ;
if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) { if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) {
nsMapiEntry directoryEntry ; nsMapiEntry directoryEntry ;
if (!mapiAddBook.StringToEntry(entryString, directoryEntry)) { directoryEntry.Assign(entryString) ;
PRINTF("Cannot manage uri %s.\n", entryString.get()) ; if (!mapiAddBook->DeleteEntry(*mMapiData, directoryEntry)) {
PRINTF("Cannot delete directory %s.\n", entryString.get()) ;
} }
else { else {
if (!mapiAddBook.DeleteEntry(*mMapiData, directoryEntry)) { m_AddressList->RemoveElement(aDirectory) ;
PRINTF("Cannot delete directory %s.\n", entryString.get()) ; retCode = NotifyItemDeletion(aDirectory) ;
} NS_ENSURE_SUCCESS(retCode, retCode) ;
else {
m_AddressList->RemoveElement(aDirectory) ;
retCode = NotifyItemDeletion(aDirectory) ;
NS_ENSURE_SUCCESS(retCode, retCode) ;
}
} }
} }
else { else {
@ -317,7 +348,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteDirectory(nsIAbDirectory *aDirectory)
NS_IMETHODIMP nsAbOutlookDirectory::AddCard(nsIAbCard *aData, nsIAbCard **aCard) NS_IMETHODIMP nsAbOutlookDirectory::AddCard(nsIAbCard *aData, nsIAbCard **aCard)
{ {
if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; } if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
if (aData == nsnull || aCard == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aData || !aCard) { return NS_ERROR_NULL_POINTER ; }
*aCard = nsnull ; *aCard = nsnull ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
PRBool hasCard = PR_FALSE ; PRBool hasCard = PR_FALSE ;
@ -346,35 +377,32 @@ NS_IMETHODIMP nsAbOutlookDirectory::DropCard(nsIAbCard *aData, nsIAbCard **aCard
NS_IMETHODIMP nsAbOutlookDirectory::AddMailList(nsIAbDirectory *aMailList) NS_IMETHODIMP nsAbOutlookDirectory::AddMailList(nsIAbDirectory *aMailList)
{ {
if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; } if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
if (aMailList == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aMailList) { return NS_ERROR_NULL_POINTER ; }
if (m_bIsMailList) { return NS_OK ; } if (m_bIsMailList) { return NS_OK ; }
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsMapiAddressBook mapiAddBook ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
nsCAutoString entryString ; nsCAutoString entryString ;
nsMapiEntry newEntry ; nsMapiEntry newEntry ;
PRBool didCopy = PR_FALSE ; PRBool didCopy = PR_FALSE ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
retCode = ExtractDirectoryEntry(aMailList, entryString) ; retCode = ExtractDirectoryEntry(aMailList, entryString) ;
if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) { if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) {
nsMapiEntry sourceEntry ; nsMapiEntry sourceEntry ;
if (mapiAddBook.StringToEntry(entryString, sourceEntry)) { sourceEntry.Assign(entryString) ;
mapiAddBook.CopyEntry(*mMapiData, sourceEntry, newEntry) ; mapiAddBook->CopyEntry(*mMapiData, sourceEntry, newEntry) ;
}
} }
if (newEntry.mByteCount == 0) { if (newEntry.mByteCount == 0) {
if (!mapiAddBook.CreateDistList(*mMapiData, newEntry)) { if (!mapiAddBook->CreateDistList(*mMapiData, newEntry)) {
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
} }
else { didCopy = PR_TRUE ; } else { didCopy = PR_TRUE ; }
if (!mapiAddBook.EntryToString(newEntry, entryString)) { newEntry.ToString(entryString) ;
PRINTF("Cannot manage entry.\n") ;
return NS_ERROR_FAILURE ;
}
nsCAutoString uri ; nsCAutoString uri ;
uri.Assign(kOutlookDirectoryScheme) ; buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uri) ;
uri.Append(entryString) ; uri.Append(entryString) ;
nsCOMPtr<nsIRDFResource> resource ; nsCOMPtr<nsIRDFResource> resource ;
retCode = gRDFService->GetResource(uri, getter_AddRefs(resource)) ; retCode = gRDFService->GetResource(uri, getter_AddRefs(resource)) ;
@ -398,11 +426,12 @@ NS_IMETHODIMP nsAbOutlookDirectory::EditMailListToDatabase(const char *aUri)
if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; } if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsXPIDLString name ; nsXPIDLString name ;
nsMapiAddressBook mapiAddBook ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
retCode = GetListName(getter_Copies(name)) ; retCode = GetListName(getter_Copies(name)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
if (!mapiAddBook.SetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, name.get())) { if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, name.get())) {
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
retCode = CommitAddressList() ; retCode = CommitAddressList() ;
@ -411,15 +440,8 @@ NS_IMETHODIMP nsAbOutlookDirectory::EditMailListToDatabase(const char *aUri)
NS_IMETHODIMP nsAbOutlookDirectory::GetTotalCards(PRBool aSubDirectoryCount, PRUint32 *aNbCards) NS_IMETHODIMP nsAbOutlookDirectory::GetTotalCards(PRBool aSubDirectoryCount, PRUint32 *aNbCards)
{ {
if (aNbCards == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aNbCards) { return NS_ERROR_NULL_POINTER ; }
*aNbCards = 0 ; *aNbCards = mCardList.Count();
nsMapiAddressBook mapiAddBook ;
ULONG nbCards = 0 ;
if (!mapiAddBook.GetCardsCount(*mMapiData, nbCards)) {
return NS_ERROR_FAILURE ;
}
*aNbCards = NS_STATIC_CAST(PRUint32, nbCards) ;
return NS_OK ; return NS_OK ;
} }
@ -524,7 +546,7 @@ static nsresult BuildRestriction(nsIAbBooleanConditionString *aCondition,
SRestriction& aRestriction, SRestriction& aRestriction,
PRBool& aSkipItem) PRBool& aSkipItem)
{ {
if (aCondition == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aCondition) { return NS_ERROR_NULL_POINTER ; }
aSkipItem = PR_FALSE ; aSkipItem = PR_FALSE ;
nsAbBooleanConditionType conditionType = 0 ; nsAbBooleanConditionType conditionType = 0 ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
@ -658,7 +680,7 @@ static nsresult BuildRestriction(nsIAbBooleanConditionString *aCondition,
static nsresult BuildRestriction(nsIAbBooleanExpression *aLevel, static nsresult BuildRestriction(nsIAbBooleanExpression *aLevel,
SRestriction& aRestriction) SRestriction& aRestriction)
{ {
if (aLevel == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aLevel) { return NS_ERROR_NULL_POINTER ; }
aRestriction.rt = RES_COMMENT ; aRestriction.rt = RES_COMMENT ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsAbBooleanOperationType operationType = 0 ; nsAbBooleanOperationType operationType = 0 ;
@ -684,7 +706,7 @@ static nsresult BuildRestriction(nsIAbBooleanExpression *aLevel,
PRBool skipItem = PR_FALSE ; PRBool skipItem = PR_FALSE ;
PRUint32 i = 0 ; PRUint32 i = 0 ;
nsCOMPtr<nsISupports> element ; nsCOMPtr<nsISupports> element ;
for (i = 0 ; i < nbExpressions ; ++ i) { for (i = 0 ; i < nbExpressions ; ++ i) {
retCode = expressions->GetElementAt(i, getter_AddRefs(element)) ; retCode = expressions->GetElementAt(i, getter_AddRefs(element)) ;
if (NS_SUCCEEDED(retCode)) { if (NS_SUCCEEDED(retCode)) {
@ -699,7 +721,7 @@ static nsresult BuildRestriction(nsIAbBooleanExpression *aLevel,
} }
else { else {
nsCOMPtr<nsIAbBooleanExpression> subExpression (do_QueryInterface(element, &retCode)) ; nsCOMPtr<nsIAbBooleanExpression> subExpression (do_QueryInterface(element, &retCode)) ;
if (NS_SUCCEEDED(retCode)) { if (NS_SUCCEEDED(retCode)) {
retCode = BuildRestriction(subExpression, *restrictionArray) ; retCode = BuildRestriction(subExpression, *restrictionArray) ;
if (NS_SUCCEEDED(retCode)) { if (NS_SUCCEEDED(retCode)) {
@ -754,10 +776,10 @@ static nsresult BuildRestriction(nsIAbBooleanExpression *aLevel,
static nsresult BuildRestriction(nsIAbDirectoryQueryArguments *aArguments, static nsresult BuildRestriction(nsIAbDirectoryQueryArguments *aArguments,
SRestriction& aRestriction) SRestriction& aRestriction)
{ {
if (aArguments == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aArguments) { return NS_ERROR_NULL_POINTER ; }
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsCOMPtr<nsIAbBooleanExpression> booleanQuery ; nsCOMPtr<nsIAbBooleanExpression> booleanQuery ;
retCode = aArguments->GetExpression(getter_AddRefs(booleanQuery)) ; retCode = aArguments->GetExpression(getter_AddRefs(booleanQuery)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
retCode = BuildRestriction(booleanQuery, aRestriction) ; retCode = BuildRestriction(booleanQuery, aRestriction) ;
@ -813,9 +835,9 @@ static void DestroyRestriction(SRestriction& aRestriction)
nsresult FillPropertyValues(nsIAbCard *aCard, nsIAbDirectoryQueryArguments *aArguments, nsresult FillPropertyValues(nsIAbCard *aCard, nsIAbDirectoryQueryArguments *aArguments,
nsISupportsArray **aValues) nsISupportsArray **aValues)
{ {
if (aCard == nsnull || if (!aCard || !aArguments || !aValues ) {
aArguments == nsnull || return NS_ERROR_NULL_POINTER ;
aValues == nsnull) { return NS_ERROR_NULL_POINTER ; } }
*aValues = nsnull ; *aValues = nsnull ;
CharPtrArrayGuard properties ; CharPtrArrayGuard properties ;
nsCOMPtr<nsISupportsArray> values ; nsCOMPtr<nsISupportsArray> values ;
@ -826,43 +848,43 @@ nsresult FillPropertyValues(nsIAbCard *aCard, nsIAbDirectoryQueryArguments *aArg
PRUint32 i = 0 ; PRUint32 i = 0 ;
nsCAutoString cPropName ; nsCAutoString cPropName ;
nsAbDirectoryQueryPropertyValue *newValue = nsnull ; nsAbDirectoryQueryPropertyValue *newValue = nsnull ;
nsCOMPtr<nsIAbDirectoryQueryPropertyValue> propertyValue ; nsCOMPtr<nsIAbDirectoryQueryPropertyValue> propertyValue ;
for (i = 0 ; i < properties.GetSize() ; ++ i) { for (i = 0 ; i < properties.GetSize() ; ++ i) {
newValue = nsnull ; newValue = nsnull ;
cPropName.Assign(properties [i]) ; cPropName.Assign(properties [i]) ;
if (cPropName.EqualsWithConversion ("card:nsIAbCard")) { if (cPropName.EqualsWithConversion ("card:nsIAbCard")) {
nsCOMPtr<nsISupports> bogusInterface (do_QueryInterface(aCard, &retCode)) ; nsCOMPtr<nsISupports> bogusInterface (do_QueryInterface(aCard, &retCode)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
newValue = new nsAbDirectoryQueryPropertyValue (cPropName, bogusInterface) ; newValue = new nsAbDirectoryQueryPropertyValue (cPropName, bogusInterface) ;
} }
else if (cPropName.EqualsWithConversion ("card:URI")) { else if (cPropName.EqualsWithConversion ("card:URI")) {
nsCOMPtr<nsIRDFResource> rdfResource (do_QueryInterface(aCard, &retCode)) ; nsCOMPtr<nsIRDFResource> rdfResource (do_QueryInterface(aCard, &retCode)) ;
nsXPIDLCString uri; nsXPIDLCString uri;
nsAutoString convertedString ; nsAutoString convertedString ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
retCode = rdfResource->GetValue(getter_Copies(uri)) ; retCode = rdfResource->GetValue(getter_Copies(uri)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
convertedString.AssignWithConversion(uri.get()) ; convertedString.AssignWithConversion(uri.get()) ;
newValue = new nsAbDirectoryQueryPropertyValue(cPropName.get(), convertedString.get()) ; newValue = new nsAbDirectoryQueryPropertyValue(cPropName.get(), convertedString.get()) ;
} }
else { else {
nsXPIDLString value ; nsXPIDLString value ;
retCode = aCard->GetCardValue(cPropName, getter_Copies(value)) ; retCode = aCard->GetCardValue(cPropName, getter_Copies(value)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
if (value.get() != nsnull && nsCRT::strlen(value.get()) != 0) { if (value.get() && nsCRT::strlen(value.get()) != 0) {
newValue = new nsAbDirectoryQueryPropertyValue(cPropName.get(), value.get()) ; newValue = new nsAbDirectoryQueryPropertyValue(cPropName.get(), value.get()) ;
} }
} }
if (newValue != nsnull) { if (newValue) {
if (!values) { if (!values) {
NS_NewISupportsArray(getter_AddRefs(values)) ; NS_NewISupportsArray(getter_AddRefs(values)) ;
} }
propertyValue = newValue ; propertyValue = newValue ;
values->AppendElement (propertyValue) ; values->AppendElement (propertyValue) ;
} }
} }
*aValues = values ; *aValues = values ;
@ -883,8 +905,8 @@ struct QueryThreadArgs
static void QueryThreadFunc(void *aArguments) static void QueryThreadFunc(void *aArguments)
{ {
QueryThreadArgs *arguments = NS_REINTERPRET_CAST(QueryThreadArgs *, aArguments) ; QueryThreadArgs *arguments = NS_REINTERPRET_CAST(QueryThreadArgs *, aArguments) ;
if (aArguments == nsnull) { return ; } if (!aArguments) { return ; }
arguments->mThis->ExecuteQuery(arguments->mArguments, arguments->mListener, arguments->mThis->ExecuteQuery(arguments->mArguments, arguments->mListener,
arguments->mResultLimit, arguments->mTimeout, arguments->mResultLimit, arguments->mTimeout,
arguments->mThreadId) ; arguments->mThreadId) ;
@ -896,15 +918,15 @@ nsresult nsAbOutlookDirectory::DoQuery(nsIAbDirectoryQueryArguments *aArguments,
PRInt32 aResultLimit, PRInt32 aTimeout, PRInt32 aResultLimit, PRInt32 aTimeout,
PRInt32 *aReturnValue) PRInt32 *aReturnValue)
{ {
if (aArguments == nsnull || if (!aArguments || !aListener || !aReturnValue) {
aListener == nsnull || return NS_ERROR_NULL_POINTER ;
aReturnValue == nsnull) { return NS_ERROR_NULL_POINTER ; } }
*aReturnValue = -1 ; *aReturnValue = -1 ;
QueryThreadArgs *threadArgs = new QueryThreadArgs ; QueryThreadArgs *threadArgs = new QueryThreadArgs ;
PRThread *newThread = nsnull ; PRThread *newThread = nsnull ;
if (threadArgs == nsnull) { if (!threadArgs) {
return NS_ERROR_OUT_OF_MEMORY ; return NS_ERROR_OUT_OF_MEMORY ;
} }
threadArgs->mThis = this ; threadArgs->mThis = this ;
@ -923,7 +945,7 @@ nsresult nsAbOutlookDirectory::DoQuery(nsIAbDirectoryQueryArguments *aArguments,
PR_GLOBAL_THREAD, PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD, PR_UNJOINABLE_THREAD,
0) ; 0) ;
if (newThread == nsnull) { if (!newThread ) {
delete threadArgs ; delete threadArgs ;
return NS_ERROR_OUT_OF_MEMORY ; return NS_ERROR_OUT_OF_MEMORY ;
} }
@ -937,8 +959,8 @@ nsresult nsAbOutlookDirectory::StopQuery(PRInt32 aContext)
{ {
nsIntegerKey contextKey(aContext) ; nsIntegerKey contextKey(aContext) ;
PRThread *queryThread = NS_REINTERPRET_CAST(PRThread *, mQueryThreads.Get(&contextKey)) ; PRThread *queryThread = NS_REINTERPRET_CAST(PRThread *, mQueryThreads.Get(&contextKey)) ;
if (queryThread != nsnull) { if (queryThread) {
PR_Interrupt(queryThread) ; PR_Interrupt(queryThread) ;
mQueryThreads.Remove(&contextKey) ; mQueryThreads.Remove(&contextKey) ;
} }
@ -956,7 +978,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::StartSearch(void)
mCardList.Reset() ; mCardList.Reset() ;
nsCOMPtr<nsIAbDirectoryQueryArguments> arguments ; nsCOMPtr<nsIAbDirectoryQueryArguments> arguments ;
nsCOMPtr<nsIAbBooleanExpression> expression ; nsCOMPtr<nsIAbBooleanExpression> expression ;
NS_NewIAbDirectoryQueryArguments(getter_AddRefs(arguments)) ; NS_NewIAbDirectoryQueryArguments(getter_AddRefs(arguments)) ;
retCode = nsAbQueryStringToExpression::Convert(mQueryString.get (), getter_AddRefs(expression)) ; retCode = nsAbQueryStringToExpression::Convert(mQueryString.get (), getter_AddRefs(expression)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
@ -1006,9 +1028,11 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
nsIAbDirectoryQueryResultListener *aListener, nsIAbDirectoryQueryResultListener *aListener,
PRInt32 aResultLimit, PRInt32 aTimeout, PRInt32 aResultLimit, PRInt32 aTimeout,
PRInt32 aThreadId) PRInt32 aThreadId)
{ {
if (aArguments == nsnull || if (!aArguments || !aListener) {
aListener == nsnull) { return NS_ERROR_NULL_POINTER ; } return NS_ERROR_NULL_POINTER ;
}
SRestriction arguments ; SRestriction arguments ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
@ -1050,7 +1074,7 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
newResult = new nsAbDirectoryQueryResult(0, aArguments, newResult = new nsAbDirectoryQueryResult(0, aArguments,
nsIAbDirectoryQueryResult::queryResultMatch, nsIAbDirectoryQueryResult::queryResultMatch,
propertyValues) ; propertyValues) ;
if (newResult == nsnull) { return NS_ERROR_OUT_OF_MEMORY ; } if (!newResult) { return NS_ERROR_OUT_OF_MEMORY ; }
result = newResult ; result = newResult ;
aListener->OnQueryItem(result) ; aListener->OnQueryItem(result) ;
} }
@ -1059,39 +1083,35 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
mQueryThreads.Remove(&hashKey) ; mQueryThreads.Remove(&hashKey) ;
return retCode ; return retCode ;
} }
nsresult nsAbOutlookDirectory::GetChildCards(nsISupportsArray **aCards, nsresult nsAbOutlookDirectory::GetChildCards(nsISupportsArray **aCards,
void *aRestriction) void *aRestriction)
{ {
if (aCards == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aCards) { return NS_ERROR_NULL_POINTER ; }
*aCards = nsnull ; *aCards = nsnull ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsCOMPtr<nsISupportsArray> cards ; nsCOMPtr<nsISupportsArray> cards ;
nsMapiAddressBook mapiAddBook ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
nsMapiEntryArray cardEntries ; nsMapiEntryArray cardEntries ;
LPSRestriction restriction = (LPSRestriction) aRestriction ; LPSRestriction restriction = (LPSRestriction) aRestriction ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
retCode = NS_NewISupportsArray(getter_AddRefs(cards)) ; retCode = NS_NewISupportsArray(getter_AddRefs(cards)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
if (!mapiAddBook.GetCards(*mMapiData, restriction, cardEntries)) { if (!mapiAddBook->GetCards(*mMapiData, restriction, cardEntries)) {
PRINTF("Cannot get cards.\n") ; PRINTF("Cannot get cards.\n") ;
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
nsCAutoString entryId ; nsCAutoString entryId ;
nsCAutoString uriName ; nsCAutoString uriName ;
nsCOMPtr<nsIRDFResource> resource ; nsCOMPtr<nsIRDFResource> resource ;
for (ULONG card = 0 ; card < cardEntries.mNbEntries ; ++ card) { for (ULONG card = 0 ; card < cardEntries.mNbEntries ; ++ card) {
if (mapiAddBook.EntryToString(cardEntries.mEntries [card], entryId)) { cardEntries.mEntries [card].ToString(entryId) ;
uriName.Assign(kOutlookCardScheme) ; buildAbWinUri(kOutlookCardScheme, mAbWinType, uriName) ;
uriName.Append(entryId) ; uriName.Append(entryId) ;
retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ; retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
cards->AppendElement(resource) ; cards->AppendElement(resource) ;
}
else {
PRINTF("Cannot manage entry %d.\n", card) ;
}
} }
*aCards = cards ; *aCards = cards ;
NS_ADDREF(*aCards) ; NS_ADDREF(*aCards) ;
@ -1100,34 +1120,31 @@ nsresult nsAbOutlookDirectory::GetChildCards(nsISupportsArray **aCards,
nsresult nsAbOutlookDirectory::GetChildNodes(nsISupportsArray **aNodes) nsresult nsAbOutlookDirectory::GetChildNodes(nsISupportsArray **aNodes)
{ {
if (aNodes == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aNodes) { return NS_ERROR_NULL_POINTER ; }
*aNodes = nsnull ; *aNodes = nsnull ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsCOMPtr<nsISupportsArray> nodes ; nsCOMPtr<nsISupportsArray> nodes ;
nsMapiAddressBook mapiAddBook ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
nsMapiEntryArray nodeEntries ; nsMapiEntryArray nodeEntries ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
retCode = NS_NewISupportsArray(getter_AddRefs(nodes)) ; retCode = NS_NewISupportsArray(getter_AddRefs(nodes)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
if (!mapiAddBook.GetNodes(*mMapiData, nodeEntries)) { if (!mapiAddBook->GetNodes(*mMapiData, nodeEntries)) {
PRINTF("Cannot get nodes.\n") ; PRINTF("Cannot get nodes.\n") ;
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
nsCAutoString entryId ; nsCAutoString entryId ;
nsCAutoString uriName ; nsCAutoString uriName ;
nsCOMPtr <nsIRDFResource> resource ; nsCOMPtr <nsIRDFResource> resource ;
for (ULONG node = 0 ; node < nodeEntries.mNbEntries ; ++ node) { for (ULONG node = 0 ; node < nodeEntries.mNbEntries ; ++ node) {
if (mapiAddBook.EntryToString(nodeEntries.mEntries [node], entryId)) { nodeEntries.mEntries [node].ToString(entryId) ;
uriName.Assign(kOutlookDirectoryScheme) ; buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uriName) ;
uriName.Append(entryId) ; uriName.Append(entryId) ;
retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ; retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
nodes->AppendElement(resource) ; nodes->AppendElement(resource) ;
}
else {
PRINTF("Cannot manage entry %d.\n", node) ;
}
} }
*aNodes = nodes ; *aNodes = nodes ;
NS_ADDREF(*aNodes) ; NS_ADDREF(*aNodes) ;
@ -1174,7 +1191,7 @@ nsresult nsAbOutlookDirectory::CommitAddressList(void)
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
nsCOMPtr<nsISupports> element ; nsCOMPtr<nsISupports> element ;
nsCOMPtr<nsIAbCard> newCard ; nsCOMPtr<nsIAbCard> newCard ;
for (i = 0 ; i < nbCards ; ++ i) { for (i = 0 ; i < nbCards ; ++ i) {
retCode = m_AddressList->GetElementAt(i, getter_AddRefs(element)) ; retCode = m_AddressList->GetElementAt(i, getter_AddRefs(element)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
@ -1183,6 +1200,7 @@ nsresult nsAbOutlookDirectory::CommitAddressList(void)
nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ; nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
retCode = CreateCard(card, getter_AddRefs(newCard)) ; retCode = CreateCard(card, getter_AddRefs(newCard)) ;
NS_ENSURE_SUCCESS(retCode, retCode) ; NS_ENSURE_SUCCESS(retCode, retCode) ;
m_AddressList->ReplaceElementAt(newCard, i) ; m_AddressList->ReplaceElementAt(newCard, i) ;
@ -1207,33 +1225,34 @@ nsresult nsAbOutlookDirectory::UpdateAddressList(void)
nsresult nsAbOutlookDirectory::CreateCard(nsIAbCard *aData, nsIAbCard **aNewCard) nsresult nsAbOutlookDirectory::CreateCard(nsIAbCard *aData, nsIAbCard **aNewCard)
{ {
if (aData == nsnull || aNewCard == nsnull) { return NS_ERROR_NULL_POINTER ; } if (!aData || !aNewCard) { return NS_ERROR_NULL_POINTER ; }
*aNewCard = nsnull ; *aNewCard = nsnull ;
nsresult retCode = NS_OK ; nsresult retCode = NS_OK ;
nsMapiAddressBook mapiAddBook ; nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
nsMapiEntry newEntry ; nsMapiEntry newEntry ;
nsCAutoString entryString ; nsCAutoString entryString ;
PRBool didCopy = PR_FALSE ; PRBool didCopy = PR_FALSE ;
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
// If we get a RDF resource and it maps onto an Outlook card uri, // If we get a RDF resource and it maps onto an Outlook card uri,
// we simply copy the contents of the Outlook card. // we simply copy the contents of the Outlook card.
retCode = ExtractCardEntry(aData, entryString) ; retCode = ExtractCardEntry(aData, entryString) ;
if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) { if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) {
nsMapiEntry sourceEntry ; nsMapiEntry sourceEntry ;
if (mapiAddBook.StringToEntry(entryString, sourceEntry)) {
if (m_bIsMailList) { sourceEntry.Assign(entryString) ;
// In the case of a mailing list, we can use the address if (m_bIsMailList) {
// as a direct template to build the new one (which is done // In the case of a mailing list, we can use the address
// by CopyEntry). // as a direct template to build the new one (which is done
mapiAddBook.CopyEntry(*mMapiData, sourceEntry, newEntry) ; // by CopyEntry).
didCopy = PR_TRUE ; mapiAddBook->CopyEntry(*mMapiData, sourceEntry, newEntry) ;
} didCopy = PR_TRUE ;
else { }
// Else, we have to create a temporary address and copy the else {
// source into it. Yes it's silly. // Else, we have to create a temporary address and copy the
mapiAddBook.CreateEntry(*mMapiData, newEntry) ; // source into it. Yes it's silly.
} mapiAddBook->CreateEntry(*mMapiData, newEntry) ;
} }
} }
// If this approach doesn't work, well we're back to creating and copying. // If this approach doesn't work, well we're back to creating and copying.
@ -1244,33 +1263,30 @@ nsresult nsAbOutlookDirectory::CreateCard(nsIAbCard *aData, nsIAbCard **aNewCard
if (m_bIsMailList) { if (m_bIsMailList) {
nsMapiEntry parentEntry ; nsMapiEntry parentEntry ;
nsMapiEntry temporaryEntry ; nsMapiEntry temporaryEntry ;
if (!mapiAddBook.GetDefaultContainer(parentEntry)) { if (!mapiAddBook->GetDefaultContainer(parentEntry)) {
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
if (!mapiAddBook.CreateEntry(parentEntry, temporaryEntry)) { if (!mapiAddBook->CreateEntry(parentEntry, temporaryEntry)) {
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
if (!mapiAddBook.CopyEntry(*mMapiData, temporaryEntry, newEntry)) { if (!mapiAddBook->CopyEntry(*mMapiData, temporaryEntry, newEntry)) {
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
if (!mapiAddBook.DeleteEntry(parentEntry, temporaryEntry)) { if (!mapiAddBook->DeleteEntry(parentEntry, temporaryEntry)) {
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
} }
// If we're on a real address book folder, we can directly create an // If we're on a real address book folder, we can directly create an
// empty card. // empty card.
else if (!mapiAddBook.CreateEntry(*mMapiData, newEntry)) { else if (!mapiAddBook->CreateEntry(*mMapiData, newEntry)) {
return NS_ERROR_FAILURE ; return NS_ERROR_FAILURE ;
} }
} }
if (!mapiAddBook.EntryToString(newEntry, entryString)) { newEntry.ToString(entryString) ;
PRINTF("Cannot manage entry.\n") ;
return NS_ERROR_FAILURE ;
}
nsCAutoString uri ; nsCAutoString uri ;
uri.Assign(kOutlookCardScheme) ; buildAbWinUri(kOutlookCardScheme, mAbWinType, uri) ;
uri.Append(entryString) ; uri.Append(entryString) ;
nsCOMPtr<nsIRDFResource> resource ; nsCOMPtr<nsIRDFResource> resource ;

View File

@ -97,6 +97,8 @@ protected:
// Data for the search interfaces // Data for the search interfaces
nsSupportsHashtable mCardList ; nsSupportsHashtable mCardList ;
PRInt32 mSearchContext ; PRInt32 mSearchContext ;
// Windows AB type
PRUint32 mAbWinType ;
private: private:
}; };

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,173 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun
* Microsystems, Inc. Portions created by Sun are
* Copyright (C) 2001 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
*/
#ifndef nsAbWinHelper_h___
#define nsAbWinHelper_h___
#include <windows.h>
#include <mapix.h>
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
struct nsMapiEntry
{
ULONG mByteCount ;
LPENTRYID mEntryId ;
nsMapiEntry(void) ;
~nsMapiEntry(void) ;
nsMapiEntry(ULONG aByteCount, LPENTRYID aEntryId) ;
void Assign(ULONG aByteCount, LPENTRYID aEntryId) ;
void Assign(const nsCString& aString) ;
void ToString(nsCString& aString) const ;
void Dump(void) const ;
} ;
struct nsMapiEntryArray
{
nsMapiEntry *mEntries ;
ULONG mNbEntries ;
nsMapiEntryArray(void) ;
~nsMapiEntryArray(void) ;
const nsMapiEntry& operator [] (int aIndex) const { return mEntries [aIndex] ; }
void CleanUp(void) ;
} ;
class nsAbWinHelper
{
public:
nsAbWinHelper(void) ;
virtual ~nsAbWinHelper(void) ;
// Get the top address books
BOOL GetFolders(nsMapiEntryArray& aFolders) ;
// Get a list of entries for cards/mailing lists in a folder/mailing list
BOOL GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction,
nsMapiEntryArray& aCards) ;
// Get a list of mailing lists in a folder
BOOL GetNodes(const nsMapiEntry& aParent, nsMapiEntryArray& aNodes) ;
// Get the number of cards/mailing lists in a folder/mailing list
BOOL GetCardsCount(const nsMapiEntry& aParent, ULONG& aNbCards) ;
// Access last MAPI error
HRESULT LastError(void) const { return mLastError ; }
// Get the value of a MAPI property of type string
BOOL GetPropertyString(const nsMapiEntry& aObject, ULONG aPropertyTag, nsCString& aValue) ;
// Same as previous, but string is returned as unicode
BOOL GetPropertyUString(const nsMapiEntry& aObject, ULONG aPropertyTag, nsString& aValue) ;
// Get multiple string MAPI properties in one call.
BOOL GetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
ULONG aNbProperties, nsStringArray& aValues) ;
// Get the value of a MAPI property of type SYSTIME
BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
WORD& aYear, WORD& aMonth, WORD& aDay) ;
// Get the value of a MAPI property of type LONG
BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
// Get the value of a MAPI property of type BIN
BOOL GetPropertyBin(const nsMapiEntry& aObject, ULONG aPropertyTag, nsMapiEntry& aValue) ;
// Tests if a container contains an entry
BOOL TestOpenEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
// Delete an entry in the address book
BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
// Set the value of a MAPI property of type string in unicode
BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag,
const PRUnichar *aValue) ;
// Same as previous, but with a bunch of properties in one call
BOOL SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
ULONG aNbProperties, nsXPIDLString *aValues) ;
// Set the value of a MAPI property of type SYSTIME
BOOL SetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
WORD aYear, WORD aMonth, WORD aDay) ;
// Create entry in the address book
BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
// Create a distribution list in the address book
BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
// Copy an existing entry in the address book
BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
// Get a default address book container
BOOL GetDefaultContainer(nsMapiEntry& aContainer) ;
// Is the helper correctly initialised?
BOOL IsOK(void) const { return mAddressBook != NULL ; }
protected:
HRESULT mLastError ;
LPADRBOOK mAddressBook ;
static ULONG mEntryCounter ;
static PRLock *mMutex ;
// Retrieve the contents of a container, with an optional restriction
BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
nsMapiEntry **aList, ULONG &aNbElements, ULONG aMapiType) ;
// Retrieve the values of a set of properties on a MAPI object
BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
ULONG aNbProperties,
LPSPropValue& aValues, ULONG& aValueCount) ;
// Set the values of a set of properties on a MAPI object
BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
const LPSPropValue& aValues) ;
// Clean-up a rowset returned by QueryRows
void MyFreeProws(LPSRowSet aSet) ;
// Allocation of a buffer for transmission to interfaces
virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) = 0 ;
// Destruction of a buffer provided by the interfaces
virtual void FreeBuffer(LPVOID aBuffer) = 0 ;
private:
} ;
enum nsAbWinType
{
nsAbWinType_Unknown,
nsAbWinType_Outlook,
nsAbWinType_OutlookExp
} ;
class nsAbWinHelperGuard
{
public :
nsAbWinHelperGuard(PRUint32 aType) ;
~nsAbWinHelperGuard(void) ;
nsAbWinHelper *operator ->(void) { return mHelper ; }
private:
nsAbWinHelper *mHelper ;
} ;
extern const char *kOutlookDirectoryScheme ;
extern const char *kOutlookStub ;
extern const char *kOutlookExpStub ;
extern const char *kOutlookCardScheme ;
nsAbWinType getAbWinType(const char *aScheme, const char *aUri,
nsCString& aStub, nsCString& aEntry) ;
void buildAbWinUri(const char *aScheme, PRUint32 aType, nsCString& aUri) ;
#endif // nsAbWinHelper_h___

File diff suppressed because it is too large Load Diff

View File

@ -24,117 +24,48 @@
#ifndef nsMapiAddressBook_h___ #ifndef nsMapiAddressBook_h___
#define nsMapiAddressBook_h___ #define nsMapiAddressBook_h___
#include <windows.h> #include "nsAbWinHelper.h"
#include <mapix.h>
class nsMapiAddressBook : public nsAbWinHelper
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
struct nsMapiEntry
{
ULONG mByteCount ;
LPENTRYID mEntryId ;
nsMapiEntry(void) ;
~nsMapiEntry(void) ;
nsMapiEntry(ULONG aByteCount, LPENTRYID aEntryId) ;
void Assign(ULONG aByteCount, LPENTRYID aEntryId) ;
void Dump(void) const ;
} ;
struct nsMapiEntryArray
{
nsMapiEntry *mEntries ;
ULONG mNbEntries ;
nsMapiEntryArray(void) ;
~nsMapiEntryArray(void) ;
const nsMapiEntry& operator [] (int aIndex) const { return mEntries [aIndex] ; }
void CleanUp(void) ;
} ;
class nsMapiAddressBook
{ {
public : public :
nsMapiAddressBook(void) ; nsMapiAddressBook(void) ;
~nsMapiAddressBook(void) ; virtual ~nsMapiAddressBook(void) ;
// Get the top address books
BOOL GetFolders(nsMapiEntryArray& aFolders) ;
// Get a list of entries for cards/mailing lists in a folder/mailing list
BOOL GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction,
nsMapiEntryArray& aCards) ;
// Get a list of mailing lists in a folder
BOOL GetNodes(const nsMapiEntry& aParent, nsMapiEntryArray& aNodes) ;
// Get the number of cards/mailing lists in a folder/mailing list
BOOL GetCardsCount(const nsMapiEntry& aParent, ULONG& aNbCards) ;
// Access last MAPI error
HRESULT LastError(void) const { return mLastError ; }
// Get the value of a MAPI property of type string
BOOL GetPropertyString(const nsMapiEntry& aObject, ULONG aPropertyTag, nsCString& aValue) ;
// Same as previous, but string is returned as unicode
BOOL GetPropertyUString(const nsMapiEntry& aObject, ULONG aPropertyTag, nsString& aValue) ;
// Get multiple string MAPI properties in one call.
BOOL GetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
ULONG aNbProperties, nsStringArray& aValues) ;
// Get the value of a MAPI property of type SYSTIME
BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
WORD& aYear, WORD& aMonth, WORD& aDay) ;
// Get the value of a MAPI property of type LONG
BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
// Get the value of a MAPI property of type BIN
BOOL GetPropertyBin(const nsMapiEntry& aObject, ULONG aPropertyTag, nsMapiEntry& aValue) ;
// Convert MAPI entries into strings and back
BOOL StringToEntry(const nsCString& aString, nsMapiEntry& aEntry) const ;
BOOL EntryToString(const nsMapiEntry& aEntry, nsCString& aString) const ;
// Tests if a container contains an entry
BOOL TestOpenEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
// Delete an entry in the address book
BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
// Set the value of a MAPI property of type string in unicode
BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag,
const PRUnichar *aValue) ;
// Same as previous, but with a bunch of properties in one call
BOOL SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
ULONG aNbProperties, nsXPIDLString *aValues) ;
// Set the value of a MAPI property of type SYSTIME
BOOL SetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
WORD aYear, WORD aMonth, WORD aDay) ;
// Create entry in the address book
BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
// Create a distribution list in the address book
BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
// Copy an existing entry in the address book
BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
// Get a default address book container
BOOL GetDefaultContainer(nsMapiEntry& aContainer) ;
protected : protected :
// Class members to handle the library/entry points
private : static HMODULE mLibrary ;
LPMAPISESSION mSession ; static PRInt32 mLibUsage ;
LPADRBOOK mAddressBook ; static LPMAPIINITIALIZE mMAPIInitialize ;
BOOL mLogonDone ; static LPMAPIUNINITIALIZE mMAPIUninitialize ;
BOOL mInitialized ; static LPMAPIALLOCATEBUFFER mMAPIAllocateBuffer ;
HRESULT mLastError ; static LPMAPIFREEBUFFER mMAPIFreeBuffer ;
static ULONG mEntryCounter ; static LPMAPILOGONEX mMAPILogonEx ;
// Shared session and address book used by all instances.
// For reasons best left unknown, MAPI doesn't seem to like
// having different threads playing with supposedly different
// sessions and address books. They ll end up fighting over
// the same resources, with hangups and GPF resulting. Not nice.
// So it seems that if everybody (as long as some client is
// still alive) is using the same sessions and address books,
// MAPI feels better. And who are we to get in the way of MAPI
// happiness? Thus the following class members:
static BOOL mInitialized ;
static BOOL mLogonDone ;
static LPMAPISESSION mRootSession ;
static LPADRBOOK mRootBook ;
// Load the MAPI environment // Load the MAPI environment
BOOL Initialize(void) ; BOOL Initialize(void) ;
// Retrieve the contents of a container, with an optional restriction // Allocation of a buffer for transmission to interfaces
BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction, virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) ;
nsMapiEntry **aList, ULONG &aNbElements, ULONG aMapiType) ; // Destruction of a buffer provided by the interfaces
// Retrieve the values of a set of properties on a MAPI object virtual void FreeBuffer(LPVOID aBuffer) ;
BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags, // Library management
ULONG aNbProperties, static BOOL LoadMapiLibrary(void) ;
LPSPropValue& aValues, ULONG& aValueCount) ; static void FreeMapiLibrary(void) ;
// Set the values of a set of properties on a MAPI object
BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties, private :
const LPSPropValue& aValues) ;
} ; } ;
#endif // nsMapiAddressBook_h___ #endif // nsMapiAddressBook_h___

View File

@ -0,0 +1,124 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun
* Microsystems, Inc. Portions created by Sun are
* Copyright (C) 2001 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
*/
#include "nsWabAddressBook.h"
#include "nsAbUtils.h"
#include "nsAutoLock.h"
#include "nslog.h"
NS_IMPL_LOG(nsWabAddressBookLog)
#define PRINTF NS_LOG_PRINTF(nsWabAddressBookLog)
#define FLUSH NS_LOG_FLUSH(nsWabAddressBookLog)
HMODULE nsWabAddressBook::mLibrary = NULL ;
PRInt32 nsWabAddressBook::mLibUsage = 0 ;
LPWABOPEN nsWabAddressBook::mWABOpen = NULL ;
LPWABOBJECT nsWabAddressBook::mRootSession = NULL ;
LPADRBOOK nsWabAddressBook::mRootBook = NULL ;
BOOL nsWabAddressBook::LoadWabLibrary(void)
{
if (mLibrary) { ++ mLibUsage ; return TRUE ; }
// We try to fetch the location of the WAB DLL from the registry
TCHAR wabDLLPath [MAX_PATH] ;
DWORD keyType = 0 ;
ULONG byteCount = sizeof(wabDLLPath) ;
HKEY keyHandle = NULL ;
wabDLLPath [MAX_PATH - 1] = 0 ;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
RegQueryValueEx(keyHandle, "", NULL, &keyType, (LPBYTE) wabDLLPath, &byteCount) ;
}
if (keyHandle) { RegCloseKey(keyHandle) ; }
mLibrary = LoadLibrary( (lstrlen(wabDLLPath)) ? wabDLLPath : WAB_DLL_NAME );
if (!mLibrary) { return FALSE ; }
++ mLibUsage ;
mWABOpen = NS_REINTERPRET_CAST(LPWABOPEN, GetProcAddress(mLibrary, "WABOpen")) ;
if (!mWABOpen) { return FALSE ; }
HRESULT retCode = mWABOpen(&mRootBook, &mRootSession, NULL, 0) ;
if (HR_FAILED(retCode)) {
PRINTF("Cannot initialize WAB %08x.\n", retCode) ; return FALSE ;
}
return TRUE ;
}
void nsWabAddressBook::FreeWabLibrary(void)
{
if (mLibrary) {
if (-- mLibUsage == 0) {
if (mRootBook) { mRootBook->Release() ; }
if (mRootSession) { mRootSession->Release() ; }
FreeLibrary(mLibrary) ;
mLibrary = NULL ;
}
}
}
MOZ_DECL_CTOR_COUNTER(nsWabAddressBook)
nsWabAddressBook::nsWabAddressBook(void)
: nsAbWinHelper()
{
BOOL result = Initialize() ;
NS_ASSERTION(result == TRUE, "Couldn't initialize Wab Helper") ;
MOZ_COUNT_CTOR(nsWabAddressBook) ;
}
nsWabAddressBook::~nsWabAddressBook(void)
{
nsAutoLock guard(mMutex) ;
FreeWabLibrary() ;
MOZ_COUNT_DTOR(nsWabAddressBook) ;
}
BOOL nsWabAddressBook::Initialize(void)
{
if (mAddressBook) { return TRUE ; }
nsAutoLock guard(mMutex) ;
if (!LoadWabLibrary()) {
PRINTF("Cannot load library.\n") ;
return FALSE ;
}
mAddressBook = mRootBook ;
return TRUE ;
}
void nsWabAddressBook::AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer)
{
mRootSession->AllocateBuffer(aByteCount, aBuffer) ;
}
void nsWabAddressBook::FreeBuffer(LPVOID aBuffer)
{
mRootSession->FreeBuffer(aBuffer) ;
}

View File

@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun
* Microsystems, Inc. Portions created by Sun are
* Copyright (C) 2001 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
*/
#ifndef nsWabAddressBook_h___
#define nsWabAddressBook_h___
#include "nsAbWinHelper.h"
#include <wab.h>
class nsWabAddressBook : public nsAbWinHelper
{
public :
nsWabAddressBook(void) ;
virtual ~nsWabAddressBook(void) ;
protected :
// Session and address book that will be shared by all instances
// (see nsMapiAddressBook.h for details)
static LPWABOBJECT mRootSession ;
static LPADRBOOK mRootBook ;
// Class members to handle library loading/entry points
static PRInt32 mLibUsage ;
static HMODULE mLibrary ;
static LPWABOPEN mWABOpen ;
// Load the WAB environment
BOOL Initialize(void) ;
// Allocation of a buffer for transmission to interfaces
virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) ;
// Destruction of a buffer provided by the interfaces
virtual void FreeBuffer(LPVOID aBuffer) ;
// Manage the library
static BOOL LoadWabLibrary(void) ;
static void FreeWabLibrary(void) ;
private :
} ;
// Additional definitions for WAB stuff. These properties are
// only defined with regards to the default character sizes,
// and not in two _A and _W versions...
#define PR_BUSINESS_ADDRESS_CITY_A PR_LOCALITY_A
#define PR_BUSINESS_ADDRESS_COUNTRY_A PR_COUNTRY_A
#define PR_BUSINESS_ADDRESS_POSTAL_CODE_A PR_POSTAL_CODE_A
#define PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_A PR_STATE_OR_PROVINCE_A
#define PR_BUSINESS_ADDRESS_STREET_A PR_STREET_ADDRESS_A
#define PR_BUSINESS_ADDRESS_CITY_W PR_LOCALITY_W
#define PR_BUSINESS_ADDRESS_COUNTRY_W PR_COUNTRY_W
#define PR_BUSINESS_ADDRESS_POSTAL_CODE_W PR_POSTAL_CODE_W
#define PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_W PR_STATE_OR_PROVINCE_W
#define PR_BUSINESS_ADDRESS_STREET_W PR_STREET_ADDRESS_W
#endif // nsWABAddressBook_h___