1 Index: directory/xpcom/base/public/nsILDAPConnection.idl
2 ===================================================================
3 RCS file: /mozilla/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl,v
4 retrieving revision 1.1.1.1
5 retrieving revision 1.2
6 diff -u -w -b -i -r1.1.1.1 -r1.2
7 --- miss/build/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl 22 Oct 2003 02:37:04 -0000 1.1.1.1
8 +++ miss/build/mozilla/directory/xpcom/base/public/nsILDAPConnection.idl 22 Oct 2003 09:45:04 -0000 1.2
10 * @exception NS_ERROR_FAILURE
11 * @exception NS_ERROR_UNEXPECTED internal error
13 - void init(in string aHost, in short aPort, in boolean aSSL,
14 + void init(in string aHost, in long aPort, in boolean aSSL,
16 in nsILDAPMessageListener aMessageListener);
18 Index: directory/xpcom/base/src/nsLDAPConnection.cpp
19 ===================================================================
20 RCS file: /mozilla/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp,v
21 retrieving revision 1.1.1.1
22 retrieving revision 1.2
23 diff -u -w -b -i -r1.1.1.1 -r1.2
24 --- miss/build/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp 22 Oct 2003 02:37:04 -0000 1.1.1.1
25 +++ miss/build/mozilla/directory/xpcom/base/src/nsLDAPConnection.cpp 22 Oct 2003 09:45:04 -0000 1.2
27 #include "nsIConsoleService.h"
28 #include "nsIDNSService.h"
29 #include "nsIRequestObserver.h"
30 -#include "nsIProxyObjectManager.h"
33 const char kConsoleServiceContractId[] = "@mozilla.org/consoleservice;1";
38 -nsLDAPConnection::Init(const char *aHost, PRInt16 aPort, PRBool aSSL,
39 +nsLDAPConnection::Init(const char *aHost, PRInt32 aPort, PRBool aSSL,
40 const PRUnichar *aBindName,
41 nsILDAPMessageListener *aMessageListener)
43 - nsCOMPtr<nsIDNSListener> selfProxy;
46 if ( !aHost || !aMessageListener) {
48 return NS_ERROR_FAILURE;
51 - // Get a proxy object so the callback happens on the current thread.
52 - // This is now a Synchronous proxy, due to the fact that the DNS
53 - // service hands out data which it later deallocates, and the async
54 - // proxy makes this unreliable. See bug 102227 for more details.
56 - rv = NS_GetProxyForObject(NS_CURRENT_EVENTQ,
57 - NS_GET_IID(nsIDNSListener),
58 - NS_STATIC_CAST(nsIDNSListener*, this),
59 - PROXY_SYNC | PROXY_ALWAYS,
60 - getter_AddRefs(selfProxy));
62 - if (NS_FAILED(rv)) {
63 - NS_ERROR("nsLDAPConnection::Init(): couldn't "
64 - "create proxy to this object for callback");
65 - return NS_ERROR_FAILURE;
68 // Do the pre-resolve of the hostname, using the DNS service. This
69 // will also initialize the LDAP connection properly, once we have
71 return NS_ERROR_FAILURE;
73 rv = pDNSService->Lookup(aHost,
76 + this, // SDBC change
78 getter_AddRefs(mDNSRequest));
80 Index: directory/xpcom/base/src/nsLDAPConnection.h
81 ===================================================================
82 RCS file: /mozilla/mozilla/directory/xpcom/base/src/nsLDAPConnection.h,v
83 retrieving revision 1.1.1.1
84 retrieving revision 1.2
85 diff -u -w -b -i -r1.1.1.1 -r1.2
86 --- miss/build/mozilla/directory/xpcom/base/src/nsLDAPConnection.h 22 Oct 2003 02:37:04 -0000 1.1.1.1
87 +++ miss/build/mozilla/directory/xpcom/base/src/nsLDAPConnection.h 22 Oct 2003 09:45:04 -0000 1.2
89 nsSupportsHashtable *mPendingOperations; // keep these around for callbacks
90 nsLDAPConnectionLoop *mRunnable; // nsIRunnable object
92 - PRInt16 mPort; // The LDAP port we're binding to
93 + PRInt32 mPort; // The LDAP port we're binding to
94 PRBool mSSL; // the options
96 nsCString mResolvedIP; // Preresolved list of host IPs
97 Index: mailnews/addrbook/Makefile.in
98 ===================================================================
99 RCS file: /mozilla/mozilla/mailnews/addrbook/Makefile.in,v
100 retrieving revision 1.1.1.1
101 retrieving revision 1.2
102 diff -u -w -b -i -r1.1.1.1 -r1.2
103 --- miss/build/mozilla/mailnews/addrbook/Makefile.in 22 Oct 2003 02:43:08 -0000 1.1.1.1
104 +++ miss/build/mozilla/mailnews/addrbook/Makefile.in 9 Dec 2003 03:27:41 -0000 1.2
106 EXTRA_COMPONENTS += src/nsLDAPPrefsService.js
109 -DIRS = public src build
110 +DIRS = public src build
112 include $(topsrcdir)/config/rules.mk
114 Index: mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp
115 ===================================================================
116 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp,v
117 retrieving revision 1.1.1.1
118 retrieving revision 1.2
119 diff -u -w -b -i -r1.1.1.1 -r1.2
120 --- miss/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp 22 Oct 2003 02:43:10 -0000 1.1.1.1
121 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp 22 Oct 2003 09:45:04 -0000 1.2
123 #include "nsAbBoolExprToLDAPFilter.h"
124 #include "nsAbLDAPProperties.h"
125 #include "nsXPIDLString.h"
126 +#include "nsAbUtils.h"
128 const int nsAbBoolExprToLDAPFilter::TRANSLATE_CARD_PROPERTY = 1 << 0 ;
129 const int nsAbBoolExprToLDAPFilter::ALLOW_NON_CONVERTABLE_CARD_PROPERTY = 1 << 1 ;
135 + * 3rd party query integration with Mozilla is achieved
136 + * by calling nsAbLDAPDirectoryQuery::DoQuery(). Thus
137 + * we can arrive here with a query asking for all the
138 + * ldap attributes using the card:nsIAbCard interface.
140 + * So we need to check that we are not creating a condition
141 + * filter against this otherwise we can end an
142 + * invalid filter equal to "(|)".
147 + nsCOMPtr<nsISupports> item;
148 + rv = childExpressions->GetElementAt (0, getter_AddRefs (item));
149 + NS_ENSURE_SUCCESS(rv, rv);
151 + nsCOMPtr<nsIAbBooleanConditionString> childCondition(do_QueryInterface(item, &rv));
152 + if (NS_SUCCEEDED(rv))
154 + nsXPIDLCString name;
155 + rv = childCondition->GetName (getter_Copies (name));
156 + NS_ENSURE_SUCCESS(rv, rv);
158 + if(name.Equals("card:nsIAbCard"))
163 filter += NS_LITERAL_CSTRING("(");
166 @@ -157,13 +187,16 @@
167 rv = condition->GetName (getter_Copies (name));
168 NS_ENSURE_SUCCESS(rv, rv);
170 - const char* ldapProperty = name.get ();
171 + CharPtrArrayGuard attrs;
172 if (flags & TRANSLATE_CARD_PROPERTY)
174 - const MozillaLdapPropertyRelation* p =
175 - MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (name.get ());
177 - ldapProperty = p->ldapProperty;
178 + if(const MozillaLdapPropertyRelation* property =
179 + MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (name.get ()))
181 + // allow even single ldap attribute mapppings to go through this to simplify the filter creation later.
182 + rv = MozillaLdapPropertyRelator::getAllLDAPAttrsFromMozilla (property->ldapProperty, attrs.GetSizeAddr(), attrs.GetArrayAddr() );
183 + NS_ENSURE_SUCCESS(rv, rv);
185 else if (!(flags & ALLOW_NON_CONVERTABLE_CARD_PROPERTY))
189 NS_ENSURE_SUCCESS(rv, rv);
190 NS_ConvertUCS2toUTF8 vUTF8 (value);
192 + // check if using multiple ldap attributes
193 + if(attrs.GetSize() == 1 )
194 + GenerateSingleFilter(conditionType,filter,vUTF8,attrs.GetArray()[0]);
197 + // add the opening brace if using multiple ldap attributes
198 + switch (conditionType)
200 + // 'NOT' conditionals use the 'AND' operator
201 + case nsIAbBooleanConditionTypes::DoesNotExist:
202 + case nsIAbBooleanConditionTypes::DoesNotContain:
203 + case nsIAbBooleanConditionTypes::IsNot:
204 + filter += NS_LITERAL_CSTRING("(&");
207 + filter += NS_LITERAL_CSTRING("(|");
210 + GenerateMultipleFilter(conditionType,filter,vUTF8,&attrs);
211 + // add the closing brace if using multiple ldap attributes
212 + filter += NS_LITERAL_CSTRING(")");
217 +void nsAbBoolExprToLDAPFilter:: GenerateSingleFilter(
218 + nsAbBooleanConditionType conditionType,
220 + NS_ConvertUCS2toUTF8 &vUTF8,
221 + const char *ldapProperty)
223 switch (conditionType)
225 case nsIAbBooleanConditionTypes::DoesNotExist:
233 +void nsAbBoolExprToLDAPFilter:: GenerateMultipleFilter(
234 + nsAbBooleanConditionType conditionType,
236 + NS_ConvertUCS2toUTF8 &vUTF8,
237 + CharPtrArrayGuard *pAttrs)
240 + PRUint16 inner = 0;
243 + * This function is based on the fact that we are trying to generate support
244 + * for multiple occurring ldap attributes. Consider the following query:
245 + * (PagerNumber,=,123456) where PagerNumber = pager|pagerphone translates to:
246 + * (|(&(pager=*)(pager=123456))(&(!(pager=*))(pagerphone=123456)))
247 + * This can be shortened to:
248 + * (|(pager=123456)(&(!(pager=*))(pagerphone=123456)))
250 + * i.e. use the first occurring attribute if it exists otherwise if first
251 + * does not exist use the second etc. The assumption is that the first
252 + * always takes precedence.
253 + * This translates to:
254 + * GenerateSingleFilter(Is);
255 + * GenerateSingleFilter(DoesNotExists);
256 + * GenerateSingleFilter(Is);
259 + for (i = 0; i < pAttrs->GetSize(); i++)
262 + GenerateSingleFilter(conditionType,filter,vUTF8,pAttrs->GetArray()[i]);
265 + filter += NS_LITERAL_CSTRING("(&");
266 + nsAbBooleanConditionType doesNotExistsType = nsIAbBooleanConditionTypes::DoesNotExist;
267 + for(inner = 0; inner < i; ++inner)
269 + GenerateSingleFilter(doesNotExistsType,filter,vUTF8,pAttrs->GetArray()[inner]);
271 + GenerateSingleFilter(conditionType,filter,vUTF8,pAttrs->GetArray()[i]);
272 + filter += NS_LITERAL_CSTRING(")");
276 Index: mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h
277 ===================================================================
278 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h,v
279 retrieving revision 1.1.1.1
280 retrieving revision 1.2
281 diff -u -w -b -i -r1.1.1.1 -r1.2
282 --- miss/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h 22 Oct 2003 02:43:10 -0000 1.1.1.1
283 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h 22 Oct 2003 09:45:04 -0000 1.2
285 #include "nsIAbBooleanExpression.h"
286 #include "nsCOMPtr.h"
287 #include "nsString.h"
288 +#include "nsAbUtils.h"
290 class nsAbBoolExprToLDAPFilter
293 nsIAbBooleanConditionString* condition,
296 + static void GenerateMultipleFilter(
297 + nsAbBooleanConditionType conditionType,
299 + NS_ConvertUCS2toUTF8 &vUTF8,
300 + CharPtrArrayGuard *pAttrs);
301 + static void GenerateSingleFilter(
302 + nsAbBooleanConditionType conditionType,
304 + NS_ConvertUCS2toUTF8 &vUTF8,
305 + const char *ldapProperty);
309 Index: mailnews/addrbook/src/nsAbLDAPDirectory.cpp
310 ===================================================================
311 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp,v
312 retrieving revision 1.1.1.1
313 retrieving revision 1.3
314 diff -u -w -b -i -r1.1.1.1 -r1.3
315 --- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp 22 Oct 2003 02:43:10 -0000 1.1.1.1
316 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp 8 Jan 2004 04:26:20 -0000 1.3
317 @@ -112,15 +112,82 @@
319 // use mURINoQuery to get a prefName
320 nsCAutoString prefName;
321 - prefName = nsDependentCString(mURINoQuery.get() + kLDAPDirectoryRootLen) + NS_LITERAL_CSTRING(".uri");
322 + prefName = nsDependentCString(mURINoQuery.get() + kLDAPDirectoryRootLen) ;
324 // turn moz-abldapdirectory://ldap_2.servers.nscpphonebook into -> "ldap_2.servers.nscpphonebook.uri"
326 - rv = prefs->CopyCharPref(prefName.get(), getter_Copies(URI));
327 + nsCAutoString uriPrefName;
328 + uriPrefName = prefName + NS_LITERAL_CSTRING(".uri");
329 + rv = prefs->CopyCharPref(uriPrefName.get(), getter_Copies(URI));
333 + * A recent change in Mozilla now means that the LDAP Address Book
334 + * RDF Resource URI is based on the unique preference name value i.e.
335 + * [moz-abldapdirectory://prefName]
336 + * Prior to this valid change it was based on the actual uri i.e.
337 + * [moz-abldapdirectory://host:port/basedn]
338 + * Basing the resource on the prefName allows these attributes to
341 + * But the uri value was also the means by which third-party
342 + * products could integrate with Mozilla's LDAP Address Books without
343 + * necessarily having an entry in the preferences file or more importantly
344 + * needing to be able to change the preferences entries. Thus to set the
345 + * URI Spec now, it is only necessary to read the uri pref entry, while in the case
346 + * where it is not a preference, we need to replace the "moz-abldapdirectory".
348 + nsCAutoString tempLDAPURL(mURINoQuery);
349 + tempLDAPURL.ReplaceSubstring("moz-abldapdirectory:", "ldap:");
350 + rv = mURL->SetSpec(tempLDAPURL);
351 NS_ENSURE_SUCCESS(rv,rv);
353 + nsCAutoString aHost;
354 + mURL->GetHost(aHost);
355 + aHost.ReplaceChar('.','_');
356 + prefName = nsDependentCString("ldap_2.servers.") + aHost;
358 + rv = prefs->GetBoolPref(
359 + PromiseFlatCString(prefName
360 + + NS_LITERAL_CSTRING(".UseSSL")).get(),
364 + // If use SSL,ldap url will look like this ldaps://host:port/.....
365 + if (!NS_FAILED(rv) && useSSL)
367 + tempLDAPURL.ReplaceSubstring("ldap:", "ldaps:");
368 + rv = mURL->SetSpec(tempLDAPURL);
370 + //NS_FAILED(rv) means ldap_2.servers.nscpphonebook.UseSSL not exist
376 rv = mURL->SetSpec(URI);
378 NS_ENSURE_SUCCESS(rv, rv);
380 + // get the login information, if there is any
382 + rv = prefs->GetCharPref(
383 + PromiseFlatCString(prefName
384 + + NS_LITERAL_CSTRING(".auth.dn")).get(),
385 + getter_Copies(mLogin));
386 + if (NS_FAILED(rv)) {
387 + mLogin.Truncate(); // zero out mLogin
390 + // get the password information, if there is any
392 + rv = prefs->GetCharPref(
393 + PromiseFlatCString(prefName
394 + + NS_LITERAL_CSTRING(".auth.pwd")).get(),
395 + getter_Copies(mPassword));
396 + if (NS_FAILED(rv)) {
397 + mPassword.Truncate(); // zero out mLogin
400 mConnection = do_CreateInstance(NS_LDAPCONNECTION_CONTRACTID, &rv);
401 NS_ENSURE_SUCCESS(rv, rv);
402 Index: mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
403 ===================================================================
404 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp,v
405 retrieving revision 1.1.1.1
406 retrieving revision 1.3
407 diff -u -w -b -i -r1.1.1.1 -r1.3
408 --- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp 22 Oct 2003 02:43:10 -0000 1.1.1.1
409 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp 8 Jan 2004 04:26:20 -0000 1.3
411 PRInt32 resultLimit = -1,
412 PRInt32 timeOut = 0);
413 virtual ~nsAbQueryLDAPMessageListener ();
415 + void SetPassword(const nsAString& aPassword){m_sPassword = aPassword;};
417 nsresult OnLDAPMessageBind (nsILDAPMessage *aMessage);
418 nsresult OnLDAPMessageSearchEntry (nsILDAPMessage *aMessage,
423 + nsAutoString m_sPassword;
425 nsCOMPtr<nsILDAPOperation> mSearchOperation;
429 do_CreateInstance(NS_LDAPOPERATION_CONTRACTID, &rv);
430 NS_ENSURE_SUCCESS(rv, rv);
433 nsCOMPtr<nsILDAPMessageListener> proxyListener;
434 rv = NS_GetProxyForObject(NS_UI_THREAD_EVENTQ,
435 NS_GET_IID(nsILDAPMessageListener),
436 @@ -261,10 +264,14 @@
437 getter_AddRefs(proxyListener));
439 rv = ldapOperation->Init(mConnection, proxyListener);
442 + rv = ldapOperation->Init(mConnection, this);
444 NS_ENSURE_SUCCESS(rv, rv);
447 - rv = ldapOperation->SimpleBind(nsnull);
448 + rv = ldapOperation->SimpleBind(m_sPassword.get());
449 NS_ENSURE_SUCCESS(rv, rv);
453 mSearchOperation = do_CreateInstance(NS_LDAPOPERATION_CONTRACTID, &rv);
454 NS_ENSURE_SUCCESS(rv, rv);
457 nsCOMPtr<nsIProxyObjectManager> proxyMgr =
458 do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
459 NS_ENSURE_SUCCESS(rv, rv);
461 NS_ENSURE_SUCCESS(rv, rv);
463 rv = mSearchOperation->Init (mConnection, proxyListener);
466 + rv = mSearchOperation->Init (mConnection, this);
468 NS_ENSURE_SUCCESS(rv, rv);
472 rv = nsAbBoolExprToLDAPFilter::Convert (expression, filter);
473 NS_ENSURE_SUCCESS(rv, rv);
476 + * Mozilla itself cannot arrive here with a blank filter
477 + * as the nsAbLDAPDirectory::StartSearch() disallows it.
478 + * But 3rd party LDAP query integration with Mozilla begins
481 + * Default the filter string if blank, otherwise it gets
482 + * set to (objectclass=*) which returns everything. Set
483 + * the default to (objectclass=inetorgperson) as this
484 + * is the most appropriate default objectclass which is
485 + * central to the makeup of the mozilla ldap address book
488 + if(filter.IsEmpty())
490 + filter += NS_LITERAL_CSTRING("(objectclass=inetorgperson)");
493 // Set up the search ldap url
494 nsCOMPtr<nsILDAPURL> directoryUrl;
497 if (_messageListener == NULL)
498 return NS_ERROR_OUT_OF_MEMORY;
500 + nsAutoString wPassword;
501 + wPassword.AssignWithConversion(mPassword.get());
502 + _messageListener->SetPassword(wPassword);
504 messageListener = _messageListener;
505 nsVoidKey key (NS_REINTERPRET_CAST(void *,contextID));
509 *_retval = contextID;
511 + nsAutoString wLogin;
512 + wLogin.AssignWithConversion(mLogin.get());
514 // Now lets initialize the LDAP connection properly. We'll kick
515 // off the bind operation in the callback function, |OnLDAPInit()|.
516 - rv = ldapConnection->Init(host.get(), port, options, nsnull,
517 + rv = ldapConnection->Init(host.get(), port, options, wLogin.get(),
519 NS_ENSURE_SUCCESS(rv, rv);
521 Index: mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h
522 ===================================================================
523 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h,v
524 retrieving revision 1.1.1.1
525 retrieving revision 1.2
526 diff -u -w -b -i -r1.1.1.1 -r1.2
527 --- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h 22 Oct 2003 02:43:10 -0000 1.1.1.1
528 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h 8 Jan 2004 04:26:20 -0000 1.2
530 friend class nsAbQueryLDAPMessageListener;
531 nsresult RemoveListener (PRInt32 contextID);
532 nsresult Initiate ();
533 + nsXPIDLCString mLogin; // authenticate to the LDAP server as...
534 + nsXPIDLCString mPassword; // password to the LDAP server as...
538 Index: mailnews/addrbook/src/nsAbLDAPProperties.cpp
539 ===================================================================
540 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp,v
541 retrieving revision 1.1.1.1
542 retrieving revision 1.2
543 diff -u -w -b -i -r1.1.1.1 -r1.2
544 --- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp 22 Oct 2003 02:43:10 -0000 1.1.1.1
545 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp 22 Oct 2003 09:45:04 -0000 1.2
547 #include "nsAbLDAPProperties.h"
549 #include "nsAbUtils.h"
552 #include "nsCOMPtr.h"
553 #include "nsString.h"
555 If there are multiple entries for a mozilla
556 property the first takes precedence.
558 + But where we need to do a query against
559 + a multiple occurring ldap attribute we
560 + need to OR all the possible ldap entries e.g.
562 + (CellularNumber=123456) translates to
563 + (|(mobile=123456)(&(!(mobile=*))(cellphone=123456))(&(!(mobile=*))(!(cellphone=*))(carphone=123456)))
565 + i.e. use the first occurring attribute otherwise if
566 + first does not exist use the second etc.
568 + [Multiple occurring ldap attributes do not
569 + include aliases. We have also ignored the case
570 + for including 'displayname' as the first occurring
571 + attribute 'cn' is a required attribute.]
575 1) Generality is maintained when mapping from
576 @@ -101,55 +117,32 @@
577 {MozillaProperty_String, "FaxNumber", "fax"},
578 // organizationalPerson
579 {MozillaProperty_String, "FaxNumber", "facsimiletelephonenumber"},
581 - {MozillaProperty_String, "PagerNumber", "pager"},
583 - {MozillaProperty_String, "PagerNumber", "pagerphone"},
585 - {MozillaProperty_String, "CellularNumber", "mobile"},
587 - {MozillaProperty_String, "CellularNumber", "cellphone"},
589 - {MozillaProperty_String, "CellularNumber", "carphone"},
591 + {MozillaProperty_String, "PagerNumber", "pager,pagerphone"},
592 + // inetOrgPerson ? ?
593 + {MozillaProperty_String, "CellularNumber", "mobile,cellphone,carphone"},
595 // No Home* properties defined yet
597 - // organizationalPerson
598 - {MozillaProperty_String, "WorkAddress", "postofficebox"},
600 - {MozillaProperty_String, "WorkAddress", "streetaddress"},
601 + // organizationalPerson ?
602 + {MozillaProperty_String, "WorkAddress", "postofficebox,streetaddress"},
604 {MozillaProperty_String, "WorkCity", "l"},
606 {MozillaProperty_String, "WorkCity", "locality"},
608 - {MozillaProperty_String, "WorkState", "st"},
610 - {MozillaProperty_String, "WorkState", "region"},
611 - // organizationalPerson
612 - {MozillaProperty_String, "WorkZipCode", "postalcode"},
614 - {MozillaProperty_String, "WorkZipCode", "zip"},
616 + {MozillaProperty_String, "WorkState", "st,region"},
617 + // organizationalPerson ?
618 + {MozillaProperty_String, "WorkZipCode", "postalcode,zip"},
620 {MozillaProperty_String, "WorkCountry", "countryname"},
622 // organizationalPerson
623 {MozillaProperty_String, "JobTitle", "title"},
625 - {MozillaProperty_String, "Department", "ou"},
627 - {MozillaProperty_String, "Department", "orgunit"},
629 - {MozillaProperty_String, "Department", "department"},
631 - {MozillaProperty_String, "Department", "departmentnumber"},
633 - {MozillaProperty_String, "Company", "o"},
635 - {MozillaProperty_String, "Company", "company"},
637 - {MozillaProperty_String, "WorkCountry", "countryname"},
640 + {MozillaProperty_String, "Department", "ou,orgunit,department,departmentnumber"},
642 + {MozillaProperty_String, "Company", "o,company"},
644 {MozillaProperty_String, "WebPage1", "workurl"},
648 {MozillaProperty_String, "Custom4", "custom4"},
651 - {MozillaProperty_String, "Notes", "notes"},
653 - {MozillaProperty_String, "Notes", "description"},
655 + {MozillaProperty_String, "Notes", "notes,description"},
658 {MozillaProperty_Int, "PreferMailFormat", "xmozillausehtmlmail"},
659 @@ -208,10 +199,22 @@
660 if (IsInitialized) { return ; }
662 for (int i = tableSize - 1 ; i >= 0 ; -- i) {
663 - nsCStringKey keyMozilla (table [i].mozillaProperty, -1, nsCStringKey::NEVER_OWN);
664 - nsCStringKey keyLdap (table [i].ldapProperty, -1, nsCStringKey::NEVER_OWN);
666 + char *attrToken = nsnull;
667 + char *LDAPProperty = nsCRT::strdup(table[i].ldapProperty);
668 + char *tmpLDAPProperty;
670 + attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty);
671 + while (attrToken != nsnull)
673 + while ( ' ' == *attrToken)
675 + nsCStringKey keyLdap (attrToken, -1, nsCStringKey::NEVER_OWN);
676 mLdapToMozilla.Put(&keyLdap, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(MozillaLdapPropertyRelation*, &table[i]))) ;
677 + attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty);
680 + nsCStringKey keyMozilla (table [i].mozillaProperty, -1, nsCStringKey::NEVER_OWN);
681 mMozillaToLdap.Put(&keyMozilla, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(MozillaLdapPropertyRelation*, &table[i]))) ;
683 IsInitialized = PR_TRUE;
684 @@ -233,10 +236,13 @@
685 const MozillaLdapPropertyRelation* MozillaLdapPropertyRelator::findMozillaPropertyFromLdap (const char* ldapProperty)
689 + char *tmpLDAPProperty;
690 + attrToken = nsCRT::strtok(NS_CONST_CAST(char *,ldapProperty), ",", &tmpLDAPProperty);
691 // ensure that we always do a case insensitive comparison
692 // against the incoming ldap attributes.
693 - nsCAutoString lowercasedProp (ldapProperty) ;
694 - ToLowerCase(nsDependentCString(ldapProperty),lowercasedProp);
695 + nsCAutoString lowercasedProp (attrToken) ;
696 + ToLowerCase(nsDependentCString(attrToken),lowercasedProp);
697 nsCStringKey key (lowercasedProp) ;
699 return NS_REINTERPRET_CAST(const MozillaLdapPropertyRelation *, mLdapToMozilla.Get(&key)) ;
707 +// Parse the input string which may contain a single ldap attribute or multiple attributes in the form
708 +// "string" or "string1,string2,string3" respectively and assign to the array.
709 +nsresult MozillaLdapPropertyRelator::getAllLDAPAttrsFromMozilla (const char* aLDAPProperty, PRUint32 *aAttrCount, char * **aAttributes)
711 + NS_ENSURE_ARG_POINTER(aAttrCount);
712 + NS_ENSURE_ARG_POINTER(aAttributes);
714 + nsresult rv = NS_OK;
717 + // we must have at least one attribute
720 + // if no multiple ldap attributes then allocate our single entry and exit
721 + if (!strchr(aLDAPProperty,','))
723 + if (!(*aAttributes = NS_STATIC_CAST(char **, nsMemory::Alloc(sizeof(char *)))))
724 + return NS_ERROR_OUT_OF_MEMORY;
725 + if (!((*aAttributes)[0] = nsCRT::strdup(aLDAPProperty)))
726 + return NS_ERROR_OUT_OF_MEMORY;
731 + char *attrToken = nsnull;
732 + char *LDAPProperty = nsnull;
733 + char *tmpLDAPProperty;
735 + if((LDAPProperty = nsCRT::strdup(aLDAPProperty)) == nsnull)
736 + return NS_ERROR_OUT_OF_MEMORY;
738 + // set our tokenizer to the start
739 + attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty);
741 + // Count up the attribute names
742 + while ((attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty)) != nsnull)
745 + nsCRT::free (LDAPProperty);
746 + if(!(*aAttributes = NS_STATIC_CAST(char **, nsMemory::Alloc(*aAttrCount * sizeof(char *)))))
747 + return NS_ERROR_OUT_OF_MEMORY;
749 + if((LDAPProperty = nsCRT::strdup(aLDAPProperty)) == nsnull)
750 + return NS_ERROR_OUT_OF_MEMORY;
753 + attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty);
754 + while (nsnull != attrToken) {
755 + if(((*aAttributes)[j++] = nsCRT::strdup(attrToken)) == nsnull)
757 + nsCRT::free(LDAPProperty);
758 + return NS_ERROR_OUT_OF_MEMORY;
761 + attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty);
764 + nsCRT::free(LDAPProperty);
767 Index: mailnews/addrbook/src/nsAbLDAPProperties.h
768 ===================================================================
769 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h,v
770 retrieving revision 1.1.1.1
771 retrieving revision 1.2
772 diff -u -w -b -i -r1.1.1.1 -r1.2
773 --- miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h 22 Oct 2003 02:43:10 -0000 1.1.1.1
774 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h 22 Oct 2003 09:45:04 -0000 1.2
776 static nsresult createCardPropertyFromLDAPMessage (nsILDAPMessage* message,
778 PRBool* hasSetCardProperty);
779 + static nsresult getAllLDAPAttrsFromMozilla (const char* aLDAPProperty, PRUint32 *aAttrCount, char * **aAttributes);
783 Index: mailnews/addrbook/src/nsAbOutlookCard.cpp
784 ===================================================================
785 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp,v
786 retrieving revision 1.1.1.1
787 retrieving revision 1.2
788 diff -u -w -b -i -r1.1.1.1 -r1.2
789 --- miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp 22 Oct 2003 02:43:10 -0000 1.1.1.1
790 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp 9 Dec 2003 03:26:47 -0000 1.2
793 index_DisplayName = 0,
795 + index_SecondEmailAddress,
796 + //index_ScreenName,
800 @@ -124,32 +126,35 @@
802 static const ULONG OutlookCardMAPIProps [] =
805 - PR_EMAIL_ADDRESS_W,
809 - PR_BUSINESS_TELEPHONE_NUMBER_W,
810 - PR_HOME_TELEPHONE_NUMBER_W,
811 - PR_BUSINESS_FAX_NUMBER_W,
812 - PR_PAGER_TELEPHONE_NUMBER_W,
813 - PR_MOBILE_TELEPHONE_NUMBER_W,
814 - PR_HOME_ADDRESS_CITY_W,
815 - PR_HOME_ADDRESS_STATE_OR_PROVINCE_W,
816 - PR_HOME_ADDRESS_POSTAL_CODE_W,
817 - PR_HOME_ADDRESS_COUNTRY_W,
818 - PR_BUSINESS_ADDRESS_CITY_W,
819 - PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_W,
820 - PR_BUSINESS_ADDRESS_POSTAL_CODE_W,
821 - PR_BUSINESS_ADDRESS_COUNTRY_W,
823 - PR_DEPARTMENT_NAME_W,
825 - PR_BUSINESS_HOME_PAGE_W,
826 - PR_PERSONAL_HOME_PAGE_W,
828 + PR_DISPLAY_NAME_A,//0x8035001E,//PR_DISPLAY_NAME_A,
829 + PR_EMAIL_ADDRESS_A,//0x8034001E,//PR_EMAIL_ADDRESS_A,
830 + PR_SECOND_EMAIL_ADDRESS_A,//Second Email Address
831 + //PR_SCREEN_NAME_A,//AimScreenName
835 + PR_BUSINESS_TELEPHONE_NUMBER_A,
836 + PR_HOME_TELEPHONE_NUMBER_A,
837 + PR_BUSINESS_FAX_NUMBER_A,
838 + PR_PAGER_TELEPHONE_NUMBER_A,
839 + PR_MOBILE_TELEPHONE_NUMBER_A,
840 + PR_HOME_ADDRESS_CITY_A,
841 + PR_HOME_ADDRESS_STATE_OR_PROVINCE_A,
842 + PR_HOME_ADDRESS_POSTAL_CODE_A,
843 + PR_HOME_ADDRESS_COUNTRY_A,
844 + PR_BUSINESS_ADDRESS_CITY_A,
845 + PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_A,
846 + PR_BUSINESS_ADDRESS_POSTAL_CODE_A,
847 + PR_BUSINESS_ADDRESS_COUNTRY_A,
849 + PR_DEPARTMENT_NAME_A,
851 + PR_BUSINESS_HOME_PAGE_A,
852 + PR_PERSONAL_HOME_PAGE_A,
857 nsresult nsAbOutlookCard::Init(const char *aUri)
859 nsresult retCode = nsRDFResource::Init(aUri) ;
861 SetDisplayName(unichars [index_DisplayName]->get()) ;
862 SetNickName(unichars [index_NickName]->get()) ;
863 SetPrimaryEmail(unichars [index_EmailAddress]->get()) ;
864 + SetSecondEmail(unichars [index_SecondEmailAddress]->get()) ;
865 + //SetAimScreenName(unichars [index_ScreenName]->get()) ;
866 SetWorkPhone(unichars [index_WorkPhoneNumber]->get()) ;
867 SetHomePhone(unichars [index_HomePhoneNumber]->get()) ;
868 SetFaxNumber(unichars [index_WorkFaxNumber]->get()) ;
869 @@ -210,12 +217,12 @@
870 nsAutoString unichar ;
871 nsAutoString unicharBis ;
873 - if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_W, unichar)) {
874 + if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_A, unichar)) {
875 splitString(unichar, unicharBis) ;
876 SetHomeAddress(unichar.get()) ;
877 SetHomeAddress2(unicharBis.get()) ;
879 - if (mapiAddBook->GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_W, unichar)) {
880 + if (mapiAddBook->GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_A, unichar)) {
881 splitString(unichar, unicharBis) ;
882 SetWorkAddress(unichar.get()) ;
883 SetWorkAddress2(unicharBis.get()) ;
885 SetDisplayName(properties [index_DisplayName]) ;
886 GetNickName(getter_Copies(properties [index_NickName])) ;
887 GetPrimaryEmail(getter_Copies(properties [index_EmailAddress])) ;
888 + GetSecondEmail(getter_Copies(properties [index_SecondEmailAddress])) ;
889 + //GetAimScreenName(getter_Copies(properties [index_ScreenName])) ;
890 GetWorkPhone(getter_Copies(properties [index_WorkPhoneNumber])) ;
891 GetHomePhone(getter_Copies(properties [index_HomePhoneNumber])) ;
892 GetFaxNumber(getter_Copies(properties [index_WorkFaxNumber])) ;
893 @@ -316,11 +325,20 @@
894 GetWebPage1(getter_Copies(properties [index_WorkWebPage])) ;
895 GetWebPage2(getter_Copies(properties [index_HomeWebPage])) ;
896 GetNotes(getter_Copies(properties [index_Comments])) ;
897 - if (!mapiAddBook->SetPropertiesUString(*mMapiData, OutlookCardMAPIProps,
898 - index_LastProp, properties)) {
899 - PRINTF(("Cannot set general properties.\n")) ;
902 + for (i=0;i<index_LastProp;i++)
904 + if (!mapiAddBook->SetPropertyUString(*mMapiData,
905 + OutlookCardMAPIProps[i],
908 + PRINTF(("Cannot set properties:%d.\n",OutlookCardMAPIProps[i])) ;
912 delete [] properties ;
914 nsXPIDLString unichar ;
915 nsXPIDLString unichar2 ;
917 Index: mailnews/addrbook/src/nsAbOutlookDirFactory.cpp
918 ===================================================================
919 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp,v
920 retrieving revision 1.1.1.1
921 retrieving revision 1.2
922 diff -u -w -b -i -r1.1.1.1 -r1.2
923 --- miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp 22 Oct 2003 02:43:10 -0000 1.1.1.1
924 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp 9 Dec 2003 03:26:47 -0000 1.2
927 nsCOMPtr<nsIRDFResource> resource ;
929 - for (ULONG i = 0 ; i < folders.mNbEntries ; ++ i) {
930 - folders.mEntries [i].ToString(entryId) ;
931 + for (ULONG i = 0 ; i < folders.GetSize() ; ++ i) {
932 + folders[i].ToString(entryId) ;
933 buildAbWinUri(kOutlookDirectoryScheme, abType, uri) ;
934 uri.Append(entryId) ;
936 Index: mailnews/addrbook/src/nsAbOutlookDirectory.cpp
937 ===================================================================
938 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp,v
939 retrieving revision 1.1.1.1
940 retrieving revision 1.3
941 diff -u -w -b -i -r1.1.1.1 -r1.3
942 --- miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp 22 Oct 2003 02:43:11 -0000 1.1.1.1
943 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp 9 Dec 2003 03:26:47 -0000 1.3
945 PRINTF(("Cannot get type.\n")) ;
946 return NS_ERROR_FAILURE ;
948 - if (!mapiAddBook->GetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, unichars)) {
949 + if (!mapiAddBook->GetPropertyUString(*mMapiData, PR_DISPLAY_NAME_A, unichars)) {
950 PRINTF(("Cannot get name.\n")) ;
951 return NS_ERROR_FAILURE ;
953 @@ -161,45 +161,85 @@
957 +nsresult nsAbOutlookDirectory::BuildCardFromURI(const nsCString& uriName,nsIAbCard **aNewCard,
958 + PRBool aSearchForOld, PRBool& aIsNewCard)
960 + nsresult retCode = NS_OK ;
961 + if (aSearchForOld) {
962 + nsCStringKey key(uriName) ;
963 + nsCOMPtr<nsISupports> existingCard = mCardList.Get(&key) ;
965 + if (existingCard) {
966 + nsCOMPtr<nsIAbCard> card(do_QueryInterface(existingCard, &retCode)) ;
968 + NS_ENSURE_SUCCESS(retCode, retCode) ;
969 + NS_IF_ADDREF(*aNewCard = card) ;
970 + aIsNewCard = PR_FALSE ;
974 + aIsNewCard = PR_TRUE ;
975 + nsCOMPtr<nsIRDFResource> resource ;
977 + nsCOMPtr<nsIAbCard> childCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &retCode);
978 + NS_ENSURE_SUCCESS(retCode, retCode) ;
979 + resource = do_QueryInterface(childCard, &retCode) ;
980 + NS_ENSURE_SUCCESS(retCode, retCode) ;
981 + retCode = resource->Init(uriName.get()) ;
982 + NS_ENSURE_SUCCESS(retCode, retCode) ;
983 + NS_IF_ADDREF(*aNewCard = childCard);
987 NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
989 if (!aCards) { return NS_ERROR_NULL_POINTER ; }
991 nsCOMPtr<nsISupportsArray> cardList ;
992 + nsCStringArray uriList ;
993 + nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
996 - mCardList.Reset() ;
998 retCode = StartSearch() ;
999 - NS_NewISupportsArray(getter_AddRefs(cardList)) ;
1002 - retCode = GetChildCards(getter_AddRefs(cardList), nsnull) ;
1003 + retCode = GetChildCards(uriList, nsnull) ;
1005 + NS_NewISupportsArray(getter_AddRefs(cardList)) ;
1006 if (NS_SUCCEEDED(retCode)) {
1007 // Fill the results array and update the card list
1008 // Also update the address list and notify any changes.
1009 PRUint32 nbCards = 0 ;
1010 - nsCOMPtr<nsISupports> element ;
1011 + nsCAutoString uriName;
1012 + nsCOMPtr <nsIAbCard> childCard;
1013 + PRBool searchForOldCards = (mCardList.Count() != 0) ;
1015 + nbCards = uriList.Count();
1016 + NS_NewISupportsArray(getter_AddRefs(m_AddressList));
1018 - cardList->Enumerate(aCards) ;
1019 - cardList->Count(&nbCards) ;
1020 for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
1021 - cardList->GetElementAt(i, getter_AddRefs(element)) ;
1022 - nsVoidKey newKey (NS_STATIC_CAST(void *, element)) ;
1023 - nsCOMPtr<nsISupports> oldElement = mCardList.Get(&newKey) ;
1024 + PRBool isNewCard = PR_FALSE ;
1026 + uriList.CStringAt(i,uriName);
1027 + retCode = BuildCardFromURI(uriName,getter_AddRefs(childCard), searchForOldCards, isNewCard);
1028 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1029 + cardList->AppendElement(childCard);
1031 - if (!oldElement) {
1033 // We are dealing with a new element (probably directly
1034 // added from Outlook), we may need to sync m_AddressList
1035 - mCardList.Put(&newKey, element) ;
1036 - nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
1037 + nsCStringKey newKey(uriName) ;
1039 + mCardList.Put(&newKey, childCard) ;
1040 + nsCOMPtr<nsIAbCard> card (do_QueryInterface(childCard, &retCode)) ;
1042 NS_ENSURE_SUCCESS(retCode, retCode) ;
1043 PRBool isMailList = PR_FALSE ;
1045 retCode = card->GetIsMailList(&isMailList) ;
1046 NS_ENSURE_SUCCESS(retCode, retCode) ;
1049 // We can have mailing lists only in folder,
1050 // we must add the directory to m_AddressList
1051 @@ -222,18 +262,33 @@
1052 NotifyItemAddition(card) ;
1056 - NS_ASSERTION(oldElement == element, "Different card stored") ;
1059 + return cardList->Enumerate(aCards) ;
1062 +static nsresult ExtractUriFromCard(nsIAbCard *aCard, nsCString& aUri) {
1063 + nsresult retCode = NS_OK ;
1064 + nsCOMPtr<nsIRDFResource> resource (do_QueryInterface(aCard, &retCode)) ;
1066 + // Receiving a non-RDF card is accepted
1067 + if (NS_FAILED(retCode)) { return NS_OK ; }
1068 + nsXPIDLCString uri ;
1070 + retCode = resource->GetValue(getter_Copies(uri)) ;
1071 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1072 + aUri = uri.get() ;
1076 NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
1078 if (!aCard || !aHasCard) { return NS_ERROR_NULL_POINTER ; }
1079 - nsVoidKey key (NS_STATIC_CAST(void *, aCard)) ;
1080 + *aHasCard = PR_FALSE ;
1083 + ExtractUriFromCard(aCard, uri) ;
1084 + nsCStringKey key(uri) ;
1086 *aHasCard = mCardList.Exists(&key) ;
1088 @@ -315,7 +370,10 @@
1089 PRINTF(("Cannot delete card %s.\n", entryString.get())) ;
1092 - nsVoidKey key (NS_STATIC_CAST(void *, element)) ;
1095 + ExtractUriFromCard(card, uri) ;
1096 + nsCStringKey key(uri) ;
1098 mCardList.Remove(&key) ;
1099 if (m_IsMailList) { m_AddressList->RemoveElement(element) ; }
1100 @@ -378,7 +436,10 @@
1102 retCode = CreateCard(aData, addedCard) ;
1103 NS_ENSURE_SUCCESS(retCode, retCode) ;
1104 - nsVoidKey newKey (NS_STATIC_CAST(void *, *addedCard)) ;
1107 + ExtractUriFromCard(*addedCard, uri) ;
1108 + nsCStringKey newKey(uri) ;
1110 mCardList.Put(&newKey, *addedCard) ;
1111 if (m_IsMailList) { m_AddressList->AppendElement(*addedCard) ; }
1113 if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
1114 retCode = GetDirName(getter_Copies(name)) ;
1115 NS_ENSURE_SUCCESS(retCode, retCode) ;
1116 - if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, name.get())) {
1117 + if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_DISPLAY_NAME_A, name.get())) {
1118 return NS_ERROR_FAILURE ;
1120 retCode = CommitAddressList() ;
1122 {"DisplayName", PR_DISPLAY_NAME_A},
1123 {"NickName", PR_NICKNAME_A},
1124 {"PrimaryEmail", PR_EMAIL_ADDRESS_A},
1125 + //{"_AimScreenName",PR_SCREEN_NAME_A},
1126 + {"SecondEmail",PR_SECOND_EMAIL_ADDRESS_A},
1127 {"WorkPhone", PR_BUSINESS_TELEPHONE_NUMBER_A},
1128 {"HomePhone", PR_HOME_TELEPHONE_NUMBER_A},
1129 {"FaxNumber", PR_BUSINESS_FAX_NUMBER_A},
1130 @@ -950,6 +1013,7 @@
1132 return NS_ERROR_OUT_OF_MEMORY ;
1135 nsIntegerKey newKey(*aReturnValue) ;
1137 mQueryThreads.Put(&newKey, newThread) ;
1138 @@ -1018,7 +1082,10 @@
1140 nsresult nsAbOutlookDirectory::OnSearchFoundCard(nsIAbCard *aCard)
1142 - nsVoidKey newKey (NS_STATIC_CAST(void *, aCard)) ;
1145 + ExtractUriFromCard(aCard, uri) ;
1146 + nsCStringKey newKey(uri) ;
1147 nsresult retCode = NS_OK ;
1149 mCardList.Put(&newKey, aCard) ;
1150 @@ -1042,14 +1109,14 @@
1151 retCode = BuildRestriction(aArguments, arguments) ;
1152 NS_ENSURE_SUCCESS(retCode, retCode) ;
1153 nsCOMPtr<nsISupportsArray> resultsArray ;
1154 + nsCStringArray uriArray ;
1155 PRUint32 nbResults = 0 ;
1157 - retCode = GetChildCards(getter_AddRefs(resultsArray),
1158 + retCode = GetChildCards(uriArray,
1159 arguments.rt == RES_COMMENT ? nsnull : &arguments) ;
1160 DestroyRestriction(arguments) ;
1161 NS_ENSURE_SUCCESS(retCode, retCode) ;
1162 - retCode = resultsArray->Count(&nbResults) ;
1163 - NS_ENSURE_SUCCESS(retCode, retCode) ;
1164 + nbResults = uriArray.Count() ;
1165 nsCOMPtr<nsIAbDirectoryQueryResult> result ;
1166 nsAbDirectoryQueryResult *newResult = nsnull ;
1168 @@ -1057,15 +1124,18 @@
1169 nbResults = NS_STATIC_CAST(PRUint32, aResultLimit) ;
1172 - nsCOMPtr<nsISupports> element ;
1173 nsCOMPtr<nsISupportsArray> propertyValues ;
1175 + nsCAutoString uriName;
1176 + nsCOMPtr <nsIAbCard> card;
1178 for (i = 0 ; i < nbResults ; ++ i) {
1179 - retCode = resultsArray->GetElementAt(i, getter_AddRefs(element)) ;
1180 - NS_ENSURE_SUCCESS(retCode, retCode) ;
1181 - nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
1182 + PRBool isNewCard = PR_FALSE ;
1184 + uriArray.CStringAt(i,uriName);
1185 + retCode = BuildCardFromURI(uriName,getter_AddRefs(card), PR_FALSE, isNewCard);
1186 NS_ENSURE_SUCCESS(retCode, retCode) ;
1188 FillPropertyValues(card, aArguments, getter_AddRefs(propertyValues)) ;
1189 newResult = new nsAbDirectoryQueryResult(0, aArguments,
1190 nsIAbDirectoryQueryResult::queryResultMatch,
1191 @@ -1090,6 +1160,38 @@
1192 if (!aCards) { return NS_ERROR_NULL_POINTER ; }
1194 nsresult retCode = NS_OK ;
1196 + nsCOMPtr<nsISupportsArray> cards;
1197 + retCode = NS_NewISupportsArray(getter_AddRefs(cards));
1198 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1200 + nsCStringArray uriList;
1201 + retCode = GetChildCards(uriList,aRestriction);
1202 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1204 + nsCAutoString uriName;
1205 + nsCOMPtr <nsIAbCard> childCard;
1206 + PRUint32 nbURIs = 0 ;
1207 + nbURIs = uriList.Count();
1210 + for (i = 0 ; i < nbURIs ; ++ i) {
1211 + PRBool isNewCard = PR_FALSE ;
1213 + uriList.CStringAt(i,uriName);
1214 + retCode = BuildCardFromURI(uriName,getter_AddRefs(childCard), PR_TRUE, isNewCard);
1215 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1216 + cards->AppendElement(childCard);
1219 + NS_IF_ADDREF(*aCards = cards);
1223 +nsresult nsAbOutlookDirectory::GetChildCards(nsCStringArray& aURI,
1224 + void *aRestriction)
1226 + nsresult retCode = NS_OK ;
1227 nsCOMPtr<nsISupportsArray> cards ;
1228 nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
1229 nsMapiEntryArray cardEntries ;
1230 @@ -1104,18 +1206,14 @@
1232 nsCAutoString entryId ;
1233 nsCAutoString uriName ;
1234 - nsCOMPtr<nsIRDFResource> resource ;
1237 - for (ULONG card = 0 ; card < cardEntries.mNbEntries ; ++ card) {
1238 - cardEntries.mEntries [card].ToString(entryId) ;
1239 + for (ULONG card = 0 ; card < cardEntries.GetSize() ; ++ card) {
1240 + cardEntries [card].ToString(entryId) ;
1241 buildAbWinUri(kOutlookCardScheme, mAbWinType, uriName) ;
1242 uriName.Append(entryId) ;
1243 - retCode = gRDFService->GetResource(uriName.get(), getter_AddRefs(resource)) ;
1244 - NS_ENSURE_SUCCESS(retCode, retCode) ;
1245 - cards->AppendElement(resource) ;
1246 + aURI.AppendCString(uriName);
1249 - NS_ADDREF(*aCards) ;
1253 @@ -1139,8 +1237,8 @@
1254 nsCAutoString uriName ;
1255 nsCOMPtr <nsIRDFResource> resource ;
1257 - for (ULONG node = 0 ; node < nodeEntries.mNbEntries ; ++ node) {
1258 - nodeEntries.mEntries [node].ToString(entryId) ;
1259 + for (ULONG node = 0 ; node < nodeEntries.GetSize() ; ++ node) {
1260 + nodeEntries [node].ToString(entryId) ;
1261 buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uriName) ;
1262 uriName.Append(entryId) ;
1263 retCode = gRDFService->GetResource(uriName.get(), getter_AddRefs(resource)) ;
1264 @@ -1261,7 +1359,7 @@
1265 // In the case of a mailing list, we cannot directly create a new card,
1266 // we have to create a temporary one in a real folder (to be able to use
1267 // templates) and then copy it to the mailing list.
1268 - if (m_IsMailList) {
1269 + if (m_IsMailList && mAbWinType == nsAbWinType_OutlookExp) {
1270 nsMapiEntry parentEntry ;
1271 nsMapiEntry temporaryEntry ;
1273 @@ -1291,10 +1389,11 @@
1274 uri.Append(entryString) ;
1275 nsCOMPtr<nsIRDFResource> resource ;
1277 - retCode = gRDFService->GetResource(uri.get(), getter_AddRefs(resource)) ;
1278 + nsCOMPtr<nsIAbCard> newCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &retCode);
1279 NS_ENSURE_SUCCESS(retCode, retCode) ;
1280 - nsCOMPtr<nsIAbCard> newCard(do_QueryInterface(resource, &retCode)) ;
1282 + resource = do_QueryInterface(newCard, &retCode) ;
1283 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1284 + retCode = resource->Init(uri.get()) ;
1285 NS_ENSURE_SUCCESS(retCode, retCode) ;
1287 retCode = newCard->Copy(aData) ;
1288 Index: mailnews/addrbook/src/nsAbOutlookDirectory.h
1289 ===================================================================
1290 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h,v
1291 retrieving revision 1.1.1.1
1292 retrieving revision 1.2
1293 diff -u -w -b -i -r1.1.1.1 -r1.2
1294 --- miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h 22 Oct 2003 02:43:11 -0000 1.1.1.1
1295 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h 22 Oct 2003 09:45:04 -0000 1.2
1297 #include "nsHashtable.h"
1299 #include "nsISupportsArray.h"
1300 +#include "nsVoidArray.h"
1302 struct nsMapiEntry ;
1306 // Retrieve hierarchy as cards, with an optional restriction
1307 nsresult GetChildCards(nsISupportsArray **aCards, void *aRestriction) ;
1308 + // Retrieve hierarchy as URIs, with an optional restriction
1309 + nsresult GetChildCards(nsCStringArray& aURI, void *aRestriction) ;
1310 // Retrieve hierarchy as directories
1311 nsresult GetChildNodes(nsISupportsArray **aNodes) ;
1312 // Create a new card
1314 nsresult CommitAddressList(void) ;
1315 // Read MAPI repository
1316 nsresult UpdateAddressList(void) ;
1317 + // Search for an existing card or build a new one
1318 + nsresult BuildCardFromURI(const nsCString& uriName,nsIAbCard **aNewCard,
1319 + PRBool aSearchForOld, PRBool& aIsNewCard) ;
1321 nsMapiEntry *mMapiData ;
1322 // Container for the query threads
1323 Index: mailnews/addrbook/src/nsAbWinHelper.cpp
1324 ===================================================================
1325 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp,v
1326 retrieving revision 1.1.1.1
1327 retrieving revision 1.3
1328 diff -u -w -b -i -r1.1.1.1 -r1.3
1329 --- miss/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp 22 Oct 2003 02:43:11 -0000 1.1.1.1
1330 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp 9 Dec 2003 03:26:47 -0000 1.3
1332 #define USES_IID_IABContainer
1333 #define USES_IID_IMAPITable
1334 #define USES_IID_IDistList
1335 +#define USES_IID_IMsgStore
1336 +#define USES_IID_IMessage
1337 +#define USES_IID_IMAPIFolder
1339 #include "nsAbWinHelper.h"
1340 #include "nsAbUtils.h"
1343 #define PRINTF(args) PR_LOG(gAbWinHelperLog, PR_LOG_DEBUG, args)
1345 -// Small utility to ensure release of all MAPI interfaces
1346 -template <class tInterface> struct nsMapiInterfaceWrapper
1348 - tInterface mInterface ;
1350 - nsMapiInterfaceWrapper(void) : mInterface(NULL) {}
1351 - ~nsMapiInterfaceWrapper(void) {
1352 - if (mInterface != NULL) { mInterface->Release() ; }
1354 - operator LPUNKNOWN *(void) { return NS_REINTERPRET_CAST(LPUNKNOWN *, &mInterface) ; }
1355 - tInterface operator -> (void) const { return mInterface ; }
1356 - operator tInterface *(void) { return &mInterface ; }
1359 static void assignEntryID(LPENTRYID& aTarget, LPENTRYID aSource, ULONG aByteCount)
1361 @@ -249,24 +239,28 @@
1362 MOZ_DECL_CTOR_COUNTER(nsMapiEntryArray)
1364 nsMapiEntryArray::nsMapiEntryArray(void)
1365 -: mEntries(NULL), mNbEntries(0)
1367 MOZ_COUNT_CTOR(nsMapiEntryArray) ;
1370 nsMapiEntryArray::~nsMapiEntryArray(void)
1372 - if (mEntries) { delete [] mEntries ; }
1374 MOZ_COUNT_DTOR(nsMapiEntryArray) ;
1377 +void nsMapiEntryArray::AddItem(nsMapiEntry * aEntries)
1379 + m_array.AppendElement(aEntries);
1381 void nsMapiEntryArray::CleanUp(void)
1383 - if (mEntries != NULL) {
1384 - delete [] mEntries ;
1387 + nsMapiEntry *pEntries;
1388 + for (int i = 0; i < m_array.Count(); i++)
1390 + pEntries = (nsMapiEntry *)m_array.ElementAt( i);
1396 MOZ_DECL_CTOR_COUNTER(nsAbWinHelper)
1397 @@ -280,100 +274,55 @@
1398 // same protection (MAPI is supposed to be thread-safe).
1399 PRLock *nsAbWinHelper::mMutex = PR_NewLock() ;
1401 +int nsAbWinHelper::m_clients = 0;
1403 +PRUnichar * nsAbWinHelper::m_pUniBuff = NULL;
1404 +int nsAbWinHelper::m_uniBuffLen = 0;
1405 +char * nsAbWinHelper::m_pCStrBuff = NULL;
1406 +int nsAbWinHelper::m_cstrBuffLen = 0;
1408 nsAbWinHelper::nsAbWinHelper(void)
1409 -: mAddressBook(NULL), mLastError(S_OK)
1412 MOZ_COUNT_CTOR(nsAbWinHelper) ;
1416 nsAbWinHelper::~nsAbWinHelper(void)
1418 MOZ_COUNT_DTOR(nsAbWinHelper) ;
1421 -BOOL nsAbWinHelper::GetFolders(nsMapiEntryArray& aFolders)
1425 - aFolders.CleanUp() ;
1426 - nsMapiInterfaceWrapper<LPABCONT> rootFolder ;
1427 - nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
1428 - ULONG objType = 0 ;
1429 - ULONG rowCount = 0 ;
1430 - SRestriction restriction ;
1431 - SPropTagArray folderColumns ;
1433 - mLastError = mAddressBook->OpenEntry(0, NULL, NULL, 0, &objType,
1435 - if (HR_FAILED(mLastError)) {
1436 - PRINTF(("Cannot open root %08x.\n", mLastError)) ;
1438 + delete [] m_pUniBuff;
1439 + m_pUniBuff = NULL;
1441 + delete [] m_pCStrBuff;
1442 + m_pCStrBuff = NULL;
1443 + m_cstrBuffLen = 0;
1445 - mLastError = rootFolder->GetHierarchyTable(0, folders) ;
1446 - if (HR_FAILED(mLastError)) {
1447 - PRINTF(("Cannot get hierarchy %08x.\n", mLastError)) ;
1450 - // We only take into account modifiable containers,
1451 - // otherwise, we end up with all the directory services...
1452 - restriction.rt = RES_BITMASK ;
1453 - restriction.res.resBitMask.ulPropTag = PR_CONTAINER_FLAGS ;
1454 - restriction.res.resBitMask.relBMR = BMR_NEZ ;
1455 - restriction.res.resBitMask.ulMask = AB_MODIFIABLE ;
1456 - mLastError = folders->Restrict(&restriction, 0) ;
1457 - if (HR_FAILED(mLastError)) {
1458 - PRINTF(("Cannot restrict table %08x.\n", mLastError)) ;
1460 - folderColumns.cValues = 1 ;
1461 - folderColumns.aulPropTag [0] = PR_ENTRYID ;
1462 - mLastError = folders->SetColumns(&folderColumns, 0) ;
1463 - if (HR_FAILED(mLastError)) {
1464 - PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
1467 - mLastError = folders->GetRowCount(0, &rowCount) ;
1468 - if (HR_SUCCEEDED(mLastError)) {
1469 - aFolders.mEntries = new nsMapiEntry [rowCount] ;
1470 - aFolders.mNbEntries = 0 ;
1472 - LPSRowSet rowSet = NULL ;
1475 - mLastError = folders->QueryRows(1, 0, &rowSet) ;
1476 - if (HR_SUCCEEDED(mLastError)) {
1477 - rowCount = rowSet->cRows ;
1478 - if (rowCount > 0) {
1479 - nsMapiEntry& current = aFolders.mEntries [aFolders.mNbEntries ++] ;
1480 - SPropValue& currentValue = rowSet->aRow->lpProps [0] ;
1482 - current.Assign(currentValue.Value.bin.cb,
1483 - NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
1485 - MyFreeProws(rowSet) ;
1488 - PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
1490 - } while (rowCount > 0) ;
1492 - return HR_SUCCEEDED(mLastError) ;
1495 BOOL nsAbWinHelper::GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction,
1496 nsMapiEntryArray& aCards)
1499 - return GetContents(aParent, aRestriction, &aCards.mEntries, aCards.mNbEntries, 0) ;
1500 + return GetContents(aParent, aRestriction, &aCards, 0) ;
1503 BOOL nsAbWinHelper::GetNodes(const nsMapiEntry& aParent, nsMapiEntryArray& aNodes)
1506 - return GetContents(aParent, NULL, &aNodes.mEntries, aNodes.mNbEntries, MAPI_DISTLIST) ;
1507 + return GetContents(aParent, NULL, &aNodes, MAPI_DISTLIST) ;
1510 BOOL nsAbWinHelper::GetCardsCount(const nsMapiEntry& aParent, ULONG& aNbCards)
1513 - return GetContents(aParent, NULL, NULL, aNbCards, 0) ;
1514 + nsMapiEntryArray aCards;
1515 + BOOL ret=GetContents(aParent, NULL, &aCards, 0) ;
1516 + aNbCards=aCards.GetSize();
1520 BOOL nsAbWinHelper::GetPropertyString(const nsMapiEntry& aObject,
1522 aName = values->Value.lpszA ;
1524 else if (PROP_TYPE(values->ulPropTag) == PT_UNICODE) {
1525 - aName.AssignWithConversion(values->Value.lpszW) ;
1526 + UnicodeToCStr(values->Value.lpszW,aName) ;
1529 FreeBuffer(values) ;
1531 aName = values->Value.lpszW ;
1533 else if (PROP_TYPE(values->ulPropTag) == PT_STRING8) {
1534 - aName.AssignWithConversion(values->Value.lpszA) ;
1535 + CStrToUnicode(values->Value.lpszA,aName) ;
1538 FreeBuffer(values) ;
1539 @@ -431,16 +380,24 @@
1542 for (i = 0 ; i < valueCount ; ++ i) {
1543 - if (values [i].ulPropTag == aPropertyTags [i]) {
1545 + if (PROP_TYPE( values [i].ulPropTag) != PT_ERROR && values [i].Value.l != MAPI_E_NOT_FOUND)
1547 if (PROP_TYPE(values [i].ulPropTag) == PT_STRING8) {
1550 - temp.AssignWithConversion (values [i].Value.lpszA) ;
1551 + CStrToUnicode(values [i].Value.lpszA,temp) ;
1552 aNames.AppendString(temp) ;
1554 else if (PROP_TYPE(values [i].ulPropTag) == PT_UNICODE) {
1555 aNames.AppendString(nsAutoString (values [i].Value.lpszW)) ;
1557 + else if (aPropertyTags [i] == PR_EMAIL_ADDRESS_A) {
1558 + nsAutoString temp ;
1560 + CStrToUnicode (values [i].Value.lpszA,temp) ;
1561 + aNames.AppendString(temp) ;
1564 aNames.AppendString(nsAutoString((const PRUnichar *) "")) ;
1567 if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) { return FALSE ; }
1568 if (valueCount == 1 && values != NULL && PROP_TYPE(values->ulPropTag) == PT_SYSTIME) {
1569 SYSTEMTIME readableTime ;
1571 if (FileTimeToSystemTime(&values->Value.ft, &readableTime)) {
1572 aYear = readableTime.wYear ;
1573 aMonth = readableTime.wMonth ;
1575 nsMapiInterfaceWrapper<LPMAPIPROP> subObject ;
1578 - mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1579 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1580 &IID_IMAPIContainer, 0, &objType,
1582 if (HR_FAILED(mLastError)) {
1585 SBinaryArray entryArray ;
1587 - mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1588 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1589 &IID_IABContainer, MAPI_MODIFY, &objType,
1591 if (HR_FAILED(mLastError)) {
1592 @@ -567,14 +523,15 @@
1593 value.Value.lpszW = NS_CONST_CAST(WORD *, aValue) ;
1595 else if (PROP_TYPE(aPropertyTag) == PT_STRING8) {
1596 - alternativeValue.AssignWithConversion(aValue) ;
1597 + UnicodeToCStr(aValue,alternativeValue) ;
1598 value.Value.lpszA = NS_CONST_CAST(char *, alternativeValue.get()) ;
1601 PRINTF(("Property %08x is not a string.\n", aPropertyTag)) ;
1604 - return SetMAPIProperties(aObject, 1, &value) ;
1605 + LPSPropValue values=&value;
1606 + return SetMAPIProperties(aObject, 1, values) ;
1609 BOOL nsAbWinHelper::SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
1611 values [currentValue ++].Value.lpszW = NS_CONST_CAST(WORD *, aValues [i].get()) ;
1613 else if (PROP_TYPE(aPropertiesTag [i]) == PT_STRING8) {
1614 - alternativeValue.AssignWithConversion(aValues [i].get()) ;
1615 + UnicodeToCStr(aValues [i].get(),alternativeValue) ;
1616 values [currentValue ++].Value.lpszA = nsCRT::strdup(alternativeValue.get()) ;
1620 readableTime.wSecond = 0 ;
1621 readableTime.wMilliseconds = 0 ;
1622 if (SystemTimeToFileTime(&readableTime, &value.Value.ft)) {
1623 - return SetMAPIProperties(aObject, 1, &value) ;
1624 + LPSPropValue values=&value;
1625 + return SetMAPIProperties(aObject, 1, values) ;
1630 nsMapiInterfaceWrapper<LPABCONT> container ;
1633 - mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
1634 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
1635 &IID_IABContainer, MAPI_MODIFY, &objType,
1637 if (HR_FAILED(mLastError)) {
1639 nsMapiInterfaceWrapper<LPABCONT> container ;
1642 - mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
1643 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
1644 &IID_IABContainer, MAPI_MODIFY, &objType,
1646 if (HR_FAILED(mLastError)) {
1648 nsMapiInterfaceWrapper<LPABCONT> container ;
1651 - mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1652 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1653 &IID_IABContainer, MAPI_MODIFY, &objType,
1655 if (HR_FAILED(mLastError)) {
1656 @@ -801,194 +759,77 @@
1660 -BOOL nsAbWinHelper::GetDefaultContainer(nsMapiEntry& aContainer)
1662 - LPENTRYID entryId = NULL ;
1663 - ULONG byteCount = 0 ;
1665 - mLastError = mAddressBook->GetPAB(&byteCount, &entryId) ;
1666 - if (HR_FAILED(mLastError)) {
1667 - PRINTF(("Cannot get PAB %08x.\n", mLastError)) ;
1670 - aContainer.Assign(byteCount, entryId) ;
1671 - FreeBuffer(entryId) ;
1677 - ContentsColumnEntryId = 0,
1678 - ContentsColumnObjectType,
1679 - ContentsColumnsSize
1682 -static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
1684 - ContentsColumnsSize,
1691 -BOOL nsAbWinHelper::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
1692 - nsMapiEntry **aList, ULONG& aNbElements, ULONG aMapiType)
1693 +void nsAbWinHelper::MyFreeProws(LPSRowSet aRowset)
1695 - if (aList != NULL) { *aList = NULL ; }
1697 - nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
1698 - nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
1699 - ULONG objType = 0 ;
1700 - ULONG rowCount = 0 ;
1701 + if (aRowset == NULL) { return ; }
1704 - mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
1705 - &IID_IMAPIContainer, 0, &objType,
1707 - if (HR_FAILED(mLastError)) {
1708 - PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
1711 - // Here, flags for WAB and MAPI could be different, so this works
1712 - // only as long as we don't want to use any flag in GetContentsTable
1713 - mLastError = parent->GetContentsTable(0, contents) ;
1714 - if (HR_FAILED(mLastError)) {
1715 - PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
1718 - if (aRestriction != NULL) {
1719 - mLastError = contents->Restrict(aRestriction, 0) ;
1720 - if (HR_FAILED(mLastError)) {
1721 - PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
1725 - mLastError = contents->SetColumns((LPSPropTagArray) &ContentsColumns, 0) ;
1726 - if (HR_FAILED(mLastError)) {
1727 - PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
1730 - mLastError = contents->GetRowCount(0, &rowCount) ;
1731 - if (HR_FAILED(mLastError)) {
1732 - PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
1734 + for (i = 0 ; i < aRowset->cRows ; ++ i) {
1735 + FreeBuffer(aRowset->aRow [i].lpProps) ;
1737 - if (aList != NULL) { *aList = new nsMapiEntry [rowCount] ; }
1740 - LPSRowSet rowSet = NULL ;
1743 - mLastError = contents->QueryRows(1, 0, &rowSet) ;
1744 - if (HR_FAILED(mLastError)) {
1745 - PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
1747 + FreeBuffer(aRowset) ;
1749 - rowCount = rowSet->cRows ;
1750 - if (rowCount > 0 &&
1751 - (aMapiType == 0 ||
1752 - rowSet->aRow->lpProps[ContentsColumnObjectType].Value.ul == aMapiType)) {
1753 - if (aList != NULL) {
1754 - nsMapiEntry& current = (*aList) [aNbElements] ;
1755 - SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
1757 - current.Assign(currentValue.Value.bin.cb,
1758 - NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
1759 +void nsAbWinHelper::CStrToUnicode( const char *pStr, nsString& result)
1761 + result.Truncate( 0);
1762 + int wLen = MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, 0);
1763 + if (wLen >= m_uniBuffLen)
1765 + delete [] m_pUniBuff;
1766 + m_pUniBuff = new PRUnichar[wLen + 64];
1767 + m_uniBuffLen = wLen + 64;
1772 + MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, m_uniBuffLen);
1773 + result = m_pUniBuff;
1775 - MyFreeProws(rowSet) ;
1776 - } while (rowCount > 0) ;
1780 -BOOL nsAbWinHelper::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
1781 - ULONG aNbProperties, LPSPropValue& aValue,
1782 - ULONG& aValueCount)
1783 +void nsAbWinHelper::UnicodeToCStr( const PRUnichar *pUStr,nsCString& result)
1785 - nsMapiInterfaceWrapper<LPMAPIPROP> object ;
1786 - ULONG objType = 0 ;
1787 - LPSPropTagArray properties = NULL ;
1790 - mLastError = mAddressBook->OpenEntry(aObject.mByteCount, aObject.mEntryId,
1791 - &IID_IMAPIProp, 0, &objType,
1793 - if (HR_FAILED(mLastError)) {
1794 - PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
1796 + result.Truncate( 0);
1797 + int cLen = WideCharToMultiByte( CP_ACP, 0, pUStr, -1, m_pCStrBuff, 0,NULL,NULL);
1798 + if (cLen >= m_cstrBuffLen) {
1800 + delete [] m_pCStrBuff;
1801 + m_pCStrBuff = new char[cLen + 64];
1802 + m_cstrBuffLen = cLen + 64;
1804 - AllocateBuffer(CbNewSPropTagArray(aNbProperties),
1805 - NS_REINTERPRET_CAST(void **, &properties)) ;
1806 - properties->cValues = aNbProperties ;
1807 - for (i = 0 ; i < aNbProperties ; ++ i) {
1808 - properties->aulPropTag [i] = aPropertyTags [i] ;
1810 + WideCharToMultiByte( CP_ACP, 0, pUStr, -1, m_pCStrBuff, m_cstrBuffLen,NULL,NULL);
1811 + result = m_pCStrBuff;
1813 - mLastError = object->GetProps(properties, 0, &aValueCount, &aValue) ;
1814 - FreeBuffer(properties) ;
1815 - if (HR_FAILED(mLastError)) {
1816 - PRINTF(("Cannot get props %08x.\n", mLastError)) ;
1818 - return HR_SUCCEEDED(mLastError) ;
1821 -BOOL nsAbWinHelper::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
1822 - const LPSPropValue& aValues)
1824 - nsMapiInterfaceWrapper<LPMAPIPROP> object ;
1825 - ULONG objType = 0 ;
1826 - LPSPropProblemArray problems = NULL ;
1827 +static nsAbWinHelper *getOutlookAddressBook(void) {
1828 + static nsMapiAddressBook *addressBook = NULL ;
1830 - mLastError = mAddressBook->OpenEntry(aObject.mByteCount, aObject.mEntryId,
1831 - &IID_IMAPIProp, MAPI_MODIFY, &objType,
1833 - if (HR_FAILED(mLastError)) {
1834 - PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
1837 - mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
1838 - if (HR_FAILED(mLastError)) {
1839 - PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
1842 - if (problems != NULL) {
1843 - for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
1844 - PRINTF(("Problem %d: index %d code %08x.\n", i,
1845 - problems->aProblem [i].ulIndex,
1846 - problems->aProblem [i].scode)) ;
1849 - mLastError = object->SaveChanges(0) ;
1850 - if (HR_FAILED(mLastError)) {
1851 - PRINTF(("Cannot commit changes %08x.\n", mLastError)) ;
1853 - return HR_SUCCEEDED(mLastError) ;
1854 + if (addressBook == NULL) { addressBook = new nsMapiAddressBook ; }
1855 + return addressBook ;
1858 -void nsAbWinHelper::MyFreeProws(LPSRowSet aRowset)
1860 - if (aRowset == NULL) { return ; }
1862 +static nsAbWinHelper *getOutlookExpAddressBook(void) {
1863 + static nsWabAddressBook *addressBook = NULL ;
1865 - for (i = 0 ; i < aRowset->cRows ; ++ i) {
1866 - FreeBuffer(aRowset->aRow [i].lpProps) ;
1868 - FreeBuffer(aRowset) ;
1869 + if (addressBook == NULL) { addressBook = new nsWabAddressBook ; }
1870 + return addressBook ;
1873 nsAbWinHelperGuard::nsAbWinHelperGuard(PRUint32 aType)
1877 - case nsAbWinType_Outlook: mHelper = new nsMapiAddressBook ; break ;
1878 - case nsAbWinType_OutlookExp: mHelper = new nsWabAddressBook ; break ;
1879 + case nsAbWinType_Outlook: mHelper = getOutlookAddressBook() ; break ;
1880 + case nsAbWinType_OutlookExp: mHelper = getOutlookExpAddressBook() ; break ;
1885 nsAbWinHelperGuard::~nsAbWinHelperGuard(void)
1890 const char *kOutlookDirectoryScheme = "moz-aboutlookdirectory://" ;
1891 Index: mailnews/addrbook/src/nsAbWinHelper.h
1892 ===================================================================
1893 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsAbWinHelper.h,v
1894 retrieving revision 1.1.1.1
1895 retrieving revision 1.2
1896 diff -u -w -b -i -r1.1.1.1 -r1.2
1897 --- miss/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.h 22 Oct 2003 02:43:11 -0000 1.1.1.1
1898 +++ miss/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.h 9 Dec 2003 03:26:47 -0000 1.2
1900 #include "nsVoidArray.h"
1901 #include "nsXPIDLString.h"
1903 +#define PR_SECOND_EMAIL_ADDRESS_A 0x8033001E
1904 +#define PR_SCREEN_NAME_A 0x805B001E
1907 +// Small utility to ensure release of all MAPI interfaces
1908 +template <class tInterface> struct nsMapiInterfaceWrapper
1910 + tInterface mInterface ;
1912 + nsMapiInterfaceWrapper(void) : mInterface(NULL) {}
1913 + ~nsMapiInterfaceWrapper(void) {
1914 + if (mInterface ) { mInterface->Release() ; }
1916 + operator LPUNKNOWN *(void) { return NS_REINTERPRET_CAST(LPUNKNOWN *, &mInterface) ; }
1917 + tInterface operator -> (void) const { return mInterface ; }
1918 + operator tInterface *(void) { return &mInterface ; }
1926 struct nsMapiEntryArray
1928 - nsMapiEntry *mEntries ;
1929 - ULONG mNbEntries ;
1931 nsMapiEntryArray(void) ;
1932 ~nsMapiEntryArray(void) ;
1934 - const nsMapiEntry& operator [] (int aIndex) const { return mEntries [aIndex] ; }
1935 + void AddItem(nsMapiEntry * aEntries);
1936 + void AddItem( ULONG mByteCount , LPENTRYID mEntryId )
1938 + nsMapiEntry * aEntries=new nsMapiEntry();
1939 + aEntries->Assign(mByteCount,mEntryId);
1940 + AddItem(aEntries);
1943 + ULONG GetSize( void) { return( m_array.Count());}
1944 + nsMapiEntry& operator [] (int aIndex) { return *(nsMapiEntry*)m_array.ElementAt(aIndex); }
1945 + nsMapiEntry* ElementAt(int aIndex) { return (nsMapiEntry*)m_array.ElementAt(aIndex); }
1946 void CleanUp(void) ;
1947 + void Remove(nsMapiEntry * aEntries){ m_array.RemoveElement(aEntries); }
1948 + void Remove(int index){ m_array.RemoveElementAt(index); }
1949 + ULONG IndexOf(nsMapiEntry * aEntries){return m_array.IndexOf(aEntries);};
1951 + nsVoidArray m_array;
1957 virtual ~nsAbWinHelper(void) ;
1959 // Get the top address books
1960 - BOOL GetFolders(nsMapiEntryArray& aFolders) ;
1961 + virtual BOOL GetFolders(nsMapiEntryArray& aFolders) =0;
1962 // Get a list of entries for cards/mailing lists in a folder/mailing list
1963 BOOL GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction,
1964 nsMapiEntryArray& aCards) ;
1965 @@ -97,18 +129,14 @@
1966 BOOL GetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
1967 ULONG aNbProperties, nsStringArray& aValues) ;
1968 // Get the value of a MAPI property of type SYSTIME
1969 - BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
1970 + virtual BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
1971 WORD& aYear, WORD& aMonth, WORD& aDay) ;
1972 - // Get the value of a MAPI property of type LONG
1973 - BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
1974 // Get the value of a MAPI property of type BIN
1975 BOOL GetPropertyBin(const nsMapiEntry& aObject, ULONG aPropertyTag, nsMapiEntry& aValue) ;
1976 // Tests if a container contains an entry
1977 BOOL TestOpenEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
1978 - // Delete an entry in the address book
1979 - BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
1980 // Set the value of a MAPI property of type string in unicode
1981 - BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag,
1982 + virtual BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag,
1983 const PRUnichar *aValue) ;
1984 // Same as previous, but with a bunch of properties in one call
1985 BOOL SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
1986 @@ -117,32 +145,44 @@
1987 BOOL SetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
1988 WORD aYear, WORD aMonth, WORD aDay) ;
1989 // Create entry in the address book
1990 - BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
1991 + virtual BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
1992 + // Delete an entry in the address book
1993 + virtual BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
1994 // Create a distribution list in the address book
1995 - BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
1996 + virtual BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
1997 // Copy an existing entry in the address book
1998 - BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
1999 + virtual BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
2000 // Get a default address book container
2001 - BOOL GetDefaultContainer(nsMapiEntry& aContainer) ;
2002 + virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer) =0;
2003 // Is the helper correctly initialised?
2004 - BOOL IsOK(void) const { return mAddressBook != NULL ; }
2005 + virtual BOOL IsOK(void) =0;/*const { return mAddressBook != NULL ; }*/
2007 + // Get the value of a MAPI property of type LONG
2008 + virtual BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
2011 HRESULT mLastError ;
2012 - LPADRBOOK mAddressBook ;
2013 static ULONG mEntryCounter ;
2014 static PRLock *mMutex ;
2016 + virtual HRESULT OpenEntry(ULONG cbEntryID,
2017 + LPENTRYID lpEntryID,
2018 + LPCIID lpInterface,
2020 + ULONG FAR * lpulObjType,
2021 + LPUNKNOWN FAR * lppUnk
2024 // Retrieve the contents of a container, with an optional restriction
2025 - BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
2026 - nsMapiEntry **aList, ULONG &aNbElements, ULONG aMapiType) ;
2027 + virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
2028 + nsMapiEntryArray *aList, ULONG aMapiType) =0;
2029 // Retrieve the values of a set of properties on a MAPI object
2030 - BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
2031 + virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
2032 ULONG aNbProperties,
2033 - LPSPropValue& aValues, ULONG& aValueCount) ;
2034 + LPSPropValue& aValues, ULONG& aValueCount) =0;
2035 // Set the values of a set of properties on a MAPI object
2036 - BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
2037 - const LPSPropValue& aValues) ;
2038 + virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
2039 + LPSPropValue& aValues) =0;
2040 // Clean-up a rowset returned by QueryRows
2041 void MyFreeProws(LPSRowSet aSet) ;
2042 // Allocation of a buffer for transmission to interfaces
2043 @@ -150,7 +190,16 @@
2044 // Destruction of a buffer provided by the interfaces
2045 virtual void FreeBuffer(LPVOID aBuffer) = 0 ;
2047 + static void CStrToUnicode( const char *pStr, nsString& result);
2048 + static void UnicodeToCStr( const PRUnichar *pStr, nsCString& result);
2051 + static int m_clients;
2052 + static PRUnichar * m_pUniBuff;
2053 + static int m_uniBuffLen;
2054 + static char * m_pCStrBuff;
2055 + static int m_cstrBuffLen;
2062 nsAbWinHelper *operator ->(void) { return mHelper ; }
2064 + static void FreeWinAbLibrarys();
2066 nsAbWinHelper *mHelper ;
2068 Index: mailnews/addrbook/src/nsMapiAddressBook.cpp
2069 ===================================================================
2070 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp,v
2071 retrieving revision 1.1.1.1
2072 retrieving revision 1.2
2073 diff -u -w -b -i -r1.1.1.1 -r1.2
2074 --- miss/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp 22 Oct 2003 02:43:11 -0000 1.1.1.1
2075 +++ miss/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp 9 Dec 2003 03:26:47 -0000 1.2
2080 +static char * stristr(const char *big, const char *little)
2084 + if (!big || !little || !*big || !*little)
2086 + len = strlen(little);
2088 + for( ; *big; big++ )
2089 + if(!_strnicmp (big, little, 1) && ! _strnicmp (big, little, len) )
2090 + return (char *)big;
2097 static PRLogModuleInfo* gMapiAddressBookLog
2098 = PR_NewLogModule("nsMapiAddressBookLog");
2101 #define PRINTF(args) PR_LOG(gMapiAddressBookLog, PR_LOG_DEBUG, args)
2103 +#define OUTLOOK_EMAIL_DIAPLAY_MAPI_ID 0x00008005 //use to get and set display
2104 +#define OUTLOOK_EMAIL1_MAPI_ID 0x00008084 //use to get and set primary email address
2105 +#define OUTLOOK_EMAIL2_MAPI_ID 0x00008094 //use to get and set second email address
2106 +#define OUTLOOK_EMAIL_SCREEN_NAME 0x8061001E //use to get and set screen name
2107 +#define OUTLOOK_EMAIL_ORGID 0x00008085 //use to get orginal entryid to add to distlist
2108 +#define OUTLOOK_EMAIL_LIST1 0x00008054 //use to get distlist table
2109 +#define OUTLOOK_EMAIL_LIST2 0x00008055 //use to set distlist table
2111 +static const TagMap TagMaps[]={
2112 + {PR_DISPLAY_NAME_A, OUTLOOK_EMAIL_DIAPLAY_MAPI_ID, PT_STRING8},
2113 + {PR_EMAIL_ADDRESS_A, OUTLOOK_EMAIL1_MAPI_ID, PT_STRING8},
2114 + {PR_SECOND_EMAIL_ADDRESS_A, OUTLOOK_EMAIL2_MAPI_ID, PT_STRING8},
2115 + {PR_SCREEN_NAME_A, OUTLOOK_EMAIL_SCREEN_NAME, PT_STRING8}};
2118 + ieidPR_ENTRYID = 0,
2119 + ieidPR_OBJECT_TYPE,
2120 + ieidPR_DISPLAY_NAME,
2121 + ieidPR_MESSAGE_CLASS,
2122 + ieidPR_STORE_ENTRYID,
2123 + ieidPR_MESSAGE_RECIPIENTS,
2127 +static const SizedSPropTagArray(ieidMax, ptaEid)=
2136 + PR_MESSAGE_RECIPIENTS
2142 + ContentsColumnEntryId = 0,
2143 + ContentsColumnObjectType,
2144 + ContentsColumnMessageClass,
2145 + ContentsColumnsSize
2148 +static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
2150 + ContentsColumnsSize,
2158 HMODULE nsMapiAddressBook::mLibrary = NULL ;
2159 PRInt32 nsMapiAddressBook::mLibUsage = 0 ;
2161 BOOL nsMapiAddressBook::mInitialized = FALSE ;
2162 BOOL nsMapiAddressBook::mLogonDone = FALSE ;
2163 LPMAPISESSION nsMapiAddressBook::mRootSession = NULL ;
2164 -LPADRBOOK nsMapiAddressBook::mRootBook = NULL ;
2166 BOOL nsMapiAddressBook::LoadMapiLibrary(void)
2168 @@ -106,22 +175,19 @@
2171 if (HR_FAILED(retCode)) {
2172 - PRINTF(("Cannot logon to MAPI %08x.\n", retCode)) ; return FALSE ;
2173 + PRINTF(("Cannot logon to MAPI %08x.\n", retCode)) ;
2177 - retCode = mRootSession->OpenAddressBook(0, NULL, 0, &mRootBook) ;
2178 - if (HR_FAILED(retCode)) {
2179 - PRINTF(("Cannot open MAPI address book %08x.\n", retCode)) ;
2182 return HR_SUCCEEDED(retCode) ;
2185 void nsMapiAddressBook::FreeMapiLibrary(void)
2188 - if (-- mLibUsage == 0) {
2189 + if (--mLibUsage < 0) {
2191 - if (mRootBook) { mRootBook->Release() ; }
2194 mRootSession->Logoff(NULL, 0, 0) ;
2198 FreeLibrary(mLibrary) ;
2199 + mRootSession = NULL;
2206 BOOL result = Initialize() ;
2208 NS_ASSERTION(result == TRUE, "Couldn't initialize Mapi Helper") ;
2209 MOZ_COUNT_CTOR(nsMapiAddressBook) ;
2211 @@ -154,35 +220,1691 @@
2212 nsMapiAddressBook::~nsMapiAddressBook(void)
2214 nsAutoLock guard(mMutex) ;
2218 MOZ_COUNT_DTOR(nsMapiAddressBook) ;
2221 -BOOL nsMapiAddressBook::Initialize(void)
2222 +LPSPropValue nsMapiAddressBook::GetMapiProperty( LPMAPIPROP pProp, ULONG tag)
2224 - if (mAddressBook) { return TRUE ; }
2225 - nsAutoLock guard(mMutex) ;
2229 - if (!LoadMapiLibrary()) {
2230 - PRINTF(("Cannot load library.\n")) ;
2231 + int sz = CbNewSPropTagArray( 1);
2232 + SPropTagArray *pTag = (SPropTagArray *) new char[sz];
2233 + pTag->cValues = 1;
2234 + pTag->aulPropTag[0] = tag;
2235 + LPSPropValue lpProp = NULL;
2236 + ULONG cValues = 0;
2237 + HRESULT hr = pProp->GetProps( pTag, 0, &cValues, &lpProp);
2239 + if (HR_FAILED( hr) || (cValues != 1)) {
2241 + mMAPIFreeBuffer( lpProp);
2245 + if (PROP_TYPE( lpProp->ulPropTag) == PT_ERROR) {
2246 + if (lpProp->Value.l == MAPI_E_NOT_FOUND) {
2247 + mMAPIFreeBuffer( lpProp);
2255 +BOOL nsMapiAddressBook::GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYID& lpEntryId, BOOL delVal)
2260 + BOOL bResult = TRUE;
2261 + switch (PROP_TYPE(pVal->ulPropTag))
2264 + cbEntryId = pVal->Value.bin.cb;
2265 + mMAPIAllocateBuffer( cbEntryId, (LPVOID *) &lpEntryId);
2266 + memcpy( lpEntryId, pVal->Value.bin.lpb, cbEntryId);
2270 + PRINTF(( "EntryId not in BINARY prop value\n"));
2275 + if (pVal && delVal)
2276 + mMAPIFreeBuffer( pVal);
2281 +BOOL nsMapiAddressBook::HandleContentsItem(ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders)
2287 + if (oType == MAPI_MESSAGE)
2289 + if (oType == MAPI_STORE)
2291 + hr=mRootSession->OpenEntry(
2297 + (IUnknown**)&lpMsgStore);
2300 + //Add MDB to a list to make it can be released when class destroyed.
2301 + //We must leave it openned or else we can't open address store in it.
2302 + AddToMDBArray(lpMsgStore);
2304 + LPSPropValue pVal;
2305 + pVal=GetMapiProperty(lpMsgStore,PR_IPM_SUBTREE_ENTRYID);
2311 + nsMapiInterfaceWrapper<LPMAPICONTAINER> lpSubTree;
2313 + if (GetEntryIdFromProp( pVal, cbEntry, pEntry)) {
2314 + // Open up the folder!
2315 + BOOL bResult = TRUE;
2316 + bResult = lpMsgStore->OpenEntry(
2323 + mMAPIFreeBuffer( pEntry);
2324 + if (!bResult && *(LPMAPICONTAINER*)&lpSubTree) {
2325 + // Iterate the subtree with the results going into the folder list
2326 + bResult = IterateHierarchy(*(LPMAPICONTAINER*)&lpSubTree,aFolders);
2329 + PRINTF(( "GetStoreFolders: Error opening sub tree.\n"));
2333 + PRINTF(( "GetStoreFolders: Error getting entryID from sub tree property val.\n"));
2335 - mAddressBook = mRootBook ;
2338 + PRINTF(( "GetStoreFolders: Error getting sub tree property.\n"));
2343 + PRINTF(("Type:%d\n",oType));
2349 -void nsMapiAddressBook::AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer)
2350 +BOOL nsMapiAddressBook::IterateHierarchy(LPMAPICONTAINER pFolder,nsMapiEntryArray& aFolders, ULONG flags)
2352 - mMAPIAllocateBuffer(aByteCount, aBuffer) ;
2353 + // flags can be CONVENIENT_DEPTH or 0
2354 + // CONVENIENT_DEPTH will return all depths I believe instead
2355 + // of just children
2357 + nsMapiInterfaceWrapper<LPMAPITABLE> lpTable;
2358 + hr = pFolder->GetHierarchyTable( CONVENIENT_DEPTH , lpTable);
2359 + if (HR_FAILED(hr)) {
2360 + PRINTF(( "IterateHierarchy: GetContentsTable failed: 0x%lx, %d\n", (long)hr, (int)hr));
2364 -void nsMapiAddressBook::FreeBuffer(LPVOID aBuffer)
2366 + hr = lpTable->GetRowCount( 0, &rowCount);
2371 + hr = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0);
2372 + if (HR_FAILED(hr)) {
2373 + PRINTF(( "IterateHierarchy: SetColumns failed: 0x%lx, %d\n", (long)hr, (int)hr));
2377 + hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL);
2378 + if (HR_FAILED(hr)) {
2379 + PRINTF(( "IterateHierarchy: SeekRow failed: 0x%lx, %d\n", (long)hr, (int)hr));
2385 + BOOL keepGoing = TRUE;
2386 + BOOL bResult = TRUE;
2390 + hr = lpTable->QueryRows( 1, 0, &lpRow);
2392 + if (HR_FAILED(hr))
2394 - mMAPIFreeBuffer(aBuffer) ;
2395 + PRINTF(( "QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr));
2401 + cNumRows = lpRow->cRows;
2404 + LPENTRYID lpEntry = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
2405 + ULONG cb = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
2406 + ULONG oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul;
2408 + keepGoing = HandleHierarchyItem( oType, cb, lpEntry,aFolders);
2411 + MyFreeProws(lpRow);
2414 + } while ( SUCCEEDED(hr) && cNumRows && lpRow && keepGoing);
2417 + if (bResult && !keepGoing)
2422 +BOOL nsMapiAddressBook::HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders)
2425 + if (oType == MAPI_FOLDER)
2427 + nsMapiInterfaceWrapper<LPMAPICONTAINER> pFolder ;
2428 + if (!mRootSession->OpenEntry(
2436 + LPSPropValue pVal;
2439 + pVal = GetMapiProperty(*(LPMAPICONTAINER*)&pFolder, PR_CONTAINER_CLASS);
2442 + if (strcmp("IPF.Contact",pVal->Value.lpszA) == 0)
2444 + SPropValue *currentValue=GetMapiProperty( *(LPMAPICONTAINER*)&pFolder, PR_ENTRYID);
2446 + aFolders.AddItem(currentValue->Value.bin.cb,
2447 + NS_REINTERPRET_CAST(LPENTRYID, currentValue->Value.bin.lpb)) ;
2455 + PRINTF(( "GetStoreFolders - HandleHierarchyItem: Unhandled ObjectType: %ld\n", oType));
2462 +BOOL nsMapiAddressBook::GetFolders(nsMapiEntryArray& aFolders)
2464 + aFolders.CleanUp() ;
2465 + nsMapiInterfaceWrapper<LPMAPICONTAINER> rootFolder ;
2466 + nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
2467 + ULONG objType = 0 ;
2468 + ULONG rowCount = 0 ;
2470 + nsMapiInterfaceWrapper<LPMAPITABLE> lpTable;
2472 + mLastError = mRootSession->GetMsgStoresTable( 0, lpTable);
2473 + if (HR_FAILED(mLastError)) {
2474 + PRINTF(("Cannot open MAPI MsgStores %08x.\n", mLastError));
2475 + return mLastError;
2478 + mLastError = lpTable->GetRowCount( 0, &rowCount);
2480 + mLastError = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0);
2481 + if (FAILED(mLastError))
2482 + return( mLastError);
2483 + mLastError = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL);
2484 + if (FAILED(mLastError))
2485 + return mLastError;
2489 + BOOL keepGoing = TRUE;
2490 + BOOL bResult = TRUE;
2494 + mLastError = lpTable->QueryRows( 1, 0, &lpRow);
2496 + if (HR_FAILED(mLastError)){
2502 + cNumRows = lpRow->cRows;
2505 + LPENTRYID lpEID = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
2506 + ULONG cbEID = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
2507 + ULONG oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul;
2510 + keepGoing = HandleContentsItem( oType, cbEID, lpEID,aFolders);
2512 + MyFreeProws( lpRow);
2515 + } while ( SUCCEEDED(mLastError) && cNumRows && lpRow && keepGoing);
2518 + return HR_SUCCEEDED(mLastError) ;
2520 +BOOL nsMapiAddressBook::CorrectRestriction(const LPMAPIPROP aMapiProp,ULONG aRestrictionNum, LPSRestriction aRestriction)
2522 + ULONG conditionType = 0 ;
2524 + if (!aRestriction)
2526 + for (ulResIndex=0;ulResIndex < aRestrictionNum;ulResIndex++)
2528 + conditionType = aRestriction[ulResIndex].rt;
2529 + switch (conditionType)
2532 + aRestriction[ulResIndex].res.resExist.ulPropTag =
2533 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resExist.ulPropTag);
2535 + case RES_BITMASK :
2536 + aRestriction[ulResIndex].res.resBitMask.ulPropTag =
2537 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resBitMask.ulPropTag);
2539 + case RES_CONTENT :
2540 + aRestriction[ulResIndex].res.resContent.ulPropTag =
2541 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resContent.ulPropTag);
2542 + aRestriction[ulResIndex].res.resContent.lpProp->ulPropTag =
2543 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resContent.lpProp->ulPropTag);
2545 + case RES_PROPERTY :
2546 + aRestriction[ulResIndex].res.resProperty.ulPropTag =
2547 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resProperty.ulPropTag);
2548 + aRestriction[ulResIndex].res.resProperty.lpProp->ulPropTag =
2549 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resProperty.lpProp->ulPropTag);
2552 + aRestriction[ulResIndex].res.resSize.ulPropTag =
2553 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resSize.ulPropTag);
2555 + case RES_COMPAREPROPS :
2556 + aRestriction[ulResIndex].res.resCompareProps.ulPropTag1 =
2557 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resCompareProps.ulPropTag1);
2558 + aRestriction[ulResIndex].res.resCompareProps.ulPropTag2 =
2559 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resCompareProps.ulPropTag2);
2562 + CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resNot.lpRes);
2565 + CorrectRestriction(aMapiProp,
2566 + aRestriction[ulResIndex].res.resAnd.cRes,
2567 + aRestriction[ulResIndex].res.resAnd.lpRes);
2570 + CorrectRestriction(aMapiProp,
2571 + aRestriction[ulResIndex].res.resOr.cRes,
2572 + aRestriction[ulResIndex].res.resOr.lpRes);
2575 + case RES_COMMENT :
2576 + CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resComment.lpRes);
2577 + aRestriction[ulResIndex].res.resComment.lpProp->ulPropTag =
2578 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resComment.lpProp->ulPropTag);
2580 + case RES_SUBRESTRICTION :
2581 + CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resSub.lpRes);
2589 +BOOL nsMapiAddressBook::Filter( LPSRestriction aRestriction,nsMapiEntryArray * aList)
2591 + if (!aRestriction)
2594 + ULONG conditionType = 0 ;
2596 + nsMapiEntryArray listOut;
2597 + ULONG listindex=0;
2599 + nsMapiEntryArray listDel;
2603 + ULONG resCount = 0;
2604 + ULONG resIndex = 0;
2606 + listsize = aList->GetSize();
2607 + conditionType = aRestriction->rt;
2608 + switch (conditionType)
2611 + case RES_BITMASK :
2612 + case RES_CONTENT :
2613 + case RES_PROPERTY :
2615 + case RES_COMPAREPROPS :
2616 + case RES_COMMENT :
2617 + case RES_SUBRESTRICTION :
2619 + while(listindex < aList->GetSize())
2621 + if (!FilterOnOneRow(aList->ElementAt(listindex),aRestriction))
2622 + aList->Remove(listindex);
2629 + aRestriction->res.resNot.ulReserved = 1;
2633 + if (conditionType == RES_OR)
2635 + for(listindex=0;listindex<aList->GetSize();listindex++)
2637 + listDel.AddItem(aList->ElementAt(listindex));
2641 + resCount = aRestriction->res.resAnd.cRes;
2642 + //notice that SAndRestriction ,SNotRestriction ,SOrRestriction
2643 + //use the same struct
2644 + for (resIndex = 0;resIndex < resCount;resIndex++)
2646 + //can't call listOut.CleanUp() here
2647 + //because it will destroy all Element too
2648 + while(listOut.GetSize())
2650 + listOut.Remove(0);
2653 + for(listindex=0;listindex<aList->GetSize();listindex++)
2655 + listOut.AddItem(aList->ElementAt(listindex));
2658 + Filter(&aRestriction->res.resAnd.lpRes[resIndex],&listOut);
2659 + if (conditionType == RES_NOT)
2661 + for(listindex=0;listindex<listOut.GetSize();listindex++)
2663 + aList->Remove(listOut.ElementAt(listindex));
2666 + else if (conditionType == RES_AND )
2668 + for(listindex=0;listindex<listOut.GetSize();listindex++)
2670 + if (!aList->IndexOf(listOut.ElementAt(listindex)))
2672 + aList->Remove(listOut.ElementAt(listindex));
2676 + else if (conditionType == RES_OR )
2678 + for(listindex=0;listindex<listOut.GetSize();listindex++)
2680 + listDel.Remove(listOut.ElementAt(listindex));
2682 + if (listDel.GetSize() == 0)
2688 + if (conditionType == RES_OR)
2690 + for(listindex=0;listindex<listDel.GetSize();listindex++)
2692 + aList->Remove(listDel.ElementAt(listindex));
2698 + while(listDel.GetSize())
2700 + listDel.Remove(0);
2702 + while(listOut.GetSize())
2704 + listOut.Remove(0);
2711 +BOOL nsMapiAddressBook::FilterOnOneRow(nsMapiEntry *aEntry,LPSRestriction aRestriction)
2713 + LPMAPIPROP object ;
2714 + ULONG objType = 0 ;
2715 + LPSPropValue realValue = NULL ;
2716 + LPSPropValue resValue = NULL ;
2717 + ULONG valueCount = 0 ;
2719 + mLastError = OpenEntry(aEntry->mByteCount, aEntry->mEntryId,
2720 + &IID_IMAPIProp, 0, &objType,
2721 + (IUnknown **)&object) ;
2723 + if (HR_FAILED(mLastError)) {
2724 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
2728 + ULONG conditionType = 0 ;
2729 + conditionType = aRestriction->rt;
2731 + switch (conditionType)
2734 + if (!GetMAPIProperties(*aEntry,&aRestriction->res.resExist.ulPropTag,1,realValue,valueCount))
2738 + case RES_CONTENT :
2739 + if (!GetMAPIProperties(*aEntry,&aRestriction->res.resContent.ulPropTag,1,realValue,valueCount))
2741 + resValue = aRestriction->res.resContent.lpProp;
2743 + case RES_PROPERTY :
2744 + if (!GetMAPIProperties(*aEntry,&aRestriction->res.resProperty.ulPropTag,1,realValue,valueCount))
2746 + resValue = aRestriction->res.resProperty.lpProp;
2748 + case RES_BITMASK :
2749 + return FALSE; //not support
2752 + return FALSE;//not been used now
2754 + case RES_COMPAREPROPS :
2755 + return FALSE;//not been used now
2758 + return FALSE;//not need care here
2761 + return FALSE;//not need care here
2764 + return FALSE;//not need care here
2766 + case RES_COMMENT :
2767 + return TRUE;//comment
2769 + case RES_SUBRESTRICTION :
2770 + return FALSE;//not been used now
2773 + return AtomyFilter(aRestriction,realValue,resValue);
2777 +BOOL nsMapiAddressBook::AtomyFilter(LPSRestriction aRestriction,LPSPropValue aRealValue,LPSPropValue aFilterValue)
2779 + ULONG conditionType = 0 ;
2780 + conditionType = aRestriction->rt;
2782 + BOOL bTagEq=(aRealValue &&
2783 + PROP_TYPE( aRealValue->ulPropTag ) != PT_ERROR) &&
2785 + // PROP_TYPE( aRealValue->ulPropTag ) == PROP_TYPE( aFilterValue->ulPropTag ));
2786 + switch (conditionType)
2789 + return (aRealValue && PROP_TYPE( aRealValue->ulPropTag ) != PT_ERROR) ;
2791 + case RES_CONTENT :
2794 + switch(aRestriction->res.resContent.ulFuzzyLevel)
2796 + case FL_FULLSTRING :
2797 + return !stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA);
2800 + return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) == aRealValue->Value.lpszA;
2802 + case FL_SUBSTRING :
2804 + return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != NULL;
2810 + case RES_PROPERTY :
2813 + switch(aRestriction->res.resProperty.relop)
2816 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) >= 0;
2819 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) > 0;
2822 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) <= 0;
2825 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) < 0;
2828 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) == 0;
2831 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != 0;
2835 + return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != NULL;
2842 + case RES_BITMASK :
2843 + return FALSE; //not support
2846 + return FALSE;//not been used now
2848 + case RES_COMPAREPROPS :
2849 + return FALSE;//not been used now
2852 + return FALSE;//not need care here
2855 + return FALSE;//not need care here
2858 + return FALSE;//not need care here
2860 + case RES_COMMENT :
2861 + return TRUE;//comment
2863 + case RES_SUBRESTRICTION :
2864 + return FALSE;//not been used now
2870 +BOOL nsMapiAddressBook::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
2871 + nsMapiEntryArray *aList, ULONG aMapiType)
2876 + nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
2877 + nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
2878 + ULONG objType = 0 ;
2879 + ULONG rowCount = 0 ;
2882 + nsMapiInterfaceWrapper<LPMAPIPROP> pFolder;
2884 + aParent.ToString(cs);
2886 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
2887 + 0, 0, &objType, pFolder);
2888 + if (HR_FAILED(mLastError))
2890 + PRINTF(("Cannot open folder %08x.\n", mLastError)) ;
2895 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&pFolder,PR_MESSAGE_CLASS);
2896 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
2899 + LPSPropValue aValue = NULL ;
2900 + ULONG aValueCount = 0 ;
2902 + LPSPropTagArray properties = NULL ;
2903 + mMAPIAllocateBuffer(CbNewSPropTagArray(1),
2904 + (void **)&properties);
2905 + properties->cValues = 1;
2906 + properties->aulPropTag [0] = GetEmailPropertyTag(*(LPMAPIPROP*)&pFolder,OUTLOOK_EMAIL_LIST1);
2907 + hr = pFolder->GetProps(properties, 0, &aValueCount, &aValue) ;
2909 + SBinaryArray *sa=&aValue->Value.MVbin;
2915 + nsMapiEntry testEntry;
2917 + for (idx=0;sa->lpbin && idx<sa->cValues ;idx++)
2919 + lpEID= (LPENTRYID) sa->lpbin[idx].lpb;
2920 + cbEID = sa->lpbin[idx].cb;
2921 + testEntry.Assign(sa->lpbin[idx].cb,NS_REINTERPRET_CAST(LPENTRYID,sa->lpbin[idx].lpb));
2923 + if (GetPropertyString(testEntry,PR_MESSAGE_CLASS,sClass)) //Error get property
2925 + aList->AddItem(cbEID,lpEID);
2928 + Filter(aRestriction,aList);
2932 + if (aRestriction && !CorrectRestriction(*(LPMAPICONTAINER*)&pFolder,1,aRestriction))
2934 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
2935 + &IID_IMAPIContainer, 0, &objType,
2937 + if (HR_FAILED(mLastError)) {
2938 + PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
2942 + mLastError = parent->GetContentsTable(0, contents) ;
2943 + if (HR_FAILED(mLastError)) {
2944 + PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
2947 + if (aRestriction) {
2948 + mLastError = contents->Restrict(aRestriction, TBL_BATCH) ;
2949 + if (HR_FAILED(mLastError)) {
2950 + PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
2954 + mLastError = contents->SetColumns((LPSPropTagArray)&ContentsColumns, 0);
2955 + if (HR_FAILED(mLastError)) {
2956 + PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
2959 + mLastError = contents->GetRowCount(0, &rowCount) ;
2960 + if (HR_FAILED(mLastError)) {
2961 + PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
2965 + LPSRowSet rowSet = NULL ;
2968 + mLastError = contents->QueryRows(1, 0, &rowSet) ;
2969 + if (HR_FAILED(mLastError)) {
2970 + PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
2973 + rowCount = rowSet->cRows ;
2974 + if (rowCount > 0 && aList)
2976 + if (aMapiType == 0 || rowSet->aRow->lpProps[ContentsColumnObjectType].Value.ul == aMapiType)
2978 + SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
2979 + aList->AddItem(currentValue.Value.bin.cb,
2980 + NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
2982 + else if (aMapiType == MAPI_DISTLIST)
2984 + if (strcmp("IPM.DistList",rowSet->aRow->lpProps[ContentsColumnMessageClass].Value.lpszA)==0)
2986 + SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
2987 + aList->AddItem(currentValue.Value.bin.cb,
2988 + NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
2994 + MyFreeProws(rowSet) ;
2995 + } while (rowCount > 0) ;
3002 +BOOL nsMapiAddressBook::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
3003 + ULONG aNbProperties, LPSPropValue& aValue,
3004 + ULONG& aValueCount)
3006 + nsMapiInterfaceWrapper<LPMAPIPROP> object ;
3007 + ULONG objType = 0 ;
3008 + LPSPropTagArray properties = NULL ;
3011 + mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
3012 + &IID_IMAPIProp, 0, &objType,
3015 + if (HR_FAILED(mLastError)) {
3016 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3019 + AllocateBuffer(CbNewSPropTagArray(aNbProperties),
3020 + NS_REINTERPRET_CAST(void **, &properties));
3021 + properties->cValues = aNbProperties ;
3022 + for (i = 0 ; i < aNbProperties ; ++ i)
3024 + properties->aulPropTag [i] = GetRealMapiPropertyTag(*(LPMAPIPROP*)&object,aPropertyTags [i],TRUE);
3026 + mLastError = object->GetProps(properties, 0 , &aValueCount, &aValue) ;
3027 + FreeBuffer(properties) ;
3029 + if (HR_FAILED(mLastError)) {
3030 + PRINTF(("Error get props %08x.\n", mLastError)) ;
3032 + return HR_SUCCEEDED(mLastError);
3035 +BOOL nsMapiAddressBook::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
3036 + LPSPropValue& aValues)
3038 + nsMapiInterfaceWrapper<LPMESSAGE> object;
3039 + ULONG objType = 0 ;
3040 + LPSPropProblemArray problems = NULL ;
3043 + LPMDB lpMsgStore=GetMsgStore(aObject);
3049 + mLastError = lpMsgStore->OpenEntry(aObject.mByteCount, aObject.mEntryId,
3050 + &IID_IMessage, MAPI_MODIFY , &objType,
3052 + lpMsgStore->Release();
3054 + if (HR_FAILED(mLastError)) {
3055 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3058 + for (i = 0 ; i < aNbProperties ; ++ i)
3060 + aValues[i].ulPropTag = GetRealMapiPropertyTag(*(LPMESSAGE*)&object,aValues[i].ulPropTag,TRUE);
3062 + mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
3063 + if (HR_FAILED(mLastError)) {
3064 + PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
3068 + for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
3069 + PRINTF(("Problem %d: index %d code %08x.\n", i,
3070 + problems->aProblem [i].ulIndex,
3071 + problems->aProblem [i].scode)) ;
3074 + mLastError = object->SaveChanges(0) ;
3075 + if (MAPI_E_OBJECT_CHANGED == mLastError)
3077 + mLastError = object->SaveChanges(FORCE_SAVE ) ;
3079 + return HR_SUCCEEDED(mLastError) ;
3082 +BOOL nsMapiAddressBook::GetDefaultContainer(nsMapiEntry& aContainer)
3087 +BOOL nsMapiAddressBook::IsOK(void)
3089 + return mRootSession && mLibUsage;
3092 +BOOL nsMapiAddressBook::Initialize(void)
3095 + nsAutoLock guard(mMutex) ;
3097 + if (!LoadMapiLibrary()) {
3098 + PRINTF(("Cannot load library.\n")) ;
3104 +void nsMapiAddressBook::AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer)
3106 + mMAPIAllocateBuffer(aByteCount, aBuffer) ;
3109 +void nsMapiAddressBook::FreeBuffer(LPVOID aBuffer)
3111 + mMAPIFreeBuffer(aBuffer) ;
3114 +ULONG nsMapiAddressBook::GetEmailPropertyTag(LPMAPIPROP lpProp, LONG nameID)
3116 + static GUID emailGUID =
3118 + 0x00062004, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46
3122 + MAPINAMEID mapiNameID;
3123 + mapiNameID.lpguid = &emailGUID;
3124 + mapiNameID.ulKind = MNID_ID;
3125 + mapiNameID.Kind.lID = nameID;
3127 + LPMAPINAMEID lpMapiNames = &mapiNameID;
3128 + LPSPropTagArray lpMailTagArray = NULL;
3130 + HRESULT result = lpProp->GetIDsFromNames(1L, &lpMapiNames, 0, &lpMailTagArray);
3131 + if (result == S_OK)
3133 + ULONG lTag = lpMailTagArray->aulPropTag[0];
3134 + mMAPIFreeBuffer(lpMailTagArray);
3139 +ULONG nsMapiAddressBook::GetRealMapiPropertyTag(LPMAPIPROP lpProp, LONG aPropertyTag,BOOL aTest)
3141 + LPSPropValue addr;
3142 + ULONG upRealTag=aPropertyTag;
3143 + ULONG lSize=sizeof(TagMaps) / sizeof(TagMap);
3145 + for(int i=0; i<lSize; i++)
3147 + if (TagMaps[i].AddressTag == aPropertyTag)
3150 + ULONG kPriEmailColumn=GetEmailPropertyTag(lpProp,TagMaps[i].NameID);
3153 + if (PR_DISPLAY_NAME_A == aPropertyTag)
3155 + //We need not change PR_DISPLAY_NAME_A tag if we are not using an address
3156 + LPSPropValue msgClass=GetMapiProperty(lpProp,PR_MESSAGE_CLASS);
3157 + if (msgClass && !strcmp("IPM.Contact",msgClass->Value.lpszA))
3159 + if (kPriEmailColumn)
3160 + upRealTag = kPriEmailColumn | TagMaps[i].TypeMask;
3164 + FreeBuffer(msgClass);
3165 + upRealTag = aPropertyTag;
3168 + else //PR_DISPLAY_NAME_A == aPropertyTag
3170 + addr=GetMapiProperty(lpProp,aPropertyTag);
3171 + if (!addr || PROP_TYPE( addr->ulPropTag) == PT_ERROR ||
3172 + addr->Value.l == MAPI_E_NOT_FOUND)
3174 + if (kPriEmailColumn)
3175 + upRealTag = kPriEmailColumn | TagMaps[i].TypeMask;
3181 + if (kPriEmailColumn)
3182 + upRealTag = kPriEmailColumn | TagMaps[i].TypeMask;
3185 + break; //we find it,exit
3192 +BOOL nsMapiAddressBook::GetPropertyLong(const nsMapiEntry& aObject,
3193 + ULONG aPropertyTag,
3197 + LPSPropValue values = NULL ;
3198 + ULONG valueCount = 0 ;
3200 + if (PR_OBJECT_TYPE == aPropertyTag)
3202 + nsMapiInterfaceWrapper<LPMAPIFOLDER> pFolder ;
3204 + mLastError = OpenEntry(aObject.mByteCount,aObject.mEntryId,
3205 + NULL,0,&objType, pFolder);
3206 + if (HR_FAILED(mLastError))
3208 + PRINTF(("Cannot open folder %08x.\n", mLastError)) ;
3211 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIFOLDER*)&pFolder,PR_MESSAGE_CLASS);
3212 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
3214 + FreeBuffer(msgClass);
3215 + aValue = MAPI_DISTLIST;
3220 + if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount))
3223 + if (valueCount == 1 && values && PROP_TYPE(values->ulPropTag) == PT_LONG) {
3224 + aValue = values->Value.ul ;
3226 + FreeBuffer(values) ;
3230 +BOOL nsMapiAddressBook::GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
3231 + WORD& aYear, WORD& aMonth, WORD& aDay)
3236 + LPSPropValue values = NULL ;
3237 + ULONG valueCount = 0 ;
3239 + if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount))
3242 + if (valueCount == 1 && values && PROP_TYPE(values->ulPropTag) == PT_SYSTIME) {
3243 + SYSTEMTIME readableTime ;
3244 + FILETIME localTime ;
3245 + FileTimeToLocalFileTime(&values->Value.ft,&localTime);
3246 + if (FileTimeToSystemTime(&localTime, &readableTime)) {
3247 + aYear = readableTime.wYear ;
3248 + aMonth = readableTime.wMonth ;
3249 + aDay = readableTime.wDay ;
3252 + FreeBuffer(values) ;
3256 +HRESULT nsMapiAddressBook::OpenEntry(ULONG cbEntryID,
3257 + LPENTRYID lpEntryID,
3258 + LPCIID lpInterface,
3260 + ULONG FAR * lpulObjType,
3261 + LPUNKNOWN FAR * lppUnk
3269 + rv=mRootSession->OpenEntry(cbEntryID,
3281 + if (HR_FAILED(rv) && !m_MDBArray.Count())
3283 + //There are no openned Message store,so we have to open them all
3284 + nsMapiEntryArray aFolders;
3285 + if (GetFolders(aFolders))
3289 + rv=mRootSession->OpenEntry(cbEntryID,
3306 +BOOL nsMapiAddressBook::AddEntryToList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry)
3308 + nsMapiInterfaceWrapper<LPMAPIPROP> container ;
3309 + ULONG objType = 0 ;
3311 + nsMapiEntry parentEntry;
3312 + if (!GetEntryParent(aDistlist,parentEntry))
3315 + LPMDB lpMsgStore=GetMsgStore(parentEntry);
3319 + mLastError = lpMsgStore->OpenEntry(aDistlist.mByteCount, aDistlist.mEntryId,
3320 + &IID_IMAPIProp, MAPI_MODIFY, &objType,
3322 + lpMsgStore->Release();
3324 + if (HR_FAILED(mLastError))
3329 + When add mail address to distlist,Mapi need update 2 tag.
3331 + //update OUTLOOK_EMAIL_LIST1
3332 + ULONG listTag=GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST1) | PT_MV_BINARY;
3333 + SBinaryArray oldChilds;
3334 + LPSBinary bins=NULL;
3335 + SBinaryArray newChilds;
3336 + LPSPropValue oldChildValue = NULL ;
3337 + ULONG valueCount = 0 ;
3339 + if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
3341 + PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
3345 + if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
3347 + oldChilds = oldChildValue->Value.MVbin;
3348 + newChilds.cValues=oldChilds.cValues + 1;
3349 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3350 + newChilds.lpbin = bins;
3351 + for (ULONG i=0;i<oldChilds.cValues;i++)
3353 + newChilds.lpbin[i].lpb = oldChilds.lpbin[i].lpb;
3354 + newChilds.lpbin[i].cb = oldChilds.lpbin[i].cb;
3359 + newChilds.cValues = 1;
3360 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3361 + newChilds.lpbin = bins;
3364 + nsMapiEntry orgEntryID;
3365 + if (!GetPropertyBin(aNewEntry,
3366 + GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_ORGID) | PT_BINARY,
3371 + newChilds.lpbin[newChilds.cValues-1].lpb = NS_REINTERPRET_CAST(unsigned char *, orgEntryID.mEntryId);
3372 + newChilds.lpbin[newChilds.cValues-1].cb = orgEntryID.mByteCount;
3374 + SPropValue childs;
3375 + childs.ulPropTag = listTag;
3376 + childs.Value.MVbin = newChilds;
3378 + LPSPropProblemArray problems = NULL ;
3379 + mLastError = container->SetProps(1, &childs, &problems) ;
3380 + if (HR_FAILED(mLastError)) {
3381 + PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
3385 + //update OUTLOOK_EMAIL_LIST2
3386 + listTag = GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST2) | PT_MV_BINARY;
3387 + if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
3389 + PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
3393 + if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
3395 + oldChilds = oldChildValue->Value.MVbin;
3396 + newChilds.cValues=oldChilds.cValues + 1;
3397 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3398 + newChilds.lpbin = bins;
3399 + for (ULONG i=0;i<oldChilds.cValues;i++)
3401 + newChilds.lpbin[i].lpb = oldChilds.lpbin[i].lpb;
3402 + newChilds.lpbin[i].cb = oldChilds.lpbin[i].cb;
3407 + newChilds.cValues = 1;
3408 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3409 + newChilds.lpbin = bins;
3413 + Need more work here.
3414 + There are two kind of mail address in outlook DistList.
3415 + One is sample,not include in parent folder.
3416 + The other is a link to a unattached address in parents folders.
3417 + Currently we can only add first kind of address to a outlook distlist.
3420 + newChilds.lpbin[newChilds.cValues-1].lpb = NS_REINTERPRET_CAST(unsigned char *, orgEntryID.mEntryId);
3421 + newChilds.lpbin[newChilds.cValues-1].cb = orgEntryID.mByteCount;
3423 + childs.ulPropTag = listTag;
3424 + childs.Value.MVbin = newChilds;
3426 + mLastError = container->SetProps(1, &childs, &problems) ;
3427 + if (HR_FAILED(mLastError))
3429 + PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
3433 + mMAPIFreeBuffer(bins);
3435 + mLastError = container->SaveChanges(KEEP_OPEN_READONLY) ;
3436 + if (HR_FAILED(mLastError)) {
3437 + PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
3443 +BOOL nsMapiAddressBook::DeleteEntryFromList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry)
3445 + nsMapiInterfaceWrapper<LPMAPIPROP> container ;
3446 + ULONG objType = 0 ;
3448 + nsMapiEntry parentEntry;
3449 + if (!GetEntryParent(aDistlist,parentEntry))
3452 + LPMDB lpMsgStore=GetMsgStore(parentEntry);
3456 + mLastError = lpMsgStore->OpenEntry(aDistlist.mByteCount, aDistlist.mEntryId,
3457 + &IID_IMAPIProp, MAPI_MODIFY, &objType,
3459 + lpMsgStore->Release();
3461 + if (HR_FAILED(mLastError))
3464 + When delete mail address from distlist,Mapi need update 2 tag.
3466 + //update OUTLOOK_EMAIL_LIST1
3467 + ULONG listTag=GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST1) | PT_MV_BINARY;
3469 + SBinaryArray oldChilds;
3470 + LPSBinary bins=NULL;
3471 + SBinaryArray newChilds;
3472 + LPSPropValue oldChildValue = NULL ;
3473 + ULONG valueCount = 0 ;
3475 + newChilds.lpbin=NULL;
3477 + ULONG lDeleteEntry=0;
3480 + if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
3482 + PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
3486 + if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
3488 + oldChilds = oldChildValue->Value.MVbin;
3489 + newChilds.cValues=oldChilds.cValues - 1;
3490 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3491 + newChilds.lpbin = bins;
3492 + for (oldIndex=0;oldIndex<oldChilds.cValues;oldIndex++)
3494 + if ( oldChilds.lpbin[oldIndex].cb == aNewEntry.mByteCount &&
3495 + !memcmp((void*)(oldChilds.lpbin[oldIndex].lpb+4),
3496 + (void*)(aNewEntry.mEntryId->ab),
3497 + oldChilds.lpbin[oldIndex].cb-4))
3499 + lDeleteEntry=oldIndex;
3503 + newChilds.lpbin[newIndex].lpb = oldChilds.lpbin[oldIndex].lpb;
3504 + newChilds.lpbin[newIndex].cb = oldChilds.lpbin[oldIndex].cb;
3513 + SPropValue childs;
3514 + LPSPropProblemArray problems = NULL ;
3516 + if (newChilds.cValues == 0)
3518 + SPropTagArray delTags;
3519 + delTags.cValues = 1;
3520 + delTags.aulPropTag[0] = listTag;
3522 + mLastError = container->DeleteProps(&delTags, &problems) ;
3526 + childs.ulPropTag = listTag;
3527 + childs.Value.MVbin = newChilds;
3528 + mLastError = container->SetProps(1, &childs, &problems) ;
3531 + if (HR_FAILED(mLastError)) {
3532 + PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
3536 + //update OUTLOOK_EMAIL_LIST2
3537 + listTag = GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST2) | PT_MV_BINARY;
3538 + if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
3540 + PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
3545 + if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
3547 + oldChilds = oldChildValue->Value.MVbin;
3548 + newChilds.cValues=oldChilds.cValues - 1;
3549 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3550 + newChilds.lpbin = bins;
3551 + for (oldIndex=0;oldIndex<oldChilds.cValues;oldIndex++)
3553 + if (oldIndex != lDeleteEntry)
3555 + newChilds.lpbin[newIndex].lpb = oldChilds.lpbin[oldIndex].lpb;
3556 + newChilds.lpbin[newIndex].cb = oldChilds.lpbin[oldIndex].cb;
3563 + newChilds.cValues = 1;
3564 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3565 + newChilds.lpbin = bins;
3570 + if (newChilds.cValues == 0)
3572 + SPropTagArray delTags;
3573 + delTags.cValues = 1;
3574 + delTags.aulPropTag[0] = listTag;
3576 + mLastError = container->DeleteProps(&delTags, &problems) ;
3580 + childs.ulPropTag = listTag;
3581 + childs.Value.MVbin = newChilds;
3582 + mLastError = container->SetProps(1, &childs, &problems) ;
3584 + if (HR_FAILED(mLastError)) {
3585 + PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
3589 + mMAPIFreeBuffer(bins);
3591 + mLastError = container->SaveChanges(KEEP_OPEN_READONLY) ;
3592 + if (HR_FAILED(mLastError)) {
3593 + PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
3600 +BOOL nsMapiAddressBook::GetEntryParent(const nsMapiEntry& aParent, nsMapiEntry& aParentEntry)
3602 + nsMapiInterfaceWrapper<LPMAPIPROP> object ;
3603 + ULONG objType = 0 ;
3604 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
3605 + &IID_IMAPIProp, 0, &objType,
3606 + (IUnknown **)&object) ;
3608 + if (HR_FAILED(mLastError)) {
3609 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3612 + SPropValue *parentID=GetMapiProperty(*(LPMAPIPROP*)&object, PR_PARENT_ENTRYID);
3614 + if (parentID->Value.l == MAPI_E_NOT_FOUND)
3616 + aParentEntry.Assign(parentID->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, parentID->Value.bin.lpb));
3619 +BOOL nsMapiAddressBook::CreateEntryInList(const nsMapiEntry& aDistlist, nsMapiEntry& aNewEntry)
3621 + nsMapiInterfaceWrapper<LPMAPIPROP> container ;
3622 + ULONG objType = 0 ;
3624 + nsMapiEntry parentEntry;
3625 + if (!GetEntryParent(aDistlist,parentEntry))
3629 + nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
3630 + if (!CreateEntry(parentEntry,aNewEntry)) //Create a entry in parent folder
3633 + return AddEntryToList(aDistlist,aNewEntry);
3636 +BOOL nsMapiAddressBook::CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry)
3638 + nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
3639 + ULONG objType = 0 ;
3641 + nsMapiInterfaceWrapper<LPMAPIPROP> object;
3642 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
3643 + &IID_IMAPIProp, 0, &objType,
3646 + if (HR_FAILED(mLastError)) {
3647 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3650 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
3652 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
3653 + return CreateEntryInList(aParent,aNewEntry); //Create entry in DistList
3655 + LPMDB lpMsgStore=GetMsgStore(aParent);
3660 + mLastError = lpMsgStore->OpenEntry(aParent.mByteCount, aParent.mEntryId,
3661 + &IID_IMAPIFolder, MAPI_MODIFY, &objType,
3663 + lpMsgStore->Release();
3665 + if (HR_FAILED(mLastError))
3668 + nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
3670 + mLastError = container->CreateMessage(&IID_IMessage,
3673 + if (HR_FAILED(mLastError)) {
3674 + PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
3677 + SPropValue messageclass ;
3678 + LPSPropProblemArray problems = NULL ;
3679 + nsCString tempName ;
3681 + messageclass.ulPropTag = PR_MESSAGE_CLASS_A ;
3682 + tempName.Assign("IPM.Contact") ;
3683 + messageclass.Value.lpszA = NS_CONST_CAST(char *, tempName.get()) ;
3684 + mLastError = newEntry->SetProps(1, &messageclass, &problems) ;
3685 + if (HR_FAILED(mLastError)) {
3686 + PRINTF(("Cannot set temporary name %08x.\n", mLastError)) ;
3689 + mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
3690 + if (HR_FAILED(mLastError)) {
3691 + PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
3695 + SPropTagArray property ;
3696 + LPSPropValue value = NULL ;
3697 + ULONG valueCount = 0 ;
3699 + property.cValues = 1 ;
3700 + property.aulPropTag [0] = PR_ENTRYID ;
3701 + mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
3702 + if (HR_FAILED(mLastError) || valueCount != 1) {
3703 + PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
3706 + aNewEntry.Assign(value->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
3707 + FreeBuffer(value) ;
3711 +BOOL nsMapiAddressBook::CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry)
3713 + nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
3714 + ULONG objType = 0 ;
3716 + LPMDB lpMsgStore=GetMsgStore(aParent);
3719 + mLastError = lpMsgStore->OpenEntry(aParent.mByteCount, aParent.mEntryId,
3720 + &IID_IMAPIFolder, MAPI_MODIFY, &objType,
3722 + lpMsgStore->Release();
3724 + if (HR_FAILED(mLastError)) {
3725 + PRINTF(("Cannot open container %08x.\n", mLastError)) ;
3729 + nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
3730 + mLastError = container->CreateMessage(&IID_IMAPIProp,
3733 + if (HR_FAILED(mLastError)) {
3734 + PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
3737 + SPropValue messageclass ;
3738 + LPSPropProblemArray problems = NULL ;
3739 + nsCString tempName ;
3741 + messageclass.ulPropTag = PR_MESSAGE_CLASS_A ;
3742 + tempName.Assign("IPM.DistList") ;
3743 + messageclass.Value.lpszA = NS_CONST_CAST(char *, tempName.get()) ;
3744 + mLastError = newEntry->SetProps(1, &messageclass, &problems) ;
3745 + if (HR_FAILED(mLastError)) {
3746 + PRINTF(("Cannot set PR_MESSAGE_CLASS_A %08x.\n", mLastError)) ;
3749 + mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
3750 + if (HR_FAILED(mLastError)) {
3751 + PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
3755 + ULONG valueCount = 0 ;
3756 + SPropTagArray property ;
3757 + LPSPropValue value = NULL ;
3759 + property.cValues = 1 ;
3760 + property.aulPropTag [0] = PR_ENTRYID ;
3761 + mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
3762 + if (HR_FAILED(mLastError) || valueCount != 1) {
3763 + PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
3766 + aNewEntry.Assign(value->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
3768 + FreeBuffer(value) ;
3773 +BOOL nsMapiAddressBook::CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource,
3774 + nsMapiEntry& aTarget)
3776 + nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
3777 + nsMapiInterfaceWrapper<LPMAPIFOLDER> targetFolder ;
3778 + ULONG objType = 0 ;
3779 + nsMapiInterfaceWrapper<LPMAPIPROP> object;
3780 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
3781 + &IID_IMAPIProp, 0, &objType,
3784 + if (HR_FAILED(mLastError)) {
3785 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3788 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
3790 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
3792 + //Add Entry To DistList
3793 + if (!AddEntryToList(aContainer,aSource))
3795 + aTarget.Assign(aSource.mByteCount,aSource.mEntryId);
3800 + SBinaryArray entryArray ;
3802 + entry.cb = aSource.mByteCount ;
3803 + entry.lpb = NS_REINTERPRET_CAST(LPBYTE, aSource.mEntryId) ;
3804 + entryArray.cValues = 1 ;
3805 + entryArray.lpbin = &entry ;
3807 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
3808 + &IID_IMAPIFolder, MAPI_MODIFY, &objType,
3810 + if (HR_FAILED(mLastError)) {
3811 + PRINTF(("Cannot open container %08x.\n", mLastError)) ;
3815 + mLastError = OpenEntry(aTarget.mByteCount, aTarget.mEntryId,
3816 + &IID_IMAPIFolder, MAPI_MODIFY, &objType,
3818 + if (HR_FAILED(mLastError)) {
3819 + PRINTF(("Cannot open Target folder %08x.\n", mLastError)) ;
3823 + nsMapiInterfaceWrapper<LPMAPIPROP> newEntry ;
3825 + mLastError = container->CopyMessages(&entryArray,
3827 + (void*)&targetFolder,
3831 + if (HR_FAILED(mLastError)) {
3832 + PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
3838 +BOOL nsMapiAddressBook::DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry)
3840 + nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
3841 + ULONG objType = 0 ;
3843 + SBinaryArray entryArray ;
3846 + nsMapiInterfaceWrapper<LPMAPIPROP> object;
3847 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
3848 + &IID_IMAPIProp, 0, &objType,
3851 + if (HR_FAILED(mLastError)) {
3852 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3855 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
3857 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
3858 + return DeleteEntryFromList(aContainer,aEntry); //Delete Entry from DistList
3860 + LPMDB lpMsgStore=GetMsgStore(aContainer);
3864 + mLastError = lpMsgStore->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
3865 + &IID_IMAPIFolder, MAPI_MODIFY, &objType,
3867 + lpMsgStore->Release();
3868 + if (HR_FAILED(mLastError)) {
3869 + PRINTF(("Cannot open container %08x.\n", mLastError)) ;
3872 + entry.cb = aEntry.mByteCount ;
3873 + entry.lpb = NS_REINTERPRET_CAST(LPBYTE, aEntry.mEntryId) ;
3874 + entryArray.cValues = 1 ;
3875 + entryArray.lpbin = &entry ;
3876 + mLastError = container->DeleteMessages(&entryArray, 0,0,0) ;
3877 + if (HR_FAILED(mLastError)) {
3878 + PRINTF(("Cannot delete entry %08x.\n", mLastError)) ;
3884 +//Use to open message store in write mode
3885 +LPMDB nsMapiAddressBook::GetMsgStore(const nsMapiEntry& aEntry)
3887 + nsMapiInterfaceWrapper<LPMAPIPROP> object;
3890 + mLastError = OpenEntry(aEntry.mByteCount, aEntry.mEntryId,
3891 + &IID_IMAPIProp, MAPI_BEST_ACCESS , &objType,
3893 + if (HR_FAILED(mLastError)) {
3894 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3897 + SPropValue *svMsgSore=GetMapiProperty( *(LPMAPIPROP*)&object, PR_STORE_ENTRYID);;
3899 + LPMDB lpMsgStore=NULL;
3900 + mLastError=mRootSession->OpenMsgStore(0,
3901 + svMsgSore->Value.bin.cb,
3902 + (ENTRYID*)svMsgSore->Value.bin.lpb,
3904 + MDB_NO_MAIL | MDB_WRITE ,
3907 + if (HR_FAILED(mLastError)) {
3908 + PRINTF(("Cannot open MsgStore %08x.\n", mLastError)) ;
3912 + return lpMsgStore;
3914 Index: mailnews/addrbook/src/nsMapiAddressBook.h
3915 ===================================================================
3916 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h,v
3917 retrieving revision 1.1.1.1
3918 retrieving revision 1.2
3919 diff -u -w -b -i -r1.1.1.1 -r1.2
3920 --- miss/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h 22 Oct 2003 02:43:11 -0000 1.1.1.1
3921 +++ miss/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h 9 Dec 2003 03:26:47 -0000 1.2
3924 #include "nsAbWinHelper.h"
3932 class nsMapiAddressBook : public nsAbWinHelper
3935 nsMapiAddressBook(void) ;
3936 virtual ~nsMapiAddressBook(void) ;
3938 + // Get the top address books
3939 + virtual BOOL GetFolders(nsMapiEntryArray& aFolders);
3941 + // Get a default address book container
3942 + virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer);
3943 + // Is the helper correctly initialised?
3944 + virtual BOOL IsOK(void);
3945 + virtual BOOL GetPropertyLong(const nsMapiEntry& aObject,
3946 + ULONG aPropertyTag,
3948 + // Get the value of a MAPI property of type SYSTIME
3949 + virtual BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
3950 + WORD& aYear, WORD& aMonth, WORD& aDay);
3951 + // Create entry in the address book
3952 + virtual BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
3953 + // Delete an entry in the address book
3954 + virtual BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
3955 + // Create a distribution list in the address book
3956 + virtual BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
3957 + // Copy an existing entry in the address book
3958 + virtual BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
3960 + static void FreeMapiLibrary(void) ;
3963 // Class members to handle the library/entry points
3964 static HMODULE mLibrary ;
3966 static BOOL mInitialized ;
3967 static BOOL mLogonDone ;
3968 static LPMAPISESSION mRootSession ;
3969 - static LPADRBOOK mRootBook ;
3972 // Load the MAPI environment
3973 BOOL Initialize(void) ;
3975 + virtual HRESULT OpenEntry(ULONG cbEntryID,
3976 + LPENTRYID lpEntryID,
3977 + LPCIID lpInterface,
3979 + ULONG FAR * lpulObjType,
3980 + LPUNKNOWN FAR * lppUnk
3984 + // Retrieve the contents of a container, with an optional restriction
3985 + virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
3986 + nsMapiEntryArray *aList, ULONG aMapiType) ;
3987 + // Retrieve the values of a set of properties on a MAPI object
3988 + virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
3989 + ULONG aNbProperties,
3990 + LPSPropValue& aValues, ULONG& aValueCount) ;
3991 + // Set the values of a set of properties on a MAPI object
3992 + virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
3993 + LPSPropValue& aValues);
3996 // Allocation of a buffer for transmission to interfaces
3997 virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) ;
3998 // Destruction of a buffer provided by the interfaces
3999 virtual void FreeBuffer(LPVOID aBuffer) ;
4000 // Library management
4001 static BOOL LoadMapiLibrary(void) ;
4002 - static void FreeMapiLibrary(void) ;
4004 + BOOL HandleContentsItem(ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders);
4005 + LPSPropValue GetMapiProperty( LPMAPIPROP pProp, ULONG tag);
4006 + BOOL GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYID& lpEntryId, BOOL delVal=FALSE);
4007 + BOOL HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders);
4008 + BOOL IterateHierarchy(IMAPIContainer * pFolder, nsMapiEntryArray& aFolders,ULONG flags=0);
4009 + ULONG GetEmailPropertyTag(LPMAPIPROP lpProp, LONG nameID);
4010 + ULONG GetRealMapiPropertyTag(LPMAPIPROP lpProp, LONG aPropertyTag,BOOL aTest=FALSE);
4011 + LPMDB GetMsgStore(const nsMapiEntry& aEntry);
4012 + BOOL CreateEntryInList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry);
4013 + BOOL AddEntryToList(const nsMapiEntry& aParent,const nsMapiEntry& aNewEntry);
4014 + BOOL DeleteEntryFromList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry);
4015 + BOOL GetEntryParent(const nsMapiEntry& aParent, nsMapiEntry& aParentEntry);
4016 + BOOL CorrectRestriction(const LPMAPIPROP aMapiProp,ULONG aRestrictionNum, LPSRestriction aRestriction);
4019 + BOOL Filter( LPSRestriction aRestriction,nsMapiEntryArray * aList);
4020 + BOOL FilterOnOneRow(nsMapiEntry *aEntry,LPSRestriction aRestriction);
4021 + BOOL AtomyFilter(LPSRestriction aRestriction,LPSPropValue aRealValue,LPSPropValue aFilterValue);
4023 + void AddToMDBArray(LPMDB aMDB)
4025 + m_MDBArray.AppendElement(aMDB);
4030 + for (int i = 0; i < m_MDBArray.Count(); i++)
4032 + mdb = (LPMDB)m_MDBArray.ElementAt(i);
4035 + m_MDBArray.Clear();
4039 + //use to keep all openned MsgStore,if we not open a message store,we can't open any thing on it
4040 + //so we have to kill message stores openned
4041 + nsVoidArray m_MDBArray;
4044 #endif // nsMapiAddressBook_h___
4045 Index: mailnews/addrbook/src/nsWabAddressBook.cpp
4046 ===================================================================
4047 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp,v
4048 retrieving revision 1.1.1.1
4049 retrieving revision 1.2
4050 diff -u -w -b -i -r1.1.1.1 -r1.2
4051 --- miss/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp 22 Oct 2003 02:43:11 -0000 1.1.1.1
4052 +++ miss/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp 9 Dec 2003 03:26:47 -0000 1.2
4055 #define PRINTF(args) PR_LOG(gWabAddressBookLog, PR_LOG_DEBUG, args)
4059 + ContentsColumnEntryId = 0,
4060 + ContentsColumnObjectType,
4061 + ContentsColumnsSize
4064 +static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
4066 + ContentsColumnsSize,
4073 HMODULE nsWabAddressBook::mLibrary = NULL ;
4074 PRInt32 nsWabAddressBook::mLibUsage = 0 ;
4075 LPWABOPEN nsWabAddressBook::mWABOpen = NULL ;
4077 MOZ_DECL_CTOR_COUNTER(nsWabAddressBook)
4079 nsWabAddressBook::nsWabAddressBook(void)
4081 +: nsAbWinHelper(),mAddressBook(NULL)
4083 BOOL result = Initialize() ;
4085 @@ -110,9 +126,254 @@
4086 MOZ_COUNT_DTOR(nsWabAddressBook) ;
4089 +BOOL nsWabAddressBook::GetFolders(nsMapiEntryArray& aFolders)
4091 + aFolders.CleanUp() ;
4092 + nsMapiInterfaceWrapper<LPABCONT> rootFolder ;
4093 + nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
4094 + ULONG objType = 0 ;
4095 + ULONG rowCount = 0 ;
4096 + SRestriction restriction ;
4097 + SPropTagArray folderColumns ;
4099 + mLastError = OpenEntry(0, NULL, NULL, 0, &objType,
4101 + if (HR_FAILED(mLastError)){
4102 + PRINTF(("Cannot open root %08x.\n", mLastError));
4105 + mLastError = rootFolder->GetHierarchyTable(0, folders);
4106 + if (HR_FAILED(mLastError)){
4107 + PRINTF(("Cannot get hierarchy %08x.\n", mLastError));
4110 + // We only take into account modifiable containers,
4111 + // otherwise, we end up with all the directory services...
4112 + restriction.rt = RES_BITMASK ;
4113 + restriction.res.resBitMask.ulPropTag = PR_CONTAINER_FLAGS ;
4114 + restriction.res.resBitMask.relBMR = BMR_NEZ ;
4115 + restriction.res.resBitMask.ulMask = AB_MODIFIABLE ;
4116 + mLastError = folders->Restrict(&restriction, 0) ;
4117 + if (HR_FAILED(mLastError)) {
4118 + PRINTF(("Cannot restrict table %08x.\n", mLastError)) ;
4120 + folderColumns.cValues = 1 ;
4121 + folderColumns.aulPropTag [0] = PR_ENTRYID ;
4122 + mLastError = folders->SetColumns(&folderColumns, 0) ;
4123 + if (HR_FAILED(mLastError)) {
4124 + PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
4127 + mLastError = folders->GetRowCount(0, &rowCount) ;
4128 + if (HR_SUCCEEDED(mLastError)) {
4130 + LPSRowSet rowSet = NULL ;
4133 + mLastError = folders->QueryRows(1, 0, &rowSet) ;
4134 + if (HR_SUCCEEDED(mLastError)) {
4135 + rowCount = rowSet->cRows ;
4136 + if (rowCount > 0) {
4137 + SPropValue& currentValue = rowSet->aRow->lpProps [0] ;
4139 + aFolders.AddItem(currentValue.Value.bin.cb,
4140 + NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
4142 + MyFreeProws(rowSet) ;
4145 + PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
4147 + } while (rowCount > 0) ;
4149 + return HR_SUCCEEDED(mLastError) ;
4151 +BOOL nsWabAddressBook::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
4152 + nsMapiEntryArray *aList, ULONG aMapiType)
4154 + if (aList) { aList->CleanUp(); }
4155 + nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
4156 + nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
4157 + ULONG objType = 0 ;
4158 + ULONG rowCount = 0 ;
4160 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
4161 + &IID_IMAPIContainer, 0, &objType,
4163 + if (HR_FAILED(mLastError)) {
4164 + PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
4167 + // Here, flags for WAB and MAPI could be different, so this works
4168 + // only as long as we don't want to use any flag in GetContentsTable
4169 + mLastError = parent->GetContentsTable(0, contents) ;
4170 + if (HR_FAILED(mLastError)) {
4171 + PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
4174 + if (aRestriction) {
4175 + mLastError = contents->Restrict(aRestriction, 0) ;
4176 + if (HR_FAILED(mLastError)) {
4177 + PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
4181 + int entryId = ContentsColumnEntryId ;
4182 + int objectType = ContentsColumnObjectType ;
4186 + LPSPropTagArray allColumns = NULL ;
4188 + mLastError = contents->QueryColumns(TBL_ALL_COLUMNS, &allColumns) ;
4189 + if (HR_FAILED(mLastError)) {
4190 + PRINTF(("Cannot query columns %08x.\n", mLastError)) ;
4194 + for (unsigned int j = 0 ; j < allColumns->cValues ; ++ j) {
4195 + if (allColumns->aulPropTag [j] == PR_ENTRYID) {
4198 + else if (allColumns->aulPropTag [j] == PR_OBJECT_TYPE) {
4202 + mLastError = contents->SetColumns(allColumns, 0) ;
4203 + if (HR_FAILED(mLastError)) {
4204 + PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
4207 + FreeBuffer(allColumns) ;
4212 + mLastError = contents->SetColumns((LPSPropTagArray) &ContentsColumns, 0) ;
4213 + if (HR_FAILED(mLastError)) {
4214 + PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
4219 + mLastError = contents->GetRowCount(0, &rowCount) ;
4220 + if (HR_FAILED(mLastError)) {
4221 + PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
4225 + LPSRowSet rowSet = NULL ;
4228 + mLastError = contents->QueryRows(1, 0, &rowSet) ;
4229 + if (HR_FAILED(mLastError)) {
4230 + PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
4233 + rowCount = rowSet->cRows ;
4234 + if (rowCount > 0 &&
4235 + (aMapiType == 0 ||
4236 + rowSet->aRow->lpProps[objectType].Value.ul == aMapiType)) {
4238 + SPropValue& currentValue = rowSet->aRow->lpProps[entryId] ;
4240 + aList->AddItem(currentValue.Value.bin.cb,
4241 + NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
4245 + MyFreeProws(rowSet) ;
4246 + } while (rowCount > 0) ;
4250 +BOOL nsWabAddressBook::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
4251 + ULONG aNbProperties, LPSPropValue& aValue,
4252 + ULONG& aValueCount)
4254 + nsMapiInterfaceWrapper<LPMAPIPROP> object ;
4255 + IMsgStore * mdb=NULL;
4256 + ULONG objType = 0 ;
4257 + LPSPropTagArray properties = NULL ;
4260 + mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
4261 + &IID_IMAPIProp, 0, &objType,
4264 + if (HR_FAILED(mLastError)){
4265 + PRINTF(("Cannot open entry %08x.\n", mLastError));
4268 + AllocateBuffer(CbNewSPropTagArray(aNbProperties),
4269 + NS_REINTERPRET_CAST(void **, &properties));
4270 + properties->cValues = aNbProperties;
4271 + for (i = 0 ; i < aNbProperties ; ++ i) {
4272 + properties->aulPropTag [i] = aPropertyTags [i];
4274 + mLastError = object->GetProps(properties, 0, &aValueCount, &aValue);
4275 + FreeBuffer(properties);
4276 + if (HR_FAILED(mLastError)){
4277 + PRINTF(("Cannot get props %08x.\n", mLastError));
4279 + return HR_SUCCEEDED(mLastError) ;
4282 +BOOL nsWabAddressBook::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
4283 + LPSPropValue& aValues)
4285 + nsMapiInterfaceWrapper<LPMAPIPROP> object ;
4286 + ULONG objType = 0 ;
4287 + LPSPropProblemArray problems = NULL ;
4289 + mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
4290 + &IID_IMAPIProp, MAPI_MODIFY, &objType,
4292 + if (HR_FAILED(mLastError)) {
4293 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
4296 + mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
4297 + if (HR_FAILED(mLastError)) {
4298 + PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
4302 + for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
4303 + PRINTF(("Problem %d: index %d code %08x.\n", i,
4304 + problems->aProblem [i].ulIndex,
4305 + problems->aProblem [i].scode));
4308 + mLastError = object->SaveChanges(0) ;
4309 + if (HR_FAILED(mLastError)) {
4310 + PRINTF(("Cannot commit changes %08x.\n", mLastError)) ;
4312 + return HR_SUCCEEDED(mLastError) ;
4315 +BOOL nsWabAddressBook::GetDefaultContainer(nsMapiEntry& aContainer)
4317 + LPENTRYID entryId = NULL;
4318 + ULONG byteCount = 0;
4320 + mLastError = mAddressBook->GetPAB(&byteCount, &entryId);
4321 + if (HR_FAILED(mLastError)){
4322 + PRINTF(("Cannot get PAB %08x.\n", mLastError));
4325 + aContainer.Assign(byteCount, entryId);
4326 + FreeBuffer(entryId) ;
4330 +BOOL nsWabAddressBook::IsOK(void)
4332 + return mAddressBook != NULL ;
4335 BOOL nsWabAddressBook::Initialize(void)
4337 - if (mAddressBook) { return TRUE ; }
4338 nsAutoLock guard(mMutex) ;
4340 if (!LoadWabLibrary()) {
4341 Index: mailnews/addrbook/src/nsWabAddressBook.h
4342 ===================================================================
4343 RCS file: /mozilla/mozilla/mailnews/addrbook/src/nsWabAddressBook.h,v
4344 retrieving revision 1.1.1.1
4345 retrieving revision 1.2
4346 diff -u -w -b -i -r1.1.1.1 -r1.2
4347 --- miss/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.h 22 Oct 2003 02:43:11 -0000 1.1.1.1
4348 +++ miss/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.h 9 Dec 2003 03:26:47 -0000 1.2
4350 nsWabAddressBook(void) ;
4351 virtual ~nsWabAddressBook(void) ;
4353 + // Get the top address books
4354 + virtual BOOL GetFolders(nsMapiEntryArray& aFolders);
4356 + // Get a default address book container
4357 + virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer);
4358 + // Is the helper correctly initialised?
4359 + virtual BOOL IsOK(void);
4360 + static void FreeWabLibrary(void) ;
4363 // Session and address book that will be shared by all instances
4364 // (see nsMapiAddressBook.h for details)
4366 static HMODULE mLibrary ;
4367 static LPWABOPEN mWABOpen ;
4369 + LPADRBOOK mAddressBook ;
4371 // Load the WAB environment
4372 BOOL Initialize(void) ;
4374 + virtual HRESULT OpenEntry(ULONG cbEntryID,
4375 + LPENTRYID lpEntryID,
4376 + LPCIID lpInterface,
4378 + ULONG FAR * lpulObjType,
4379 + LPUNKNOWN FAR * lppUnk
4382 + return mAddressBook->OpenEntry(cbEntryID,
4392 + // Retrieve the contents of a container, with an optional restriction
4393 + virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
4394 + nsMapiEntryArray *aList, ULONG aMapiType) ;
4395 + // Retrieve the values of a set of properties on a MAPI object
4396 + virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
4397 + ULONG aNbProperties,
4398 + LPSPropValue& aValues, ULONG& aValueCount) ;
4399 + // Set the values of a set of properties on a MAPI object
4400 + virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
4401 + LPSPropValue& aValues) ;
4403 // Allocation of a buffer for transmission to interfaces
4404 virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) ;
4405 // Destruction of a buffer provided by the interfaces
4406 virtual void FreeBuffer(LPVOID aBuffer) ;
4407 // Manage the library
4408 static BOOL LoadWabLibrary(void) ;
4409 - static void FreeWabLibrary(void) ;
4413 Index: profile/src/nsProfile.cpp
4414 ===================================================================
4415 RCS file: /mozilla/mozilla/profile/src/nsProfile.cpp,v
4416 retrieving revision 1.1.1.1
4417 retrieving revision 1.2
4418 diff -u -w -b -i -r1.1.1.1 -r1.2
4419 --- miss/build/mozilla/profile/src/nsProfile.cpp 22 Oct 2003 02:40:14 -0000 1.1.1.1
4420 +++ miss/build/mozilla/profile/src/nsProfile.cpp 22 Oct 2003 09:45:04 -0000 1.2
4422 rv = curProfileDir->Exists(&exists);
4423 if (NS_FAILED(rv) || !exists)
4424 profileURLStr = PROFILE_MANAGER_URL;
4428 // If the profile is locked, we need the UI
4431 profileURLStr = PROFILE_MANAGER_URL;
4436 profileURLStr = PROFILE_SELECTION_URL;
4437 @@ -1200,6 +1202,7 @@
4439 isSwitch = PR_FALSE;
4442 nsProfileLock localLock;
4443 nsCOMPtr<nsILocalFile> localProfileDir(do_QueryInterface(profileDir, &rv));
4444 if (NS_FAILED(rv)) return rv;
4445 @@ -1209,6 +1212,7 @@
4446 NS_ERROR("Could not get profile directory lock.");
4451 nsCOMPtr<nsIObserverService> observerService =
4452 do_GetService("@mozilla.org/observer-service;1", &rv);
4453 @@ -1244,7 +1248,9 @@
4454 gProfileDataAccess->SetCurrentProfile(aCurrentProfile);
4455 gProfileDataAccess->mProfileDataChanged = PR_TRUE;
4456 gProfileDataAccess->UpdateRegistry(nsnull);
4458 mCurrentProfileLock = localLock;
4461 if (NS_FAILED(rv)) return rv;
4462 mCurrentProfileAvailable = PR_TRUE;
4463 @@ -1331,7 +1337,9 @@
4464 UpdateCurrentProfileModTime(PR_TRUE);
4465 mCurrentProfileAvailable = PR_FALSE;
4466 mCurrentProfileName.Truncate(0);
4468 mCurrentProfileLock.Unlock();
4474 --- miss/build/mozilla/.mozconfig Tue Jul 22 21:52:27 2003
4475 +++ misc/build/mozilla/.mozconfig Mon Jul 28 15:07:20 2003
4477 +ac_add_options --disable-tests
4478 +ac_add_options --disable-xprint
4479 +ac_add_options --without-system-zlib
4480 +ac_add_options --enable-ldap
4481 +ac_add_options --disable-debug
4482 +ac_add_options --enable-optimize
4483 +ac_add_options --enable-crypto
4484 +ac_add_options --enable-strip
4486 --- misc/build/mozilla/client.mk Fri Aug 1 10:14:27 2003
4487 +++ misc/build/mozilla/client.mk Fri Aug 1 10:11:31 2003
4491 ifdef _IS_FIRST_CHECKOUT
4492 -all:: checkout build
4495 -all:: checkout alldep
4499 # Windows equivalents