1 Index: directory/xpcom/base/src/nsLDAPMessage.cpp
2 ===================================================================
3 RCS file: /cvsroot/mozilla/directory/xpcom/base/src/nsLDAPMessage.cpp,v
4 retrieving revision 1.28
5 diff -u -r1.28 nsLDAPMessage.cpp
6 --- misc/build/mozilla/directory/xpcom/base/src/nsLDAPMessage.cpp 29 Jan 2004 22:04:23 -0000 1.28
7 +++ misc/build/mozilla/directory/xpcom/base/src/nsLDAPMessage.cpp 17 May 2004 03:23:37 -0000
11 for ( i = 0 ; i < numVals ; i++ ) {
12 - (*aValues)[i] = UTF8ToNewUnicode(nsDependentCString(values[i]));
13 + if (IsUTF8(nsDependentCString(values[i])))
14 + (*aValues)[i] = UTF8ToNewUnicode(nsDependentCString(values[i]));
16 + (*aValues)[i] = ToNewUnicode(nsDependentCString(values[i]));
18 if ( ! (*aValues)[i] ) {
19 NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, aValues);
20 ldap_value_free(values);
21 Index: mailnews/addrbook/src/Makefile.in
22 ===================================================================
23 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/Makefile.in,v
24 retrieving revision 1.47
25 diff -u -r1.47 Makefile.in
26 --- misc/build/mozilla/mailnews/addrbook/src/Makefile.in 6 Oct 2003 17:48:56 -0000 1.47
27 +++ misc/build/mozilla/mailnews/addrbook/src/Makefile.in 17 May 2004 03:23:53 -0000
31 nsMsgVCardService.cpp \
36 Index: mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp
37 ===================================================================
38 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp,v
39 retrieving revision 1.4
40 diff -u -r1.4 nsAbBoolExprToLDAPFilter.cpp
41 --- misc/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp 11 Oct 2002 08:17:13 -0000 1.4
42 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.cpp 17 May 2004 03:23:53 -0000
44 #include "nsAbBoolExprToLDAPFilter.h"
45 #include "nsAbLDAPProperties.h"
46 #include "nsXPIDLString.h"
47 +#include "nsAbUtils.h"
49 const int nsAbBoolExprToLDAPFilter::TRANSLATE_CARD_PROPERTY = 1 << 0 ;
50 const int nsAbBoolExprToLDAPFilter::ALLOW_NON_CONVERTABLE_CARD_PROPERTY = 1 << 1 ;
52 rv = condition->GetName (getter_Copies (name));
53 NS_ENSURE_SUCCESS(rv, rv);
55 - const char* ldapProperty = name.get ();
56 + CharPtrArrayGuard attrs;
57 if (flags & TRANSLATE_CARD_PROPERTY)
59 - const MozillaLdapPropertyRelation* p =
60 - MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (name.get ());
62 - ldapProperty = p->ldapProperty;
63 + if(const MozillaLdapPropertyRelation* property =
64 + MozillaLdapPropertyRelator::findLdapPropertyFromMozilla (name.get ()))
66 + // allow even single ldap attribute mapppings to go through this to simplify the filter creation later.
67 + rv = MozillaLdapPropertyRelator::getAllLDAPAttrsFromMozilla (property->ldapProperty, attrs.GetSizeAddr(), attrs.GetArrayAddr() );
68 + NS_ENSURE_SUCCESS(rv, rv);
70 else if (!(flags & ALLOW_NON_CONVERTABLE_CARD_PROPERTY))
74 NS_ENSURE_SUCCESS(rv, rv);
75 NS_ConvertUCS2toUTF8 vUTF8 (value);
77 + // check if using multiple ldap attributes
78 + if(attrs.GetSize() == 1 )
79 + GenerateSingleFilter(conditionType,filter,vUTF8,attrs.GetArray()[0]);
82 + // add the opening brace if using multiple ldap attributes
83 + switch (conditionType)
85 + // 'NOT' conditionals use the 'AND' operator
86 + case nsIAbBooleanConditionTypes::DoesNotExist:
87 + case nsIAbBooleanConditionTypes::DoesNotContain:
88 + case nsIAbBooleanConditionTypes::IsNot:
89 + filter += NS_LITERAL_CSTRING("(&");
92 + filter += NS_LITERAL_CSTRING("(|");
95 + GenerateMultipleFilter(conditionType,filter,vUTF8,&attrs);
96 + // add the closing brace if using multiple ldap attributes
97 + filter += NS_LITERAL_CSTRING(")");
102 +void nsAbBoolExprToLDAPFilter:: GenerateSingleFilter(
103 + nsAbBooleanConditionType conditionType,
105 + NS_ConvertUCS2toUTF8 &vUTF8,
106 + const char *ldapProperty)
108 switch (conditionType)
110 case nsIAbBooleanConditionTypes::DoesNotExist:
118 +void nsAbBoolExprToLDAPFilter:: GenerateMultipleFilter(
119 + nsAbBooleanConditionType conditionType,
121 + NS_ConvertUCS2toUTF8 &vUTF8,
122 + CharPtrArrayGuard *pAttrs)
125 + PRUint16 inner = 0;
128 + * This function is based on the fact that we are trying to generate support
129 + * for multiple occurring ldap attributes. Consider the following query:
130 + * (PagerNumber,=,123456) where PagerNumber = pager|pagerphone translates to:
131 + * (|(&(pager=*)(pager=123456))(&(!(pager=*))(pagerphone=123456)))
132 + * This can be shortened to:
133 + * (|(pager=123456)(&(!(pager=*))(pagerphone=123456)))
135 + * i.e. use the first occurring attribute if it exists otherwise if first
136 + * does not exist use the second etc. The assumption is that the first
137 + * always takes precedence.
138 + * This translates to:
139 + * GenerateSingleFilter(Is);
140 + * GenerateSingleFilter(DoesNotExists);
141 + * GenerateSingleFilter(Is);
144 + for (i = 0; i < pAttrs->GetSize(); i++)
147 + GenerateSingleFilter(conditionType,filter,vUTF8,pAttrs->GetArray()[i]);
150 + filter += NS_LITERAL_CSTRING("(&");
151 + nsAbBooleanConditionType doesNotExistsType = nsIAbBooleanConditionTypes::DoesNotExist;
152 + for(inner = 0; inner < i; ++inner)
154 + GenerateSingleFilter(doesNotExistsType,filter,vUTF8,pAttrs->GetArray()[inner]);
156 + GenerateSingleFilter(conditionType,filter,vUTF8,pAttrs->GetArray()[i]);
157 + filter += NS_LITERAL_CSTRING(")");
161 Index: mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h
162 ===================================================================
163 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h,v
164 retrieving revision 1.2
165 diff -u -r1.2 nsAbBoolExprToLDAPFilter.h
166 --- misc/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h 28 Sep 2001 20:06:21 -0000 1.2
167 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbBoolExprToLDAPFilter.h 17 May 2004 03:23:53 -0000
169 #include "nsIAbBooleanExpression.h"
170 #include "nsCOMPtr.h"
171 #include "nsString.h"
172 +#include "nsAbUtils.h"
174 class nsAbBoolExprToLDAPFilter
177 nsIAbBooleanConditionString* condition,
180 + static void GenerateMultipleFilter(
181 + nsAbBooleanConditionType conditionType,
183 + NS_ConvertUCS2toUTF8 &vUTF8,
184 + CharPtrArrayGuard *pAttrs);
185 + static void GenerateSingleFilter(
186 + nsAbBooleanConditionType conditionType,
188 + NS_ConvertUCS2toUTF8 &vUTF8,
189 + const char *ldapProperty);
193 Index: mailnews/addrbook/src/nsAbLDAPDirectory.cpp
194 ===================================================================
195 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp,v
196 retrieving revision 1.17
197 diff -u -r1.17 nsAbLDAPDirectory.cpp
198 --- misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp 14 Feb 2004 02:09:27 -0000 1.17
199 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectory.cpp 17 May 2004 03:23:53 -0000
200 @@ -118,11 +118,13 @@
202 // use mURINoQuery to get a prefName
203 nsCAutoString prefName;
204 - prefName = nsDependentCString(mURINoQuery.get() + kLDAPDirectoryRootLen) + NS_LITERAL_CSTRING(".uri");
205 + prefName = nsDependentCString(mURINoQuery.get() + kLDAPDirectoryRootLen) ;
207 // turn moz-abldapdirectory://ldap_2.servers.nscpphonebook into -> "ldap_2.servers.nscpphonebook.uri"
209 - rv = prefs->CopyCharPref(prefName.get(), getter_Copies(URI));
210 + nsCAutoString uriPrefName;
211 + uriPrefName = prefName + NS_LITERAL_CSTRING(".uri");
212 + rv = prefs->CopyCharPref(uriPrefName.get(), getter_Copies(URI));
217 nsCAutoString tempLDAPURL(mURINoQuery);
218 tempLDAPURL.ReplaceSubstring("moz-abldapdirectory:", "ldap:");
219 rv = mURL->SetSpec(tempLDAPURL);
220 + NS_ENSURE_SUCCESS(rv,rv);
222 + nsCAutoString aHost;
223 + mURL->GetHost(aHost);
224 + aHost.ReplaceChar('.','_');
225 + prefName = nsDependentCString("ldap_2.servers.") + aHost;
227 + rv = prefs->GetBoolPref(
228 + PromiseFlatCString(prefName
229 + + NS_LITERAL_CSTRING(".UseSSL")).get(),
233 + // If use SSL,ldap url will look like this ldaps://host:port/.....
234 + if (!NS_FAILED(rv) && useSSL)
236 + tempLDAPURL.ReplaceSubstring("ldap:", "ldaps:");
237 + rv = mURL->SetSpec(tempLDAPURL);
239 + //NS_FAILED(rv) means ldap_2.servers.nscpphonebook.UseSSL not exist
244 @@ -156,24 +179,29 @@
245 // get the login information, if there is any
247 rv = prefs->GetCharPref(
248 - PromiseFlatCString(
249 - Substring(mURINoQuery, kLDAPDirectoryRootLen,
250 - mURINoQuery.Length() - kLDAPDirectoryRootLen)
251 + PromiseFlatCString(prefName
252 + NS_LITERAL_CSTRING(".auth.dn")).get(),
253 getter_Copies(mLogin));
255 mLogin.Truncate(); // zero out mLogin
258 + // get the password information, if there is any
260 + rv = prefs->GetCharPref(
261 + PromiseFlatCString(prefName
262 + + NS_LITERAL_CSTRING(".auth.pwd")).get(),
263 + getter_Copies(mPassword));
264 + if (NS_FAILED(rv)) {
265 + mPassword.Truncate(); // zero out mLogin
267 // get the protocol version, if there is any. using a string pref
268 // here instead of an int, as protocol versions sometimes have names like
271 nsXPIDLCString protocolVersion;
272 rv = prefs->GetCharPref(
273 - PromiseFlatCString(
274 - Substring(mURINoQuery, kLDAPDirectoryRootLen,
275 - mURINoQuery.Length() - kLDAPDirectoryRootLen)
276 + PromiseFlatCString(prefName
277 + NS_LITERAL_CSTRING(".protocolVersion")).get(),
278 getter_Copies(protocolVersion));
280 Index: mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
281 ===================================================================
282 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp,v
283 retrieving revision 1.22
284 diff -u -r1.22 nsAbLDAPDirectoryQuery.cpp
285 --- misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp 14 Feb 2004 02:09:27 -0000 1.22
286 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp 17 May 2004 03:23:53 -0000
288 PRInt32 resultLimit = -1,
289 PRInt32 timeOut = 0);
290 virtual ~nsAbQueryLDAPMessageListener ();
292 + void SetPassword(const nsAString& aPassword){m_sPassword = aPassword;};
294 nsresult OnLDAPMessageBind (nsILDAPMessage *aMessage);
295 nsresult OnLDAPMessageSearchEntry (nsILDAPMessage *aMessage,
300 + nsAutoString m_sPassword;
302 nsCOMPtr<nsILDAPOperation> mSearchOperation;
307 // If mLogin is set, we're expected to use it to get a password.
309 - if (!mDirectoryQuery->mLogin.IsEmpty()) {
310 + if (!mDirectoryQuery->mLogin.IsEmpty() && !m_sPassword.Length()) {
311 // XXX hack until nsUTF8AutoString exists
312 #define nsUTF8AutoString nsCAutoString
313 nsUTF8AutoString spec;
314 @@ -398,10 +400,13 @@
315 rv = ldapOperation->Init(mConnection, proxyListener, nsnull);
316 NS_ENSURE_SUCCESS(rv, rv);
319 - rv = ldapOperation->SimpleBind(NS_ConvertUCS2toUTF8(passwd));
322 + if (m_sPassword.Length())
323 + rv = ldapOperation->SimpleBind(NS_ConvertUCS2toUTF8(m_sPassword));
325 + rv = ldapOperation->SimpleBind(NS_ConvertUCS2toUTF8(passwd));
326 NS_ENSURE_SUCCESS(rv, rv);
332 rv = getLdapReturnAttributes (arguments, returnAttributes);
333 NS_ENSURE_SUCCESS(rv, rv);
338 nsCOMPtr<nsISupports> supportsExpression;
339 rv = arguments->GetExpression (getter_AddRefs (supportsExpression));
342 if (_messageListener == NULL)
343 return NS_ERROR_OUT_OF_MEMORY;
345 + nsAutoString wPassword;
346 + wPassword.AssignWithConversion(mPassword.get());
347 + _messageListener->SetPassword(wPassword);
349 messageListener = _messageListener;
350 nsVoidKey key (NS_REINTERPRET_CAST(void *,contextID));
352 Index: mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h
353 ===================================================================
354 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h,v
355 retrieving revision 1.6
356 diff -u -r1.6 nsAbLDAPDirectoryQuery.h
357 --- misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h 14 Feb 2004 02:09:27 -0000 1.6
358 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.h 17 May 2004 03:23:53 -0000
360 nsresult RemoveListener (PRInt32 contextID);
361 nsresult Initiate ();
362 nsXPIDLCString mLogin; // authenticate to the LDAP server as...
363 + nsXPIDLCString mPassword; // password to the LDAP server as...
364 nsCOMPtr<nsILDAPURL> mDirectoryUrl; // the URL for the server
365 PRUint32 mProtocolVersion; // version of LDAP (see nsILDAPConnection.idl)
367 Index: mailnews/addrbook/src/nsAbLDAPProperties.cpp
368 ===================================================================
369 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp,v
370 retrieving revision 1.11
371 diff -u -r1.11 nsAbLDAPProperties.cpp
372 --- misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp 22 Mar 2003 15:43:29 -0000 1.11
373 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.cpp 17 May 2004 03:23:53 -0000
375 #include "nsAbLDAPProperties.h"
377 #include "nsAbUtils.h"
380 #include "nsCOMPtr.h"
381 #include "nsString.h"
383 If there are multiple entries for a mozilla
384 property the first takes precedence.
386 + But where we need to do a query against
387 + a multiple occurring ldap attribute we
388 + need to OR all the possible ldap entries e.g.
390 + (CellularNumber=123456) translates to
391 + (|(mobile=123456)(&(!(mobile=*))(cellphone=123456))(&(!(mobile=*))(!(cellphone=*))(carphone=123456)))
393 + i.e. use the first occurring attribute otherwise if
394 + first does not exist use the second etc.
396 + [Multiple occurring ldap attributes do not
397 + include aliases. We have also ignored the case
398 + for including 'displayname' as the first occurring
399 + attribute 'cn' is a required attribute.]
403 1) Generality is maintained when mapping from
404 @@ -101,52 +117,32 @@
405 {MozillaProperty_String, "FaxNumber", "fax"},
406 // organizationalPerson
407 {MozillaProperty_String, "FaxNumber", "facsimiletelephonenumber"},
409 - {MozillaProperty_String, "PagerNumber", "pager"},
411 - {MozillaProperty_String, "PagerNumber", "pagerphone"},
413 - {MozillaProperty_String, "CellularNumber", "mobile"},
415 - {MozillaProperty_String, "CellularNumber", "cellphone"},
417 - {MozillaProperty_String, "CellularNumber", "carphone"},
419 + {MozillaProperty_String, "PagerNumber", "pager,pagerphone"},
420 + // inetOrgPerson,?,?
421 + {MozillaProperty_String, "CellularNumber", "mobile,cellphone,carphone"},
423 // No Home* properties defined yet
425 - // organizationalPerson
426 - {MozillaProperty_String, "WorkAddress", "postofficebox"},
428 - {MozillaProperty_String, "WorkAddress", "streetaddress"},
429 + // organizationalPerson,?
430 + {MozillaProperty_String, "WorkAddress", "postofficebox,streetaddress"},
432 {MozillaProperty_String, "WorkCity", "l"},
434 {MozillaProperty_String, "WorkCity", "locality"},
436 - {MozillaProperty_String, "WorkState", "st"},
438 - {MozillaProperty_String, "WorkState", "region"},
439 - // organizationalPerson
440 - {MozillaProperty_String, "WorkZipCode", "postalcode"},
442 - {MozillaProperty_String, "WorkZipCode", "zip"},
443 + {MozillaProperty_String, "WorkState", "st,region"},
444 + // organizationalPerson,?
445 + {MozillaProperty_String, "WorkZipCode", "postalcode,zip"},
447 {MozillaProperty_String, "WorkCountry", "countryname"},
449 // organizationalPerson
450 {MozillaProperty_String, "JobTitle", "title"},
452 - {MozillaProperty_String, "Department", "ou"},
454 - {MozillaProperty_String, "Department", "orgunit"},
456 - {MozillaProperty_String, "Department", "department"},
458 - {MozillaProperty_String, "Department", "departmentnumber"},
460 - {MozillaProperty_String, "Company", "o"},
462 - {MozillaProperty_String, "Company", "company"},
463 + {MozillaProperty_String, "Department", "ou,orgunit,department,departmentnumber"},
465 + {MozillaProperty_String, "Company", "o,company"},
467 {MozillaProperty_String, "WorkCountry", "countryname"},
471 {MozillaProperty_String, "Custom4", "custom4"},
474 - {MozillaProperty_String, "Notes", "notes"},
476 - {MozillaProperty_String, "Notes", "description"},
478 + {MozillaProperty_String, "Notes", "notes,description"},
481 {MozillaProperty_Int, "PreferMailFormat", "xmozillausehtmlmail"},
482 @@ -209,10 +203,22 @@
483 if (IsInitialized) { return ; }
485 for (int i = tableSize - 1 ; i >= 0 ; -- i) {
486 - nsCStringKey keyMozilla (table [i].mozillaProperty, -1, nsCStringKey::NEVER_OWN);
487 - nsCStringKey keyLdap (table [i].ldapProperty, -1, nsCStringKey::NEVER_OWN);
489 + char *attrToken = nsnull;
490 + char *LDAPProperty = nsCRT::strdup(table[i].ldapProperty);
491 + char *tmpLDAPProperty;
493 + attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty);
494 + while (attrToken != nsnull)
496 + while ( ' ' == *attrToken)
498 + nsCStringKey keyLdap (attrToken, -1, nsCStringKey::NEVER_OWN);
499 mLdapToMozilla.Put(&keyLdap, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(MozillaLdapPropertyRelation*, &table[i]))) ;
500 + attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty);
503 + nsCStringKey keyMozilla (table [i].mozillaProperty, -1, nsCStringKey::NEVER_OWN);
504 mMozillaToLdap.Put(&keyMozilla, NS_REINTERPRET_CAST(void *, NS_CONST_CAST(MozillaLdapPropertyRelation*, &table[i]))) ;
506 IsInitialized = PR_TRUE;
507 @@ -234,10 +240,13 @@
508 const MozillaLdapPropertyRelation* MozillaLdapPropertyRelator::findMozillaPropertyFromLdap (const char* ldapProperty)
512 + char *tmpLDAPProperty;
513 + attrToken = nsCRT::strtok(NS_CONST_CAST(char *,ldapProperty), ",", &tmpLDAPProperty);
514 // ensure that we always do a case insensitive comparison
515 // against the incoming ldap attributes.
516 - nsCAutoString lowercasedProp(ldapProperty);
517 - ToLowerCase(nsDependentCString(ldapProperty), lowercasedProp);
518 + nsCAutoString lowercasedProp (attrToken) ;
519 + ToLowerCase(nsDependentCString(attrToken),lowercasedProp);
520 nsCStringKey key(lowercasedProp);
522 return NS_REINTERPRET_CAST(const MozillaLdapPropertyRelation *, mLdapToMozilla.Get(&key)) ;
530 +// Parse the input string which may contain a single ldap attribute or multiple attributes in the form
531 +// "string" or "string1,string2,string3" respectively and assign to the array.
532 +nsresult MozillaLdapPropertyRelator::getAllLDAPAttrsFromMozilla (const char* aLDAPProperty, PRUint32 *aAttrCount, char * **aAttributes)
534 + NS_ENSURE_ARG_POINTER(aAttrCount);
535 + NS_ENSURE_ARG_POINTER(aAttributes);
537 + nsresult rv = NS_OK;
540 + // we must have at least one attribute
543 + // if no multiple ldap attributes then allocate our single entry and exit
544 + if (!strchr(aLDAPProperty,','))
546 + if (!(*aAttributes = NS_STATIC_CAST(char **, nsMemory::Alloc(sizeof(char *)))))
547 + return NS_ERROR_OUT_OF_MEMORY;
548 + if (!((*aAttributes)[0] = nsCRT::strdup(aLDAPProperty)))
549 + return NS_ERROR_OUT_OF_MEMORY;
554 + char *attrToken = nsnull;
555 + char *LDAPProperty = nsnull;
556 + char *tmpLDAPProperty;
558 + if((LDAPProperty = nsCRT::strdup(aLDAPProperty)) == nsnull)
559 + return NS_ERROR_OUT_OF_MEMORY;
561 + // set our tokenizer to the start
562 + attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty);
564 + // Count up the attribute names
565 + while ((attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty)) != nsnull)
568 + nsCRT::free (LDAPProperty);
569 + if(!(*aAttributes = NS_STATIC_CAST(char **, nsMemory::Alloc(*aAttrCount * sizeof(char *)))))
570 + return NS_ERROR_OUT_OF_MEMORY;
572 + if((LDAPProperty = nsCRT::strdup(aLDAPProperty)) == nsnull)
573 + return NS_ERROR_OUT_OF_MEMORY;
576 + attrToken = nsCRT::strtok(LDAPProperty, ",", &tmpLDAPProperty);
577 + while (nsnull != attrToken) {
578 + if(((*aAttributes)[j++] = nsCRT::strdup(attrToken)) == nsnull)
580 + nsCRT::free(LDAPProperty);
581 + return NS_ERROR_OUT_OF_MEMORY;
584 + attrToken = nsCRT::strtok(tmpLDAPProperty, ",", &tmpLDAPProperty);
587 + nsCRT::free(LDAPProperty);
590 Index: mailnews/addrbook/src/nsAbLDAPProperties.h
591 ===================================================================
592 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h,v
593 retrieving revision 1.7
594 diff -u -r1.7 nsAbLDAPProperties.h
595 --- misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h 9 Apr 2002 09:27:24 -0000 1.7
596 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbLDAPProperties.h 17 May 2004 03:23:53 -0000
598 static nsresult createCardPropertyFromLDAPMessage (nsILDAPMessage* message,
600 PRBool* hasSetCardProperty);
601 + static nsresult getAllLDAPAttrsFromMozilla (const char* aLDAPProperty, PRUint32 *aAttrCount, char * **aAttributes);
605 Index: mailnews/addrbook/src/nsAbMDBCardProperty.cpp
606 ===================================================================
607 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbMDBCardProperty.cpp,v
608 retrieving revision 1.15
609 diff -u -r1.15 nsAbMDBCardProperty.cpp
610 --- misc/build/mozilla/mailnews/addrbook/src/nsAbMDBCardProperty.cpp 12 Nov 2002 19:19:56 -0000 1.15
611 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbMDBCardProperty.cpp 17 May 2004 03:23:53 -0000
615 mCardDatabase->EditCard(this, PR_TRUE);
616 - mCardDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
618 + return mCardDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
621 return NS_ERROR_FAILURE;
622 Index: mailnews/addrbook/src/nsAbMDBDirectory.cpp
623 ===================================================================
624 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbMDBDirectory.cpp,v
625 retrieving revision 1.36
626 diff -u -r1.36 nsAbMDBDirectory.cpp
627 --- misc/build/mozilla/mailnews/addrbook/src/nsAbMDBDirectory.cpp 9 Mar 2004 14:42:24 -0000 1.36
628 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbMDBDirectory.cpp 17 May 2004 03:23:53 -0000
633 - mDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
634 + rv = mDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
639 return NS_ERROR_NOT_IMPLEMENTED;
644 rv = GetAbDatabase();
646 @@ -713,10 +714,11 @@
647 mDatabase->CreateNewListCardAndAddToDB(this, m_dbRowID, newCard, PR_TRUE);
649 mDatabase->CreateNewCardAndAddToDB(newCard, PR_TRUE);
650 - mDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
651 + rv = mDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
653 + NS_ENSURE_SUCCESS(rv, rv);
654 NS_IF_ADDREF(*addedCard = newCard);
659 NS_IMETHODIMP nsAbMDBDirectory::DropCard(nsIAbCard* aCard, PRBool needToCopyCard)
660 Index: mailnews/addrbook/src/nsAbOutlookCard.cpp
661 ===================================================================
662 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp,v
663 retrieving revision 1.14
664 diff -u -r1.14 nsAbOutlookCard.cpp
665 --- misc/build/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp 9 Mar 2004 15:18:40 -0000 1.14
666 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbOutlookCard.cpp 17 May 2004 03:23:53 -0000
669 index_DisplayName = 0,
671 + index_SecondEmailAddress,
675 @@ -124,32 +125,34 @@
677 static const ULONG OutlookCardMAPIProps [] =
680 - PR_EMAIL_ADDRESS_W,
684 - PR_BUSINESS_TELEPHONE_NUMBER_W,
685 - PR_HOME_TELEPHONE_NUMBER_W,
686 - PR_BUSINESS_FAX_NUMBER_W,
687 - PR_PAGER_TELEPHONE_NUMBER_W,
688 - PR_MOBILE_TELEPHONE_NUMBER_W,
689 - PR_HOME_ADDRESS_CITY_W,
690 - PR_HOME_ADDRESS_STATE_OR_PROVINCE_W,
691 - PR_HOME_ADDRESS_POSTAL_CODE_W,
692 - PR_HOME_ADDRESS_COUNTRY_W,
693 - PR_BUSINESS_ADDRESS_CITY_W,
694 - PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_W,
695 - PR_BUSINESS_ADDRESS_POSTAL_CODE_W,
696 - PR_BUSINESS_ADDRESS_COUNTRY_W,
698 - PR_DEPARTMENT_NAME_W,
700 - PR_BUSINESS_HOME_PAGE_W,
701 - PR_PERSONAL_HOME_PAGE_W,
703 + PR_DISPLAY_NAME_A,//0x8035001E
704 + PR_EMAIL_ADDRESS_A,//0x8034001E
705 + PR_SECOND_EMAIL_ADDRESS_A,//Second Email Address
709 + PR_BUSINESS_TELEPHONE_NUMBER_A,
710 + PR_HOME_TELEPHONE_NUMBER_A,
711 + PR_BUSINESS_FAX_NUMBER_A,
712 + PR_PAGER_TELEPHONE_NUMBER_A,
713 + PR_MOBILE_TELEPHONE_NUMBER_A,
714 + PR_HOME_ADDRESS_CITY_A,
715 + PR_HOME_ADDRESS_STATE_OR_PROVINCE_A,
716 + PR_HOME_ADDRESS_POSTAL_CODE_A,
717 + PR_HOME_ADDRESS_COUNTRY_A,
718 + PR_BUSINESS_ADDRESS_CITY_A,
719 + PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE_A,
720 + PR_BUSINESS_ADDRESS_POSTAL_CODE_A,
721 + PR_BUSINESS_ADDRESS_COUNTRY_A,
723 + PR_DEPARTMENT_NAME_A,
725 + PR_BUSINESS_HOME_PAGE_A,
726 + PR_PERSONAL_HOME_PAGE_A,
731 nsresult nsAbOutlookCard::Init(const char *aUri)
733 nsresult retCode = nsRDFResource::Init(aUri) ;
735 SetDisplayName(unichars [index_DisplayName]->get()) ;
736 SetNickName(unichars [index_NickName]->get()) ;
737 SetPrimaryEmail(unichars [index_EmailAddress]->get()) ;
738 + SetSecondEmail(unichars [index_SecondEmailAddress]->get()) ;
739 SetWorkPhone(unichars [index_WorkPhoneNumber]->get()) ;
740 SetHomePhone(unichars [index_HomePhoneNumber]->get()) ;
741 SetFaxNumber(unichars [index_WorkFaxNumber]->get()) ;
742 @@ -210,12 +214,12 @@
743 nsAutoString unichar ;
744 nsAutoString unicharBis ;
746 - if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_W, unichar)) {
747 + if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_A, unichar)) {
748 splitString(unichar, unicharBis) ;
749 SetHomeAddress(unichar.get()) ;
750 SetHomeAddress2(unicharBis.get()) ;
752 - if (mapiAddBook->GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_W, unichar)) {
753 + if (mapiAddBook->GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_A, unichar)) {
754 splitString(unichar, unicharBis) ;
755 SetWorkAddress(unichar.get()) ;
756 SetWorkAddress2(unicharBis.get()) ;
758 SetDisplayName(properties [index_DisplayName]) ;
759 GetNickName(getter_Copies(properties [index_NickName])) ;
760 GetPrimaryEmail(getter_Copies(properties [index_EmailAddress])) ;
761 + GetSecondEmail(getter_Copies(properties [index_SecondEmailAddress])) ;
762 GetWorkPhone(getter_Copies(properties [index_WorkPhoneNumber])) ;
763 GetHomePhone(getter_Copies(properties [index_HomePhoneNumber])) ;
764 GetFaxNumber(getter_Copies(properties [index_WorkFaxNumber])) ;
766 GetWebPage1(getter_Copies(properties [index_WorkWebPage])) ;
767 GetWebPage2(getter_Copies(properties [index_HomeWebPage])) ;
768 GetNotes(getter_Copies(properties [index_Comments])) ;
769 - if (!mapiAddBook->SetPropertiesUString(*mMapiData, OutlookCardMAPIProps,
770 - index_LastProp, properties)) {
771 - PRINTF(("Cannot set general properties.\n")) ;
774 + for (i=0;i<index_LastProp;i++)
776 + if (!mapiAddBook->SetPropertyUString(*mMapiData,
777 + OutlookCardMAPIProps[i],
780 + PRINTF(("Cannot set properties:%d.\n",OutlookCardMAPIProps[i])) ;
783 delete [] properties ;
784 nsXPIDLString unichar ;
785 Index: mailnews/addrbook/src/nsAbOutlookDirFactory.cpp
786 ===================================================================
787 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp,v
788 retrieving revision 1.9
789 diff -u -r1.9 nsAbOutlookDirFactory.cpp
790 --- misc/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp 25 Feb 2003 21:36:33 -0000 1.9
791 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp 17 May 2004 03:23:53 -0000
794 nsCOMPtr<nsIRDFResource> resource ;
796 - for (ULONG i = 0 ; i < folders.mNbEntries ; ++ i) {
797 - folders.mEntries [i].ToString(entryId) ;
798 + for (ULONG i = 0 ; i < folders.GetSize() ; ++ i) {
799 + folders[i].ToString(entryId) ;
800 buildAbWinUri(kOutlookDirectoryScheme, abType, uri) ;
801 uri.Append(entryId) ;
803 Index: mailnews/addrbook/src/nsAbOutlookDirectory.cpp
804 ===================================================================
805 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp,v
806 retrieving revision 1.18
807 diff -u -r1.18 nsAbOutlookDirectory.cpp
808 --- misc/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp 5 Feb 2004 18:33:06 -0000 1.18
809 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.cpp 17 May 2004 03:23:53 -0000
811 PRINTF(("Cannot get type.\n")) ;
812 return NS_ERROR_FAILURE ;
814 - if (!mapiAddBook->GetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, unichars)) {
815 + if (!mapiAddBook->GetPropertyUString(*mMapiData, PR_DISPLAY_NAME_A, unichars)) {
816 PRINTF(("Cannot get name.\n")) ;
817 return NS_ERROR_FAILURE ;
819 @@ -163,45 +163,85 @@
823 +nsresult nsAbOutlookDirectory::BuildCardFromURI(const nsCString& uriName,nsIAbCard **aNewCard,
824 + PRBool aSearchForOld, PRBool& aIsNewCard)
826 + nsresult retCode = NS_OK ;
827 + if (aSearchForOld) {
828 + nsCStringKey key(uriName) ;
829 + nsCOMPtr<nsISupports> existingCard = mCardList.Get(&key) ;
831 + if (existingCard) {
832 + nsCOMPtr<nsIAbCard> card(do_QueryInterface(existingCard, &retCode)) ;
834 + NS_ENSURE_SUCCESS(retCode, retCode) ;
835 + NS_IF_ADDREF(*aNewCard = card) ;
836 + aIsNewCard = PR_FALSE ;
840 + aIsNewCard = PR_TRUE ;
841 + nsCOMPtr<nsIRDFResource> resource ;
843 + nsCOMPtr<nsIAbCard> childCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &retCode);
844 + NS_ENSURE_SUCCESS(retCode, retCode) ;
845 + resource = do_QueryInterface(childCard, &retCode) ;
846 + NS_ENSURE_SUCCESS(retCode, retCode) ;
847 + retCode = resource->Init(uriName.get()) ;
848 + NS_ENSURE_SUCCESS(retCode, retCode) ;
849 + NS_IF_ADDREF(*aNewCard = childCard);
853 NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
855 if (!aCards) { return NS_ERROR_NULL_POINTER ; }
857 nsCOMPtr<nsISupportsArray> cardList ;
858 + nsCStringArray uriList ;
859 + nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
862 - mCardList.Reset() ;
864 retCode = StartSearch() ;
865 - NS_NewISupportsArray(getter_AddRefs(cardList)) ;
868 - retCode = GetChildCards(getter_AddRefs(cardList), nsnull) ;
869 + retCode = GetChildCards(uriList, nsnull) ;
871 + NS_NewISupportsArray(getter_AddRefs(cardList)) ;
872 if (NS_SUCCEEDED(retCode)) {
873 // Fill the results array and update the card list
874 // Also update the address list and notify any changes.
875 PRUint32 nbCards = 0 ;
876 - nsCOMPtr<nsISupports> element ;
877 + nsCAutoString uriName;
878 + nsCOMPtr <nsIAbCard> childCard;
879 + PRBool searchForOldCards = 0; //(mCardList.Count() != 0) ;
881 + nbCards = uriList.Count();
882 + NS_NewISupportsArray(getter_AddRefs(m_AddressList));
884 - cardList->Enumerate(aCards) ;
885 - cardList->Count(&nbCards) ;
886 for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
887 - cardList->GetElementAt(i, getter_AddRefs(element)) ;
888 - nsVoidKey newKey (NS_STATIC_CAST(void *, element)) ;
889 - nsCOMPtr<nsISupports> oldElement = mCardList.Get(&newKey) ;
890 + PRBool isNewCard = PR_FALSE ;
893 + uriList.CStringAt(i,uriName);
894 + retCode = BuildCardFromURI(uriName,getter_AddRefs(childCard), searchForOldCards, isNewCard);
895 + NS_ENSURE_SUCCESS(retCode, retCode) ;
896 + cardList->AppendElement(childCard);
899 // We are dealing with a new element (probably directly
900 // added from Outlook), we may need to sync m_AddressList
901 - mCardList.Put(&newKey, element) ;
902 - nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
903 + nsCStringKey newKey(uriName) ;
905 + mCardList.Put(&newKey, childCard) ;
906 + nsCOMPtr<nsIAbCard> card (do_QueryInterface(childCard, &retCode)) ;
908 NS_ENSURE_SUCCESS(retCode, retCode) ;
909 PRBool isMailList = PR_FALSE ;
911 retCode = card->GetIsMailList(&isMailList) ;
912 NS_ENSURE_SUCCESS(retCode, retCode) ;
915 // We can have mailing lists only in folder,
916 // we must add the directory to m_AddressList
917 @@ -224,18 +264,33 @@
918 NotifyItemAddition(card) ;
922 - NS_ASSERTION(oldElement == element, "Different card stored") ;
925 + return cardList->Enumerate(aCards) ;
928 +static nsresult ExtractUriFromCard(nsIAbCard *aCard, nsCString& aUri) {
929 + nsresult retCode = NS_OK ;
930 + nsCOMPtr<nsIRDFResource> resource (do_QueryInterface(aCard, &retCode)) ;
932 + // Receiving a non-RDF card is accepted
933 + if (NS_FAILED(retCode)) { return NS_OK ; }
934 + nsXPIDLCString uri ;
936 + retCode = resource->GetValue(getter_Copies(uri)) ;
937 + NS_ENSURE_SUCCESS(retCode, retCode) ;
942 NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
944 if (!aCard || !aHasCard) { return NS_ERROR_NULL_POINTER ; }
945 - nsVoidKey key (NS_STATIC_CAST(void *, aCard)) ;
946 + *aHasCard = PR_FALSE ;
949 + ExtractUriFromCard(aCard, uri) ;
950 + nsCStringKey key(uri) ;
952 *aHasCard = mCardList.Exists(&key) ;
955 PRINTF(("Cannot delete card %s.\n", entryString.get())) ;
958 - nsVoidKey key (NS_STATIC_CAST(void *, element)) ;
961 + ExtractUriFromCard(card, uri) ;
962 + nsCStringKey key(uri) ;
964 mCardList.Remove(&key) ;
965 if (m_IsMailList) { m_AddressList->RemoveElement(element) ; }
968 retCode = CreateCard(aData, addedCard) ;
969 NS_ENSURE_SUCCESS(retCode, retCode) ;
970 - nsVoidKey newKey (NS_STATIC_CAST(void *, *addedCard)) ;
973 + ExtractUriFromCard(*addedCard, uri) ;
974 + nsCStringKey newKey(uri) ;
976 mCardList.Put(&newKey, *addedCard) ;
977 if (m_IsMailList) { m_AddressList->AppendElement(*addedCard) ; }
979 if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
980 retCode = GetDirName(getter_Copies(name)) ;
981 NS_ENSURE_SUCCESS(retCode, retCode) ;
982 - if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_DISPLAY_NAME_W, name.get())) {
983 + if (!mapiAddBook->SetPropertyUString(*mMapiData, PR_DISPLAY_NAME_A, name.get())) {
984 return NS_ERROR_FAILURE ;
986 retCode = CommitAddressList() ;
988 {"DisplayName", PR_DISPLAY_NAME_A},
989 {"NickName", PR_NICKNAME_A},
990 {"PrimaryEmail", PR_EMAIL_ADDRESS_A},
991 + {"SecondEmail",PR_SECOND_EMAIL_ADDRESS_A},
992 {"WorkPhone", PR_BUSINESS_TELEPHONE_NUMBER_A},
993 {"HomePhone", PR_HOME_TELEPHONE_NUMBER_A},
994 {"FaxNumber", PR_BUSINESS_FAX_NUMBER_A},
995 @@ -1032,7 +1094,10 @@
997 nsresult nsAbOutlookDirectory::OnSearchFoundCard(nsIAbCard *aCard)
999 - nsVoidKey newKey (NS_STATIC_CAST(void *, aCard)) ;
1002 + ExtractUriFromCard(aCard, uri) ;
1003 + nsCStringKey newKey(uri) ;
1004 nsresult retCode = NS_OK ;
1006 mCardList.Put(&newKey, aCard) ;
1007 @@ -1056,14 +1121,14 @@
1008 retCode = BuildRestriction(aArguments, arguments) ;
1009 NS_ENSURE_SUCCESS(retCode, retCode) ;
1010 nsCOMPtr<nsISupportsArray> resultsArray ;
1011 + nsCStringArray uriArray ;
1012 PRUint32 nbResults = 0 ;
1014 - retCode = GetChildCards(getter_AddRefs(resultsArray),
1015 + retCode = GetChildCards(uriArray,
1016 arguments.rt == RES_COMMENT ? nsnull : &arguments) ;
1017 DestroyRestriction(arguments) ;
1018 NS_ENSURE_SUCCESS(retCode, retCode) ;
1019 - retCode = resultsArray->Count(&nbResults) ;
1020 - NS_ENSURE_SUCCESS(retCode, retCode) ;
1021 + nbResults = uriArray.Count() ;
1022 nsCOMPtr<nsIAbDirectoryQueryResult> result ;
1023 nsAbDirectoryQueryResult *newResult = nsnull ;
1025 @@ -1071,15 +1136,18 @@
1026 nbResults = NS_STATIC_CAST(PRUint32, aResultLimit) ;
1029 - nsCOMPtr<nsISupports> element ;
1030 nsCOMPtr<nsISupportsArray> propertyValues ;
1032 + nsCAutoString uriName;
1033 + nsCOMPtr <nsIAbCard> card;
1035 for (i = 0 ; i < nbResults ; ++ i) {
1036 - retCode = resultsArray->GetElementAt(i, getter_AddRefs(element)) ;
1037 - NS_ENSURE_SUCCESS(retCode, retCode) ;
1038 - nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
1039 + PRBool isNewCard = PR_FALSE ;
1041 + uriArray.CStringAt(i,uriName);
1042 + retCode = BuildCardFromURI(uriName,getter_AddRefs(card), PR_FALSE, isNewCard);
1043 NS_ENSURE_SUCCESS(retCode, retCode) ;
1045 FillPropertyValues(card, aArguments, getter_AddRefs(propertyValues)) ;
1046 newResult = new nsAbDirectoryQueryResult(0, aArguments,
1047 nsIAbDirectoryQueryResult::queryResultMatch,
1048 @@ -1104,13 +1172,43 @@
1049 if (!aCards) { return NS_ERROR_NULL_POINTER ; }
1051 nsresult retCode = NS_OK ;
1052 - nsCOMPtr<nsISupportsArray> cards ;
1054 + nsCOMPtr<nsISupportsArray> cards;
1055 + retCode = NS_NewISupportsArray(getter_AddRefs(cards));
1056 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1058 + nsCStringArray uriList;
1059 + retCode = GetChildCards(uriList,aRestriction);
1060 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1062 + nsCAutoString uriName;
1063 + nsCOMPtr <nsIAbCard> childCard;
1064 + PRUint32 nbURIs = 0 ;
1065 + nbURIs = uriList.Count();
1068 + for (i = 0 ; i < nbURIs ; ++ i) {
1069 + PRBool isNewCard = PR_FALSE ;
1071 + uriList.CStringAt(i,uriName);
1072 + retCode = BuildCardFromURI(uriName,getter_AddRefs(childCard), PR_TRUE, isNewCard);
1073 + NS_ENSURE_SUCCESS(retCode, retCode) ;
1074 + cards->AppendElement(childCard);
1077 + NS_IF_ADDREF(*aCards = cards);
1081 +nsresult nsAbOutlookDirectory::GetChildCards(nsCStringArray& aURI,
1082 + void *aRestriction)
1084 + nsresult retCode = NS_OK ;
1085 nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
1086 nsMapiEntryArray cardEntries ;
1087 LPSRestriction restriction = (LPSRestriction) aRestriction ;
1089 if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
1090 - retCode = NS_NewISupportsArray(getter_AddRefs(cards)) ;
1091 NS_ENSURE_SUCCESS(retCode, retCode) ;
1092 if (!mapiAddBook->GetCards(*mMapiData, restriction, cardEntries)) {
1093 PRINTF(("Cannot get cards.\n")) ;
1094 @@ -1119,22 +1217,14 @@
1095 nsCAutoString entryId ;
1096 nsCAutoString uriName ;
1097 nsCOMPtr<nsIRDFResource> resource ;
1098 - nsCOMPtr <nsIAbCard> childCard;
1100 - for (ULONG card = 0 ; card < cardEntries.mNbEntries ; ++ card) {
1101 - cardEntries.mEntries [card].ToString(entryId) ;
1104 + for (ULONG card = 0 ; card < cardEntries.GetSize() ; ++ card) {
1105 + cardEntries [card].ToString(entryId) ;
1106 buildAbWinUri(kOutlookCardScheme, mAbWinType, uriName) ;
1107 uriName.Append(entryId) ;
1108 - childCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &retCode);
1109 - NS_ENSURE_SUCCESS(retCode, retCode) ;
1110 - resource = do_QueryInterface(childCard, &retCode) ;
1111 - NS_ENSURE_SUCCESS(retCode, retCode) ;
1112 - retCode = resource->Init(uriName.get()) ;
1113 - NS_ENSURE_SUCCESS(retCode, retCode) ;
1114 - cards->AppendElement(childCard) ;
1115 + aURI.AppendCString(uriName);
1118 - NS_ADDREF(*aCards) ;
1122 @@ -1158,8 +1248,8 @@
1123 nsCAutoString uriName ;
1124 nsCOMPtr <nsIRDFResource> resource ;
1126 - for (ULONG node = 0 ; node < nodeEntries.mNbEntries ; ++ node) {
1127 - nodeEntries.mEntries [node].ToString(entryId) ;
1128 + for (ULONG node = 0 ; node < nodeEntries.GetSize() ; ++ node) {
1129 + nodeEntries [node].ToString(entryId) ;
1130 buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uriName) ;
1131 uriName.Append(entryId) ;
1132 retCode = gRDFService->GetResource(uriName, getter_AddRefs(resource)) ;
1133 @@ -1280,7 +1370,7 @@
1134 // In the case of a mailing list, we cannot directly create a new card,
1135 // we have to create a temporary one in a real folder (to be able to use
1136 // templates) and then copy it to the mailing list.
1137 - if (m_IsMailList) {
1138 + if (m_IsMailList && mAbWinType == nsAbWinType_OutlookExp) {
1139 nsMapiEntry parentEntry ;
1140 nsMapiEntry temporaryEntry ;
1142 Index: mailnews/addrbook/src/nsAbOutlookDirectory.h
1143 ===================================================================
1144 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h,v
1145 retrieving revision 1.6
1146 diff -u -r1.6 nsAbOutlookDirectory.h
1147 --- misc/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h 5 Feb 2004 18:33:06 -0000 1.6
1148 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbOutlookDirectory.h 17 May 2004 03:23:53 -0000
1150 #include "nsHashtable.h"
1152 #include "nsISupportsArray.h"
1153 +#include "nsVoidArray.h"
1155 struct nsMapiEntry ;
1159 // Retrieve hierarchy as cards, with an optional restriction
1160 nsresult GetChildCards(nsISupportsArray **aCards, void *aRestriction) ;
1161 + // Retrieve hierarchy as URIs, with an optional restriction
1162 + nsresult GetChildCards(nsCStringArray& aURI, void *aRestriction) ;
1163 // Retrieve hierarchy as directories
1164 nsresult GetChildNodes(nsISupportsArray **aNodes) ;
1165 // Create a new card
1167 nsresult CommitAddressList(void) ;
1168 // Read MAPI repository
1169 nsresult UpdateAddressList(void) ;
1170 + // Search for an existing card or build a new one
1171 + nsresult BuildCardFromURI(const nsCString& uriName,nsIAbCard **aNewCard,
1172 + PRBool aSearchForOld, PRBool& aIsNewCard) ;
1174 nsMapiEntry *mMapiData ;
1175 // Container for the query threads
1176 Index: mailnews/addrbook/src/nsAbWinHelper.cpp
1177 ===================================================================
1178 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp,v
1179 retrieving revision 1.13
1180 diff -u -r1.13 nsAbWinHelper.cpp
1181 --- misc/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp 24 Dec 2003 19:55:05 -0000 1.13
1182 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.cpp 17 May 2004 03:23:53 -0000
1184 #define USES_IID_IABContainer
1185 #define USES_IID_IMAPITable
1186 #define USES_IID_IDistList
1187 +#define USES_IID_IMsgStore
1188 +#define USES_IID_IMessage
1189 +#define USES_IID_IMAPIFolder
1191 #include "nsAbWinHelper.h"
1192 #include "nsAbUtils.h"
1195 #define PRINTF(args) PR_LOG(gAbWinHelperLog, PR_LOG_DEBUG, args)
1197 -// Small utility to ensure release of all MAPI interfaces
1198 -template <class tInterface> struct nsMapiInterfaceWrapper
1200 - tInterface mInterface ;
1202 - nsMapiInterfaceWrapper(void) : mInterface(NULL) {}
1203 - ~nsMapiInterfaceWrapper(void) {
1204 - if (mInterface != NULL) { mInterface->Release() ; }
1206 - operator LPUNKNOWN *(void) { return NS_REINTERPRET_CAST(LPUNKNOWN *, &mInterface) ; }
1207 - tInterface operator -> (void) const { return mInterface ; }
1208 - operator tInterface *(void) { return &mInterface ; }
1211 static void assignEntryID(LPENTRYID& aTarget, LPENTRYID aSource, ULONG aByteCount)
1213 @@ -249,24 +239,28 @@
1214 MOZ_DECL_CTOR_COUNTER(nsMapiEntryArray)
1216 nsMapiEntryArray::nsMapiEntryArray(void)
1217 -: mEntries(NULL), mNbEntries(0)
1219 MOZ_COUNT_CTOR(nsMapiEntryArray) ;
1222 nsMapiEntryArray::~nsMapiEntryArray(void)
1224 - if (mEntries) { delete [] mEntries ; }
1226 MOZ_COUNT_DTOR(nsMapiEntryArray) ;
1229 +void nsMapiEntryArray::AddItem(nsMapiEntry * aEntries)
1231 + m_array.AppendElement(aEntries);
1233 void nsMapiEntryArray::CleanUp(void)
1235 - if (mEntries != NULL) {
1236 - delete [] mEntries ;
1239 + nsMapiEntry *pEntries;
1240 + for (int i = 0; i < m_array.Count(); i++)
1242 + pEntries = (nsMapiEntry *)m_array.ElementAt( i);
1248 MOZ_DECL_CTOR_COUNTER(nsAbWinHelper)
1249 @@ -280,100 +274,55 @@
1250 // same protection (MAPI is supposed to be thread-safe).
1251 PRLock *nsAbWinHelper::mMutex = PR_NewLock() ;
1253 +int nsAbWinHelper::m_clients = 0;
1255 +PRUnichar * nsAbWinHelper::m_pUniBuff = NULL;
1256 +int nsAbWinHelper::m_uniBuffLen = 0;
1257 +char * nsAbWinHelper::m_pCStrBuff = NULL;
1258 +int nsAbWinHelper::m_cstrBuffLen = 0;
1260 nsAbWinHelper::nsAbWinHelper(void)
1261 -: mAddressBook(NULL), mLastError(S_OK)
1264 MOZ_COUNT_CTOR(nsAbWinHelper) ;
1268 nsAbWinHelper::~nsAbWinHelper(void)
1270 MOZ_COUNT_DTOR(nsAbWinHelper) ;
1273 -BOOL nsAbWinHelper::GetFolders(nsMapiEntryArray& aFolders)
1277 - aFolders.CleanUp() ;
1278 - nsMapiInterfaceWrapper<LPABCONT> rootFolder ;
1279 - nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
1280 - ULONG objType = 0 ;
1281 - ULONG rowCount = 0 ;
1282 - SRestriction restriction ;
1283 - SPropTagArray folderColumns ;
1285 - mLastError = mAddressBook->OpenEntry(0, NULL, NULL, 0, &objType,
1287 - if (HR_FAILED(mLastError)) {
1288 - PRINTF(("Cannot open root %08x.\n", mLastError)) ;
1290 + delete [] m_pUniBuff;
1291 + m_pUniBuff = NULL;
1293 + delete [] m_pCStrBuff;
1294 + m_pCStrBuff = NULL;
1295 + m_cstrBuffLen = 0;
1297 - mLastError = rootFolder->GetHierarchyTable(0, folders) ;
1298 - if (HR_FAILED(mLastError)) {
1299 - PRINTF(("Cannot get hierarchy %08x.\n", mLastError)) ;
1302 - // We only take into account modifiable containers,
1303 - // otherwise, we end up with all the directory services...
1304 - restriction.rt = RES_BITMASK ;
1305 - restriction.res.resBitMask.ulPropTag = PR_CONTAINER_FLAGS ;
1306 - restriction.res.resBitMask.relBMR = BMR_NEZ ;
1307 - restriction.res.resBitMask.ulMask = AB_MODIFIABLE ;
1308 - mLastError = folders->Restrict(&restriction, 0) ;
1309 - if (HR_FAILED(mLastError)) {
1310 - PRINTF(("Cannot restrict table %08x.\n", mLastError)) ;
1312 - folderColumns.cValues = 1 ;
1313 - folderColumns.aulPropTag [0] = PR_ENTRYID ;
1314 - mLastError = folders->SetColumns(&folderColumns, 0) ;
1315 - if (HR_FAILED(mLastError)) {
1316 - PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
1319 - mLastError = folders->GetRowCount(0, &rowCount) ;
1320 - if (HR_SUCCEEDED(mLastError)) {
1321 - aFolders.mEntries = new nsMapiEntry [rowCount] ;
1322 - aFolders.mNbEntries = 0 ;
1324 - LPSRowSet rowSet = NULL ;
1327 - mLastError = folders->QueryRows(1, 0, &rowSet) ;
1328 - if (HR_SUCCEEDED(mLastError)) {
1329 - rowCount = rowSet->cRows ;
1330 - if (rowCount > 0) {
1331 - nsMapiEntry& current = aFolders.mEntries [aFolders.mNbEntries ++] ;
1332 - SPropValue& currentValue = rowSet->aRow->lpProps [0] ;
1334 - current.Assign(currentValue.Value.bin.cb,
1335 - NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
1337 - MyFreeProws(rowSet) ;
1340 - PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
1342 - } while (rowCount > 0) ;
1344 - return HR_SUCCEEDED(mLastError) ;
1348 BOOL nsAbWinHelper::GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction,
1349 nsMapiEntryArray& aCards)
1352 - return GetContents(aParent, aRestriction, &aCards.mEntries, aCards.mNbEntries, 0) ;
1353 + return GetContents(aParent, aRestriction, &aCards, 0) ;
1356 BOOL nsAbWinHelper::GetNodes(const nsMapiEntry& aParent, nsMapiEntryArray& aNodes)
1359 - return GetContents(aParent, NULL, &aNodes.mEntries, aNodes.mNbEntries, MAPI_DISTLIST) ;
1360 + return GetContents(aParent, NULL, &aNodes, MAPI_DISTLIST) ;
1363 BOOL nsAbWinHelper::GetCardsCount(const nsMapiEntry& aParent, ULONG& aNbCards)
1366 - return GetContents(aParent, NULL, NULL, aNbCards, 0) ;
1367 + nsMapiEntryArray aCards;
1368 + BOOL ret=GetContents(aParent, NULL, &aCards, 0) ;
1369 + aNbCards=aCards.GetSize();
1373 BOOL nsAbWinHelper::GetPropertyString(const nsMapiEntry& aObject,
1375 aName = values->Value.lpszA ;
1377 else if (PROP_TYPE(values->ulPropTag) == PT_UNICODE) {
1378 - aName.AssignWithConversion(values->Value.lpszW) ;
1379 + UnicodeToCStr(values->Value.lpszW,aName) ;
1382 FreeBuffer(values) ;
1384 aName = values->Value.lpszW ;
1386 else if (PROP_TYPE(values->ulPropTag) == PT_STRING8) {
1387 - aName.AssignWithConversion(values->Value.lpszA) ;
1388 + CStrToUnicode(values->Value.lpszA,aName) ;
1391 FreeBuffer(values) ;
1392 @@ -431,16 +380,22 @@
1395 for (i = 0 ; i < valueCount ; ++ i) {
1396 - if (PROP_ID(values [i].ulPropTag) == PROP_ID(aPropertyTags [i])) {
1397 + if (PROP_TYPE( values [i].ulPropTag) != PT_ERROR && values [i].Value.l != MAPI_E_NOT_FOUND){
1398 if (PROP_TYPE(values [i].ulPropTag) == PT_STRING8) {
1401 - temp.AssignWithConversion (values [i].Value.lpszA) ;
1402 + CStrToUnicode(values [i].Value.lpszA,temp) ;
1403 aNames.AppendString(temp) ;
1405 else if (PROP_TYPE(values [i].ulPropTag) == PT_UNICODE) {
1406 aNames.AppendString(nsAutoString (values [i].Value.lpszW)) ;
1408 + else if (aPropertyTags [i] == PR_EMAIL_ADDRESS_A) {
1409 + nsAutoString temp ;
1411 + CStrToUnicode (values [i].Value.lpszA,temp) ;
1412 + aNames.AppendString(temp) ;
1415 aNames.AppendString(nsAutoString((const PRUnichar *) "")) ;
1418 if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount)) { return FALSE ; }
1419 if (valueCount == 1 && values != NULL && PROP_TYPE(values->ulPropTag) == PT_SYSTIME) {
1420 SYSTEMTIME readableTime ;
1422 if (FileTimeToSystemTime(&values->Value.ft, &readableTime)) {
1423 aYear = readableTime.wYear ;
1424 aMonth = readableTime.wMonth ;
1426 nsMapiInterfaceWrapper<LPMAPIPROP> subObject ;
1429 - mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1430 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1431 &IID_IMAPIContainer, 0, &objType,
1433 if (HR_FAILED(mLastError)) {
1436 SBinaryArray entryArray ;
1438 - mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1439 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1440 &IID_IABContainer, MAPI_MODIFY, &objType,
1442 if (HR_FAILED(mLastError)) {
1443 @@ -567,14 +521,15 @@
1444 value.Value.lpszW = NS_CONST_CAST(WORD *, aValue) ;
1446 else if (PROP_TYPE(aPropertyTag) == PT_STRING8) {
1447 - alternativeValue.AssignWithConversion(aValue) ;
1448 + UnicodeToCStr(aValue,alternativeValue) ;
1449 value.Value.lpszA = NS_CONST_CAST(char *, alternativeValue.get()) ;
1452 PRINTF(("Property %08x is not a string.\n", aPropertyTag)) ;
1455 - return SetMAPIProperties(aObject, 1, &value) ;
1456 + LPSPropValue values=&value;
1457 + return SetMAPIProperties(aObject, 1, values) ;
1460 BOOL nsAbWinHelper::SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
1462 values [currentValue ++].Value.lpszW = NS_CONST_CAST(WORD *, aValues [i].get()) ;
1464 else if (PROP_TYPE(aPropertiesTag [i]) == PT_STRING8) {
1465 - alternativeValue.AssignWithConversion(aValues [i].get()) ;
1466 + UnicodeToCStr(aValues [i].get(),alternativeValue) ;
1467 char *av = nsCRT::strdup(alternativeValue.get()) ;
1471 readableTime.wSecond = 0 ;
1472 readableTime.wMilliseconds = 0 ;
1473 if (SystemTimeToFileTime(&readableTime, &value.Value.ft)) {
1474 - return SetMAPIProperties(aObject, 1, &value) ;
1475 + LPSPropValue values=&value;
1476 + return SetMAPIProperties(aObject, 1, values) ;
1481 nsMapiInterfaceWrapper<LPABCONT> container ;
1484 - mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
1485 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
1486 &IID_IABContainer, MAPI_MODIFY, &objType,
1488 if (HR_FAILED(mLastError)) {
1490 nsMapiInterfaceWrapper<LPABCONT> container ;
1493 - mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
1494 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
1495 &IID_IABContainer, MAPI_MODIFY, &objType,
1497 if (HR_FAILED(mLastError)) {
1499 nsMapiInterfaceWrapper<LPABCONT> container ;
1502 - mLastError = mAddressBook->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1503 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
1504 &IID_IABContainer, MAPI_MODIFY, &objType,
1506 if (HR_FAILED(mLastError)) {
1507 @@ -810,194 +766,77 @@
1511 -BOOL nsAbWinHelper::GetDefaultContainer(nsMapiEntry& aContainer)
1513 - LPENTRYID entryId = NULL ;
1514 - ULONG byteCount = 0 ;
1516 - mLastError = mAddressBook->GetPAB(&byteCount, &entryId) ;
1517 - if (HR_FAILED(mLastError)) {
1518 - PRINTF(("Cannot get PAB %08x.\n", mLastError)) ;
1521 - aContainer.Assign(byteCount, entryId) ;
1522 - FreeBuffer(entryId) ;
1528 - ContentsColumnEntryId = 0,
1529 - ContentsColumnObjectType,
1530 - ContentsColumnsSize
1533 -static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
1535 - ContentsColumnsSize,
1542 -BOOL nsAbWinHelper::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
1543 - nsMapiEntry **aList, ULONG& aNbElements, ULONG aMapiType)
1544 +void nsAbWinHelper::MyFreeProws(LPSRowSet aRowset)
1546 - if (aList != NULL) { *aList = NULL ; }
1548 - nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
1549 - nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
1550 - ULONG objType = 0 ;
1551 - ULONG rowCount = 0 ;
1552 + if (aRowset == NULL) { return ; }
1555 - mLastError = mAddressBook->OpenEntry(aParent.mByteCount, aParent.mEntryId,
1556 - &IID_IMAPIContainer, 0, &objType,
1558 - if (HR_FAILED(mLastError)) {
1559 - PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
1562 - // Here, flags for WAB and MAPI could be different, so this works
1563 - // only as long as we don't want to use any flag in GetContentsTable
1564 - mLastError = parent->GetContentsTable(0, contents) ;
1565 - if (HR_FAILED(mLastError)) {
1566 - PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
1568 + for (i = 0 ; i < aRowset->cRows ; ++ i) {
1569 + FreeBuffer(aRowset->aRow [i].lpProps) ;
1571 - if (aRestriction != NULL) {
1572 - mLastError = contents->Restrict(aRestriction, 0) ;
1573 - if (HR_FAILED(mLastError)) {
1574 - PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
1578 - mLastError = contents->SetColumns((LPSPropTagArray) &ContentsColumns, 0) ;
1579 - if (HR_FAILED(mLastError)) {
1580 - PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
1583 - mLastError = contents->GetRowCount(0, &rowCount) ;
1584 - if (HR_FAILED(mLastError)) {
1585 - PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
1588 - if (aList != NULL) { *aList = new nsMapiEntry [rowCount] ; }
1591 - LPSRowSet rowSet = NULL ;
1594 - mLastError = contents->QueryRows(1, 0, &rowSet) ;
1595 - if (HR_FAILED(mLastError)) {
1596 - PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
1599 - rowCount = rowSet->cRows ;
1600 - if (rowCount > 0 &&
1601 - (aMapiType == 0 ||
1602 - rowSet->aRow->lpProps[ContentsColumnObjectType].Value.ul == aMapiType)) {
1603 - if (aList != NULL) {
1604 - nsMapiEntry& current = (*aList) [aNbElements] ;
1605 - SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
1607 - current.Assign(currentValue.Value.bin.cb,
1608 - NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
1609 + FreeBuffer(aRowset) ;
1611 +void nsAbWinHelper::CStrToUnicode( const char *pStr, nsString& result)
1613 + result.Truncate( 0);
1614 + int wLen = MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, 0);
1615 + if (wLen >= m_uniBuffLen)
1617 + delete [] m_pUniBuff;
1618 + m_pUniBuff = new PRUnichar[wLen + 64];
1619 + m_uniBuffLen = wLen + 64;
1624 + MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, m_uniBuffLen);
1625 + result = m_pUniBuff;
1627 - MyFreeProws(rowSet) ;
1628 - } while (rowCount > 0) ;
1632 -BOOL nsAbWinHelper::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
1633 - ULONG aNbProperties, LPSPropValue& aValue,
1634 - ULONG& aValueCount)
1635 +void nsAbWinHelper::UnicodeToCStr( const PRUnichar *pUStr,nsCString& result)
1637 - nsMapiInterfaceWrapper<LPMAPIPROP> object ;
1638 - ULONG objType = 0 ;
1639 - LPSPropTagArray properties = NULL ;
1642 - mLastError = mAddressBook->OpenEntry(aObject.mByteCount, aObject.mEntryId,
1643 - &IID_IMAPIProp, 0, &objType,
1645 - if (HR_FAILED(mLastError)) {
1646 - PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
1648 + result.Truncate( 0);
1649 + int cLen = WideCharToMultiByte( CP_ACP, 0, pUStr, -1, m_pCStrBuff, 0,NULL,NULL);
1650 + if (cLen >= m_cstrBuffLen) {
1652 + delete [] m_pCStrBuff;
1653 + m_pCStrBuff = new char[cLen + 64];
1654 + m_cstrBuffLen = cLen + 64;
1656 - AllocateBuffer(CbNewSPropTagArray(aNbProperties),
1657 - NS_REINTERPRET_CAST(void **, &properties)) ;
1658 - properties->cValues = aNbProperties ;
1659 - for (i = 0 ; i < aNbProperties ; ++ i) {
1660 - properties->aulPropTag [i] = aPropertyTags [i] ;
1662 - mLastError = object->GetProps(properties, 0, &aValueCount, &aValue) ;
1663 - FreeBuffer(properties) ;
1664 - if (HR_FAILED(mLastError)) {
1665 - PRINTF(("Cannot get props %08x.\n", mLastError)) ;
1667 + WideCharToMultiByte( CP_ACP, 0, pUStr, -1, m_pCStrBuff, m_cstrBuffLen,NULL,NULL);
1668 + result = m_pCStrBuff;
1670 - return HR_SUCCEEDED(mLastError) ;
1673 -BOOL nsAbWinHelper::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
1674 - const LPSPropValue& aValues)
1676 - nsMapiInterfaceWrapper<LPMAPIPROP> object ;
1677 - ULONG objType = 0 ;
1678 - LPSPropProblemArray problems = NULL ;
1679 +static nsAbWinHelper *getOutlookAddressBook(void) {
1680 + static nsMapiAddressBook *addressBook = NULL ;
1682 - mLastError = mAddressBook->OpenEntry(aObject.mByteCount, aObject.mEntryId,
1683 - &IID_IMAPIProp, MAPI_MODIFY, &objType,
1685 - if (HR_FAILED(mLastError)) {
1686 - PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
1689 - mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
1690 - if (HR_FAILED(mLastError)) {
1691 - PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
1694 - if (problems != NULL) {
1695 - for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
1696 - PRINTF(("Problem %d: index %d code %08x.\n", i,
1697 - problems->aProblem [i].ulIndex,
1698 - problems->aProblem [i].scode)) ;
1701 - mLastError = object->SaveChanges(0) ;
1702 - if (HR_FAILED(mLastError)) {
1703 - PRINTF(("Cannot commit changes %08x.\n", mLastError)) ;
1705 - return HR_SUCCEEDED(mLastError) ;
1706 + if (addressBook == NULL) { addressBook = new nsMapiAddressBook ; }
1707 + return addressBook ;
1710 -void nsAbWinHelper::MyFreeProws(LPSRowSet aRowset)
1712 - if (aRowset == NULL) { return ; }
1714 +static nsAbWinHelper *getOutlookExpAddressBook(void) {
1715 + static nsWabAddressBook *addressBook = NULL ;
1717 - for (i = 0 ; i < aRowset->cRows ; ++ i) {
1718 - FreeBuffer(aRowset->aRow [i].lpProps) ;
1720 - FreeBuffer(aRowset) ;
1721 + if (addressBook == NULL) { addressBook = new nsWabAddressBook ; }
1722 + return addressBook ;
1725 nsAbWinHelperGuard::nsAbWinHelperGuard(PRUint32 aType)
1729 - case nsAbWinType_Outlook: mHelper = new nsMapiAddressBook ; break ;
1730 - case nsAbWinType_OutlookExp: mHelper = new nsWabAddressBook ; break ;
1731 + case nsAbWinType_Outlook: mHelper = getOutlookAddressBook() ; break ;
1732 + case nsAbWinType_OutlookExp: mHelper = getOutlookExpAddressBook() ; break ;
1737 nsAbWinHelperGuard::~nsAbWinHelperGuard(void)
1742 const char *kOutlookDirectoryScheme = "moz-aboutlookdirectory://" ;
1743 Index: mailnews/addrbook/src/nsAbWinHelper.h
1744 ===================================================================
1745 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAbWinHelper.h,v
1746 retrieving revision 1.2
1747 diff -u -r1.2 nsAbWinHelper.h
1748 --- misc/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.h 28 Sep 2001 20:06:23 -0000 1.2
1749 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbWinHelper.h 17 May 2004 03:23:53 -0000
1751 #include "nsVoidArray.h"
1752 #include "nsXPIDLString.h"
1754 +#define PR_SECOND_EMAIL_ADDRESS_A 0x8033001E
1755 +#define PR_SCREEN_NAME_A 0x805B001E
1758 +// Small utility to ensure release of all MAPI interfaces
1759 +template <class tInterface> struct nsMapiInterfaceWrapper
1761 + tInterface mInterface ;
1763 + nsMapiInterfaceWrapper(void) : mInterface(NULL) {}
1764 + ~nsMapiInterfaceWrapper(void) {
1765 + if (mInterface ) { mInterface->Release() ; }
1767 + operator LPUNKNOWN *(void) { return NS_REINTERPRET_CAST(LPUNKNOWN *, &mInterface) ; }
1768 + tInterface operator -> (void) const { return mInterface ; }
1769 + operator tInterface *(void) { return &mInterface ; }
1777 struct nsMapiEntryArray
1779 - nsMapiEntry *mEntries ;
1780 - ULONG mNbEntries ;
1782 nsMapiEntryArray(void) ;
1783 ~nsMapiEntryArray(void) ;
1785 - const nsMapiEntry& operator [] (int aIndex) const { return mEntries [aIndex] ; }
1786 + void AddItem(nsMapiEntry * aEntries);
1787 + void AddItem( ULONG mByteCount , LPENTRYID mEntryId )
1789 + nsMapiEntry * aEntries=new nsMapiEntry();
1790 + aEntries->Assign(mByteCount,mEntryId);
1791 + AddItem(aEntries);
1794 + ULONG GetSize( void) { return( m_array.Count());}
1795 + nsMapiEntry& operator [] (int aIndex) { return *(nsMapiEntry*)m_array.ElementAt(aIndex); }
1796 + nsMapiEntry* ElementAt(int aIndex) { return (nsMapiEntry*)m_array.ElementAt(aIndex); }
1797 void CleanUp(void) ;
1798 + void Remove(nsMapiEntry * aEntries){ m_array.RemoveElement(aEntries); }
1799 + void Remove(int index){ m_array.RemoveElementAt(index); }
1800 + ULONG IndexOf(nsMapiEntry * aEntries){return m_array.IndexOf(aEntries);};
1802 + nsVoidArray m_array;
1808 virtual ~nsAbWinHelper(void) ;
1810 // Get the top address books
1811 - BOOL GetFolders(nsMapiEntryArray& aFolders) ;
1812 + virtual BOOL GetFolders(nsMapiEntryArray& aFolders) =0;
1813 // Get a list of entries for cards/mailing lists in a folder/mailing list
1814 BOOL GetCards(const nsMapiEntry& aParent, LPSRestriction aRestriction,
1815 nsMapiEntryArray& aCards) ;
1816 @@ -97,18 +129,14 @@
1817 BOOL GetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
1818 ULONG aNbProperties, nsStringArray& aValues) ;
1819 // Get the value of a MAPI property of type SYSTIME
1820 - BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
1821 + virtual BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
1822 WORD& aYear, WORD& aMonth, WORD& aDay) ;
1823 - // Get the value of a MAPI property of type LONG
1824 - BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
1825 // Get the value of a MAPI property of type BIN
1826 BOOL GetPropertyBin(const nsMapiEntry& aObject, ULONG aPropertyTag, nsMapiEntry& aValue) ;
1827 // Tests if a container contains an entry
1828 BOOL TestOpenEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
1829 - // Delete an entry in the address book
1830 - BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
1831 // Set the value of a MAPI property of type string in unicode
1832 - BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag,
1833 + virtual BOOL SetPropertyUString (const nsMapiEntry& aObject, ULONG aPropertyTag,
1834 const PRUnichar *aValue) ;
1835 // Same as previous, but with a bunch of properties in one call
1836 BOOL SetPropertiesUString(const nsMapiEntry& aObject, const ULONG *aPropertiesTag,
1837 @@ -117,32 +145,44 @@
1838 BOOL SetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
1839 WORD aYear, WORD aMonth, WORD aDay) ;
1840 // Create entry in the address book
1841 - BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
1842 + virtual BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
1843 + // Delete an entry in the address book
1844 + virtual BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
1845 // Create a distribution list in the address book
1846 - BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
1847 + virtual BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
1848 // Copy an existing entry in the address book
1849 - BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
1850 + virtual BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
1851 // Get a default address book container
1852 - BOOL GetDefaultContainer(nsMapiEntry& aContainer) ;
1853 + virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer) =0;
1854 // Is the helper correctly initialised?
1855 - BOOL IsOK(void) const { return mAddressBook != NULL ; }
1856 + virtual BOOL IsOK(void) =0;/*const { return mAddressBook != NULL ; }*/
1858 + // Get the value of a MAPI property of type LONG
1859 + virtual BOOL GetPropertyLong(const nsMapiEntry& aObject, ULONG aPropertyTag, ULONG& aValue) ;
1862 HRESULT mLastError ;
1863 - LPADRBOOK mAddressBook ;
1864 static ULONG mEntryCounter ;
1865 static PRLock *mMutex ;
1867 + virtual HRESULT OpenEntry(ULONG cbEntryID,
1868 + LPENTRYID lpEntryID,
1869 + LPCIID lpInterface,
1871 + ULONG FAR * lpulObjType,
1872 + LPUNKNOWN FAR * lppUnk
1875 // Retrieve the contents of a container, with an optional restriction
1876 - BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
1877 - nsMapiEntry **aList, ULONG &aNbElements, ULONG aMapiType) ;
1878 + virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
1879 + nsMapiEntryArray *aList, ULONG aMapiType) =0;
1880 // Retrieve the values of a set of properties on a MAPI object
1881 - BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
1882 + virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
1883 ULONG aNbProperties,
1884 - LPSPropValue& aValues, ULONG& aValueCount) ;
1885 + LPSPropValue& aValues, ULONG& aValueCount) =0;
1886 // Set the values of a set of properties on a MAPI object
1887 - BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
1888 - const LPSPropValue& aValues) ;
1889 + virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
1890 + LPSPropValue& aValues) =0;
1891 // Clean-up a rowset returned by QueryRows
1892 void MyFreeProws(LPSRowSet aSet) ;
1893 // Allocation of a buffer for transmission to interfaces
1894 @@ -150,7 +190,16 @@
1895 // Destruction of a buffer provided by the interfaces
1896 virtual void FreeBuffer(LPVOID aBuffer) = 0 ;
1898 + static void CStrToUnicode( const char *pStr, nsString& result);
1899 + static void UnicodeToCStr( const PRUnichar *pStr, nsCString& result);
1902 + static int m_clients;
1903 + static PRUnichar * m_pUniBuff;
1904 + static int m_uniBuffLen;
1905 + static char * m_pCStrBuff;
1906 + static int m_cstrBuffLen;
1913 nsAbWinHelper *operator ->(void) { return mHelper ; }
1915 + static void FreeWinAbLibrarys();
1917 nsAbWinHelper *mHelper ;
1919 Index: mailnews/addrbook/src/nsAddrDatabase.cpp
1920 ===================================================================
1921 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAddrDatabase.cpp,v
1922 retrieving revision 1.118
1923 diff -u -r1.118 nsAddrDatabase.cpp
1924 --- misc/build/mozilla/mailnews/addrbook/src/nsAddrDatabase.cpp 24 Dec 2003 17:18:08 -0000 1.118
1925 +++ misc/build/mozilla/mailnews/addrbook/src/nsAddrDatabase.cpp 17 May 2004 03:23:55 -0000
1928 static const char kMailListAddressFormat[] = "Address%d";
1930 +extern int getMD5sum(const char * fileName,char * sum);
1931 +extern int testMD5sum(const char * fileName,char * sum);
1933 static NS_DEFINE_CID(kCMorkFactory, NS_MORK_CID);
1935 nsAddrDatabase::nsAddrDatabase()
1938 m_dbDirectory(nsnull)
1940 + memset(m_dbMd5Sum,0,33);
1943 nsAddrDatabase::~nsAddrDatabase()
1944 @@ -720,7 +724,11 @@
1945 NS_RELEASE(oldFile); // always release our file ref, store has own
1950 + ret = getMD5sum(nativeFileName,m_dbMd5Sum);
1952 + ret = NS_ERROR_FAILURE;
1954 nsCRT::free(nativeFileName);
1956 if (NS_SUCCEEDED(ret) && thumb)
1957 @@ -817,6 +825,17 @@
1958 nsresult err = NS_OK;
1959 nsIMdbThumb *commitThumb = nsnull;
1961 + const char *pFilename = m_dbName.GetCString(); /* do not free */
1962 + char *nativeFileName = nsCRT::strdup(pFilename);
1963 +#if defined(XP_PC) || defined(XP_MAC)
1964 + UnixToNative(nativeFileName);
1966 + if (testMD5sum(nativeFileName,m_dbMd5Sum))
1968 + nsCRT::free(nativeFileName);
1969 + return NS_ERROR_FILE_ACCESS_DENIED;
1972 if (commitType == nsAddrDBCommitType::kLargeCommit || commitType == nsAddrDBCommitType::kSessionCommit)
1974 mdb_percent outActualWaste = 0;
1975 @@ -867,6 +886,10 @@
1976 // ### do something with error, but clear it now because mork errors out on commits.
1978 GetEnv()->ClearErrors();
1979 + if (NS_SUCCEEDED(err) && getMD5sum(nativeFileName,m_dbMd5Sum))
1980 + err = NS_ERROR_FAILURE;
1981 + nsCRT::free(nativeFileName);
1986 Index: mailnews/addrbook/src/nsAddrDatabase.h
1987 ===================================================================
1988 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsAddrDatabase.h,v
1989 retrieving revision 1.46
1990 diff -u -r1.46 nsAddrDatabase.h
1991 --- misc/build/mozilla/mailnews/addrbook/src/nsAddrDatabase.h 28 Jan 2004 17:22:13 -0000 1.46
1992 +++ misc/build/mozilla/mailnews/addrbook/src/nsAddrDatabase.h 17 May 2004 03:23:55 -0000
1994 nsIMdbTable *m_mdbPabTable;
1995 nsIMdbTable *m_mdbDeletedCardsTable;
1996 nsFileSpec m_dbName;
1997 + char m_dbMd5Sum[33];
1998 PRBool m_mdbTokensInitialized;
1999 nsVoidArray /*<nsIAddrDBListener>*/ *m_ChangeListeners;
2001 Index: mailnews/addrbook/src/nsMapiAddressBook.cpp
2002 ===================================================================
2003 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp,v
2004 retrieving revision 1.7
2005 diff -u -r1.7 nsMapiAddressBook.cpp
2006 --- misc/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp 30 Oct 2001 07:59:16 -0000 1.7
2007 +++ misc/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.cpp 17 May 2004 03:23:55 -0000
2012 +static char * stristr(const char *big, const char *little)
2016 + if (!big || !little || !*big || !*little)
2018 + len = strlen(little);
2020 + for( ; *big; big++ )
2021 + if(!_strnicmp (big, little, 1) && ! _strnicmp (big, little, len) )
2022 + return (char *)big;
2029 static PRLogModuleInfo* gMapiAddressBookLog
2030 = PR_NewLogModule("nsMapiAddressBookLog");
2033 #define PRINTF(args) PR_LOG(gMapiAddressBookLog, PR_LOG_DEBUG, args)
2035 +#define OUTLOOK_EMAIL_DIAPLAY_MAPI_ID 0x00008005 //use to get and set display
2036 +#define OUTLOOK_EMAIL1_MAPI_ID 0x00008084 //use to get and set primary email address
2037 +#define OUTLOOK_EMAIL2_MAPI_ID 0x00008094 //use to get and set second email address
2038 +#define OUTLOOK_EMAIL_SCREEN_NAME 0x8061001E //use to get and set screen name
2039 +#define OUTLOOK_EMAIL_ORGID 0x00008085 //use to get orginal entryid to add to distlist
2040 +#define OUTLOOK_EMAIL_LIST1 0x00008054 //use to get distlist table
2041 +#define OUTLOOK_EMAIL_LIST2 0x00008055 //use to set distlist table
2043 +static const TagMap TagMaps[]={
2044 + {PR_DISPLAY_NAME_A, OUTLOOK_EMAIL_DIAPLAY_MAPI_ID, PT_STRING8},
2045 + {PR_EMAIL_ADDRESS_A, OUTLOOK_EMAIL1_MAPI_ID, PT_STRING8},
2046 + {PR_SECOND_EMAIL_ADDRESS_A, OUTLOOK_EMAIL2_MAPI_ID, PT_STRING8},
2047 + {PR_SCREEN_NAME_A, OUTLOOK_EMAIL_SCREEN_NAME, PT_STRING8}};
2050 + ieidPR_ENTRYID = 0,
2051 + ieidPR_OBJECT_TYPE,
2052 + ieidPR_DISPLAY_NAME,
2053 + ieidPR_MESSAGE_CLASS,
2054 + ieidPR_STORE_ENTRYID,
2055 + ieidPR_MESSAGE_RECIPIENTS,
2059 +static const SizedSPropTagArray(ieidMax, ptaEid)=
2068 + PR_MESSAGE_RECIPIENTS
2074 + ContentsColumnEntryId = 0,
2075 + ContentsColumnObjectType,
2076 + ContentsColumnMessageClass,
2077 + ContentsColumnsSize
2080 +static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
2082 + ContentsColumnsSize,
2090 HMODULE nsMapiAddressBook::mLibrary = NULL ;
2091 PRInt32 nsMapiAddressBook::mLibUsage = 0 ;
2093 BOOL nsMapiAddressBook::mInitialized = FALSE ;
2094 BOOL nsMapiAddressBook::mLogonDone = FALSE ;
2095 LPMAPISESSION nsMapiAddressBook::mRootSession = NULL ;
2096 -LPADRBOOK nsMapiAddressBook::mRootBook = NULL ;
2097 +#define MAPI_NO_COINIT 8
2099 BOOL nsMapiAddressBook::LoadMapiLibrary(void)
2102 mMAPILogonEx = NS_REINTERPRET_CAST(LPMAPILOGONEX,
2103 GetProcAddress(mLibrary, "MAPILogonEx")) ;
2104 if (!mMAPILogonEx) { return FALSE ; }
2105 - MAPIINIT_0 mapiInit = { MAPI_INIT_VERSION, MAPI_MULTITHREAD_NOTIFICATIONS } ;
2106 + MAPIINIT_0 mapiInit = { MAPI_INIT_VERSION, MAPI_MULTITHREAD_NOTIFICATIONS | MAPI_NO_COINIT } ;
2107 HRESULT retCode = mMAPIInitialize(&mapiInit) ;
2109 if (HR_FAILED(retCode)) {
2110 @@ -106,22 +176,19 @@
2113 if (HR_FAILED(retCode)) {
2114 - PRINTF(("Cannot logon to MAPI %08x.\n", retCode)) ; return FALSE ;
2115 + PRINTF(("Cannot logon to MAPI %08x.\n", retCode)) ;
2119 - retCode = mRootSession->OpenAddressBook(0, NULL, 0, &mRootBook) ;
2120 - if (HR_FAILED(retCode)) {
2121 - PRINTF(("Cannot open MAPI address book %08x.\n", retCode)) ;
2124 return HR_SUCCEEDED(retCode) ;
2127 void nsMapiAddressBook::FreeMapiLibrary(void)
2130 - if (-- mLibUsage == 0) {
2131 + if (--mLibUsage < 0) {
2133 - if (mRootBook) { mRootBook->Release() ; }
2136 mRootSession->Logoff(NULL, 0, 0) ;
2140 FreeLibrary(mLibrary) ;
2141 + mRootSession = NULL;
2148 BOOL result = Initialize() ;
2150 NS_ASSERTION(result == TRUE, "Couldn't initialize Mapi Helper") ;
2151 MOZ_COUNT_CTOR(nsMapiAddressBook) ;
2153 @@ -154,22 +221,882 @@
2154 nsMapiAddressBook::~nsMapiAddressBook(void)
2156 nsAutoLock guard(mMutex) ;
2160 MOZ_COUNT_DTOR(nsMapiAddressBook) ;
2163 +LPSPropValue nsMapiAddressBook::GetMapiProperty( LPMAPIPROP pProp, ULONG tag)
2168 + int sz = CbNewSPropTagArray( 1);
2169 + SPropTagArray *pTag = (SPropTagArray *) new char[sz];
2170 + pTag->cValues = 1;
2171 + pTag->aulPropTag[0] = tag;
2172 + LPSPropValue lpProp = NULL;
2173 + ULONG cValues = 0;
2174 + HRESULT hr = pProp->GetProps( pTag, 0, &cValues, &lpProp);
2176 + if (HR_FAILED( hr) || (cValues != 1)) {
2178 + mMAPIFreeBuffer( lpProp);
2182 + if (PROP_TYPE( lpProp->ulPropTag) == PT_ERROR) {
2183 + if (lpProp->Value.l == MAPI_E_NOT_FOUND) {
2184 + mMAPIFreeBuffer( lpProp);
2192 +BOOL nsMapiAddressBook::GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYID& lpEntryId, BOOL delVal)
2197 + BOOL bResult = TRUE;
2198 + switch (PROP_TYPE(pVal->ulPropTag))
2201 + cbEntryId = pVal->Value.bin.cb;
2202 + mMAPIAllocateBuffer( cbEntryId, (LPVOID *) &lpEntryId);
2203 + memcpy( lpEntryId, pVal->Value.bin.lpb, cbEntryId);
2207 + PRINTF(( "EntryId not in BINARY prop value\n"));
2212 + if (pVal && delVal)
2213 + mMAPIFreeBuffer( pVal);
2218 +BOOL nsMapiAddressBook::HandleContentsItem(ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders)
2224 + if (oType == MAPI_MESSAGE)
2226 + if (oType == MAPI_STORE)
2228 + hr=mRootSession->OpenEntry(
2234 + (IUnknown**)&lpMsgStore);
2237 + //Add MDB to a list to make it can be released when class destroyed.
2238 + //We must leave it openned or else we can't open address store in it.
2239 + AddToMDBArray(lpMsgStore);
2241 + LPSPropValue pVal;
2242 + pVal=GetMapiProperty(lpMsgStore,PR_IPM_SUBTREE_ENTRYID);
2248 + nsMapiInterfaceWrapper<LPMAPICONTAINER> lpSubTree;
2250 + if (GetEntryIdFromProp( pVal, cbEntry, pEntry)) {
2251 + // Open up the folder!
2252 + BOOL bResult = TRUE;
2253 + bResult = lpMsgStore->OpenEntry(
2260 + mMAPIFreeBuffer( pEntry);
2261 + if (!bResult && *(LPMAPICONTAINER*)&lpSubTree) {
2262 + // Iterate the subtree with the results going into the folder list
2263 + bResult = IterateHierarchy(*(LPMAPICONTAINER*)&lpSubTree,aFolders);
2266 + PRINTF(( "GetStoreFolders: Error opening sub tree.\n"));
2270 + PRINTF(( "GetStoreFolders: Error getting entryID from sub tree property val.\n"));
2274 + PRINTF(( "GetStoreFolders: Error getting sub tree property.\n"));
2279 + PRINTF(("Type:%d\n",oType));
2285 +BOOL nsMapiAddressBook::IterateHierarchy(LPMAPICONTAINER pFolder,nsMapiEntryArray& aFolders, ULONG flags)
2287 + // flags can be CONVENIENT_DEPTH or 0
2288 + // CONVENIENT_DEPTH will return all depths I believe instead
2289 + // of just children
2291 + nsMapiInterfaceWrapper<LPMAPITABLE> lpTable;
2292 + hr = pFolder->GetHierarchyTable( CONVENIENT_DEPTH , lpTable);
2293 + if (HR_FAILED(hr)) {
2294 + PRINTF(( "IterateHierarchy: GetContentsTable failed: 0x%lx, %d\n", (long)hr, (int)hr));
2299 + hr = lpTable->GetRowCount( 0, &rowCount);
2304 + hr = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0);
2305 + if (HR_FAILED(hr)) {
2306 + PRINTF(( "IterateHierarchy: SetColumns failed: 0x%lx, %d\n", (long)hr, (int)hr));
2310 + hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL);
2311 + if (HR_FAILED(hr)) {
2312 + PRINTF(( "IterateHierarchy: SeekRow failed: 0x%lx, %d\n", (long)hr, (int)hr));
2318 + BOOL keepGoing = TRUE;
2319 + BOOL bResult = TRUE;
2323 + hr = lpTable->QueryRows( 1, 0, &lpRow);
2325 + if (HR_FAILED(hr))
2327 + PRINTF(( "QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr));
2333 + cNumRows = lpRow->cRows;
2336 + LPENTRYID lpEntry = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
2337 + ULONG cb = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
2338 + ULONG oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul;
2340 + keepGoing = HandleHierarchyItem( oType, cb, lpEntry,aFolders);
2343 + MyFreeProws(lpRow);
2346 + } while ( SUCCEEDED(hr) && cNumRows && lpRow && keepGoing);
2349 + if (bResult && !keepGoing)
2354 +BOOL nsMapiAddressBook::HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders)
2357 + if (oType == MAPI_FOLDER)
2359 + nsMapiInterfaceWrapper<LPMAPICONTAINER> pFolder ;
2360 + if (!mRootSession->OpenEntry(
2368 + LPSPropValue pVal;
2371 + pVal = GetMapiProperty(*(LPMAPICONTAINER*)&pFolder, PR_CONTAINER_CLASS);
2374 + if (strcmp("IPF.Contact",pVal->Value.lpszA) == 0)
2376 + SPropValue *currentValue=GetMapiProperty( *(LPMAPICONTAINER*)&pFolder, PR_ENTRYID);
2378 + aFolders.AddItem(currentValue->Value.bin.cb,
2379 + NS_REINTERPRET_CAST(LPENTRYID, currentValue->Value.bin.lpb)) ;
2387 + PRINTF(( "GetStoreFolders - HandleHierarchyItem: Unhandled ObjectType: %ld\n", oType));
2394 +BOOL nsMapiAddressBook::GetFolders(nsMapiEntryArray& aFolders)
2396 + aFolders.CleanUp() ;
2397 + nsMapiInterfaceWrapper<LPMAPICONTAINER> rootFolder ;
2398 + nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
2399 + ULONG objType = 0 ;
2400 + ULONG rowCount = 0 ;
2402 + nsMapiInterfaceWrapper<LPMAPITABLE> lpTable;
2404 + mLastError = mRootSession->GetMsgStoresTable( 0, lpTable);
2405 + if (HR_FAILED(mLastError)) {
2406 + PRINTF(("Cannot open MAPI MsgStores %08x.\n", mLastError));
2407 + return mLastError;
2410 + mLastError = lpTable->GetRowCount( 0, &rowCount);
2412 + mLastError = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0);
2413 + if (FAILED(mLastError))
2414 + return( mLastError);
2415 + mLastError = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL);
2416 + if (FAILED(mLastError))
2417 + return mLastError;
2421 + BOOL keepGoing = TRUE;
2422 + BOOL bResult = TRUE;
2426 + mLastError = lpTable->QueryRows( 1, 0, &lpRow);
2428 + if (HR_FAILED(mLastError)){
2434 + cNumRows = lpRow->cRows;
2437 + LPENTRYID lpEID = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
2438 + ULONG cbEID = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
2439 + ULONG oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul;
2442 + keepGoing = HandleContentsItem( oType, cbEID, lpEID,aFolders);
2444 + MyFreeProws( lpRow);
2447 + } while ( SUCCEEDED(mLastError) && cNumRows && lpRow && keepGoing);
2450 + return HR_SUCCEEDED(mLastError) ;
2452 +BOOL nsMapiAddressBook::CorrectRestriction(const LPMAPIPROP aMapiProp,ULONG aRestrictionNum, LPSRestriction aRestriction)
2454 + ULONG conditionType = 0 ;
2456 + if (!aRestriction)
2458 + for (ulResIndex=0;ulResIndex < aRestrictionNum;ulResIndex++)
2460 + conditionType = aRestriction[ulResIndex].rt;
2461 + switch (conditionType)
2464 + aRestriction[ulResIndex].res.resExist.ulPropTag =
2465 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resExist.ulPropTag);
2467 + case RES_BITMASK :
2468 + aRestriction[ulResIndex].res.resBitMask.ulPropTag =
2469 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resBitMask.ulPropTag);
2471 + case RES_CONTENT :
2472 + aRestriction[ulResIndex].res.resContent.ulPropTag =
2473 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resContent.ulPropTag);
2474 + aRestriction[ulResIndex].res.resContent.lpProp->ulPropTag =
2475 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resContent.lpProp->ulPropTag);
2477 + case RES_PROPERTY :
2478 + aRestriction[ulResIndex].res.resProperty.ulPropTag =
2479 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resProperty.ulPropTag);
2480 + aRestriction[ulResIndex].res.resProperty.lpProp->ulPropTag =
2481 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resProperty.lpProp->ulPropTag);
2484 + aRestriction[ulResIndex].res.resSize.ulPropTag =
2485 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resSize.ulPropTag);
2487 + case RES_COMPAREPROPS :
2488 + aRestriction[ulResIndex].res.resCompareProps.ulPropTag1 =
2489 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resCompareProps.ulPropTag1);
2490 + aRestriction[ulResIndex].res.resCompareProps.ulPropTag2 =
2491 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resCompareProps.ulPropTag2);
2494 + CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resNot.lpRes);
2497 + CorrectRestriction(aMapiProp,
2498 + aRestriction[ulResIndex].res.resAnd.cRes,
2499 + aRestriction[ulResIndex].res.resAnd.lpRes);
2502 + CorrectRestriction(aMapiProp,
2503 + aRestriction[ulResIndex].res.resOr.cRes,
2504 + aRestriction[ulResIndex].res.resOr.lpRes);
2507 + case RES_COMMENT :
2508 + CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resComment.lpRes);
2509 + aRestriction[ulResIndex].res.resComment.lpProp->ulPropTag =
2510 + GetRealMapiPropertyTag(aMapiProp,aRestriction[ulResIndex].res.resComment.lpProp->ulPropTag);
2512 + case RES_SUBRESTRICTION :
2513 + CorrectRestriction(aMapiProp,1,aRestriction[ulResIndex].res.resSub.lpRes);
2521 +BOOL nsMapiAddressBook::Filter( LPSRestriction aRestriction,nsMapiEntryArray * aList)
2523 + if (!aRestriction)
2526 + ULONG conditionType = 0 ;
2528 + nsMapiEntryArray listOut;
2529 + ULONG listindex=0;
2531 + nsMapiEntryArray listDel;
2535 + ULONG resCount = 0;
2536 + ULONG resIndex = 0;
2538 + listsize = aList->GetSize();
2539 + conditionType = aRestriction->rt;
2540 + switch (conditionType)
2543 + case RES_BITMASK :
2544 + case RES_CONTENT :
2545 + case RES_PROPERTY :
2547 + case RES_COMPAREPROPS :
2548 + case RES_COMMENT :
2549 + case RES_SUBRESTRICTION :
2551 + while(listindex < aList->GetSize())
2553 + if (!FilterOnOneRow(aList->ElementAt(listindex),aRestriction))
2554 + aList->Remove(listindex);
2561 + aRestriction->res.resNot.ulReserved = 1;
2565 + if (conditionType == RES_OR)
2567 + for(listindex=0;listindex<aList->GetSize();listindex++)
2569 + listDel.AddItem(aList->ElementAt(listindex));
2573 + resCount = aRestriction->res.resAnd.cRes;
2574 + //notice that SAndRestriction ,SNotRestriction ,SOrRestriction
2575 + //use the same struct
2576 + for (resIndex = 0;resIndex < resCount;resIndex++)
2578 + //can't call listOut.CleanUp() here
2579 + //because it will destroy all Element too
2580 + while(listOut.GetSize())
2582 + listOut.Remove(0);
2585 + for(listindex=0;listindex<aList->GetSize();listindex++)
2587 + listOut.AddItem(aList->ElementAt(listindex));
2590 + Filter(&aRestriction->res.resAnd.lpRes[resIndex],&listOut);
2591 + if (conditionType == RES_NOT)
2593 + for(listindex=0;listindex<listOut.GetSize();listindex++)
2595 + aList->Remove(listOut.ElementAt(listindex));
2598 + else if (conditionType == RES_AND )
2600 + for(listindex=0;listindex<listOut.GetSize();listindex++)
2602 + if (!aList->IndexOf(listOut.ElementAt(listindex)))
2604 + aList->Remove(listOut.ElementAt(listindex));
2608 + else if (conditionType == RES_OR )
2610 + for(listindex=0;listindex<listOut.GetSize();listindex++)
2612 + listDel.Remove(listOut.ElementAt(listindex));
2614 + if (listDel.GetSize() == 0)
2620 + if (conditionType == RES_OR)
2622 + for(listindex=0;listindex<listDel.GetSize();listindex++)
2624 + aList->Remove(listDel.ElementAt(listindex));
2630 + while(listDel.GetSize())
2632 + listDel.Remove(0);
2634 + while(listOut.GetSize())
2636 + listOut.Remove(0);
2643 +BOOL nsMapiAddressBook::FilterOnOneRow(nsMapiEntry *aEntry,LPSRestriction aRestriction)
2645 + LPMAPIPROP object ;
2646 + ULONG objType = 0 ;
2647 + LPSPropValue realValue = NULL ;
2648 + LPSPropValue resValue = NULL ;
2649 + ULONG valueCount = 0 ;
2651 + mLastError = OpenEntry(aEntry->mByteCount, aEntry->mEntryId,
2652 + &IID_IMAPIProp, MAPI_BEST_ACCESS, &objType,
2653 + (IUnknown **)&object) ;
2655 + if (HR_FAILED(mLastError)) {
2656 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
2660 + ULONG conditionType = 0 ;
2661 + conditionType = aRestriction->rt;
2663 + switch (conditionType)
2666 + if (!GetMAPIProperties(*aEntry,&aRestriction->res.resExist.ulPropTag,1,realValue,valueCount))
2670 + case RES_CONTENT :
2671 + if (!GetMAPIProperties(*aEntry,&aRestriction->res.resContent.ulPropTag,1,realValue,valueCount))
2673 + resValue = aRestriction->res.resContent.lpProp;
2675 + case RES_PROPERTY :
2676 + if (!GetMAPIProperties(*aEntry,&aRestriction->res.resProperty.ulPropTag,1,realValue,valueCount))
2678 + resValue = aRestriction->res.resProperty.lpProp;
2680 + case RES_BITMASK :
2681 + return FALSE; //not support
2684 + return FALSE;//not been used now
2686 + case RES_COMPAREPROPS :
2687 + return FALSE;//not been used now
2690 + return FALSE;//not need care here
2693 + return FALSE;//not need care here
2696 + return FALSE;//not need care here
2698 + case RES_COMMENT :
2699 + return TRUE;//comment
2701 + case RES_SUBRESTRICTION :
2702 + return FALSE;//not been used now
2705 + return AtomyFilter(aRestriction,realValue,resValue);
2709 +BOOL nsMapiAddressBook::AtomyFilter(LPSRestriction aRestriction,LPSPropValue aRealValue,LPSPropValue aFilterValue)
2711 + ULONG conditionType = 0 ;
2712 + conditionType = aRestriction->rt;
2714 + BOOL bTagEq=(aRealValue &&
2715 + PROP_TYPE( aRealValue->ulPropTag ) != PT_ERROR) &&
2717 + // PROP_TYPE( aRealValue->ulPropTag ) == PROP_TYPE( aFilterValue->ulPropTag ));
2718 + switch (conditionType)
2721 + return (aRealValue && PROP_TYPE( aRealValue->ulPropTag ) != PT_ERROR) ;
2723 + case RES_CONTENT :
2726 + switch(aRestriction->res.resContent.ulFuzzyLevel)
2728 + case FL_FULLSTRING :
2729 + return !stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA);
2732 + return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) == aRealValue->Value.lpszA;
2734 + case FL_SUBSTRING :
2736 + return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != NULL;
2742 + case RES_PROPERTY :
2745 + switch(aRestriction->res.resProperty.relop)
2748 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) >= 0;
2751 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) > 0;
2754 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) <= 0;
2757 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) < 0;
2760 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) == 0;
2763 + return stricmp(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != 0;
2767 + return stristr(aRealValue->Value.lpszA,aFilterValue->Value.lpszA) != NULL;
2774 + case RES_BITMASK :
2775 + return FALSE; //not support
2778 + return FALSE;//not been used now
2780 + case RES_COMPAREPROPS :
2781 + return FALSE;//not been used now
2784 + return FALSE;//not need care here
2787 + return FALSE;//not need care here
2790 + return FALSE;//not need care here
2792 + case RES_COMMENT :
2793 + return TRUE;//comment
2795 + case RES_SUBRESTRICTION :
2796 + return FALSE;//not been used now
2802 +BOOL nsMapiAddressBook::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
2803 + nsMapiEntryArray *aList, ULONG aMapiType)
2808 + nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
2809 + nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
2810 + ULONG objType = 0 ;
2811 + ULONG rowCount = 0 ;
2814 + nsMapiInterfaceWrapper<LPMAPIPROP> pFolder;
2816 + aParent.ToString(cs);
2818 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
2819 + 0, MAPI_BEST_ACCESS, &objType, pFolder);
2820 + if (HR_FAILED(mLastError))
2822 + PRINTF(("Cannot open folder %08x.\n", mLastError)) ;
2827 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&pFolder,PR_MESSAGE_CLASS);
2828 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
2831 + LPSPropValue aValue = NULL ;
2832 + ULONG aValueCount = 0 ;
2834 + LPSPropTagArray properties = NULL ;
2835 + mMAPIAllocateBuffer(CbNewSPropTagArray(1),
2836 + (void **)&properties);
2837 + properties->cValues = 1;
2838 + properties->aulPropTag [0] = GetEmailPropertyTag(*(LPMAPIPROP*)&pFolder,OUTLOOK_EMAIL_LIST1);
2839 + hr = pFolder->GetProps(properties, 0, &aValueCount, &aValue) ;
2841 + SBinaryArray *sa=&aValue->Value.MVbin;
2847 + nsMapiEntry testEntry;
2849 + for (idx=0;sa->lpbin && idx<sa->cValues ;idx++)
2851 + lpEID= (LPENTRYID) sa->lpbin[idx].lpb;
2852 + cbEID = sa->lpbin[idx].cb;
2853 + testEntry.Assign(sa->lpbin[idx].cb,NS_REINTERPRET_CAST(LPENTRYID,sa->lpbin[idx].lpb));
2855 + if (GetPropertyString(testEntry,PR_MESSAGE_CLASS,sClass)) //Error get property
2857 + aList->AddItem(cbEID,lpEID);
2860 + Filter(aRestriction,aList);
2864 + if (aRestriction && !CorrectRestriction(*(LPMAPICONTAINER*)&pFolder,1,aRestriction))
2866 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
2867 + &IID_IMAPIContainer, MAPI_BEST_ACCESS, &objType,
2869 + if (HR_FAILED(mLastError)) {
2870 + PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
2874 + mLastError = parent->GetContentsTable(0, contents) ;
2875 + if (HR_FAILED(mLastError)) {
2876 + PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
2879 + if (aRestriction) {
2880 + mLastError = contents->Restrict(aRestriction, TBL_BATCH) ;
2881 + if (HR_FAILED(mLastError)) {
2882 + PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
2886 + mLastError = contents->SetColumns((LPSPropTagArray)&ContentsColumns, 0);
2887 + if (HR_FAILED(mLastError)) {
2888 + PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
2891 + mLastError = contents->GetRowCount(0, &rowCount) ;
2892 + if (HR_FAILED(mLastError)) {
2893 + PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
2897 + LPSRowSet rowSet = NULL ;
2900 + mLastError = contents->QueryRows(1, 0, &rowSet) ;
2901 + if (HR_FAILED(mLastError)) {
2902 + PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
2905 + rowCount = rowSet->cRows ;
2906 + if (rowCount > 0 && aList)
2908 + if (aMapiType == 0 || rowSet->aRow->lpProps[ContentsColumnObjectType].Value.ul == aMapiType)
2910 + SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
2911 + aList->AddItem(currentValue.Value.bin.cb,
2912 + NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
2914 + else if (aMapiType == MAPI_DISTLIST)
2916 + if (strcmp("IPM.DistList",rowSet->aRow->lpProps[ContentsColumnMessageClass].Value.lpszA)==0)
2918 + SPropValue& currentValue = rowSet->aRow->lpProps[ContentsColumnEntryId] ;
2919 + aList->AddItem(currentValue.Value.bin.cb,
2920 + NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
2926 + MyFreeProws(rowSet) ;
2927 + } while (rowCount > 0) ;
2934 +BOOL nsMapiAddressBook::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
2935 + ULONG aNbProperties, LPSPropValue& aValue,
2936 + ULONG& aValueCount)
2938 + nsMapiInterfaceWrapper<LPMAPIPROP> object ;
2939 + ULONG objType = 0 ;
2940 + LPSPropTagArray properties = NULL ;
2943 + mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
2944 + &IID_IMAPIProp, MAPI_BEST_ACCESS, &objType,
2947 + if (HR_FAILED(mLastError)) {
2948 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
2951 + AllocateBuffer(CbNewSPropTagArray(aNbProperties),
2952 + NS_REINTERPRET_CAST(void **, &properties));
2953 + properties->cValues = aNbProperties ;
2954 + for (i = 0 ; i < aNbProperties ; ++ i)
2956 + properties->aulPropTag [i] = GetRealMapiPropertyTag(*(LPMAPIPROP*)&object,aPropertyTags [i],TRUE);
2958 + mLastError = object->GetProps(properties, 0 , &aValueCount, &aValue) ;
2959 + FreeBuffer(properties) ;
2961 + if (HR_FAILED(mLastError)) {
2962 + PRINTF(("Error get props %08x.\n", mLastError)) ;
2964 + return HR_SUCCEEDED(mLastError);
2967 +BOOL nsMapiAddressBook::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
2968 + LPSPropValue& aValues)
2970 + nsMapiInterfaceWrapper<LPMESSAGE> object;
2971 + ULONG objType = 0 ;
2972 + LPSPropProblemArray problems = NULL ;
2975 + LPMDB lpMsgStore=GetMsgStore(aObject);
2981 + mLastError = lpMsgStore->OpenEntry(aObject.mByteCount, aObject.mEntryId,
2982 + &IID_IMAPIProp, MAPI_BEST_ACCESS , &objType,
2984 + lpMsgStore->Release();
2986 + if (HR_FAILED(mLastError)) {
2987 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
2990 + for (i = 0 ; i < aNbProperties ; ++ i)
2992 + aValues[i].ulPropTag = GetRealMapiPropertyTag(*(LPMESSAGE*)&object,aValues[i].ulPropTag,TRUE);
2994 + mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
2995 + if (HR_FAILED(mLastError)) {
2996 + PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
3000 + for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
3001 + PRINTF(("Problem %d: index %d code %08x.\n", i,
3002 + problems->aProblem [i].ulIndex,
3003 + problems->aProblem [i].scode)) ;
3006 + mLastError = object->SaveChanges(0) ;
3007 + if (MAPI_E_OBJECT_CHANGED == mLastError)
3009 + mLastError = object->SaveChanges(FORCE_SAVE ) ;
3011 + return HR_SUCCEEDED(mLastError) ;
3014 +BOOL nsMapiAddressBook::GetDefaultContainer(nsMapiEntry& aContainer)
3019 +BOOL nsMapiAddressBook::IsOK(void)
3021 + return mRootSession && mLibUsage;
3024 BOOL nsMapiAddressBook::Initialize(void)
3026 - if (mAddressBook) { return TRUE ; }
3028 nsAutoLock guard(mMutex) ;
3030 if (!LoadMapiLibrary()) {
3031 PRINTF(("Cannot load library.\n")) ;
3034 - mAddressBook = mRootBook ;
3039 void nsMapiAddressBook::AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer)
3040 @@ -182,7 +1109,803 @@
3041 mMAPIFreeBuffer(aBuffer) ;
3044 +ULONG nsMapiAddressBook::GetEmailPropertyTag(LPMAPIPROP lpProp, LONG nameID)
3046 + static GUID emailGUID =
3048 + 0x00062004, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46
3052 + MAPINAMEID mapiNameID;
3053 + mapiNameID.lpguid = &emailGUID;
3054 + mapiNameID.ulKind = MNID_ID;
3055 + mapiNameID.Kind.lID = nameID;
3057 + LPMAPINAMEID lpMapiNames = &mapiNameID;
3058 + LPSPropTagArray lpMailTagArray = NULL;
3060 + HRESULT result = lpProp->GetIDsFromNames(1L, &lpMapiNames, 0, &lpMailTagArray);
3061 + if (result == S_OK)
3063 + ULONG lTag = lpMailTagArray->aulPropTag[0];
3064 + mMAPIFreeBuffer(lpMailTagArray);
3069 +ULONG nsMapiAddressBook::GetRealMapiPropertyTag(LPMAPIPROP lpProp, LONG aPropertyTag,BOOL aTest)
3071 + LPSPropValue addr;
3072 + ULONG upRealTag=aPropertyTag;
3073 + ULONG lSize=sizeof(TagMaps) / sizeof(TagMap);
3075 + for(int i=0; i<lSize; i++)
3077 + if (TagMaps[i].AddressTag == aPropertyTag)
3080 + ULONG kPriEmailColumn=GetEmailPropertyTag(lpProp,TagMaps[i].NameID);
3083 + if (PR_DISPLAY_NAME_A == aPropertyTag)
3085 + //We need not change PR_DISPLAY_NAME_A tag if we are not using an address
3086 + LPSPropValue msgClass=GetMapiProperty(lpProp,PR_MESSAGE_CLASS);
3087 + if (msgClass && !strcmp("IPM.Contact",msgClass->Value.lpszA))
3089 + if (kPriEmailColumn)
3090 + upRealTag = kPriEmailColumn | TagMaps[i].TypeMask;
3094 + FreeBuffer(msgClass);
3095 + upRealTag = aPropertyTag;
3098 + else //PR_DISPLAY_NAME_A == aPropertyTag
3100 + addr=GetMapiProperty(lpProp,aPropertyTag);
3101 + if (!addr || PROP_TYPE( addr->ulPropTag) == PT_ERROR ||
3102 + addr->Value.l == MAPI_E_NOT_FOUND)
3104 + if (kPriEmailColumn)
3105 + upRealTag = kPriEmailColumn | TagMaps[i].TypeMask;
3111 + if (kPriEmailColumn)
3112 + upRealTag = kPriEmailColumn | TagMaps[i].TypeMask;
3115 + break; //we find it,exit
3122 +BOOL nsMapiAddressBook::GetPropertyLong(const nsMapiEntry& aObject,
3123 + ULONG aPropertyTag,
3127 + LPSPropValue values = NULL ;
3128 + ULONG valueCount = 0 ;
3130 + if (PR_OBJECT_TYPE == aPropertyTag)
3132 + nsMapiInterfaceWrapper<LPMAPIFOLDER> pFolder ;
3134 + mLastError = OpenEntry(aObject.mByteCount,aObject.mEntryId,
3135 + NULL,MAPI_BEST_ACCESS,&objType, pFolder);
3136 + if (HR_FAILED(mLastError))
3138 + PRINTF(("Cannot open folder %08x.\n", mLastError)) ;
3141 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIFOLDER*)&pFolder,PR_MESSAGE_CLASS);
3142 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
3144 + FreeBuffer(msgClass);
3145 + aValue = MAPI_DISTLIST;
3150 + if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount))
3153 + if (valueCount == 1 && values && PROP_TYPE(values->ulPropTag) == PT_LONG) {
3154 + aValue = values->Value.ul ;
3156 + FreeBuffer(values) ;
3160 +BOOL nsMapiAddressBook::GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
3161 + WORD& aYear, WORD& aMonth, WORD& aDay)
3166 + LPSPropValue values = NULL ;
3167 + ULONG valueCount = 0 ;
3169 + if (!GetMAPIProperties(aObject, &aPropertyTag, 1, values, valueCount))
3172 + if (valueCount == 1 && values && PROP_TYPE(values->ulPropTag) == PT_SYSTIME) {
3173 + SYSTEMTIME readableTime ;
3174 + FILETIME localTime ;
3175 + FileTimeToLocalFileTime(&values->Value.ft,&localTime);
3176 + if (FileTimeToSystemTime(&localTime, &readableTime)) {
3177 + aYear = readableTime.wYear ;
3178 + aMonth = readableTime.wMonth ;
3179 + aDay = readableTime.wDay ;
3182 + FreeBuffer(values) ;
3186 +HRESULT nsMapiAddressBook::OpenEntry(ULONG cbEntryID,
3187 + LPENTRYID lpEntryID,
3188 + LPCIID lpInterface,
3190 + ULONG FAR * lpulObjType,
3191 + LPUNKNOWN FAR * lppUnk
3199 + rv=mRootSession->OpenEntry(cbEntryID,
3211 + if (HR_FAILED(rv) && !m_MDBArray.Count())
3213 + //There are no openned Message store,so we have to open them all
3214 + nsMapiEntryArray aFolders;
3215 + if (GetFolders(aFolders))
3219 + rv=mRootSession->OpenEntry(cbEntryID,
3236 +BOOL nsMapiAddressBook::AddEntryToList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry)
3238 + nsMapiInterfaceWrapper<LPMAPIPROP> container ;
3239 + ULONG objType = 0 ;
3241 + nsMapiEntry parentEntry;
3242 + if (!GetEntryParent(aDistlist,parentEntry))
3245 + LPMDB lpMsgStore=GetMsgStore(parentEntry);
3249 + mLastError = lpMsgStore->OpenEntry(aDistlist.mByteCount, aDistlist.mEntryId,
3250 + &IID_IMAPIProp, MAPI_BEST_ACCESS, &objType,
3252 + lpMsgStore->Release();
3254 + if (HR_FAILED(mLastError))
3259 + When add mail address to distlist,Mapi need update 2 tag.
3261 + //update OUTLOOK_EMAIL_LIST1
3262 + ULONG listTag=GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST1) | PT_MV_BINARY;
3263 + SBinaryArray oldChilds;
3264 + LPSBinary bins=NULL;
3265 + SBinaryArray newChilds;
3266 + LPSPropValue oldChildValue = NULL ;
3267 + ULONG valueCount = 0 ;
3269 + if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
3271 + PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
3275 + if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
3277 + oldChilds = oldChildValue->Value.MVbin;
3278 + newChilds.cValues=oldChilds.cValues + 1;
3279 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3280 + newChilds.lpbin = bins;
3281 + for (ULONG i=0;i<oldChilds.cValues;i++)
3283 + newChilds.lpbin[i].lpb = oldChilds.lpbin[i].lpb;
3284 + newChilds.lpbin[i].cb = oldChilds.lpbin[i].cb;
3289 + newChilds.cValues = 1;
3290 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3291 + newChilds.lpbin = bins;
3294 + nsMapiEntry orgEntryID;
3295 + if (!GetPropertyBin(aNewEntry,
3296 + GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_ORGID) | PT_BINARY,
3301 + newChilds.lpbin[newChilds.cValues-1].lpb = NS_REINTERPRET_CAST(unsigned char *, orgEntryID.mEntryId);
3302 + newChilds.lpbin[newChilds.cValues-1].cb = orgEntryID.mByteCount;
3304 + SPropValue childs;
3305 + childs.ulPropTag = listTag;
3306 + childs.Value.MVbin = newChilds;
3308 + LPSPropProblemArray problems = NULL ;
3309 + mLastError = container->SetProps(1, &childs, &problems) ;
3310 + if (HR_FAILED(mLastError)) {
3311 + PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
3315 + //update OUTLOOK_EMAIL_LIST2
3316 + listTag = GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST2) | PT_MV_BINARY;
3317 + if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
3319 + PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
3323 + if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
3325 + oldChilds = oldChildValue->Value.MVbin;
3326 + newChilds.cValues=oldChilds.cValues + 1;
3327 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3328 + newChilds.lpbin = bins;
3329 + for (ULONG i=0;i<oldChilds.cValues;i++)
3331 + newChilds.lpbin[i].lpb = oldChilds.lpbin[i].lpb;
3332 + newChilds.lpbin[i].cb = oldChilds.lpbin[i].cb;
3337 + newChilds.cValues = 1;
3338 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3339 + newChilds.lpbin = bins;
3343 + Need more work here.
3344 + There are two kind of mail address in outlook DistList.
3345 + One is sample,not include in parent folder.
3346 + The other is a link to a unattached address in parents folders.
3347 + Currently we can only add first kind of address to a outlook distlist.
3350 + newChilds.lpbin[newChilds.cValues-1].lpb = NS_REINTERPRET_CAST(unsigned char *, orgEntryID.mEntryId);
3351 + newChilds.lpbin[newChilds.cValues-1].cb = orgEntryID.mByteCount;
3353 + childs.ulPropTag = listTag;
3354 + childs.Value.MVbin = newChilds;
3356 + mLastError = container->SetProps(1, &childs, &problems) ;
3357 + if (HR_FAILED(mLastError))
3359 + PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
3363 + mMAPIFreeBuffer(bins);
3365 + mLastError = container->SaveChanges(KEEP_OPEN_READONLY) ;
3366 + if (HR_FAILED(mLastError)) {
3367 + PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
3373 +BOOL nsMapiAddressBook::DeleteEntryFromList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry)
3375 + nsMapiInterfaceWrapper<LPMAPIPROP> container ;
3376 + ULONG objType = 0 ;
3378 + nsMapiEntry parentEntry;
3379 + if (!GetEntryParent(aDistlist,parentEntry))
3382 + LPMDB lpMsgStore=GetMsgStore(parentEntry);
3386 + mLastError = lpMsgStore->OpenEntry(aDistlist.mByteCount, aDistlist.mEntryId,
3387 + &IID_IMAPIProp, MAPI_BEST_ACCESS, &objType,
3389 + lpMsgStore->Release();
3391 + if (HR_FAILED(mLastError))
3394 + When delete mail address from distlist,Mapi need update 2 tag.
3396 + //update OUTLOOK_EMAIL_LIST1
3397 + ULONG listTag=GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST1) | PT_MV_BINARY;
3399 + SBinaryArray oldChilds;
3400 + LPSBinary bins=NULL;
3401 + SBinaryArray newChilds;
3402 + LPSPropValue oldChildValue = NULL ;
3403 + ULONG valueCount = 0 ;
3405 + newChilds.lpbin=NULL;
3407 + ULONG lDeleteEntry=0;
3410 + if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
3412 + PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
3416 + if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
3418 + oldChilds = oldChildValue->Value.MVbin;
3419 + newChilds.cValues=oldChilds.cValues - 1;
3420 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3421 + newChilds.lpbin = bins;
3422 + for (oldIndex=0;oldIndex<oldChilds.cValues;oldIndex++)
3424 + if ( oldChilds.lpbin[oldIndex].cb == aNewEntry.mByteCount &&
3425 + !memcmp((void*)(oldChilds.lpbin[oldIndex].lpb+4),
3426 + (void*)(aNewEntry.mEntryId->ab),
3427 + oldChilds.lpbin[oldIndex].cb-4))
3429 + lDeleteEntry=oldIndex;
3433 + newChilds.lpbin[newIndex].lpb = oldChilds.lpbin[oldIndex].lpb;
3434 + newChilds.lpbin[newIndex].cb = oldChilds.lpbin[oldIndex].cb;
3443 + SPropValue childs;
3444 + LPSPropProblemArray problems = NULL ;
3446 + if (newChilds.cValues == 0)
3448 + SPropTagArray delTags;
3449 + delTags.cValues = 1;
3450 + delTags.aulPropTag[0] = listTag;
3452 + mLastError = container->DeleteProps(&delTags, &problems) ;
3456 + childs.ulPropTag = listTag;
3457 + childs.Value.MVbin = newChilds;
3458 + mLastError = container->SetProps(1, &childs, &problems) ;
3461 + if (HR_FAILED(mLastError)) {
3462 + PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
3466 + //update OUTLOOK_EMAIL_LIST2
3467 + listTag = GetEmailPropertyTag(*(LPMAPIPROP*)&container,OUTLOOK_EMAIL_LIST2) | PT_MV_BINARY;
3468 + if (!GetMAPIProperties(aDistlist, &listTag, 1, oldChildValue, valueCount))
3470 + PRINTF(("Cannot get old childs %08x.\n", mLastError)) ;
3475 + if (! (oldChildValue->Value.l == MAPI_E_NOT_FOUND))
3477 + oldChilds = oldChildValue->Value.MVbin;
3478 + newChilds.cValues=oldChilds.cValues - 1;
3479 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3480 + newChilds.lpbin = bins;
3481 + for (oldIndex=0;oldIndex<oldChilds.cValues;oldIndex++)
3483 + if (oldIndex != lDeleteEntry)
3485 + newChilds.lpbin[newIndex].lpb = oldChilds.lpbin[oldIndex].lpb;
3486 + newChilds.lpbin[newIndex].cb = oldChilds.lpbin[oldIndex].cb;
3493 + newChilds.cValues = 1;
3494 + mMAPIAllocateBuffer(sizeof(SBinary) * newChilds.cValues,(void**)& bins);
3495 + newChilds.lpbin = bins;
3500 + if (newChilds.cValues == 0)
3502 + SPropTagArray delTags;
3503 + delTags.cValues = 1;
3504 + delTags.aulPropTag[0] = listTag;
3506 + mLastError = container->DeleteProps(&delTags, &problems) ;
3510 + childs.ulPropTag = listTag;
3511 + childs.Value.MVbin = newChilds;
3512 + mLastError = container->SetProps(1, &childs, &problems) ;
3514 + if (HR_FAILED(mLastError)) {
3515 + PRINTF(("Cannot set childs %08x.\n", mLastError)) ;
3519 + mMAPIFreeBuffer(bins);
3521 + mLastError = container->SaveChanges(KEEP_OPEN_READONLY) ;
3522 + if (HR_FAILED(mLastError)) {
3523 + PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
3530 +BOOL nsMapiAddressBook::GetEntryParent(const nsMapiEntry& aParent, nsMapiEntry& aParentEntry)
3532 + nsMapiInterfaceWrapper<LPMAPIPROP> object ;
3533 + ULONG objType = 0 ;
3534 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
3535 + &IID_IMAPIProp, MAPI_BEST_ACCESS, &objType,
3536 + (IUnknown **)&object) ;
3538 + if (HR_FAILED(mLastError)) {
3539 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3542 + SPropValue *parentID=GetMapiProperty(*(LPMAPIPROP*)&object, PR_PARENT_ENTRYID);
3544 + if (parentID->Value.l == MAPI_E_NOT_FOUND)
3546 + aParentEntry.Assign(parentID->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, parentID->Value.bin.lpb));
3549 +BOOL nsMapiAddressBook::CreateEntryInList(const nsMapiEntry& aDistlist, nsMapiEntry& aNewEntry)
3551 + nsMapiInterfaceWrapper<LPMAPIPROP> container ;
3552 + ULONG objType = 0 ;
3554 + nsMapiEntry parentEntry;
3555 + if (!GetEntryParent(aDistlist,parentEntry))
3559 + nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
3560 + if (!CreateEntry(parentEntry,aNewEntry)) //Create a entry in parent folder
3563 + return AddEntryToList(aDistlist,aNewEntry);
3566 +BOOL nsMapiAddressBook::CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry)
3568 + nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
3569 + ULONG objType = 0 ;
3571 + nsMapiInterfaceWrapper<LPMAPIPROP> object;
3572 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
3573 + &IID_IMAPIProp, MAPI_BEST_ACCESS, &objType,
3576 + if (HR_FAILED(mLastError)) {
3577 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3580 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
3582 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
3583 + return CreateEntryInList(aParent,aNewEntry); //Create entry in DistList
3585 + LPMDB lpMsgStore=GetMsgStore(aParent);
3590 + mLastError = lpMsgStore->OpenEntry(aParent.mByteCount, aParent.mEntryId,
3591 + &IID_IMAPIFolder, MAPI_BEST_ACCESS, &objType,
3593 + lpMsgStore->Release();
3595 + if (HR_FAILED(mLastError))
3598 + nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
3600 + mLastError = container->CreateMessage(&IID_IMessage,
3603 + if (HR_FAILED(mLastError)) {
3604 + PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
3607 + SPropValue messageclass ;
3608 + LPSPropProblemArray problems = NULL ;
3609 + nsCString tempName ;
3611 + messageclass.ulPropTag = PR_MESSAGE_CLASS_A ;
3612 + tempName.Assign("IPM.Contact") ;
3613 + messageclass.Value.lpszA = NS_CONST_CAST(char *, tempName.get()) ;
3614 + mLastError = newEntry->SetProps(1, &messageclass, &problems) ;
3615 + if (HR_FAILED(mLastError)) {
3616 + PRINTF(("Cannot set temporary name %08x.\n", mLastError)) ;
3619 + mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
3620 + if (HR_FAILED(mLastError)) {
3621 + PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
3625 + SPropTagArray property ;
3626 + LPSPropValue value = NULL ;
3627 + ULONG valueCount = 0 ;
3629 + property.cValues = 1 ;
3630 + property.aulPropTag [0] = PR_ENTRYID ;
3631 + mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
3632 + if (HR_FAILED(mLastError) || valueCount != 1) {
3633 + PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
3636 + aNewEntry.Assign(value->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
3637 + FreeBuffer(value) ;
3641 +BOOL nsMapiAddressBook::CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry)
3643 + nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
3644 + ULONG objType = 0 ;
3646 + LPMDB lpMsgStore=GetMsgStore(aParent);
3649 + mLastError = lpMsgStore->OpenEntry(aParent.mByteCount, aParent.mEntryId,
3650 + &IID_IMAPIFolder, MAPI_BEST_ACCESS, &objType,
3652 + lpMsgStore->Release();
3654 + if (HR_FAILED(mLastError)) {
3655 + PRINTF(("Cannot open container %08x.\n", mLastError)) ;
3659 + nsMapiInterfaceWrapper<LPMESSAGE> newEntry ;
3660 + mLastError = container->CreateMessage(&IID_IMAPIProp,
3663 + if (HR_FAILED(mLastError)) {
3664 + PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
3667 + SPropValue messageclass ;
3668 + LPSPropProblemArray problems = NULL ;
3669 + nsCString tempName ;
3671 + messageclass.ulPropTag = PR_MESSAGE_CLASS_A ;
3672 + tempName.Assign("IPM.DistList") ;
3673 + messageclass.Value.lpszA = NS_CONST_CAST(char *, tempName.get()) ;
3674 + mLastError = newEntry->SetProps(1, &messageclass, &problems) ;
3675 + if (HR_FAILED(mLastError)) {
3676 + PRINTF(("Cannot set PR_MESSAGE_CLASS_A %08x.\n", mLastError)) ;
3679 + mLastError = newEntry->SaveChanges(KEEP_OPEN_READONLY) ;
3680 + if (HR_FAILED(mLastError)) {
3681 + PRINTF(("Cannot commit new entry %08x.\n", mLastError)) ;
3685 + ULONG valueCount = 0 ;
3686 + SPropTagArray property ;
3687 + LPSPropValue value = NULL ;
3689 + property.cValues = 1 ;
3690 + property.aulPropTag [0] = PR_ENTRYID ;
3691 + mLastError = newEntry->GetProps(&property, 0, &valueCount, &value) ;
3692 + if (HR_FAILED(mLastError) || valueCount != 1) {
3693 + PRINTF(("Cannot get entry id %08x.\n", mLastError)) ;
3696 + aNewEntry.Assign(value->Value.bin.cb, NS_REINTERPRET_CAST(LPENTRYID, value->Value.bin.lpb)) ;
3698 + FreeBuffer(value) ;
3703 +BOOL nsMapiAddressBook::CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource,
3704 + nsMapiEntry& aTarget)
3706 + nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
3707 + nsMapiInterfaceWrapper<LPMAPIFOLDER> targetFolder ;
3708 + ULONG objType = 0 ;
3709 + nsMapiInterfaceWrapper<LPMAPIPROP> object;
3710 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
3711 + &IID_IMAPIProp, MAPI_BEST_ACCESS, &objType,
3714 + if (HR_FAILED(mLastError)) {
3715 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3718 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
3720 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
3722 + //Add Entry To DistList
3723 + if (!AddEntryToList(aContainer,aSource))
3725 + aTarget.Assign(aSource.mByteCount,aSource.mEntryId);
3730 + SBinaryArray entryArray ;
3732 + entry.cb = aSource.mByteCount ;
3733 + entry.lpb = NS_REINTERPRET_CAST(LPBYTE, aSource.mEntryId) ;
3734 + entryArray.cValues = 1 ;
3735 + entryArray.lpbin = &entry ;
3737 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
3738 + &IID_IMAPIFolder, MAPI_BEST_ACCESS, &objType,
3740 + if (HR_FAILED(mLastError)) {
3741 + PRINTF(("Cannot open container %08x.\n", mLastError)) ;
3745 + mLastError = OpenEntry(aTarget.mByteCount, aTarget.mEntryId,
3746 + &IID_IMAPIFolder, MAPI_BEST_ACCESS, &objType,
3748 + if (HR_FAILED(mLastError)) {
3749 + PRINTF(("Cannot open Target folder %08x.\n", mLastError)) ;
3753 + nsMapiInterfaceWrapper<LPMAPIPROP> newEntry ;
3755 + mLastError = container->CopyMessages(&entryArray,
3757 + (void*)&targetFolder,
3761 + if (HR_FAILED(mLastError)) {
3762 + PRINTF(("Cannot create new entry %08x.\n", mLastError)) ;
3768 +BOOL nsMapiAddressBook::DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry)
3770 + nsMapiInterfaceWrapper<LPMAPIFOLDER> container ;
3771 + ULONG objType = 0 ;
3773 + SBinaryArray entryArray ;
3776 + nsMapiInterfaceWrapper<LPMAPIPROP> object;
3777 + mLastError = OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
3778 + &IID_IMAPIProp, MAPI_BEST_ACCESS, &objType,
3781 + if (HR_FAILED(mLastError)) {
3782 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3785 + LPSPropValue msgClass=GetMapiProperty(*(LPMAPIPROP*)&object,PR_MESSAGE_CLASS);
3787 + if (msgClass && strcmp("IPM.DistList",msgClass->Value.lpszA) == 0)
3788 + return DeleteEntryFromList(aContainer,aEntry); //Delete Entry from DistList
3790 + LPMDB lpMsgStore=GetMsgStore(aContainer);
3794 + mLastError = lpMsgStore->OpenEntry(aContainer.mByteCount, aContainer.mEntryId,
3795 + &IID_IMAPIFolder, MAPI_BEST_ACCESS, &objType,
3797 + lpMsgStore->Release();
3798 + if (HR_FAILED(mLastError)) {
3799 + PRINTF(("Cannot open container %08x.\n", mLastError)) ;
3802 + entry.cb = aEntry.mByteCount ;
3803 + entry.lpb = NS_REINTERPRET_CAST(LPBYTE, aEntry.mEntryId) ;
3804 + entryArray.cValues = 1 ;
3805 + entryArray.lpbin = &entry ;
3806 + mLastError = container->DeleteMessages(&entryArray, 0,0,0) ;
3807 + if (HR_FAILED(mLastError)) {
3808 + PRINTF(("Cannot delete entry %08x.\n", mLastError)) ;
3814 +//Use to open message store in write mode
3815 +LPMDB nsMapiAddressBook::GetMsgStore(const nsMapiEntry& aEntry)
3817 + nsMapiInterfaceWrapper<LPMAPIPROP> object;
3820 + mLastError = OpenEntry(aEntry.mByteCount, aEntry.mEntryId,
3821 + &IID_IMAPIProp, MAPI_BEST_ACCESS , &objType,
3823 + if (HR_FAILED(mLastError)) {
3824 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
3827 + SPropValue *svMsgSore=GetMapiProperty( *(LPMAPIPROP*)&object, PR_STORE_ENTRYID);;
3829 + LPMDB lpMsgStore=NULL;
3830 + mLastError=mRootSession->OpenMsgStore(0,
3831 + svMsgSore->Value.bin.cb,
3832 + (ENTRYID*)svMsgSore->Value.bin.lpb,
3834 + MAPI_BEST_ACCESS ,
3837 + if (HR_FAILED(mLastError)) {
3838 + PRINTF(("Cannot open MsgStore %08x.\n", mLastError)) ;
3842 + return lpMsgStore;
3844 Index: mailnews/addrbook/src/nsMapiAddressBook.h
3845 ===================================================================
3846 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h,v
3847 retrieving revision 1.3
3848 diff -u -r1.3 nsMapiAddressBook.h
3849 --- misc/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h 28 Sep 2001 20:06:25 -0000 1.3
3850 +++ misc/build/mozilla/mailnews/addrbook/src/nsMapiAddressBook.h 17 May 2004 03:23:55 -0000
3853 #include "nsAbWinHelper.h"
3861 class nsMapiAddressBook : public nsAbWinHelper
3864 nsMapiAddressBook(void) ;
3865 virtual ~nsMapiAddressBook(void) ;
3867 + // Get the top address books
3868 + virtual BOOL GetFolders(nsMapiEntryArray& aFolders);
3870 + // Get a default address book container
3871 + virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer);
3872 + // Is the helper correctly initialised?
3873 + virtual BOOL IsOK(void);
3874 + virtual BOOL GetPropertyLong(const nsMapiEntry& aObject,
3875 + ULONG aPropertyTag,
3877 + // Get the value of a MAPI property of type SYSTIME
3878 + virtual BOOL GetPropertyDate(const nsMapiEntry& aObject, ULONG aPropertyTag,
3879 + WORD& aYear, WORD& aMonth, WORD& aDay);
3880 + // Create entry in the address book
3881 + virtual BOOL CreateEntry(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
3882 + // Delete an entry in the address book
3883 + virtual BOOL DeleteEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aEntry) ;
3884 + // Create a distribution list in the address book
3885 + virtual BOOL CreateDistList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry) ;
3886 + // Copy an existing entry in the address book
3887 + virtual BOOL CopyEntry(const nsMapiEntry& aContainer, const nsMapiEntry& aSource, nsMapiEntry& aTarget) ;
3889 + static void FreeMapiLibrary(void) ;
3892 // Class members to handle the library/entry points
3893 static HMODULE mLibrary ;
3895 static BOOL mInitialized ;
3896 static BOOL mLogonDone ;
3897 static LPMAPISESSION mRootSession ;
3898 - static LPADRBOOK mRootBook ;
3901 // Load the MAPI environment
3902 BOOL Initialize(void) ;
3904 + virtual HRESULT OpenEntry(ULONG cbEntryID,
3905 + LPENTRYID lpEntryID,
3906 + LPCIID lpInterface,
3908 + ULONG FAR * lpulObjType,
3909 + LPUNKNOWN FAR * lppUnk
3913 + // Retrieve the contents of a container, with an optional restriction
3914 + virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
3915 + nsMapiEntryArray *aList, ULONG aMapiType) ;
3916 + // Retrieve the values of a set of properties on a MAPI object
3917 + virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
3918 + ULONG aNbProperties,
3919 + LPSPropValue& aValues, ULONG& aValueCount) ;
3920 + // Set the values of a set of properties on a MAPI object
3921 + virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
3922 + LPSPropValue& aValues);
3925 // Allocation of a buffer for transmission to interfaces
3926 virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) ;
3927 // Destruction of a buffer provided by the interfaces
3928 virtual void FreeBuffer(LPVOID aBuffer) ;
3929 // Library management
3930 static BOOL LoadMapiLibrary(void) ;
3931 - static void FreeMapiLibrary(void) ;
3933 + BOOL HandleContentsItem(ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders);
3934 + LPSPropValue GetMapiProperty( LPMAPIPROP pProp, ULONG tag);
3935 + BOOL GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYID& lpEntryId, BOOL delVal=FALSE);
3936 + BOOL HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry,nsMapiEntryArray& aFolders);
3937 + BOOL IterateHierarchy(IMAPIContainer * pFolder, nsMapiEntryArray& aFolders,ULONG flags=0);
3938 + ULONG GetEmailPropertyTag(LPMAPIPROP lpProp, LONG nameID);
3939 + ULONG GetRealMapiPropertyTag(LPMAPIPROP lpProp, LONG aPropertyTag,BOOL aTest=FALSE);
3940 + LPMDB GetMsgStore(const nsMapiEntry& aEntry);
3941 + BOOL CreateEntryInList(const nsMapiEntry& aParent, nsMapiEntry& aNewEntry);
3942 + BOOL AddEntryToList(const nsMapiEntry& aParent,const nsMapiEntry& aNewEntry);
3943 + BOOL DeleteEntryFromList(const nsMapiEntry& aDistlist, const nsMapiEntry& aNewEntry);
3944 + BOOL GetEntryParent(const nsMapiEntry& aParent, nsMapiEntry& aParentEntry);
3945 + BOOL CorrectRestriction(const LPMAPIPROP aMapiProp,ULONG aRestrictionNum, LPSRestriction aRestriction);
3948 + BOOL Filter( LPSRestriction aRestriction,nsMapiEntryArray * aList);
3949 + BOOL FilterOnOneRow(nsMapiEntry *aEntry,LPSRestriction aRestriction);
3950 + BOOL AtomyFilter(LPSRestriction aRestriction,LPSPropValue aRealValue,LPSPropValue aFilterValue);
3952 + void AddToMDBArray(LPMDB aMDB)
3954 + m_MDBArray.AppendElement(aMDB);
3959 + for (int i = 0; i < m_MDBArray.Count(); i++)
3961 + mdb = (LPMDB)m_MDBArray.ElementAt(i);
3964 + m_MDBArray.Clear();
3968 + //use to keep all openned MsgStore,if we not open a message store,we can't open any thing on it
3969 + //so we have to kill message stores openned
3970 + nsVoidArray m_MDBArray;
3973 #endif // nsMapiAddressBook_h___
3974 Index: mailnews/addrbook/src/nsWabAddressBook.cpp
3975 ===================================================================
3976 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp,v
3977 retrieving revision 1.6
3978 diff -u -r1.6 nsWabAddressBook.cpp
3979 --- misc/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp 30 Oct 2001 07:59:16 -0000 1.6
3980 +++ misc/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.cpp 17 May 2004 03:23:55 -0000
3983 #define PRINTF(args) PR_LOG(gWabAddressBookLog, PR_LOG_DEBUG, args)
3987 + ContentsColumnEntryId = 0,
3988 + ContentsColumnObjectType,
3989 + ContentsColumnsSize
3992 +static const SizedSPropTagArray(ContentsColumnsSize, ContentsColumns) =
3994 + ContentsColumnsSize,
4001 HMODULE nsWabAddressBook::mLibrary = NULL ;
4002 PRInt32 nsWabAddressBook::mLibUsage = 0 ;
4003 LPWABOPEN nsWabAddressBook::mWABOpen = NULL ;
4005 MOZ_DECL_CTOR_COUNTER(nsWabAddressBook)
4007 nsWabAddressBook::nsWabAddressBook(void)
4009 +: nsAbWinHelper(),mAddressBook(NULL)
4011 BOOL result = Initialize() ;
4013 @@ -110,9 +126,254 @@
4014 MOZ_COUNT_DTOR(nsWabAddressBook) ;
4017 +BOOL nsWabAddressBook::GetFolders(nsMapiEntryArray& aFolders)
4019 + aFolders.CleanUp() ;
4020 + nsMapiInterfaceWrapper<LPABCONT> rootFolder ;
4021 + nsMapiInterfaceWrapper<LPMAPITABLE> folders ;
4022 + ULONG objType = 0 ;
4023 + ULONG rowCount = 0 ;
4024 + SRestriction restriction ;
4025 + SPropTagArray folderColumns ;
4027 + mLastError = OpenEntry(0, NULL, NULL, 0, &objType,
4029 + if (HR_FAILED(mLastError)){
4030 + PRINTF(("Cannot open root %08x.\n", mLastError));
4033 + mLastError = rootFolder->GetHierarchyTable(0, folders);
4034 + if (HR_FAILED(mLastError)){
4035 + PRINTF(("Cannot get hierarchy %08x.\n", mLastError));
4038 + // We only take into account modifiable containers,
4039 + // otherwise, we end up with all the directory services...
4040 + restriction.rt = RES_BITMASK ;
4041 + restriction.res.resBitMask.ulPropTag = PR_CONTAINER_FLAGS ;
4042 + restriction.res.resBitMask.relBMR = BMR_NEZ ;
4043 + restriction.res.resBitMask.ulMask = AB_MODIFIABLE ;
4044 + mLastError = folders->Restrict(&restriction, 0) ;
4045 + if (HR_FAILED(mLastError)) {
4046 + PRINTF(("Cannot restrict table %08x.\n", mLastError)) ;
4048 + folderColumns.cValues = 1 ;
4049 + folderColumns.aulPropTag [0] = PR_ENTRYID ;
4050 + mLastError = folders->SetColumns(&folderColumns, 0) ;
4051 + if (HR_FAILED(mLastError)) {
4052 + PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
4055 + mLastError = folders->GetRowCount(0, &rowCount) ;
4056 + if (HR_SUCCEEDED(mLastError)) {
4058 + LPSRowSet rowSet = NULL ;
4061 + mLastError = folders->QueryRows(1, 0, &rowSet) ;
4062 + if (HR_SUCCEEDED(mLastError)) {
4063 + rowCount = rowSet->cRows ;
4064 + if (rowCount > 0) {
4065 + SPropValue& currentValue = rowSet->aRow->lpProps [0] ;
4067 + aFolders.AddItem(currentValue.Value.bin.cb,
4068 + NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
4070 + MyFreeProws(rowSet) ;
4073 + PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
4075 + } while (rowCount > 0) ;
4077 + return HR_SUCCEEDED(mLastError) ;
4079 +BOOL nsWabAddressBook::GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
4080 + nsMapiEntryArray *aList, ULONG aMapiType)
4082 + if (aList) { aList->CleanUp(); }
4083 + nsMapiInterfaceWrapper<LPMAPICONTAINER> parent ;
4084 + nsMapiInterfaceWrapper<LPMAPITABLE> contents ;
4085 + ULONG objType = 0 ;
4086 + ULONG rowCount = 0 ;
4088 + mLastError = OpenEntry(aParent.mByteCount, aParent.mEntryId,
4089 + &IID_IMAPIContainer, 0, &objType,
4091 + if (HR_FAILED(mLastError)) {
4092 + PRINTF(("Cannot open parent %08x.\n", mLastError)) ;
4095 + // Here, flags for WAB and MAPI could be different, so this works
4096 + // only as long as we don't want to use any flag in GetContentsTable
4097 + mLastError = parent->GetContentsTable(0, contents) ;
4098 + if (HR_FAILED(mLastError)) {
4099 + PRINTF(("Cannot get contents %08x.\n", mLastError)) ;
4102 + if (aRestriction) {
4103 + mLastError = contents->Restrict(aRestriction, 0) ;
4104 + if (HR_FAILED(mLastError)) {
4105 + PRINTF(("Cannot set restriction %08x.\n", mLastError)) ;
4109 + int entryId = ContentsColumnEntryId ;
4110 + int objectType = ContentsColumnObjectType ;
4114 + LPSPropTagArray allColumns = NULL ;
4116 + mLastError = contents->QueryColumns(TBL_ALL_COLUMNS, &allColumns) ;
4117 + if (HR_FAILED(mLastError)) {
4118 + PRINTF(("Cannot query columns %08x.\n", mLastError)) ;
4122 + for (unsigned int j = 0 ; j < allColumns->cValues ; ++ j) {
4123 + if (allColumns->aulPropTag [j] == PR_ENTRYID) {
4126 + else if (allColumns->aulPropTag [j] == PR_OBJECT_TYPE) {
4130 + mLastError = contents->SetColumns(allColumns, 0) ;
4131 + if (HR_FAILED(mLastError)) {
4132 + PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
4135 + FreeBuffer(allColumns) ;
4140 + mLastError = contents->SetColumns((LPSPropTagArray) &ContentsColumns, 0) ;
4141 + if (HR_FAILED(mLastError)) {
4142 + PRINTF(("Cannot set columns %08x.\n", mLastError)) ;
4147 + mLastError = contents->GetRowCount(0, &rowCount) ;
4148 + if (HR_FAILED(mLastError)) {
4149 + PRINTF(("Cannot get result count %08x.\n", mLastError)) ;
4153 + LPSRowSet rowSet = NULL ;
4156 + mLastError = contents->QueryRows(1, 0, &rowSet) ;
4157 + if (HR_FAILED(mLastError)) {
4158 + PRINTF(("Cannot query rows %08x.\n", mLastError)) ;
4161 + rowCount = rowSet->cRows ;
4162 + if (rowCount > 0 &&
4163 + (aMapiType == 0 ||
4164 + rowSet->aRow->lpProps[objectType].Value.ul == aMapiType)) {
4166 + SPropValue& currentValue = rowSet->aRow->lpProps[entryId] ;
4168 + aList->AddItem(currentValue.Value.bin.cb,
4169 + NS_REINTERPRET_CAST(LPENTRYID, currentValue.Value.bin.lpb)) ;
4173 + MyFreeProws(rowSet) ;
4174 + } while (rowCount > 0) ;
4178 +BOOL nsWabAddressBook::GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
4179 + ULONG aNbProperties, LPSPropValue& aValue,
4180 + ULONG& aValueCount)
4182 + nsMapiInterfaceWrapper<LPMAPIPROP> object ;
4183 + IMsgStore * mdb=NULL;
4184 + ULONG objType = 0 ;
4185 + LPSPropTagArray properties = NULL ;
4188 + mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
4189 + &IID_IMAPIProp, 0, &objType,
4192 + if (HR_FAILED(mLastError)){
4193 + PRINTF(("Cannot open entry %08x.\n", mLastError));
4196 + AllocateBuffer(CbNewSPropTagArray(aNbProperties),
4197 + NS_REINTERPRET_CAST(void **, &properties));
4198 + properties->cValues = aNbProperties;
4199 + for (i = 0 ; i < aNbProperties ; ++ i) {
4200 + properties->aulPropTag [i] = aPropertyTags [i];
4202 + mLastError = object->GetProps(properties, 0, &aValueCount, &aValue);
4203 + FreeBuffer(properties);
4204 + if (HR_FAILED(mLastError)){
4205 + PRINTF(("Cannot get props %08x.\n", mLastError));
4207 + return HR_SUCCEEDED(mLastError) ;
4210 +BOOL nsWabAddressBook::SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
4211 + LPSPropValue& aValues)
4213 + nsMapiInterfaceWrapper<LPMAPIPROP> object ;
4214 + ULONG objType = 0 ;
4215 + LPSPropProblemArray problems = NULL ;
4217 + mLastError = OpenEntry(aObject.mByteCount, aObject.mEntryId,
4218 + &IID_IMAPIProp, MAPI_MODIFY, &objType,
4220 + if (HR_FAILED(mLastError)) {
4221 + PRINTF(("Cannot open entry %08x.\n", mLastError)) ;
4224 + mLastError = object->SetProps(aNbProperties, aValues, &problems) ;
4225 + if (HR_FAILED(mLastError)) {
4226 + PRINTF(("Cannot update the object %08x.\n", mLastError)) ;
4230 + for (ULONG i = 0 ; i < problems->cProblem ; ++ i) {
4231 + PRINTF(("Problem %d: index %d code %08x.\n", i,
4232 + problems->aProblem [i].ulIndex,
4233 + problems->aProblem [i].scode));
4236 + mLastError = object->SaveChanges(0) ;
4237 + if (HR_FAILED(mLastError)) {
4238 + PRINTF(("Cannot commit changes %08x.\n", mLastError)) ;
4240 + return HR_SUCCEEDED(mLastError) ;
4243 +BOOL nsWabAddressBook::GetDefaultContainer(nsMapiEntry& aContainer)
4245 + LPENTRYID entryId = NULL;
4246 + ULONG byteCount = 0;
4248 + mLastError = mAddressBook->GetPAB(&byteCount, &entryId);
4249 + if (HR_FAILED(mLastError)){
4250 + PRINTF(("Cannot get PAB %08x.\n", mLastError));
4253 + aContainer.Assign(byteCount, entryId);
4254 + FreeBuffer(entryId) ;
4258 +BOOL nsWabAddressBook::IsOK(void)
4260 + return mAddressBook != NULL ;
4263 BOOL nsWabAddressBook::Initialize(void)
4265 - if (mAddressBook) { return TRUE ; }
4266 nsAutoLock guard(mMutex) ;
4268 if (!LoadWabLibrary()) {
4269 Index: mailnews/addrbook/src/nsWabAddressBook.h
4270 ===================================================================
4271 RCS file: /cvsroot/mozilla/mailnews/addrbook/src/nsWabAddressBook.h,v
4272 retrieving revision 1.2
4273 diff -u -r1.2 nsWabAddressBook.h
4274 --- misc/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.h 28 Sep 2001 20:06:25 -0000 1.2
4275 +++ misc/build/mozilla/mailnews/addrbook/src/nsWabAddressBook.h 17 May 2004 03:23:55 -0000
4277 nsWabAddressBook(void) ;
4278 virtual ~nsWabAddressBook(void) ;
4280 + // Get the top address books
4281 + virtual BOOL GetFolders(nsMapiEntryArray& aFolders);
4283 + // Get a default address book container
4284 + virtual BOOL GetDefaultContainer(nsMapiEntry& aContainer);
4285 + // Is the helper correctly initialised?
4286 + virtual BOOL IsOK(void);
4287 + static void FreeWabLibrary(void) ;
4290 // Session and address book that will be shared by all instances
4291 // (see nsMapiAddressBook.h for details)
4293 static HMODULE mLibrary ;
4294 static LPWABOPEN mWABOpen ;
4296 + LPADRBOOK mAddressBook ;
4298 // Load the WAB environment
4299 BOOL Initialize(void) ;
4301 + virtual HRESULT OpenEntry(ULONG cbEntryID,
4302 + LPENTRYID lpEntryID,
4303 + LPCIID lpInterface,
4305 + ULONG FAR * lpulObjType,
4306 + LPUNKNOWN FAR * lppUnk
4309 + return mAddressBook->OpenEntry(cbEntryID,
4319 + // Retrieve the contents of a container, with an optional restriction
4320 + virtual BOOL GetContents(const nsMapiEntry& aParent, LPSRestriction aRestriction,
4321 + nsMapiEntryArray *aList, ULONG aMapiType) ;
4322 + // Retrieve the values of a set of properties on a MAPI object
4323 + virtual BOOL GetMAPIProperties(const nsMapiEntry& aObject, const ULONG *aPropertyTags,
4324 + ULONG aNbProperties,
4325 + LPSPropValue& aValues, ULONG& aValueCount) ;
4326 + // Set the values of a set of properties on a MAPI object
4327 + virtual BOOL SetMAPIProperties(const nsMapiEntry& aObject, ULONG aNbProperties,
4328 + LPSPropValue& aValues) ;
4330 // Allocation of a buffer for transmission to interfaces
4331 virtual void AllocateBuffer(ULONG aByteCount, LPVOID *aBuffer) ;
4332 // Destruction of a buffer provided by the interfaces
4333 virtual void FreeBuffer(LPVOID aBuffer) ;
4334 // Manage the library
4335 static BOOL LoadWabLibrary(void) ;
4336 - static void FreeWabLibrary(void) ;
4340 Index: profile/src/nsProfile.cpp
4341 ===================================================================
4342 RCS file: /cvsroot/mozilla/profile/src/nsProfile.cpp,v
4343 retrieving revision 1.298
4344 diff -u -r1.298 nsProfile.cpp
4345 --- misc/build/mozilla/profile/src/nsProfile.cpp 28 Feb 2004 22:34:02 -0000 1.298
4346 +++ misc/build/mozilla/profile/src/nsProfile.cpp 17 May 2004 03:24:08 -0000
4350 #include "nsProfile.h"
4351 +#ifdef MOZ_PROFILELOCKING
4352 #include "nsProfileLock.h"
4354 #include "nsIPrefService.h"
4355 #include "nsIPrefBranch.h"
4357 @@ -499,12 +501,14 @@
4358 profileURLStr = PROFILE_MANAGER_URL;
4361 +#ifdef MOZ_PROFILELOCKING
4362 // If the profile is locked, we need the UI
4363 nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(curProfileDir));
4364 nsProfileLock tempLock;
4365 rv = tempLock.Lock(localFile);
4367 profileURLStr = PROFILE_MANAGER_URL;
4372 @@ -1173,7 +1177,7 @@
4375 isSwitch = PR_FALSE;
4377 +#ifdef MOZ_PROFILELOCKING
4378 nsProfileLock localLock;
4379 nsCOMPtr<nsILocalFile> localProfileDir(do_QueryInterface(profileDir, &rv));
4380 if (NS_FAILED(rv)) return rv;
4381 @@ -1183,7 +1187,7 @@
4382 NS_ERROR("Could not get profile directory lock.");
4387 nsCOMPtr<nsIObserverService> observerService =
4388 do_GetService("@mozilla.org/observer-service;1", &rv);
4389 NS_ENSURE_TRUE(observerService, NS_ERROR_FAILURE);
4390 @@ -1237,8 +1241,10 @@
4391 UpdateCurrentProfileModTime(PR_FALSE);
4394 +#ifdef MOZ_PROFILELOCKING
4395 // Do the profile switch
4396 localLock.Unlock(); // gDirServiceProvider will get and hold its own lock
4398 gDirServiceProvider->SetProfileDir(profileDir);
4399 mCurrentProfileName.Assign(aCurrentProfile);
4400 gProfileDataAccess->SetCurrentProfile(aCurrentProfile);
4401 Index: security/nss/lib/nss/config.mk
4402 ===================================================================
4403 RCS file: /cvsroot/mozilla/security/nss/lib/nss/config.mk,v
4404 retrieving revision 1.21
4405 diff -u -r1.21 config.mk
4406 --- misc/build/mozilla/security/nss/lib/nss/config.mk 20 Apr 2003 04:23:32 -0000 1.21
4407 +++ misc/build/mozilla/security/nss/lib/nss/config.mk 17 May 2004 03:24:08 -0000
4409 ifeq ($(OS_TARGET),SunOS)
4410 # The -R '$ORIGIN' linker option instructs libnss3.so to search for its
4411 # dependencies (libsoftokn3.so) in the same directory where it resides.
4412 -MKSHLIB += -R '$$ORIGIN'
4413 +#MKSHLIB += -R '$$ORIGIN'
4416 ifeq (,$(filter-out WINNT WIN95,$(OS_TARGET)))
4417 --- misc/build/mozilla/security/nss/lib/nss/nss.def 2004-07-13 10:38:04.000000000 +0800
4418 +++ misc/build/mozilla/security/nss/lib/nss/nss.def 2004-05-20 01:32:27.000000000 +0800
4420 CERT_CheckCertValidTimes;
4421 CERT_CreateCertificateRequest;
4422 CERT_ChangeCertTrust;
4423 +CERT_DecodeDERCertificate;
4425 CERT_DestroyCertificateRequest;
4426 CERT_DestroyCertList;
4429 PK11_GetBestSlotMultiple;
4430 PK11_GetBestWrapMechanism;
4431 +PK11_GetCertFromPrivateKey;
4432 PK11_GetCurrentWrapIndex;
4435 Index: security/nss/lib/softoken/config.mk
4436 ===================================================================
4437 RCS file: /cvsroot/mozilla/security/nss/lib/softoken/config.mk,v
4438 retrieving revision 1.14
4439 diff -u -r1.14 config.mk
4440 --- misc/build/mozilla/security/nss/lib/softoken/config.mk 16 May 2003 20:21:20 -0000 1.14
4441 +++ misc/build/mozilla/security/nss/lib/softoken/config.mk 17 May 2004 03:24:08 -0000
4443 ifeq ($(CPU_ARCH),sparc)
4444 # The -R '$ORIGIN' linker option instructs libsoftokn3.so to search for its
4445 # dependencies (libfreebl_*.so) in the same directory where it resides.
4446 -MKSHLIB += -R '$$ORIGIN'
4447 +#MKSHLIB += -R '$$ORIGIN'
4452 Index: mailnews/addrbook/src/nsAbMD5sum.cpp
4453 ===================================================================
4454 --- misc/mozilla/mailnews/addrbook/src/nsAbMD5sum.cpp 2005-01-09 00:07:11.359375000 -0500
4455 +++ misc/build/mozilla/mailnews/addrbook/src/nsAbMD5sum.cpp 2004-03-29 16:43:58.000000000 +0800
4459 + * The contents of this file are subject to the Mozilla Public
4460 + * License Version 1.1 (the "License"); you may not use this file
4461 + * except in compliance with the License. You may obtain a copy of
4462 + * the License at http://www.mozilla.org/MPL/
4464 + * Software distributed under the License is distributed on an "AS
4465 + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
4466 + * implied. See the License for the specific language governing
4467 + * rights and limitations under the License.
4469 + * The Original Code is the Netscape security libraries.
4471 + * The Initial Developer of the Original Code is Netscape
4472 + * Communications Corporation. Portions created by Netscape are
4473 + * Copyright (C) 1994-2000 Netscape Communications Corporation. All
4474 + * Rights Reserved.
4478 + * Alternatively, the contents of this file may be used under the
4479 + * terms of the GNU General Public License Version 2 or later (the
4480 + * "GPL"), in which case the provisions of the GPL are applicable
4481 + * instead of those above. If you wish to allow use of your
4482 + * version of this file only under the terms of the GPL and not to
4483 + * allow others to use your version of this file under the MPL,
4484 + * indicate your decision by deleting the provisions above and
4485 + * replace them with the notice and other provisions required by
4486 + * the GPL. If you do not delete the provisions above, a recipient
4487 + * may use your version of this file under either the MPL or the
4491 +#include <stdlib.h>
4495 +#include "prtypes.h"
4496 +#include "prlong.h"
4498 +#include "nsMemory.h"
4500 +#define MD5_HASH_LEN 16
4501 +#define MD5_BUFFER_SIZE 64
4502 +#define MD5_END_BUFFER (MD5_BUFFER_SIZE - 8)
4504 +#define CV0_1 0x67452301
4505 +#define CV0_2 0xefcdab89
4506 +#define CV0_3 0x98badcfe
4507 +#define CV0_4 0x10325476
4509 +#define T1_0 0xd76aa478
4510 +#define T1_1 0xe8c7b756
4511 +#define T1_2 0x242070db
4512 +#define T1_3 0xc1bdceee
4513 +#define T1_4 0xf57c0faf
4514 +#define T1_5 0x4787c62a
4515 +#define T1_6 0xa8304613
4516 +#define T1_7 0xfd469501
4517 +#define T1_8 0x698098d8
4518 +#define T1_9 0x8b44f7af
4519 +#define T1_10 0xffff5bb1
4520 +#define T1_11 0x895cd7be
4521 +#define T1_12 0x6b901122
4522 +#define T1_13 0xfd987193
4523 +#define T1_14 0xa679438e
4524 +#define T1_15 0x49b40821
4526 +#define T2_0 0xf61e2562
4527 +#define T2_1 0xc040b340
4528 +#define T2_2 0x265e5a51
4529 +#define T2_3 0xe9b6c7aa
4530 +#define T2_4 0xd62f105d
4531 +#define T2_5 0x02441453
4532 +#define T2_6 0xd8a1e681
4533 +#define T2_7 0xe7d3fbc8
4534 +#define T2_8 0x21e1cde6
4535 +#define T2_9 0xc33707d6
4536 +#define T2_10 0xf4d50d87
4537 +#define T2_11 0x455a14ed
4538 +#define T2_12 0xa9e3e905
4539 +#define T2_13 0xfcefa3f8
4540 +#define T2_14 0x676f02d9
4541 +#define T2_15 0x8d2a4c8a
4543 +#define T3_0 0xfffa3942
4544 +#define T3_1 0x8771f681
4545 +#define T3_2 0x6d9d6122
4546 +#define T3_3 0xfde5380c
4547 +#define T3_4 0xa4beea44
4548 +#define T3_5 0x4bdecfa9
4549 +#define T3_6 0xf6bb4b60
4550 +#define T3_7 0xbebfbc70
4551 +#define T3_8 0x289b7ec6
4552 +#define T3_9 0xeaa127fa
4553 +#define T3_10 0xd4ef3085
4554 +#define T3_11 0x04881d05
4555 +#define T3_12 0xd9d4d039
4556 +#define T3_13 0xe6db99e5
4557 +#define T3_14 0x1fa27cf8
4558 +#define T3_15 0xc4ac5665
4560 +#define T4_0 0xf4292244
4561 +#define T4_1 0x432aff97
4562 +#define T4_2 0xab9423a7
4563 +#define T4_3 0xfc93a039
4564 +#define T4_4 0x655b59c3
4565 +#define T4_5 0x8f0ccc92
4566 +#define T4_6 0xffeff47d
4567 +#define T4_7 0x85845dd1
4568 +#define T4_8 0x6fa87e4f
4569 +#define T4_9 0xfe2ce6e0
4570 +#define T4_10 0xa3014314
4571 +#define T4_11 0x4e0811a1
4572 +#define T4_12 0xf7537e82
4573 +#define T4_13 0xbd3af235
4574 +#define T4_14 0x2ad7d2bb
4575 +#define T4_15 0xeb86d391
4665 +struct MD5ContextStr {
4666 + PRUint32 lsbInput;
4667 + PRUint32 msbInput;
4674 +typedef struct MD5ContextStr MD5Context;
4678 +int MD5_Hash(unsigned char *dest, const char *src);
4679 +int MD5_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length);
4680 +MD5Context * MD5_NewContext(void);
4681 +void MD5_DestroyContext(MD5Context *cx, PRBool freeit);
4682 +void MD5_Begin(MD5Context *cx);
4683 +static void md5_compress(MD5Context *cx);
4684 +void MD5_Update(MD5Context *cx, const unsigned char *input, unsigned int inputLen);
4685 +void MD5_End(MD5Context *cx, unsigned char *digest,
4686 + unsigned int *digestLen, unsigned int maxDigestLen);
4687 +unsigned int MD5_FlattenSize(MD5Context *cx);
4688 +int MD5_Flatten(MD5Context *cx, unsigned char *space);
4689 +MD5Context * MD5_Resurrect(unsigned char *space, void *arg);
4690 +void MD5_TraceState(MD5Context *cx);
4693 +MD5_Hash(unsigned char *dest, const char *src)
4695 + return MD5_HashBuf(dest, (unsigned char *)src, PL_strlen(src));
4699 +MD5_HashBuf(unsigned char *dest, const unsigned char *src, uint32 src_length)
4702 + MD5Context *cx = MD5_NewContext();
4704 +// PORT_SetError(PR_OUT_OF_MEMORY_ERROR);
4708 + MD5_Update(cx, src, src_length);
4709 + MD5_End(cx, dest, &len, MD5_HASH_LEN);
4710 + MD5_DestroyContext(cx, PR_TRUE);
4715 +MD5_NewContext(void)
4717 + MD5Context *cx = (MD5Context *)malloc(sizeof(MD5Context));
4719 +// PORT_SetError(PR_OUT_OF_MEMORY_ERROR);
4726 +MD5_DestroyContext(MD5Context *cx, PRBool freeit)
4734 +MD5_Begin(MD5Context *cx)
4738 + memset(cx->inBuf, 0, sizeof(cx->inBuf));
4739 + cx->cv[0] = CV0_1;
4740 + cx->cv[1] = CV0_2;
4741 + cx->cv[2] = CV0_3;
4742 + cx->cv[3] = CV0_4;
4745 +#define cls(i32, s) (tmp = i32, tmp << s | tmp >> (32 - s))
4747 +#define MASK 0x00ff00ff
4748 +#ifdef IS_LITTLE_ENDIAN
4749 +#define lendian(i32) \
4752 +#define lendian(i32) \
4753 + (tmp = i32 >> 16 | i32 << 16, (tmp & MASK) << 8 | tmp >> 8 & MASK)
4756 +#if defined(SOLARIS) || defined(HPUX)
4757 +#define addto64(sumhigh, sumlow, addend) \
4758 + sumlow += addend; sumhigh += (sumlow < addend);
4760 +#define addto64(sumhigh, sumlow, addend) \
4761 + sumlow += addend; if (sumlow < addend) ++sumhigh;
4764 +#define F(X, Y, Z) \
4765 + ((X & Y) | ((~X) & Z))
4767 +#define G(X, Y, Z) \
4768 + ((X & Z) | (Y & (~Z)))
4770 +#define H(X, Y, Z) \
4773 +#define I(X, Y, Z) \
4776 +#define FF(a, b, c, d, bufint, s, ti) \
4777 + a = b + cls(a + F(b, c, d) + bufint + ti, s)
4779 +#define GG(a, b, c, d, bufint, s, ti) \
4780 + a = b + cls(a + G(b, c, d) + bufint + ti, s)
4782 +#define HH(a, b, c, d, bufint, s, ti) \
4783 + a = b + cls(a + H(b, c, d) + bufint + ti, s)
4785 +#define II(a, b, c, d, bufint, s, ti) \
4786 + a = b + cls(a + I(b, c, d) + bufint + ti, s)
4789 +md5_compress(MD5Context *cx)
4791 + PRUint32 a, b, c, d;
4797 +#ifndef IS_LITTLE_ENDIAN
4798 + cx->u.w[0] = lendian(cx->u.w[0]);
4799 + cx->u.w[1] = lendian(cx->u.w[1]);
4800 + cx->u.w[2] = lendian(cx->u.w[2]);
4801 + cx->u.w[3] = lendian(cx->u.w[3]);
4802 + cx->u.w[4] = lendian(cx->u.w[4]);
4803 + cx->u.w[5] = lendian(cx->u.w[5]);
4804 + cx->u.w[6] = lendian(cx->u.w[6]);
4805 + cx->u.w[7] = lendian(cx->u.w[7]);
4806 + cx->u.w[8] = lendian(cx->u.w[8]);
4807 + cx->u.w[9] = lendian(cx->u.w[9]);
4808 + cx->u.w[10] = lendian(cx->u.w[10]);
4809 + cx->u.w[11] = lendian(cx->u.w[11]);
4810 + cx->u.w[12] = lendian(cx->u.w[12]);
4811 + cx->u.w[13] = lendian(cx->u.w[13]);
4812 + cx->u.w[14] = lendian(cx->u.w[14]);
4813 + cx->u.w[15] = lendian(cx->u.w[15]);
4815 + FF(a, b, c, d, cx->u.w[R1B0 ], S1_0, T1_0);
4816 + FF(d, a, b, c, cx->u.w[R1B1 ], S1_1, T1_1);
4817 + FF(c, d, a, b, cx->u.w[R1B2 ], S1_2, T1_2);
4818 + FF(b, c, d, a, cx->u.w[R1B3 ], S1_3, T1_3);
4819 + FF(a, b, c, d, cx->u.w[R1B4 ], S1_0, T1_4);
4820 + FF(d, a, b, c, cx->u.w[R1B5 ], S1_1, T1_5);
4821 + FF(c, d, a, b, cx->u.w[R1B6 ], S1_2, T1_6);
4822 + FF(b, c, d, a, cx->u.w[R1B7 ], S1_3, T1_7);
4823 + FF(a, b, c, d, cx->u.w[R1B8 ], S1_0, T1_8);
4824 + FF(d, a, b, c, cx->u.w[R1B9 ], S1_1, T1_9);
4825 + FF(c, d, a, b, cx->u.w[R1B10], S1_2, T1_10);
4826 + FF(b, c, d, a, cx->u.w[R1B11], S1_3, T1_11);
4827 + FF(a, b, c, d, cx->u.w[R1B12], S1_0, T1_12);
4828 + FF(d, a, b, c, cx->u.w[R1B13], S1_1, T1_13);
4829 + FF(c, d, a, b, cx->u.w[R1B14], S1_2, T1_14);
4830 + FF(b, c, d, a, cx->u.w[R1B15], S1_3, T1_15);
4831 + GG(a, b, c, d, cx->u.w[R2B0 ], S2_0, T2_0);
4832 + GG(d, a, b, c, cx->u.w[R2B1 ], S2_1, T2_1);
4833 + GG(c, d, a, b, cx->u.w[R2B2 ], S2_2, T2_2);
4834 + GG(b, c, d, a, cx->u.w[R2B3 ], S2_3, T2_3);
4835 + GG(a, b, c, d, cx->u.w[R2B4 ], S2_0, T2_4);
4836 + GG(d, a, b, c, cx->u.w[R2B5 ], S2_1, T2_5);
4837 + GG(c, d, a, b, cx->u.w[R2B6 ], S2_2, T2_6);
4838 + GG(b, c, d, a, cx->u.w[R2B7 ], S2_3, T2_7);
4839 + GG(a, b, c, d, cx->u.w[R2B8 ], S2_0, T2_8);
4840 + GG(d, a, b, c, cx->u.w[R2B9 ], S2_1, T2_9);
4841 + GG(c, d, a, b, cx->u.w[R2B10], S2_2, T2_10);
4842 + GG(b, c, d, a, cx->u.w[R2B11], S2_3, T2_11);
4843 + GG(a, b, c, d, cx->u.w[R2B12], S2_0, T2_12);
4844 + GG(d, a, b, c, cx->u.w[R2B13], S2_1, T2_13);
4845 + GG(c, d, a, b, cx->u.w[R2B14], S2_2, T2_14);
4846 + GG(b, c, d, a, cx->u.w[R2B15], S2_3, T2_15);
4847 + HH(a, b, c, d, cx->u.w[R3B0 ], S3_0, T3_0);
4848 + HH(d, a, b, c, cx->u.w[R3B1 ], S3_1, T3_1);
4849 + HH(c, d, a, b, cx->u.w[R3B2 ], S3_2, T3_2);
4850 + HH(b, c, d, a, cx->u.w[R3B3 ], S3_3, T3_3);
4851 + HH(a, b, c, d, cx->u.w[R3B4 ], S3_0, T3_4);
4852 + HH(d, a, b, c, cx->u.w[R3B5 ], S3_1, T3_5);
4853 + HH(c, d, a, b, cx->u.w[R3B6 ], S3_2, T3_6);
4854 + HH(b, c, d, a, cx->u.w[R3B7 ], S3_3, T3_7);
4855 + HH(a, b, c, d, cx->u.w[R3B8 ], S3_0, T3_8);
4856 + HH(d, a, b, c, cx->u.w[R3B9 ], S3_1, T3_9);
4857 + HH(c, d, a, b, cx->u.w[R3B10], S3_2, T3_10);
4858 + HH(b, c, d, a, cx->u.w[R3B11], S3_3, T3_11);
4859 + HH(a, b, c, d, cx->u.w[R3B12], S3_0, T3_12);
4860 + HH(d, a, b, c, cx->u.w[R3B13], S3_1, T3_13);
4861 + HH(c, d, a, b, cx->u.w[R3B14], S3_2, T3_14);
4862 + HH(b, c, d, a, cx->u.w[R3B15], S3_3, T3_15);
4863 + II(a, b, c, d, cx->u.w[R4B0 ], S4_0, T4_0);
4864 + II(d, a, b, c, cx->u.w[R4B1 ], S4_1, T4_1);
4865 + II(c, d, a, b, cx->u.w[R4B2 ], S4_2, T4_2);
4866 + II(b, c, d, a, cx->u.w[R4B3 ], S4_3, T4_3);
4867 + II(a, b, c, d, cx->u.w[R4B4 ], S4_0, T4_4);
4868 + II(d, a, b, c, cx->u.w[R4B5 ], S4_1, T4_5);
4869 + II(c, d, a, b, cx->u.w[R4B6 ], S4_2, T4_6);
4870 + II(b, c, d, a, cx->u.w[R4B7 ], S4_3, T4_7);
4871 + II(a, b, c, d, cx->u.w[R4B8 ], S4_0, T4_8);
4872 + II(d, a, b, c, cx->u.w[R4B9 ], S4_1, T4_9);
4873 + II(c, d, a, b, cx->u.w[R4B10], S4_2, T4_10);
4874 + II(b, c, d, a, cx->u.w[R4B11], S4_3, T4_11);
4875 + II(a, b, c, d, cx->u.w[R4B12], S4_0, T4_12);
4876 + II(d, a, b, c, cx->u.w[R4B13], S4_1, T4_13);
4877 + II(c, d, a, b, cx->u.w[R4B14], S4_2, T4_14);
4878 + II(b, c, d, a, cx->u.w[R4B15], S4_3, T4_15);
4886 +MD5_Update(MD5Context *cx, const unsigned char *input, unsigned int inputLen)
4888 + PRUint32 bytesToConsume;
4889 + PRUint32 inBufIndex = cx->lsbInput & 63;
4891 + /* Add the number of input bytes to the 64-bit input counter. */
4892 + addto64(cx->msbInput, cx->lsbInput, inputLen);
4894 + /* There is already data in the buffer. Fill with input. */
4895 + bytesToConsume = PR_MIN(inputLen, MD5_BUFFER_SIZE - inBufIndex);
4896 + memcpy(&cx->inBuf[inBufIndex], input, bytesToConsume);
4897 + if (inBufIndex + bytesToConsume >= MD5_BUFFER_SIZE)
4898 + /* The buffer is filled. Run the compression function. */
4900 + /* Remaining input. */
4901 + inputLen -= bytesToConsume;
4902 + input += bytesToConsume;
4905 + /* Iterate over 64-byte chunks of the message. */
4906 + while (inputLen >= MD5_BUFFER_SIZE) {
4907 + memcpy(cx->inBuf, input, MD5_BUFFER_SIZE);
4909 + inputLen -= MD5_BUFFER_SIZE;
4910 + input += MD5_BUFFER_SIZE;
4913 + /* Tail of message (message bytes mod 64). */
4915 + memcpy(cx->inBuf, input, inputLen);
4918 +static const unsigned char padbytes[] = {
4919 + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4920 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4921 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4922 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4923 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4924 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4925 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4926 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4927 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4928 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4929 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4930 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4934 +MD5_End(MD5Context *cx, unsigned char *digest,
4935 + unsigned int *digestLen, unsigned int maxDigestLen)
4937 +#ifndef IS_LITTLE_ENDIAN
4940 + PRUint32 lowInput, highInput;
4941 + PRUint32 inBufIndex = cx->lsbInput & 63;
4943 + if (maxDigestLen < MD5_HASH_LEN) {
4944 +// PORT_SetError(SEC_ERROR_INVALID_ARGS);
4948 + /* Copy out the length of bits input before padding. */
4949 + lowInput = cx->lsbInput;
4950 + highInput = (cx->msbInput << 3) | (lowInput >> 29);
4953 + if (inBufIndex < MD5_END_BUFFER) {
4954 + MD5_Update(cx, padbytes, MD5_END_BUFFER - inBufIndex);
4956 + MD5_Update(cx, padbytes,
4957 + MD5_END_BUFFER + MD5_BUFFER_SIZE - inBufIndex);
4960 + /* Store the number of bytes input (before padding) in final 64 bits. */
4961 + cx->u.w[14] = lendian(lowInput);
4962 + cx->u.w[15] = lendian(highInput);
4964 + /* Final call to compress. */
4967 + /* Copy the resulting values out of the chain variables into return buf. */
4968 + *digestLen = MD5_HASH_LEN;
4969 +#ifndef IS_LITTLE_ENDIAN
4970 + cx->cv[0] = lendian(cx->cv[0]);
4971 + cx->cv[1] = lendian(cx->cv[1]);
4972 + cx->cv[2] = lendian(cx->cv[2]);
4973 + cx->cv[3] = lendian(cx->cv[3]);
4975 + memcpy(digest, cx->cv, MD5_HASH_LEN);
4979 +MD5_FlattenSize(MD5Context *cx)
4981 + return sizeof(*cx);
4985 +MD5_Flatten(MD5Context *cx, unsigned char *space)
4987 + memcpy(space, cx, sizeof(*cx));
4992 +MD5_Resurrect(unsigned char *space, void *arg)
4994 + MD5Context *cx = MD5_NewContext();
4996 + memcpy(cx, space, sizeof(*cx));
5001 +MD5_TraceState(MD5Context *cx)
5003 +// PORT_SetError(PR_NOT_IMPLEMENTED_ERROR);
5007 +md5_stream (FILE *stream, unsigned char *dest)
5009 + /* Important: BLOCKSIZE must be a multiple of 64. */
5010 +#define BLOCKSIZE 4096
5012 + MD5Context *cx = MD5_NewContext();
5014 +// PORT_SetError(PR_OUT_OF_MEMORY_ERROR);
5018 + unsigned char buffer[BLOCKSIZE + 72];
5021 + /* Initialize the computation context. */
5024 + /* Iterate over full file contents. */
5027 + /* We read the file in blocks of BLOCKSIZE bytes. One call of the
5028 + computation function processes the whole buffer so that with the
5029 + next round of the loop another block can be read. */
5033 + /* Read block. Take care for partial reads. */
5036 + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
5040 + while (sum < BLOCKSIZE && n != 0);
5041 + if (n == 0 && ferror (stream))
5044 + /* If end of file is reached, end the loop. */
5048 + /* Process buffer with BLOCKSIZE bytes. Note that
5049 + BLOCKSIZE % 64 == 0
5051 + MD5_Update(cx, buffer, BLOCKSIZE);
5054 + /* Add the last bytes if necessary. */
5056 + MD5_Update(cx, buffer, sum);
5058 + MD5_End(cx, dest, &len, MD5_HASH_LEN);
5059 + MD5_DestroyContext(cx, PR_TRUE);
5064 +int getMD5sum(const char * fileName,char * sum)
5066 + unsigned char bin_sum[16];
5070 + FILE *fp=fopen(fileName,"rb");
5073 + len=md5_stream(fp,bin_sum);
5075 + for (int i = 0; i < len; ++i)
5076 + sprintf (sum,"%s%02x",sum, bin_sum[i]);
5084 +int testMD5sum(const char * fileName,char * sum)
5086 + char newSum[33]="";
5087 + if (getMD5sum(fileName,newSum))
5089 + return strcmp(newSum,sum);
5093 ===================================================================
5094 RCS file: /cvsroot/mozilla/jpeg/jmorecfg.h,v
5095 retrieving revision 3.12
5096 diff -u -r3.12 jmorecfg.h
5097 --- misc/build/mozilla/jpeg/jmorecfg.h 5 Mar 2004 22:17:45 -0000 3.12
5098 +++ misc/build/mozilla/jpeg/jmorecfg.h 17 May 2004 03:48:38 -0000
5100 /* Defines for MMX/SSE2 support. */
5102 #if defined(XP_WIN32) && defined(_M_IX86)
5103 -#define HAVE_MMX_INTEL_MNEMONICS
5104 -#define HAVE_SSE2_INTEL_MNEMONICS
5105 +//#define HAVE_MMX_INTEL_MNEMONICS
5106 +//#define HAVE_SSE2_INTEL_MNEMONICS