mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 05:45:37 +00:00
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:
parent
e3c127fac5
commit
64d4399050
@ -111,6 +111,8 @@ CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsAbBooleanExpression.obj \
|
||||
.\$(OBJDIR)\nsAbDirectoryRDFResource.obj \
|
||||
.\$(OBJDIR)\nsAbQueryStringToExpression.obj \
|
||||
.\$(OBJDIR)\nsAbWinHelper.obj \
|
||||
.\$(OBJDIR)\nsWabAddressBook.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
@ -22,7 +22,7 @@
|
||||
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
|
||||
*/
|
||||
#include "nsAbOutlookCard.h"
|
||||
#include "nsMapiAddressBook.h"
|
||||
#include "nsAbWinHelper.h"
|
||||
|
||||
#include "nslog.h"
|
||||
|
||||
@ -35,7 +35,7 @@ extern const char *kOutlookDirectoryScheme ;
|
||||
extern const char *kOutlookCardScheme ;
|
||||
|
||||
nsAbOutlookCard::nsAbOutlookCard(void)
|
||||
: nsRDFResource(), nsAbCardProperty(), mMapiData(nsnull)
|
||||
: nsRDFResource(), nsAbCardProperty(), mAbWinType(nsAbWinType_Unknown), mMapiData(nsnull)
|
||||
{
|
||||
mMapiData = new nsMapiEntry ;
|
||||
}
|
||||
@ -132,23 +132,22 @@ nsresult nsAbOutlookCard::Init(const char *aUri)
|
||||
nsresult retCode = nsRDFResource::Init(aUri) ;
|
||||
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsCAutoString subUri ;
|
||||
PRInt32 schemeLength = nsCRT::strlen(kOutlookCardScheme) ;
|
||||
nsCAutoString entry ;
|
||||
nsCAutoString stub ;
|
||||
|
||||
if (nsCRT::strncmp(mURI, kOutlookCardScheme, schemeLength) != 0) {
|
||||
mAbWinType = getAbWinType(kOutlookCardScheme, mURI, stub, entry) ;
|
||||
if (mAbWinType == nsAbWinType_Unknown) {
|
||||
PRINTF("Huge problem URI=%s.\n", mURI) ;
|
||||
return NS_ERROR_INVALID_ARG ;
|
||||
}
|
||||
subUri = mURI + schemeLength ;
|
||||
if (!mapiAddBook.StringToEntry(subUri, *mMapiData)) {
|
||||
PRINTF("Cannot parse string %s.\n", subUri.get()) ;
|
||||
return NS_ERROR_INVALID_ARG ;
|
||||
}
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
mMapiData->Assign(entry) ;
|
||||
nsStringArray unichars ;
|
||||
ULONG i = 0 ;
|
||||
|
||||
if (mapiAddBook.GetPropertiesUString(*mMapiData, OutlookCardMAPIProps, index_LastProp, unichars)) {
|
||||
if (mapiAddBook->GetPropertiesUString(*mMapiData, OutlookCardMAPIProps, index_LastProp, unichars)) {
|
||||
SetFirstName(unichars [index_FirstName]->get()) ;
|
||||
SetLastName(unichars [index_LastName]->get()) ;
|
||||
SetDisplayName(unichars [index_DisplayName]->get()) ;
|
||||
@ -177,23 +176,23 @@ nsresult nsAbOutlookCard::Init(const char *aUri)
|
||||
ULONG cardType = 0 ;
|
||||
nsCAutoString normalChars ;
|
||||
|
||||
if (mapiAddBook.GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, cardType)) {
|
||||
if (mapiAddBook->GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, cardType)) {
|
||||
SetIsMailList(cardType == MAPI_DISTLIST) ;
|
||||
if (cardType == MAPI_DISTLIST) {
|
||||
normalChars = kOutlookDirectoryScheme ;
|
||||
normalChars.Append(subUri) ;
|
||||
buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, normalChars) ;
|
||||
normalChars.Append(entry) ;
|
||||
SetMailListURI(normalChars) ;
|
||||
}
|
||||
}
|
||||
nsAutoString unichar ;
|
||||
nsAutoString unicharBis ;
|
||||
|
||||
if (mapiAddBook.GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET, unichar)) {
|
||||
if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET, unichar)) {
|
||||
splitString(unichar, unicharBis) ;
|
||||
SetHomeAddress(unichar.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) ;
|
||||
SetWorkAddress(unichar.get()) ;
|
||||
SetWorkAddress2(unicharBis.get()) ;
|
||||
@ -202,7 +201,7 @@ nsresult nsAbOutlookCard::Init(const char *aUri)
|
||||
WORD month = 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) ;
|
||||
SetBirthYear(unichar.get()) ;
|
||||
wordToUnicode(month, unichar) ;
|
||||
@ -230,12 +229,13 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
|
||||
{
|
||||
nsresult retCode = NS_OK ;
|
||||
nsXPIDLString *properties = nsnull ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAutoString utility ;
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
// First, all the standard properties in one go
|
||||
properties = new nsXPIDLString [index_LastProp] ;
|
||||
if (properties == nsnull) {
|
||||
if (!properties) {
|
||||
return NS_ERROR_OUT_OF_MEMORY ;
|
||||
}
|
||||
GetFirstName(getter_Copies(properties [index_FirstName])) ;
|
||||
@ -274,7 +274,7 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
|
||||
GetWebPage1(getter_Copies(properties [index_WorkWebPage])) ;
|
||||
GetWebPage2(getter_Copies(properties [index_HomeWebPage])) ;
|
||||
GetNotes(getter_Copies(properties [index_Comments])) ;
|
||||
if (!mapiAddBook.SetPropertiesUString(*mMapiData, OutlookCardMAPIProps,
|
||||
if (!mapiAddBook->SetPropertiesUString(*mMapiData, OutlookCardMAPIProps,
|
||||
index_LastProp, properties)) {
|
||||
PRINTF("Cannot set general properties.\n") ;
|
||||
}
|
||||
@ -290,7 +290,7 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
|
||||
utility.Assign(unichar.get()) ;
|
||||
if (utility.Length() > 0) { utility.AppendWithConversion(CRLF) ; }
|
||||
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") ;
|
||||
}
|
||||
GetWorkAddress(getter_Copies(unichar)) ;
|
||||
@ -298,7 +298,7 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
|
||||
utility.Assign(unichar.get()) ;
|
||||
if (utility.Length() > 0) { utility.AppendWithConversion(CRLF) ; }
|
||||
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") ;
|
||||
}
|
||||
GetBirthYear(getter_Copies(unichar)) ;
|
||||
@ -307,7 +307,7 @@ NS_IMETHODIMP nsAbOutlookCard::EditCardToDatabase(const char *aUri)
|
||||
UnicodeToWord(unichar.get(), month) ;
|
||||
GetBirthDay(getter_Copies(unichar)) ;
|
||||
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") ;
|
||||
}
|
||||
return retCode ;
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
|
||||
protected:
|
||||
nsMapiEntry *mMapiData ;
|
||||
PRUint32 mAbWinType ;
|
||||
|
||||
private:
|
||||
};
|
||||
|
@ -22,7 +22,7 @@
|
||||
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
|
||||
*/
|
||||
#include "nsAbOutlookDirFactory.h"
|
||||
#include "nsMapiAddressBook.h"
|
||||
#include "nsAbWinHelper.h"
|
||||
#include "nsIAbDirectory.h"
|
||||
|
||||
#include "nsIRDFService.h"
|
||||
@ -63,41 +63,69 @@ nsAbOutlookDirFactory::~nsAbOutlookDirFactory(void)
|
||||
}
|
||||
|
||||
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,
|
||||
const char **aPropertyNames,
|
||||
const PRUnichar **aPropertyValues,
|
||||
nsISimpleEnumerator **aDirectories)
|
||||
{
|
||||
if (aPropertyNames == nsnull ||
|
||||
aPropertyValues == nsnull ||
|
||||
aDirectories == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aPropertyNames || !aPropertyValues || !aDirectories) {
|
||||
return NS_ERROR_NULL_POINTER ;
|
||||
}
|
||||
*aDirectories = nsnull ;
|
||||
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 ;
|
||||
ULONG nbFolders = 0 ;
|
||||
nsCOMPtr<nsISupportsArray> directories ;
|
||||
|
||||
retCode = NS_NewISupportsArray(getter_AddRefs(directories)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
if (!mapiAddBook.GetFolders(folders)) {
|
||||
if (!mapiAddBook->IsOK() || !mapiAddBook->GetFolders(folders)) {
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
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 uri ;
|
||||
nsCOMPtr<nsIRDFResource> resource ;
|
||||
|
||||
for (ULONG i = 0 ; i < folders.mNbEntries ; ++ i) {
|
||||
if (mapiAddBook.EntryToString(folders.mEntries [i], entryId)) {
|
||||
uri.Assign(kOutlookDirectoryScheme) ;
|
||||
uri.Append(entryId) ;
|
||||
retCode = rdf->GetResource(uri, getter_AddRefs(resource)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
directories->AppendElement(resource) ;
|
||||
}
|
||||
folders.mEntries [i].ToString(entryId) ;
|
||||
buildAbWinUri(kOutlookDirectoryScheme, abType, uri) ;
|
||||
uri.Append(entryId) ;
|
||||
|
||||
retCode = rdf->GetResource(uri, getter_AddRefs(resource)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
directories->AppendElement(resource) ;
|
||||
}
|
||||
return NS_NewArrayEnumerator(aDirectories, directories) ;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
|
||||
*/
|
||||
#include "nsAbOutlookDirectory.h"
|
||||
#include "nsMapiAddressBook.h"
|
||||
#include "nsAbWinHelper.h"
|
||||
|
||||
#include "nsIRDFService.h"
|
||||
|
||||
@ -70,7 +70,8 @@ private:
|
||||
|
||||
nsAbOutlookDirectory::nsAbOutlookDirectory(void)
|
||||
: 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 ;
|
||||
mProtector = PR_NewLock() ;
|
||||
@ -85,39 +86,39 @@ nsAbOutlookDirectory::~nsAbOutlookDirectory(void)
|
||||
NS_IMPL_ISUPPORTS_INHERITED3(nsAbOutlookDirectory, nsAbDirectoryRDFResource,
|
||||
nsIAbDirectory, nsIAbDirectoryQuery, nsIAbDirectorySearch)
|
||||
|
||||
const char *kOutlookCardScheme = "moz-aboutlookcard://" ;
|
||||
const char *kOutlookDirectoryScheme = "moz-aboutlookdirectory://" ;
|
||||
|
||||
// nsIRDFResource method
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::Init(const char *aUri)
|
||||
{
|
||||
nsresult retCode = nsAbDirectoryRDFResource::Init(aUri) ;
|
||||
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAutoString unichars ;
|
||||
ULONG objectType = 0 ;
|
||||
nsCAutoString subUri ;
|
||||
PRInt32 schemeLength = nsCRT::strlen(kOutlookDirectoryScheme) ;
|
||||
nsCAutoString entry ;
|
||||
nsCAutoString stub ;
|
||||
|
||||
if (nsCRT::strncmp(mURINoQuery, kOutlookDirectoryScheme, schemeLength) != 0) {
|
||||
mAbWinType = getAbWinType(kOutlookDirectoryScheme, mURINoQuery, stub, entry) ;
|
||||
if (mAbWinType == nsAbWinType_Unknown) {
|
||||
PRINTF("Huge problem URI=%s.\n", mURINoQuery) ;
|
||||
return NS_ERROR_INVALID_ARG ;
|
||||
}
|
||||
subUri = mURINoQuery + schemeLength ;
|
||||
if (!mapiAddBook.StringToEntry(subUri, *mMapiData)) {
|
||||
PRINTF("Cannot parse string %s.\n", subUri.get()) ;
|
||||
return NS_ERROR_INVALID_ARG ;
|
||||
}
|
||||
if (!mapiAddBook.GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, objectType)) {
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
nsString prefix ;
|
||||
nsAutoString unichars ;
|
||||
ULONG objectType = 0 ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
mMapiData->Assign(entry) ;
|
||||
if (!mapiAddBook->GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, objectType)) {
|
||||
PRINTF("Cannot get type.\n") ;
|
||||
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") ;
|
||||
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) {
|
||||
SetListName(unichars.get()) ;
|
||||
SetIsMailList(PR_TRUE) ;
|
||||
@ -131,7 +132,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::Init(const char *aUri)
|
||||
// nsIAbDirectory methods
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::GetChildNodes(nsIEnumerator **aNodes)
|
||||
{
|
||||
if (aNodes == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aNodes) { return NS_ERROR_NULL_POINTER ; }
|
||||
*aNodes = nsnull ;
|
||||
nsCOMPtr<nsISupportsArray> nodeList ;
|
||||
nsresult retCode = NS_OK ;
|
||||
@ -148,7 +149,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildNodes(nsIEnumerator **aNodes)
|
||||
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
|
||||
{
|
||||
if (aCards == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aCards) { return NS_ERROR_NULL_POINTER ; }
|
||||
*aCards = nsnull ;
|
||||
nsCOMPtr<nsISupportsArray> cardList ;
|
||||
nsresult retCode ;
|
||||
@ -163,6 +164,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
|
||||
}
|
||||
if (NS_SUCCEEDED(retCode)) {
|
||||
// Fill the results array and update the card list
|
||||
// Also update the address list and notify any changes.
|
||||
PRUint32 nbCards = 0 ;
|
||||
nsCOMPtr<nsISupports> element ;
|
||||
|
||||
@ -171,25 +173,77 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
|
||||
for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
|
||||
cardList->GetElementAt(i, getter_AddRefs(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 ;
|
||||
}
|
||||
|
||||
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,
|
||||
const char *aPrefix, PRUint32 aPrefixSize)
|
||||
const char *aPrefix)
|
||||
{
|
||||
aEntry.Truncate() ;
|
||||
if (aPrefix == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aPrefix ) { return NS_ERROR_NULL_POINTER ; }
|
||||
nsXPIDLCString uri ;
|
||||
nsresult retCode = aResource->GetValue(getter_Copies(uri)) ;
|
||||
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
if (nsCRT::strncmp(uri.get(), aPrefix, aPrefixSize) == 0) {
|
||||
aEntry = uri.get() + aPrefixSize ;
|
||||
}
|
||||
nsCAutoString stub ;
|
||||
nsAbWinType objType = getAbWinType(aPrefix, uri.get(), stub, aEntry) ;
|
||||
|
||||
return NS_OK ;
|
||||
}
|
||||
|
||||
@ -201,8 +255,7 @@ static nsresult ExtractCardEntry(nsIAbCard *aCard, nsCString& aEntry)
|
||||
|
||||
// Receiving a non-RDF card is accepted
|
||||
if (NS_FAILED(retCode)) { return NS_OK ; }
|
||||
return ExtractEntryFromUri(resource, aEntry, kOutlookCardScheme,
|
||||
nsCRT::strlen(kOutlookCardScheme)) ;
|
||||
return ExtractEntryFromUri(resource, aEntry, kOutlookCardScheme) ;
|
||||
}
|
||||
|
||||
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
|
||||
if (NS_FAILED(retCode)) { return NS_OK ; }
|
||||
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 ;
|
||||
return ExtractEntryFromUri(resource, aEntry, kOutlookDirectoryScheme) ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
|
||||
{
|
||||
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 ;
|
||||
nsresult retCode = NS_OK ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
|
||||
retCode = aCardList->Count(&nbCards) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
@ -256,23 +292,21 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
|
||||
nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
|
||||
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
|
||||
retCode = ExtractCardEntry(card, entryString) ;
|
||||
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 {
|
||||
if (!mapiAddBook.DeleteEntry(*mMapiData, cardEntry)) {
|
||||
PRINTF("Cannot delete card %s.\n", entryString.get()) ;
|
||||
}
|
||||
else {
|
||||
nsVoidKey key (NS_STATIC_CAST(void *, element)) ;
|
||||
nsVoidKey key (NS_STATIC_CAST(void *, element)) ;
|
||||
|
||||
mCardList.Remove(&key) ;
|
||||
if (m_bIsMailList) { m_AddressList->RemoveElement(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 {
|
||||
@ -285,27 +319,24 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::DeleteDirectory(nsIAbDirectory *aDirectory)
|
||||
{
|
||||
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 ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
nsCAutoString entryString ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
retCode = ExtractDirectoryEntry(aDirectory, entryString) ;
|
||||
if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) {
|
||||
nsMapiEntry directoryEntry ;
|
||||
|
||||
if (!mapiAddBook.StringToEntry(entryString, directoryEntry)) {
|
||||
PRINTF("Cannot manage uri %s.\n", entryString.get()) ;
|
||||
directoryEntry.Assign(entryString) ;
|
||||
if (!mapiAddBook->DeleteEntry(*mMapiData, directoryEntry)) {
|
||||
PRINTF("Cannot delete directory %s.\n", entryString.get()) ;
|
||||
}
|
||||
else {
|
||||
if (!mapiAddBook.DeleteEntry(*mMapiData, directoryEntry)) {
|
||||
PRINTF("Cannot delete directory %s.\n", entryString.get()) ;
|
||||
}
|
||||
else {
|
||||
m_AddressList->RemoveElement(aDirectory) ;
|
||||
retCode = NotifyItemDeletion(aDirectory) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
}
|
||||
m_AddressList->RemoveElement(aDirectory) ;
|
||||
retCode = NotifyItemDeletion(aDirectory) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -317,7 +348,7 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteDirectory(nsIAbDirectory *aDirectory)
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::AddCard(nsIAbCard *aData, nsIAbCard **aCard)
|
||||
{
|
||||
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 ;
|
||||
nsresult retCode = NS_OK ;
|
||||
PRBool hasCard = PR_FALSE ;
|
||||
@ -346,35 +377,32 @@ NS_IMETHODIMP nsAbOutlookDirectory::DropCard(nsIAbCard *aData, nsIAbCard **aCard
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::AddMailList(nsIAbDirectory *aMailList)
|
||||
{
|
||||
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 ; }
|
||||
nsresult retCode = NS_OK ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
nsCAutoString entryString ;
|
||||
nsMapiEntry newEntry ;
|
||||
PRBool didCopy = PR_FALSE ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
retCode = ExtractDirectoryEntry(aMailList, entryString) ;
|
||||
if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) {
|
||||
nsMapiEntry sourceEntry ;
|
||||
|
||||
if (mapiAddBook.StringToEntry(entryString, sourceEntry)) {
|
||||
mapiAddBook.CopyEntry(*mMapiData, sourceEntry, newEntry) ;
|
||||
}
|
||||
sourceEntry.Assign(entryString) ;
|
||||
mapiAddBook->CopyEntry(*mMapiData, sourceEntry, newEntry) ;
|
||||
}
|
||||
if (newEntry.mByteCount == 0) {
|
||||
if (!mapiAddBook.CreateDistList(*mMapiData, newEntry)) {
|
||||
if (!mapiAddBook->CreateDistList(*mMapiData, newEntry)) {
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
}
|
||||
else { didCopy = PR_TRUE ; }
|
||||
if (!mapiAddBook.EntryToString(newEntry, entryString)) {
|
||||
PRINTF("Cannot manage entry.\n") ;
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
newEntry.ToString(entryString) ;
|
||||
nsCAutoString uri ;
|
||||
|
||||
uri.Assign(kOutlookDirectoryScheme) ;
|
||||
buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uri) ;
|
||||
uri.Append(entryString) ;
|
||||
nsCOMPtr<nsIRDFResource> 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 ; }
|
||||
nsresult retCode = NS_OK ;
|
||||
nsXPIDLString name ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
retCode = GetListName(getter_Copies(name)) ;
|
||||
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 ;
|
||||
}
|
||||
retCode = CommitAddressList() ;
|
||||
@ -411,15 +440,8 @@ NS_IMETHODIMP nsAbOutlookDirectory::EditMailListToDatabase(const char *aUri)
|
||||
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::GetTotalCards(PRBool aSubDirectoryCount, PRUint32 *aNbCards)
|
||||
{
|
||||
if (aNbCards == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
*aNbCards = 0 ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
ULONG nbCards = 0 ;
|
||||
|
||||
if (!mapiAddBook.GetCardsCount(*mMapiData, nbCards)) {
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
*aNbCards = NS_STATIC_CAST(PRUint32, nbCards) ;
|
||||
if (!aNbCards) { return NS_ERROR_NULL_POINTER ; }
|
||||
*aNbCards = mCardList.Count();
|
||||
return NS_OK ;
|
||||
}
|
||||
|
||||
@ -524,7 +546,7 @@ static nsresult BuildRestriction(nsIAbBooleanConditionString *aCondition,
|
||||
SRestriction& aRestriction,
|
||||
PRBool& aSkipItem)
|
||||
{
|
||||
if (aCondition == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aCondition) { return NS_ERROR_NULL_POINTER ; }
|
||||
aSkipItem = PR_FALSE ;
|
||||
nsAbBooleanConditionType conditionType = 0 ;
|
||||
nsresult retCode = NS_OK ;
|
||||
@ -658,7 +680,7 @@ static nsresult BuildRestriction(nsIAbBooleanConditionString *aCondition,
|
||||
static nsresult BuildRestriction(nsIAbBooleanExpression *aLevel,
|
||||
SRestriction& aRestriction)
|
||||
{
|
||||
if (aLevel == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aLevel) { return NS_ERROR_NULL_POINTER ; }
|
||||
aRestriction.rt = RES_COMMENT ;
|
||||
nsresult retCode = NS_OK ;
|
||||
nsAbBooleanOperationType operationType = 0 ;
|
||||
@ -754,7 +776,7 @@ static nsresult BuildRestriction(nsIAbBooleanExpression *aLevel,
|
||||
static nsresult BuildRestriction(nsIAbDirectoryQueryArguments *aArguments,
|
||||
SRestriction& aRestriction)
|
||||
{
|
||||
if (aArguments == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aArguments) { return NS_ERROR_NULL_POINTER ; }
|
||||
nsresult retCode = NS_OK ;
|
||||
nsCOMPtr<nsIAbBooleanExpression> booleanQuery ;
|
||||
|
||||
@ -813,9 +835,9 @@ static void DestroyRestriction(SRestriction& aRestriction)
|
||||
nsresult FillPropertyValues(nsIAbCard *aCard, nsIAbDirectoryQueryArguments *aArguments,
|
||||
nsISupportsArray **aValues)
|
||||
{
|
||||
if (aCard == nsnull ||
|
||||
aArguments == nsnull ||
|
||||
aValues == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aCard || !aArguments || !aValues ) {
|
||||
return NS_ERROR_NULL_POINTER ;
|
||||
}
|
||||
*aValues = nsnull ;
|
||||
CharPtrArrayGuard properties ;
|
||||
nsCOMPtr<nsISupportsArray> values ;
|
||||
@ -826,43 +848,43 @@ nsresult FillPropertyValues(nsIAbCard *aCard, nsIAbDirectoryQueryArguments *aArg
|
||||
PRUint32 i = 0 ;
|
||||
nsCAutoString cPropName ;
|
||||
nsAbDirectoryQueryPropertyValue *newValue = nsnull ;
|
||||
nsCOMPtr<nsIAbDirectoryQueryPropertyValue> propertyValue ;
|
||||
nsCOMPtr<nsIAbDirectoryQueryPropertyValue> propertyValue ;
|
||||
|
||||
for (i = 0 ; i < properties.GetSize() ; ++ i) {
|
||||
newValue = nsnull ;
|
||||
cPropName.Assign(properties [i]) ;
|
||||
if (cPropName.EqualsWithConversion ("card:nsIAbCard")) {
|
||||
nsCOMPtr<nsISupports> bogusInterface (do_QueryInterface(aCard, &retCode)) ;
|
||||
if (cPropName.EqualsWithConversion ("card:nsIAbCard")) {
|
||||
nsCOMPtr<nsISupports> bogusInterface (do_QueryInterface(aCard, &retCode)) ;
|
||||
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
newValue = new nsAbDirectoryQueryPropertyValue (cPropName, bogusInterface) ;
|
||||
}
|
||||
else if (cPropName.EqualsWithConversion ("card:URI")) {
|
||||
nsCOMPtr<nsIRDFResource> rdfResource (do_QueryInterface(aCard, &retCode)) ;
|
||||
nsXPIDLCString uri;
|
||||
nsAutoString convertedString ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
newValue = new nsAbDirectoryQueryPropertyValue (cPropName, bogusInterface) ;
|
||||
}
|
||||
else if (cPropName.EqualsWithConversion ("card:URI")) {
|
||||
nsCOMPtr<nsIRDFResource> rdfResource (do_QueryInterface(aCard, &retCode)) ;
|
||||
nsXPIDLCString uri;
|
||||
nsAutoString convertedString ;
|
||||
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
retCode = rdfResource->GetValue(getter_Copies(uri)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
convertedString.AssignWithConversion(uri.get()) ;
|
||||
newValue = new nsAbDirectoryQueryPropertyValue(cPropName.get(), convertedString.get()) ;
|
||||
}
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
retCode = rdfResource->GetValue(getter_Copies(uri)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
convertedString.AssignWithConversion(uri.get()) ;
|
||||
newValue = new nsAbDirectoryQueryPropertyValue(cPropName.get(), convertedString.get()) ;
|
||||
}
|
||||
else {
|
||||
nsXPIDLString value ;
|
||||
nsXPIDLString value ;
|
||||
|
||||
retCode = aCard->GetCardValue(cPropName, getter_Copies(value)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
if (value.get() != nsnull && nsCRT::strlen(value.get()) != 0) {
|
||||
retCode = aCard->GetCardValue(cPropName, getter_Copies(value)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
if (value.get() && nsCRT::strlen(value.get()) != 0) {
|
||||
newValue = new nsAbDirectoryQueryPropertyValue(cPropName.get(), value.get()) ;
|
||||
}
|
||||
}
|
||||
if (newValue != nsnull) {
|
||||
if (!values) {
|
||||
NS_NewISupportsArray(getter_AddRefs(values)) ;
|
||||
}
|
||||
propertyValue = newValue ;
|
||||
values->AppendElement (propertyValue) ;
|
||||
}
|
||||
if (newValue) {
|
||||
if (!values) {
|
||||
NS_NewISupportsArray(getter_AddRefs(values)) ;
|
||||
}
|
||||
propertyValue = newValue ;
|
||||
values->AppendElement (propertyValue) ;
|
||||
}
|
||||
}
|
||||
*aValues = values ;
|
||||
@ -884,7 +906,7 @@ static void QueryThreadFunc(void *aArguments)
|
||||
{
|
||||
QueryThreadArgs *arguments = NS_REINTERPRET_CAST(QueryThreadArgs *, aArguments) ;
|
||||
|
||||
if (aArguments == nsnull) { return ; }
|
||||
if (!aArguments) { return ; }
|
||||
arguments->mThis->ExecuteQuery(arguments->mArguments, arguments->mListener,
|
||||
arguments->mResultLimit, arguments->mTimeout,
|
||||
arguments->mThreadId) ;
|
||||
@ -896,15 +918,15 @@ nsresult nsAbOutlookDirectory::DoQuery(nsIAbDirectoryQueryArguments *aArguments,
|
||||
PRInt32 aResultLimit, PRInt32 aTimeout,
|
||||
PRInt32 *aReturnValue)
|
||||
{
|
||||
if (aArguments == nsnull ||
|
||||
aListener == nsnull ||
|
||||
aReturnValue == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aArguments || !aListener || !aReturnValue) {
|
||||
return NS_ERROR_NULL_POINTER ;
|
||||
}
|
||||
*aReturnValue = -1 ;
|
||||
|
||||
QueryThreadArgs *threadArgs = new QueryThreadArgs ;
|
||||
PRThread *newThread = nsnull ;
|
||||
|
||||
if (threadArgs == nsnull) {
|
||||
if (!threadArgs) {
|
||||
return NS_ERROR_OUT_OF_MEMORY ;
|
||||
}
|
||||
threadArgs->mThis = this ;
|
||||
@ -923,7 +945,7 @@ nsresult nsAbOutlookDirectory::DoQuery(nsIAbDirectoryQueryArguments *aArguments,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
0) ;
|
||||
if (newThread == nsnull) {
|
||||
if (!newThread ) {
|
||||
delete threadArgs ;
|
||||
return NS_ERROR_OUT_OF_MEMORY ;
|
||||
}
|
||||
@ -938,7 +960,7 @@ nsresult nsAbOutlookDirectory::StopQuery(PRInt32 aContext)
|
||||
nsIntegerKey contextKey(aContext) ;
|
||||
PRThread *queryThread = NS_REINTERPRET_CAST(PRThread *, mQueryThreads.Get(&contextKey)) ;
|
||||
|
||||
if (queryThread != nsnull) {
|
||||
if (queryThread) {
|
||||
PR_Interrupt(queryThread) ;
|
||||
mQueryThreads.Remove(&contextKey) ;
|
||||
}
|
||||
@ -1006,9 +1028,11 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
|
||||
nsIAbDirectoryQueryResultListener *aListener,
|
||||
PRInt32 aResultLimit, PRInt32 aTimeout,
|
||||
PRInt32 aThreadId)
|
||||
|
||||
{
|
||||
if (aArguments == nsnull ||
|
||||
aListener == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aArguments || !aListener) {
|
||||
return NS_ERROR_NULL_POINTER ;
|
||||
}
|
||||
SRestriction arguments ;
|
||||
nsresult retCode = NS_OK ;
|
||||
|
||||
@ -1050,7 +1074,7 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
|
||||
newResult = new nsAbDirectoryQueryResult(0, aArguments,
|
||||
nsIAbDirectoryQueryResult::queryResultMatch,
|
||||
propertyValues) ;
|
||||
if (newResult == nsnull) { return NS_ERROR_OUT_OF_MEMORY ; }
|
||||
if (!newResult) { return NS_ERROR_OUT_OF_MEMORY ; }
|
||||
result = newResult ;
|
||||
aListener->OnQueryItem(result) ;
|
||||
}
|
||||
@ -1059,21 +1083,21 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(nsIAbDirectoryQueryArguments *aArgum
|
||||
mQueryThreads.Remove(&hashKey) ;
|
||||
return retCode ;
|
||||
}
|
||||
|
||||
nsresult nsAbOutlookDirectory::GetChildCards(nsISupportsArray **aCards,
|
||||
void *aRestriction)
|
||||
{
|
||||
if (aCards == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aCards) { return NS_ERROR_NULL_POINTER ; }
|
||||
*aCards = nsnull ;
|
||||
nsresult retCode = NS_OK ;
|
||||
nsCOMPtr<nsISupportsArray> cards ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
nsMapiEntryArray cardEntries ;
|
||||
LPSRestriction restriction = (LPSRestriction) aRestriction ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
retCode = NS_NewISupportsArray(getter_AddRefs(cards)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
if (!mapiAddBook.GetCards(*mMapiData, restriction, cardEntries)) {
|
||||
if (!mapiAddBook->GetCards(*mMapiData, restriction, cardEntries)) {
|
||||
PRINTF("Cannot get cards.\n") ;
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
@ -1082,16 +1106,12 @@ nsresult nsAbOutlookDirectory::GetChildCards(nsISupportsArray **aCards,
|
||||
nsCOMPtr<nsIRDFResource> resource ;
|
||||
|
||||
for (ULONG card = 0 ; card < cardEntries.mNbEntries ; ++ card) {
|
||||
if (mapiAddBook.EntryToString(cardEntries.mEntries [card], entryId)) {
|
||||
uriName.Assign(kOutlookCardScheme) ;
|
||||
uriName.Append(entryId) ;
|
||||
retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
cards->AppendElement(resource) ;
|
||||
}
|
||||
else {
|
||||
PRINTF("Cannot manage entry %d.\n", card) ;
|
||||
}
|
||||
cardEntries.mEntries [card].ToString(entryId) ;
|
||||
buildAbWinUri(kOutlookCardScheme, mAbWinType, uriName) ;
|
||||
uriName.Append(entryId) ;
|
||||
retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
cards->AppendElement(resource) ;
|
||||
}
|
||||
*aCards = cards ;
|
||||
NS_ADDREF(*aCards) ;
|
||||
@ -1100,16 +1120,17 @@ nsresult nsAbOutlookDirectory::GetChildCards(nsISupportsArray **aCards,
|
||||
|
||||
nsresult nsAbOutlookDirectory::GetChildNodes(nsISupportsArray **aNodes)
|
||||
{
|
||||
if (aNodes == nsnull) { return NS_ERROR_NULL_POINTER ; }
|
||||
if (!aNodes) { return NS_ERROR_NULL_POINTER ; }
|
||||
*aNodes = nsnull ;
|
||||
nsresult retCode = NS_OK ;
|
||||
nsCOMPtr<nsISupportsArray> nodes ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
nsMapiEntryArray nodeEntries ;
|
||||
|
||||
if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
|
||||
retCode = NS_NewISupportsArray(getter_AddRefs(nodes)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
if (!mapiAddBook.GetNodes(*mMapiData, nodeEntries)) {
|
||||
if (!mapiAddBook->GetNodes(*mMapiData, nodeEntries)) {
|
||||
PRINTF("Cannot get nodes.\n") ;
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
@ -1118,16 +1139,12 @@ nsresult nsAbOutlookDirectory::GetChildNodes(nsISupportsArray **aNodes)
|
||||
nsCOMPtr <nsIRDFResource> resource ;
|
||||
|
||||
for (ULONG node = 0 ; node < nodeEntries.mNbEntries ; ++ node) {
|
||||
if (mapiAddBook.EntryToString(nodeEntries.mEntries [node], entryId)) {
|
||||
uriName.Assign(kOutlookDirectoryScheme) ;
|
||||
uriName.Append(entryId) ;
|
||||
retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
nodes->AppendElement(resource) ;
|
||||
}
|
||||
else {
|
||||
PRINTF("Cannot manage entry %d.\n", node) ;
|
||||
}
|
||||
nodeEntries.mEntries [node].ToString(entryId) ;
|
||||
buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uriName) ;
|
||||
uriName.Append(entryId) ;
|
||||
retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
nodes->AppendElement(resource) ;
|
||||
}
|
||||
*aNodes = nodes ;
|
||||
NS_ADDREF(*aNodes) ;
|
||||
@ -1183,6 +1200,7 @@ nsresult nsAbOutlookDirectory::CommitAddressList(void)
|
||||
nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
|
||||
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
|
||||
retCode = CreateCard(card, getter_AddRefs(newCard)) ;
|
||||
NS_ENSURE_SUCCESS(retCode, retCode) ;
|
||||
m_AddressList->ReplaceElementAt(newCard, i) ;
|
||||
@ -1207,33 +1225,34 @@ nsresult nsAbOutlookDirectory::UpdateAddressList(void)
|
||||
|
||||
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 ;
|
||||
nsresult retCode = NS_OK ;
|
||||
nsMapiAddressBook mapiAddBook ;
|
||||
nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
|
||||
nsMapiEntry newEntry ;
|
||||
nsCAutoString entryString ;
|
||||
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,
|
||||
// we simply copy the contents of the Outlook card.
|
||||
retCode = ExtractCardEntry(aData, entryString) ;
|
||||
if (NS_SUCCEEDED(retCode) && entryString.Length() > 0) {
|
||||
nsMapiEntry sourceEntry ;
|
||||
|
||||
if (mapiAddBook.StringToEntry(entryString, sourceEntry)) {
|
||||
if (m_bIsMailList) {
|
||||
// In the case of a mailing list, we can use the address
|
||||
// as a direct template to build the new one (which is done
|
||||
// by CopyEntry).
|
||||
mapiAddBook.CopyEntry(*mMapiData, sourceEntry, newEntry) ;
|
||||
didCopy = PR_TRUE ;
|
||||
}
|
||||
else {
|
||||
// Else, we have to create a temporary address and copy the
|
||||
// source into it. Yes it's silly.
|
||||
mapiAddBook.CreateEntry(*mMapiData, newEntry) ;
|
||||
}
|
||||
|
||||
sourceEntry.Assign(entryString) ;
|
||||
if (m_bIsMailList) {
|
||||
// In the case of a mailing list, we can use the address
|
||||
// as a direct template to build the new one (which is done
|
||||
// by CopyEntry).
|
||||
mapiAddBook->CopyEntry(*mMapiData, sourceEntry, newEntry) ;
|
||||
didCopy = PR_TRUE ;
|
||||
}
|
||||
else {
|
||||
// Else, we have to create a temporary address and copy the
|
||||
// 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.
|
||||
@ -1245,32 +1264,29 @@ nsresult nsAbOutlookDirectory::CreateCard(nsIAbCard *aData, nsIAbCard **aNewCard
|
||||
nsMapiEntry parentEntry ;
|
||||
nsMapiEntry temporaryEntry ;
|
||||
|
||||
if (!mapiAddBook.GetDefaultContainer(parentEntry)) {
|
||||
if (!mapiAddBook->GetDefaultContainer(parentEntry)) {
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
if (!mapiAddBook.CreateEntry(parentEntry, temporaryEntry)) {
|
||||
if (!mapiAddBook->CreateEntry(parentEntry, temporaryEntry)) {
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
if (!mapiAddBook.CopyEntry(*mMapiData, temporaryEntry, newEntry)) {
|
||||
if (!mapiAddBook->CopyEntry(*mMapiData, temporaryEntry, newEntry)) {
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
if (!mapiAddBook.DeleteEntry(parentEntry, temporaryEntry)) {
|
||||
if (!mapiAddBook->DeleteEntry(parentEntry, temporaryEntry)) {
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
}
|
||||
// If we're on a real address book folder, we can directly create an
|
||||
// empty card.
|
||||
else if (!mapiAddBook.CreateEntry(*mMapiData, newEntry)) {
|
||||
else if (!mapiAddBook->CreateEntry(*mMapiData, newEntry)) {
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
}
|
||||
if (!mapiAddBook.EntryToString(newEntry, entryString)) {
|
||||
PRINTF("Cannot manage entry.\n") ;
|
||||
return NS_ERROR_FAILURE ;
|
||||
}
|
||||
newEntry.ToString(entryString) ;
|
||||
nsCAutoString uri ;
|
||||
|
||||
uri.Assign(kOutlookCardScheme) ;
|
||||
buildAbWinUri(kOutlookCardScheme, mAbWinType, uri) ;
|
||||
uri.Append(entryString) ;
|
||||
nsCOMPtr<nsIRDFResource> resource ;
|
||||
|
||||
|
@ -97,6 +97,8 @@ protected:
|
||||
// Data for the search interfaces
|
||||
nsSupportsHashtable mCardList ;
|
||||
PRInt32 mSearchContext ;
|
||||
// Windows AB type
|
||||
PRUint32 mAbWinType ;
|
||||
|
||||
private:
|
||||
};
|
||||
|
1021
mailnews/addrbook/src/nsAbWinHelper.cpp
Normal file
1021
mailnews/addrbook/src/nsAbWinHelper.cpp
Normal file
File diff suppressed because it is too large
Load Diff
173
mailnews/addrbook/src/nsAbWinHelper.h
Normal file
173
mailnews/addrbook/src/nsAbWinHelper.h
Normal 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
@ -24,117 +24,48 @@
|
||||
#ifndef nsMapiAddressBook_h___
|
||||
#define nsMapiAddressBook_h___
|
||||
|
||||
#include <windows.h>
|
||||
#include <mapix.h>
|
||||
#include "nsAbWinHelper.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 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
|
||||
class nsMapiAddressBook : public nsAbWinHelper
|
||||
{
|
||||
public :
|
||||
nsMapiAddressBook(void) ;
|
||||
~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) ;
|
||||
virtual ~nsMapiAddressBook(void) ;
|
||||
|
||||
protected :
|
||||
|
||||
private :
|
||||
LPMAPISESSION mSession ;
|
||||
LPADRBOOK mAddressBook ;
|
||||
BOOL mLogonDone ;
|
||||
BOOL mInitialized ;
|
||||
HRESULT mLastError ;
|
||||
static ULONG mEntryCounter ;
|
||||
// Class members to handle the library/entry points
|
||||
static HMODULE mLibrary ;
|
||||
static PRInt32 mLibUsage ;
|
||||
static LPMAPIINITIALIZE mMAPIInitialize ;
|
||||
static LPMAPIUNINITIALIZE mMAPIUninitialize ;
|
||||
static LPMAPIALLOCATEBUFFER mMAPIAllocateBuffer ;
|
||||
static LPMAPIFREEBUFFER mMAPIFreeBuffer ;
|
||||
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
|
||||
BOOL Initialize(void) ;
|
||||
// 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) ;
|
||||
// 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) ;
|
||||
// Library management
|
||||
static BOOL LoadMapiLibrary(void) ;
|
||||
static void FreeMapiLibrary(void) ;
|
||||
|
||||
private :
|
||||
} ;
|
||||
|
||||
#endif // nsMapiAddressBook_h___
|
||||
|
124
mailnews/addrbook/src/nsWabAddressBook.cpp
Normal file
124
mailnews/addrbook/src/nsWabAddressBook.cpp
Normal 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) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
75
mailnews/addrbook/src/nsWabAddressBook.h
Normal file
75
mailnews/addrbook/src/nsWabAddressBook.h
Normal 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___
|
||||
|
Loading…
Reference in New Issue
Block a user