Bug 652855 - De-RDF the address book; r=standard8
authorMike Conley <mconley@mozilla.com>
Mon, 04 Jul 2011 18:03:17 -0500
changeset 8265 e3f147cb26aae09acd4909e62a06d1d33e6097fb
parent 8264 bc728348268b58d865327dcc493ca895190ef4f5
child 8266 ae84f8b74c90e52908360b1fd5cc7077b3b0ad57
push id84
push userbugzilla@standard8.plus.com
push dateTue, 16 Aug 2011 21:25:04 +0000
treeherdercomm-beta@6970c86be3cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs652855
Bug 652855 - De-RDF the address book; r=standard8
mail/base/content/ABSearchDialog.js
mail/components/addrbook/content/abCommon.js
mailnews/addrbook/public/nsAbBaseCID.h
mailnews/addrbook/public/nsIAbDirectory.idl
mailnews/addrbook/public/nsIAbMDBDirectory.idl
mailnews/addrbook/src/Makefile.in
mailnews/addrbook/src/nsAbBSDirectory.cpp
mailnews/addrbook/src/nsAbBSDirectory.h
mailnews/addrbook/src/nsAbDirProperty.cpp
mailnews/addrbook/src/nsAbDirProperty.h
mailnews/addrbook/src/nsAbDirectoryRDFResource.cpp
mailnews/addrbook/src/nsAbDirectoryRDFResource.h
mailnews/addrbook/src/nsAbLDAPDirFactory.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.h
mailnews/addrbook/src/nsAbMDBDirFactory.cpp
mailnews/addrbook/src/nsAbMDBDirProperty.cpp
mailnews/addrbook/src/nsAbMDBDirectory.cpp
mailnews/addrbook/src/nsAbMDBDirectory.h
mailnews/addrbook/src/nsAbManager.cpp
mailnews/addrbook/src/nsAbManager.h
mailnews/addrbook/src/nsAbOSXCard.h
mailnews/addrbook/src/nsAbOSXCard.mm
mailnews/addrbook/src/nsAbOSXDirectory.h
mailnews/addrbook/src/nsAbOSXDirectory.mm
mailnews/addrbook/src/nsAbOutlookDirFactory.cpp
mailnews/addrbook/src/nsAbOutlookDirectory.cpp
mailnews/addrbook/src/nsAbOutlookDirectory.h
mailnews/addrbook/src/nsAbRDFDataSource.cpp
mailnews/addrbook/src/nsAbRDFDataSource.h
mailnews/addrbook/src/nsAddrDatabase.cpp
mailnews/addrbook/src/nsDirectoryDataSource.cpp
mailnews/addrbook/src/nsDirectoryDataSource.h
mailnews/addrbook/test/unit/test_nsAbManager2.js
mailnews/base/search/src/nsMsgSearchTerm.cpp
mailnews/build/nsMailModule.cpp
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgCompose.h
mailnews/import/src/nsImportAddressBooks.cpp
--- a/mail/base/content/ABSearchDialog.js
+++ b/mail/base/content/ABSearchDialog.js
@@ -29,16 +29,18 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
+Components.utils.import("resource:///modules/mailServices.js");
+
 var searchSessionContractID = "@mozilla.org/messenger/searchSession;1";
 var gSearchSession;
 
 var nsMsgSearchScope = Components.interfaces.nsMsgSearchScope;
 var nsIMsgSearchTerm = Components.interfaces.nsIMsgSearchTerm;
 var nsMsgSearchOp = Components.interfaces.nsMsgSearchOp;
 var nsMsgSearchAttrib = Components.interfaces.nsMsgSearchAttrib;
 var nsIAbDirectory = Components.interfaces.nsIAbDirectory;
@@ -47,18 +49,16 @@ var gStatusText;
 var gSearchBundle;
 var gAddressBookBundle;
 
 var gSearchStopButton;
 var gPropertiesButton;
 var gComposeButton;
 var gSearchPhoneticName = "false";
 
-var gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
-
 var gSearchAbViewListener = {
   onSelectionChanged: function() {
     UpdateCardView();
   },
   onCountChanged: function(total) {
     var statusText;
     switch (total) {
       case 0:
@@ -148,17 +148,17 @@ function SelectDirectory(aURI)
   if ( abPopup )
     abPopup.value = selectedAB;
 
   setSearchScope(GetScopeForDirectoryURI(selectedAB));
 }
 
 function GetScopeForDirectoryURI(aURI)
 {
-  var directory = gRDF.GetResource(aURI).QueryInterface(nsIAbDirectory);
+  var directory = MailServices.ab.getDirectory(aURI);
   var booleanAnd = gSearchBooleanRadiogroup.selectedItem.value == "and";
 
   if (directory.isRemote) {
     if (booleanAnd)
       return nsMsgSearchScope.LDAPAnd;
     else 
       return nsMsgSearchScope.LDAP;
   }
--- a/mail/components/addrbook/content/abCommon.js
+++ b/mail/components/addrbook/content/abCommon.js
@@ -38,17 +38,17 @@
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 Components.utils.import("resource:///modules/mailServices.js");
 
-var gDirTree = 0;
+var gDirTree;
 var abList = 0;
 var gAbResultsTree = null;
 var gAbView = null;
 var gAddressBookBundle;
 
 var gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
 var gHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser);
 
--- a/mailnews/addrbook/public/nsAbBaseCID.h
+++ b/mailnews/addrbook/public/nsAbBaseCID.h
@@ -44,90 +44,59 @@
 
 //
 // The start of the contract ID for address book directory factories.
 //
 #define NS_AB_DIRECTORY_FACTORY_CONTRACTID_PREFIX \
   "@mozilla.org/addressbook/directory-factory;1?name="
 
 //
+// The start of the contract ID for address book directory types
+//
+#define NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX \
+  "@mozilla.org/addressbook/directory;1?type="
+
+//
 // nsAbManager
 //
 #define NS_ABMANAGER_CONTRACTID \
   "@mozilla.org/abmanager;1"
 
 #define NS_ABMANAGERSTARTUPHANDLER_CONTRACTID \
   "@mozilla.org/commandlinehandler/general-startup;1?type=addressbook"
 
 #define NS_ABMANAGER_CID \
 { /* {ad81b321-8a8a-42ca-a508-fe659de84586} */ \
   0xad81b321, 0x8a8a, 0x42ca, \
-	{ 0xa5, 0x08, 0xfe, 0x65, 0x9d, 0x8e, 0x45, 0x86 }	\
+  {0xa5, 0x08, 0xfe, 0x65, 0x9d, 0x8e, 0x45, 0x86} \
 }
 
 //
 // nsAbContentHandler
 //
 #define NS_ABCONTENTHANDLER_CID \
 { /* {a72ad552-0484-4b5f-8d45-2d79158d22e3} */ \
   0xa72ad552, 0x0484, 0x4b5f, \
-	{ 0x8d, 0x45, 0x2d, 0x79, 0x15, 0x8d, 0x22, 0xe3 }	\
-}
-
-//
-// nsAbDirectoryDataSource
-//
-#define NS_ABDIRECTORYDATASOURCE_CONTRACTID \
-  NS_RDF_DATASOURCE_CONTRACTID_PREFIX "addressdirectory"
-
-#define NS_ABDIRECTORYDATASOURCE_CID			\
-{ /* 0A79186D-F754-11d2-A2DA-001083003D0C */		\
-    0xa79186d, 0xf754, 0x11d2,				\
-    {0xa2, 0xda, 0x0, 0x10, 0x83, 0x0, 0x3d, 0xc}	\
-}
-
-//
-// nsAbBSDirectory
-//
-#define NS_ABDIRECTORY_CONTRACTID \
-  NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "moz-abdirectory"
-
-#define NS_ABDIRECTORY_CID             	 			\
-{ /* {012D3C24-1DD2-11B2-BA79-B4AD359FC461}*/			\
-    	0x012D3C24, 0x1DD2, 0x11B2,				\
-	{0xBA, 0x79, 0xB4, 0xAD, 0x35, 0x9F, 0xC4, 0x61}	\
+	{0x8d, 0x45, 0x2d, 0x79, 0x15, 0x8d, 0x22, 0xe3}	\
 }
 
 
 //
-// nsAbMDBDirectory
-//
-#define NS_ABMDBDIRECTORY_CONTRACTID \
-  NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "moz-abmdbdirectory"
-
-#define NS_ABMDBDIRECTORY_CID             		\
-{ /* {e618f894-1dd1-11b2-889c-9aaefaa90dde}*/		\
-    0xe618f894, 0x1dd1, 0x11b2,				\
-    {0x88, 0x9c, 0x9a, 0xae, 0xfa, 0xa9, 0x0d, 0xde}	\
-}
-
+// nsAbBSDirectory - the root address book
 //
-// nsAbMDBCard
-//
-#define NS_ABMDBCARD_CONTRACTID \
-  "@mozilla.org/addressbook/moz-abmdbcard;1"
+#define NS_ABDIRECTORY_CONTRACTID \
+  NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX "moz-abdirectory"
 
-#define NS_ABMDBCARD_CID				\
-{ /* {f578a5d2-1dd1-11b2-8841-f45cc5e765f8} */		\
-    0xf578a5d2, 0x1dd1, 0x11b2,				\
-    {0x88, 0x41, 0xf4, 0x5c, 0xc5, 0xe7, 0x65, 0xf8}	\
+#define NS_ABDIRECTORY_CID \
+{ /* {012D3C24-1DD2-11B2-BA79-B4AD359FC461}*/ \
+    0x012D3C24, 0x1DD2, 0x11B2, \
+    {0xBA, 0x79, 0xB4, 0xAD, 0x35, 0x9F, 0xC4, 0x61} \
 }
 
 
-
 //
 // nsAddressBookDB
 //
 #define NS_ADDRDATABASE_CONTRACTID \
   "@mozilla.org/addressbook/carddatabase;1"
 
 #define NS_ADDRDATABASE_CID						\
 { /* 63187917-1D19-11d3-A302-001083003D0C */		\
@@ -212,31 +181,57 @@
 { /* {F8B212F2-742B-4A48-B7A0-4C44D4DDB121}*/			\
 	0xF8B212F2, 0x742B, 0x4A48,				\
 	{0xB7, 0xA0, 0x4C, 0x44, 0xD4, 0xDD, 0xB1, 0x21}	\
 }
 
 //
 // mdb directory factory
 //
+#define NS_ABMDBDIRECTORY "moz-abmdbdirectory"
+
 #define NS_ABMDBDIRFACTORY_CONTRACTID \
-  NS_AB_DIRECTORY_FACTORY_CONTRACTID_PREFIX "moz-abmdbdirectory"
+  NS_AB_DIRECTORY_FACTORY_CONTRACTID_PREFIX NS_ABMDBDIRECTORY
 
 #define NS_ABMDBDIRFACTORY_CID				\
 { /* {E1CB9C8A-722D-43E4-9D7B-7CCAE4B0338A}*/			\
 	0xE1CB9C8A, 0x722D, 0x43E4,				\
 	{0x9D, 0x7B, 0x7C, 0xCA, 0xE4, 0xB0, 0x33, 0x8A}	\
 }
 
+//
+// nsAbMDBDirectory
+//
+#define NS_ABMDBDIRECTORY_CONTRACTID \
+  NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX NS_ABMDBDIRECTORY
+
+#define NS_ABMDBDIRECTORY_CID \
+{ /* {e618f894-1dd1-11b2-889c-9aaefaa90dde}*/ \
+  0xe618f894, 0x1dd1, 0x11b2, \
+  {0x88, 0x9c, 0x9a, 0xae, 0xfa, 0xa9, 0x0d, 0xde} \
+}
+
+//
+// nsAbMDBCard
+//
+#define NS_ABMDBCARD_CONTRACTID \
+  "@mozilla.org/addressbook/moz-abmdbcard;1"
+
+#define NS_ABMDBCARD_CID				\
+{ /* {f578a5d2-1dd1-11b2-8841-f45cc5e765f8} */		\
+    0xf578a5d2, 0x1dd1, 0x11b2,				\
+    {0x88, 0x41, 0xf4, 0x5c, 0xc5, 0xe7, 0x65, 0xf8}	\
+}
+
 #ifdef XP_WIN
 //
 // nsAbOutlookDirectory
 //
 #define NS_ABOUTLOOKDIRECTORY_CONTRACTID \
-  NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "moz-aboutlookdirectory"
+  NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX "moz-aboutlookdirectory"
 
 #define NS_ABOUTLOOKDIRECTORY_CID                       \
 { /* {9cc57822-0599-4c47-a399-1c6fa185a05c}*/           \
         0x9cc57822, 0x0599, 0x4c47,                     \
         {0xa3, 0x99, 0x1c, 0x6f, 0xa1, 0x85, 0xa0, 0x5c}        \
 }
 
 //
@@ -292,17 +287,17 @@
 { /* {E162E335-541B-43B4-AAEA-FE591E240CAF}*/                   \
         0xE162E335, 0x541B, 0x43B4,                             \
         {0xAA, 0xEA, 0xFE, 0x59, 0x1E, 0x24, 0x0C, 0xAF}        \
 }
 
 // nsAbLDAPDirectory
 //
 #define NS_ABLDAPDIRECTORY_CONTRACTID \
-  NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "moz-abldapdirectory"
+  NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX  "moz-abldapdirectory"
 
 #define NS_ABLDAPDIRECTORY_CID             			\
 { /* {783E2777-66D7-4826-9E4B-8AB58C228A52}*/			\
 	0x783E2777, 0x66D7, 0x4826,				\
 	{0x9E, 0x4B, 0x8A, 0xB5, 0x8C, 0x22, 0x8A, 0x52}	\
 }
 
 // nsAbLDAPDirectoryQuery
@@ -427,29 +422,29 @@
 #ifdef XP_MACOSX
 //
 // nsAbOSXDirectory
 //
 #define NS_ABOSXDIRECTORY_PREFIX "moz-abosxdirectory"
 #define NS_ABOSXCARD_PREFIX "moz-abosxcard"
 
 #define NS_ABOSXDIRECTORY_CONTRACTID \
-  NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX NS_ABOSXDIRECTORY_PREFIX
+  NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX NS_ABOSXDIRECTORY_PREFIX
 
 #define NS_ABOSXDIRECTORY_CID                            \
 { /* {83781cc6-c682-11d6-bdeb-0005024967b8}*/            \
         0x83781cc6, 0xc682, 0x11d6,                      \
         {0xbd, 0xeb, 0x00, 0x05, 0x02, 0x49, 0x67, 0xb8} \
 }
 
 //
 // nsAbOSXCard
 //
 #define NS_ABOSXCARD_CONTRACTID \
-  NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX NS_ABOSXCARD_PREFIX
+  NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX NS_ABOSXCARD_PREFIX
 
 #define NS_ABOSXCARD_CID                                 \
 { /* {89bbf582-c682-11d6-bc9d-0005024967b8}*/            \
         0x89bbf582, 0xc682, 0x11d6,                      \
         {0xbc, 0x9d, 0x00, 0x05, 0x02, 0x49, 0x67, 0xb8} \
 }
 
 //
--- a/mailnews/addrbook/public/nsIAbDirectory.idl
+++ b/mailnews/addrbook/public/nsIAbDirectory.idl
@@ -40,38 +40,51 @@
  
 #include "nsIAbCollection.idl"
 #include "nsIAbCard.idl"
 
 interface nsISimpleEnumerator;
 interface nsIArray;
 interface nsIMutableArray;
 
+/* moz-abdirectory:// is the URI to access nsAbBSDirectory,
+ * which is the root directory for all types of address books
+ * this is used to get all address book directories. */
+
 %{C++
-/* RDF root for all types of address books */
-/* use this to get all directories, create new directory*/
-#define kAllDirectoryRoot          "moz-abdirectory://" 
+#define kAllDirectoryRoot          "moz-abdirectory://"
 
 #define kPersonalAddressbook       "abook.mab"
 #define kPersonalAddressbookUri    "moz-abmdbdirectory://abook.mab"
 #define kCollectedAddressbook      "history.mab"
 #define kCollectedAddressbookUri   "moz-abmdbdirectory://history.mab"
 
 #define kABFileName_PreviousSuffix ".na2" /* final v2 address book format */
 #define kABFileName_PreviousSuffixLen 4
 #define kABFileName_CurrentSuffix ".mab"  /* v3 address book extension */
 %}
 
 /**
  * A top-level address book directory.
  *
+ * Please note that in order to be properly instantiated by nsIAbManager, every
+ * type of nsIAbDirectory must have a contract ID of the form:
+ *
+ * @mozilla.org/addressbook/directory;1?type=<AB URI Scheme>
+ *
+ * Where AB URI Scheme does not include the ://.  For example, for the Mork-based
+ * address book, the scheme is "moz-abmdbdirectory", so the contract ID for
+ * the Mork-based address book type is:
+ *
+ * @mozilla.org/addressbook/directory;1?type=moz-abmdbdirectory
+ *
  * The UUID of an nsIAbDirectory is its preference ID and its name, concatenated
  * together.
  */
-[scriptable, uuid(1f11f37e-7009-4a51-bbb1-041e9f75120a)]
+[scriptable, uuid(81927b85-11a2-4967-8c90-19ca600cedf0)]
 interface nsIAbDirectory : nsIAbCollection {
 
   /**
    * The chrome URI to use for bringing up a dialog to edit this directory.
    * When opening the dialog, use a JS argument of
    * {selectedDirectory: thisdir} where thisdir is this directory that you just
    * got the chrome URI from.
    */
@@ -87,17 +100,17 @@ interface nsIAbDirectory : nsIAbCollecti
   // XXX This should really be replaced by a QI or something better
   readonly attribute long dirType;
 
   // eliminated a bit more.
 
   // The filename for address books within this directory.
   readonly attribute ACString fileName;
 
-  // The RDF resource URI of the address book
+  // The URI of the address book
   readonly attribute ACString URI;
 
   // The position of the directory on the display.
   readonly attribute long position;
 
   // will be used for LDAP replication
   attribute unsigned long lastModifiedDate;
 
@@ -115,16 +128,22 @@ interface nsIAbDirectory : nsIAbCollecti
   readonly attribute nsISimpleEnumerator childCards;
 
   /**
    * Returns true if this directory represents a query - i.e. the rdf resource
    * was something like moz-abmdbdirectory://abook.mab?....
    */
   readonly attribute boolean isQuery;
 
+  /**
+   * Initializes a directory, pointing to a particular
+   * URI
+   */
+  void init(in string aURI);
+
   // Deletes either a mailing list or a top
   // level directory, which also updates the
   // preferences
   void deleteDirectory(in nsIAbDirectory directory);
 
   // Check if directory contains card
   // If the implementation is asynchronous the card
   // may not yet have arrived. If it is in the process
--- a/mailnews/addrbook/public/nsIAbMDBDirectory.idl
+++ b/mailnews/addrbook/public/nsIAbMDBDirectory.idl
@@ -46,17 +46,17 @@ interface nsIAddrDatabase;
 %{C++
 #define kMDBDirectoryRoot          "moz-abmdbdirectory://"
 #define kMDBDirectoryRootLen       21
 %}
 
 [scriptable, uuid(744072be-1ba0-46bc-af24-46e22567a2ea)]
 interface nsIAbMDBDirectory : nsISupports {
 
-	// Creates an RDF directory component from the
+	// Creates a directory component from the
 	// uriName, adds it to its children and returns
 	// the component
 	nsIAbDirectory addDirectory(in string uriName);
 
   /**
    * Supplies a nsILocalFile point to the database file for this directory
    *
    * @exception NS_ERROR_NOT_INITIALIZED If there is no filename preference
--- a/mailnews/addrbook/src/Makefile.in
+++ b/mailnews/addrbook/src/Makefile.in
@@ -47,35 +47,32 @@ MODULE		= addrbook
 LIBRARY_NAME	= addrbook_s
 ifndef MOZ_INCOMPLETE_EXTERNAL_LINKAGE
 MOZILLA_INTERNAL_API = 1
 LIBXUL_LIBRARY = 1
 endif
 
 CPPSRCS		= \
 		nsAbManager.cpp \
-		nsAbRDFDataSource.cpp \
-		nsDirectoryDataSource.cpp \
 		nsAbCardProperty.cpp \
 		nsDirPrefs.cpp \
 		nsAddrDatabase.cpp \
 		nsAbDirProperty.cpp \
 		nsAbAddressCollector.cpp \
 		nsAddbookProtocolHandler.cpp  \
 		nsAbMDBDirProperty.cpp \
 		nsAbMDBDirectory.cpp \
 		nsAbMDBCard.cpp \
 		nsAbBSDirectory.cpp \
 		nsAddbookUrl.cpp    \
 		nsAbDirFactoryService.cpp	\
 		nsAbMDBDirFactory.cpp	\
                 nsAbDirectoryQuery.cpp    \
                 nsAbDirectoryQueryProxy.cpp    \
                 nsAbBooleanExpression.cpp \
-                nsAbDirectoryRDFResource.cpp \
                 nsAbQueryStringToExpression.cpp \
                 nsAbView.cpp \
                 nsVCard.cpp \
                 nsVCardObj.cpp \
                 nsMsgVCardService.cpp \
                 nsAbLDIFService.cpp \
                 nsAbContentHandler.cpp \
 		$(NULL)
--- a/mailnews/addrbook/src/nsAbBSDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbBSDirectory.cpp
@@ -37,43 +37,45 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsIPrefService.h"
 #include "nsAbBSDirectory.h"
 
-#include "nsRDFCID.h"
-#include "nsIRDFService.h"
-
 #include "nsDirPrefs.h"
 #include "nsAbBaseCID.h"
 #include "nsAddrDatabase.h"
 #include "nsIAbManager.h"
 #include "nsIAbMDBDirectory.h"
 #include "nsServiceManagerUtils.h"
 #include "nsAbDirFactoryService.h"
 #include "nsAbMDBDirFactory.h"
 #include "nsArrayEnumerator.h"
 
 #include "nsCRTGlue.h"
 
 nsAbBSDirectory::nsAbBSDirectory()
-: nsRDFResource(),
-mInitialized(PR_FALSE)
+: mInitialized(PR_FALSE)
 {
   mServers.Init(13);
 }
 
 nsAbBSDirectory::~nsAbBSDirectory()
 {
 }
 
-NS_IMPL_ISUPPORTS_INHERITED1(nsAbBSDirectory, nsRDFResource, nsIAbDirectory)
+NS_IMETHODIMP nsAbBSDirectory::Init(const char *aURI)
+{
+  mURI = aURI;
+  return NS_OK;
+}
+
+NS_IMPL_ISUPPORTS_INHERITED0(nsAbBSDirectory, nsAbDirProperty)
 
 nsresult nsAbBSDirectory::CreateDirectoriesFromFactory(const nsACString &aURI,
                                                        DIR_Server *aServer,
                                                        PRBool aNotify)
 {
   nsresult rv;
 
   // Get the directory factory service
@@ -111,18 +113,16 @@ nsresult nsAbBSDirectory::CreateDirector
       continue;
     
     // Define a relationship between the preference
     // entry and the directory
     mServers.Put(childDir, aServer);
 
     mSubDirectories.AppendObject(childDir);
 
-    // Inform the listener, i.e. the RDF directory data
-    // source that a new address book has been added
     if (aNotify && abManager)
       abManager->NotifyDirectoryItemAdded(this, childDir);
   }
   
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbBSDirectory::GetChildNodes(nsISimpleEnumerator* *aResult)
@@ -315,19 +315,19 @@ NS_IMETHODIMP nsAbBSDirectory::DeleteDir
     nsCOMPtr<nsIAbDirectory> d = getDirectories.directories[i];
 
     mServers.Remove(d);
     rv = mSubDirectories.RemoveObject(d);
 
     if (abManager)
       abManager->NotifyDirectoryDeleted(this, d);
 
-    nsCOMPtr<nsIRDFResource> resource(do_QueryInterface (d, &rv));
     nsCString uri;
-    resource->GetValueUTF8(uri);
+    rv = d->GetURI(uri);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIAbDirFactory> dirFactory;
     rv = dirFactoryService->GetDirFactory(uri, getter_AddRefs(dirFactory));
     if (NS_FAILED(rv))
       continue;
 
     rv = dirFactory->DeleteDirectory(d);
   }
@@ -352,8 +352,18 @@ NS_IMETHODIMP nsAbBSDirectory::UseForAut
                                                   PRBool *aResult)
 {
   // For the "root" directory (kAllDirectoryRoot) always return true so that
   // we can search sub directories that may or may not be local.
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = PR_TRUE;
   return NS_OK;
 }
+
+NS_IMETHODIMP nsAbBSDirectory::GetURI(nsACString &aURI)
+{
+  if (mURI.IsEmpty())
+    return NS_ERROR_NOT_INITIALIZED;
+
+  aURI = mURI;
+  return NS_OK;
+}
+
--- a/mailnews/addrbook/src/nsAbBSDirectory.h
+++ b/mailnews/addrbook/src/nsAbBSDirectory.h
@@ -34,42 +34,43 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #ifndef nsAbBSDirectory_h__
 #define nsAbBSDirectory_h__
 
-#include "nsRDFResource.h"
 #include "nsAbDirProperty.h"
 
 #include "nsDataHashtable.h"
 #include "nsCOMArray.h"
 
-class nsAbBSDirectory : public nsRDFResource, public nsAbDirProperty
+class nsAbBSDirectory : public nsAbDirProperty
 {
 public:
 	NS_DECL_ISUPPORTS_INHERITED
 
 	nsAbBSDirectory();
 	virtual ~nsAbBSDirectory();
-	
+
 	// nsIAbDirectory methods
+  NS_IMETHOD Init(const char *aURI);
 	NS_IMETHOD GetChildNodes(nsISimpleEnumerator* *result);
   NS_IMETHOD CreateNewDirectory(const nsAString &aDirName,
                                 const nsACString &aURI,
                                 PRUint32 aType,
                                 const nsACString &aPrefName,
                                 nsACString &aResult);
   NS_IMETHOD CreateDirectoryByURI(const nsAString &aDisplayName,
                                   const nsACString &aURI);
   NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory);
-	NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
+  NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
   NS_IMETHOD UseForAutocomplete(const nsACString &aIdentityKey, PRBool *aResult);
+  NS_IMETHOD GetURI(nsACString &aURI);
 
 protected:
   nsresult EnsureInitialized();
 	nsresult CreateDirectoriesFromFactory(const nsACString &aURI,
                                         DIR_Server* aServer, PRBool aNotify);
 
 protected:
 	PRBool mInitialized;
--- a/mailnews/addrbook/src/nsAbDirProperty.cpp
+++ b/mailnews/addrbook/src/nsAbDirProperty.cpp
@@ -41,24 +41,25 @@
 #include "nsAbBaseCID.h"
 #include "nsIAbCard.h"
 #include "nsDirPrefs.h"
 #include "nsIPrefService.h"
 #include "nsIPrefLocalizedString.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "prmem.h"
-#include "rdf.h"
 #include "nsIAbManager.h"
 
 // From nsDirPrefs
 #define kDefaultPosition 1
 
 nsAbDirProperty::nsAbDirProperty(void)
-  : m_LastModifiedDate(0)
+  : m_LastModifiedDate(0),
+    mIsValidURI(PR_FALSE),
+    mIsQueryURI(PR_FALSE)
 {
 	m_IsMailList = PR_FALSE;
 }
 
 nsAbDirProperty::~nsAbDirProperty(void)
 {
 #if 0
   // this code causes a regression #138647
@@ -71,17 +72,17 @@ nsAbDirProperty::~nsAbDirProperty(void)
     PRInt32 i;
     for (i = count - 1; i >= 0; i--)
       m_AddressList->RemoveElementAt(i);
   }
 #endif
 }
 
 NS_IMPL_ISUPPORTS4(nsAbDirProperty, nsIAbDirectory, nsISupportsWeakReference,
-                   nsIAbCollection, nsIAbItem)
+                              nsIAbCollection, nsIAbItem)
 
 NS_IMETHODIMP nsAbDirProperty::GetUuid(nsACString &uuid)
 {
   // XXX: not all directories have a dirPrefId...
   nsresult rv = GetDirPrefId(uuid);
   NS_ENSURE_SUCCESS(rv, rv);
   uuid.Append('&');
   nsString dirName;
@@ -187,23 +188,19 @@ NS_IMETHODIMP nsAbDirProperty::GetURI(ns
 
 NS_IMETHODIMP nsAbDirProperty::GetPosition(PRInt32 *aPosition)
 {
   return GetIntValue("position", kDefaultPosition, aPosition);
 }
 
 NS_IMETHODIMP nsAbDirProperty::GetLastModifiedDate(PRUint32 *aLastModifiedDate)
 {
-	if (aLastModifiedDate)
-	{
-		*aLastModifiedDate = m_LastModifiedDate;
-		return NS_OK;
-	}
-	else
-		return NS_RDF_NO_VALUE;
+  NS_ENSURE_ARG_POINTER(aLastModifiedDate);
+  *aLastModifiedDate = m_LastModifiedDate;
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsAbDirProperty::SetLastModifiedDate(PRUint32 aLastModifiedDate)
 {
 	if (aLastModifiedDate)
 	{
 		m_LastModifiedDate = aLastModifiedDate;
 	}
@@ -288,18 +285,35 @@ NS_IMETHODIMP nsAbDirProperty::GetIsQuer
 {
   NS_ENSURE_ARG_POINTER(aResult);
   // Mailing lists are not queries by default, individual directory types
   // will override this.
   *aResult = PR_FALSE;
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsAbDirProperty::Init(const char *aURI)
+{
+  mURINoQuery = aURI;
+  mURI = aURI;
+  mIsValidURI = PR_TRUE;
+
+  PRInt32 searchCharLocation = mURINoQuery.FindChar('?');
+  if (searchCharLocation >= 0)
+  {
+    mQueryString = Substring(mURINoQuery, searchCharLocation + 1);
+    mURINoQuery.SetLength(searchCharLocation);
+    mIsQueryURI = PR_TRUE;
+  }
+
+  return NS_OK;
+}
+
 // nsIAbDirectory NOT IMPLEMENTED methods
-
 NS_IMETHODIMP
 nsAbDirProperty::GetChildNodes(nsISimpleEnumerator **childList)
 { return NS_ERROR_NOT_IMPLEMENTED; }
 
 NS_IMETHODIMP
 nsAbDirProperty::GetChildCards(nsISimpleEnumerator **childCards)
 { return NS_ERROR_NOT_IMPLEMENTED; }
 
--- a/mailnews/addrbook/src/nsAbDirProperty.h
+++ b/mailnews/addrbook/src/nsAbDirProperty.h
@@ -81,16 +81,23 @@ protected:
 	PRUint32 m_LastModifiedDate;
 
 	nsString m_ListDirName;
 	nsString m_ListName;
 	nsString m_ListNickName;
 	nsString m_Description;
 	PRBool   m_IsMailList;
 
+  nsCString mURI;
+  nsCString mQueryString;
+  nsCString mURINoQuery;
+  PRBool mIsValidURI;
+  PRBool mIsQueryURI;
+
+
   /*
    * Note that any derived implementations should ensure that this item
    * (m_DirPrefId) is correctly initialised correctly
    */
   nsCString m_DirPrefId;  // ie,"ldap_2.servers.pab"
 
   nsCOMPtr<nsIPrefBranch> m_DirectoryPrefs;
   nsCOMPtr<nsIMutableArray> m_AddressList;
deleted file mode 100644
--- a/mailnews/addrbook/src/nsAbDirectoryRDFResource.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Paul Sandoz <paul.sandoz@sun.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsAbDirectoryRDFResource.h"
-#include "nsIURL.h"
-#include "nsNetCID.h"
-#include "nsServiceManagerUtils.h"
-#include "nsComponentManagerUtils.h"
-
-nsAbDirectoryRDFResource::nsAbDirectoryRDFResource () :
-    nsRDFResource (),
-    mIsValidURI (PR_FALSE),
-    mIsQueryURI (PR_FALSE)
-{
-}
-
-nsAbDirectoryRDFResource::~nsAbDirectoryRDFResource ()
-{
-}
-
-NS_IMPL_ISUPPORTS_INHERITED0(nsAbDirectoryRDFResource, nsRDFResource)
-
-NS_IMETHODIMP nsAbDirectoryRDFResource::Init(const char* aURI)
-{
-    nsresult rv = nsRDFResource::Init (aURI);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    mURINoQuery = aURI;
-    mIsValidURI = PR_TRUE;
-
-    PRInt32 searchCharLocation = mURINoQuery.FindChar('?');
-    if (searchCharLocation >= 0) {
-        mQueryString = Substring(mURINoQuery, searchCharLocation + 1);
-        mURINoQuery.SetLength(searchCharLocation);
-        mIsQueryURI = PR_TRUE;
-    }
-
-    return rv;
-}
deleted file mode 100644
--- a/mailnews/addrbook/src/nsAbDirectoryRDFResource.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Paul Sandoz <paul.sandoz@sun.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsAbDirectoryRDFResource_h__
-#define nsAbDirectoryRDFResource_h__
-
-#include "nsRDFResource.h"
-#include "nsStringGlue.h"
-
-class nsAbDirectoryRDFResource : public nsRDFResource
-{
-public:
-    NS_DECL_ISUPPORTS_INHERITED
-
-    nsAbDirectoryRDFResource ();
-    virtual ~nsAbDirectoryRDFResource ();
-
-    // nsIRDFResource methods:
-    NS_IMETHOD Init(const char* aURI);
-    
-protected:
-    PRBool mIsValidURI;
-    PRBool mIsQueryURI;
-    nsCString mQueryString;
-    nsCString mURINoQuery;
-};
-
-#endif
-
--- a/mailnews/addrbook/src/nsAbLDAPDirFactory.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirFactory.cpp
@@ -106,9 +106,8 @@ nsAbLDAPDirFactory::GetDirectories(const
 NS_IMETHODIMP
 nsAbLDAPDirFactory::DeleteDirectory(nsIAbDirectory *directory)
 {
   // No actual deletion - as the LDAP Address Book is not physically
   // created in the corresponding CreateDirectory() unlike the Personal
   // Address Books. But we still need to return NS_OK from here.
   return NS_OK;
 }
-
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
@@ -71,31 +71,31 @@
 #include "nsMsgBaseCID.h"
 #include "nsMsgUtils.h"
 
 #define kDefaultMaxHits 100
 
 using namespace mozilla;
 
 nsAbLDAPDirectory::nsAbLDAPDirectory() :
-  nsAbDirectoryRDFResource(),
+  nsAbDirProperty(),
   mPerformingQuery(PR_FALSE),
   mContext(0),
   mLock("nsAbLDAPDirectory.mLock")
 {
   mCache.Init();
 }
 
 nsAbLDAPDirectory::~nsAbLDAPDirectory()
 {
 }
 
-NS_IMPL_ISUPPORTS_INHERITED4(nsAbLDAPDirectory, nsAbDirectoryRDFResource,
-                             nsIAbDirectory, nsISupportsWeakReference,
-                             nsIAbDirSearchListener, nsIAbLDAPDirectory)
+NS_IMPL_ISUPPORTS_INHERITED3(nsAbLDAPDirectory, nsAbDirProperty,
+                             nsISupportsWeakReference, nsIAbDirSearchListener,
+                             nsIAbLDAPDirectory)
 
 NS_IMETHODIMP nsAbLDAPDirectory::GetPropertiesChromeURI(nsACString &aResult)
 {
   aResult.AssignLiteral("chrome://messenger/content/addressbook/pref-directory-add.xul");
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbLDAPDirectory::Init(const char* aURI)
@@ -108,17 +108,17 @@ NS_IMETHODIMP nsAbLDAPDirectory::Init(co
   // that's the URI we should have been passed.
   PRInt32 searchCharLocation = uri.FindChar('?', kLDAPDirectoryRootLen);
 
   if (searchCharLocation == -1)
     m_DirPrefId = Substring(uri, kLDAPDirectoryRootLen);
   else
     m_DirPrefId = Substring(uri, kLDAPDirectoryRootLen, searchCharLocation - kLDAPDirectoryRootLen);
 
-  return nsAbDirectoryRDFResource::Init(aURI);
+  return nsAbDirProperty::Init(aURI);
 }
 
 nsresult nsAbLDAPDirectory::Initiate()
 {
   return NS_OK;
 }
 
 /* 
@@ -223,17 +223,17 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetLDAP
   // we can handle the case where the URI isn't specified (see comments
   // below)
   nsCAutoString URI;
   nsresult rv = GetStringValue("uri", EmptyCString(), URI);
   if (NS_FAILED(rv) || URI.IsEmpty())
   {
     /*
      * A recent change in Mozilla now means that the LDAP Address Book
-     * RDF Resource URI is based on the unique preference name value i.e.  
+     * URI is based on the unique preference name value i.e.
      * [moz-abldapdirectory://prefName]
      * Prior to this valid change it was based on the actual uri i.e. 
      * [moz-abldapdirectory://host:port/basedn]
      * Basing the resource on the prefName allows these attributes to 
      * change. 
      *
      * But the uri value was also the means by which third-party
      * products could integrate with Mozilla's LDAP Address Books
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.h
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.h
@@ -35,29 +35,27 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsAbLDAPDirectory_h__
 #define nsAbLDAPDirectory_h__
 
-#include "nsAbDirectoryRDFResource.h"
 #include "nsAbDirProperty.h"
 #include "nsAbLDAPDirectoryModify.h"
 #include "nsIAbDirectoryQuery.h"
 #include "nsIAbDirectorySearch.h"
 #include "nsIAbDirSearchListener.h"
 #include "nsIAbLDAPDirectory.h"
 #include "nsIMutableArray.h"
 #include "nsInterfaceHashtable.h"
 #include "mozilla/Mutex.h"
 
 class nsAbLDAPDirectory :
-  public nsAbDirectoryRDFResource,    // nsIRDFResource
   public nsAbDirProperty,             // nsIAbDirectory
   public nsAbLDAPDirectoryModify,
   public nsIAbDirectorySearch,
   public nsIAbLDAPDirectory,
   public nsIAbDirSearchListener
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
--- a/mailnews/addrbook/src/nsAbMDBDirFactory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirFactory.cpp
@@ -36,20 +36,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAbMDBDirFactory.h"
 #include "nsAbUtils.h"
-
-#include "nsIRDFService.h"
-#include "nsIRDFResource.h"
-#include "nsRDFResource.h"
+#include "nsString.h"
 #include "nsServiceManagerUtils.h"
 #include "nsILocalFile.h"
 #include "nsIAbManager.h"
 #include "nsIAbMDBDirectory.h"
 #include "nsAbMDBDirFactory.h"
 #include "nsIAddrDBListener.h"
 #include "nsIAddrDatabase.h"
 #include "nsEnumeratorUtils.h"
@@ -71,32 +68,26 @@ NS_IMETHODIMP nsAbMDBDirFactory::GetDire
                                                 const nsACString &aURI,
                                                 const nsACString &aPrefName,
                                                 nsISimpleEnumerator **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   
   nsresult rv;
 
-  nsCOMPtr<nsIRDFService> rdf = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIRDFResource> resource;
-  rv = rdf->GetResource(aURI, getter_AddRefs(resource));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = abManager->GetDirectory(aURI, getter_AddRefs(directory));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = directory->SetDirPrefId(aPrefName);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMPtr<nsILocalFile> dbPath;
   rv = abManager->GetUserProfileDirectory(getter_AddRefs(dbPath));
 
   nsCOMPtr<nsIAddrDatabase> listDatabase;
   if (NS_SUCCEEDED(rv))
   {
     nsCAutoString fileName;
       
--- a/mailnews/addrbook/src/nsAbMDBDirProperty.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirProperty.cpp
@@ -33,31 +33,29 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAbMDBDirProperty.h"	 
-#include "nsIRDFService.h"
-#include "nsIRDFResource.h"
 #include "nsIServiceManager.h"
-#include "nsRDFCID.h"
 #include "nsStringGlue.h"
 #include "nsCOMPtr.h"
 #include "nsAbBaseCID.h"
 #include "nsAddrDatabase.h"
 #include "nsIAbCard.h"
 #include "nsIAbListener.h"
 #include "nsArrayUtils.h"
 #include "mdb.h"
 #include "nsComponentManagerUtils.h"
 
 nsAbMDBDirProperty::nsAbMDBDirProperty(void)
+  : nsAbDirProperty()
 {
   m_dbRowID = 0;
 }
 
 nsAbMDBDirProperty::~nsAbMDBDirProperty(void)
 { 
 }
 
--- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp
@@ -33,18 +33,16 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAbMDBDirectory.h" 
-#include "nsIRDFService.h"
-#include "nsRDFCID.h"
 #include "nsStringGlue.h"
 #include "nsCOMPtr.h"
 #include "nsAbBaseCID.h"
 #include "nsAddrDatabase.h"
 #include "nsIAbListener.h"
 #include "nsIAbManager.h"
 #include "nsIURL.h"
 #include "nsNetCID.h"
@@ -61,33 +59,31 @@
 #include "nsDirectoryServiceUtils.h"
 #include "nsILocalFile.h"
 #include "nsComponentManagerUtils.h"
 #include "nsMemory.h"
 #include "nsArrayUtils.h"
 #include "nsUnicharUtils.h"
 
 nsAbMDBDirectory::nsAbMDBDirectory(void):
-     nsAbDirectoryRDFResource(),
+     nsAbMDBDirProperty(),
      mPerformingQuery(PR_FALSE)
 {
   mSearchCache.Init();
 }
 
 nsAbMDBDirectory::~nsAbMDBDirectory(void)
 {
   if (mDatabase) {
     mDatabase->RemoveListener(this);
   }
 }
 
-NS_IMPL_ISUPPORTS_INHERITED6(nsAbMDBDirectory, nsAbDirectoryRDFResource,
-                             nsIAbDirectory, nsISupportsWeakReference,
+NS_IMPL_ISUPPORTS_INHERITED3(nsAbMDBDirectory, nsAbMDBDirProperty,
                              nsIAbDirSearchListener,
-                             nsIAbMDBDirectory,
                              nsIAbDirectorySearch,
                              nsIAddrDBListener)
 
 NS_IMETHODIMP nsAbMDBDirectory::Init(const char *aUri)
 {
   // We need to ensure  that the m_DirPrefId is initialized properly
   nsDependentCString uri(aUri);
 
@@ -152,17 +148,17 @@ NS_IMETHODIMP nsAbMDBDirectory::Init(con
       }
     }     
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(childCount, childArray);
 
     NS_ASSERTION(!m_DirPrefId.IsEmpty(),
                  "Error, Could not set m_DirPrefId in nsAbMDBDirectory::Init");
   }
 
-  return nsAbDirectoryRDFResource::Init(aUri);
+  return nsAbDirProperty::Init(aUri);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 nsresult nsAbMDBDirectory::RemoveCardFromAddressList(nsIAbCard* card)
 {
   nsresult rv = NS_OK;
   PRUint32 listTotal;
@@ -340,24 +336,21 @@ NS_IMETHODIMP nsAbMDBDirectory::AddDirec
 
   if (!childDir || !uriName)
     return NS_ERROR_NULL_POINTER;
 
   if (mURI.IsEmpty())
     return NS_ERROR_NOT_INITIALIZED;
 
   nsresult rv = NS_OK;
-  nsCOMPtr<nsIRDFService> rdf(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-  
-  nsCOMPtr<nsIRDFResource> res;
-  rv = rdf->GetResource(nsDependentCString(uriName), getter_AddRefs(res));
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(res, &rv));
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = abManager->GetDirectory(nsDependentCString(uriName), getter_AddRefs(directory));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mSubDirectories.IndexOf(directory) == -1)
     mSubDirectories.AppendObject(directory);
   NS_IF_ADDREF(*childDir = directory);
   return rv;
 }
 
@@ -478,21 +471,22 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteCa
     // after delete, remove this query as a listener.
     nsCOMPtr<nsIAddrDatabase> database;
     rv = GetDatabase(getter_AddRefs(database));
     NS_ENSURE_SUCCESS(rv,rv);
 
     rv = database->AddListener(this);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIRDFResource> resource;
-    rv = gRDFService->GetResource(mURINoQuery, getter_AddRefs(resource));
+    nsCOMPtr<nsIAbManager> abManager =
+        do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
-    
-    nsCOMPtr<nsIAbDirectory> directory = do_QueryInterface(resource, &rv);
+
+    nsCOMPtr<nsIAbDirectory> directory;
+    rv = abManager->GetDirectory(mURINoQuery, getter_AddRefs(directory));
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = directory->DeleteCards(aCards);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = database->RemoveListener(this);
     NS_ENSURE_SUCCESS(rv, rv);
     return rv;
@@ -541,35 +535,31 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteCa
         }
         else
         {
           mDatabase->DeleteCard(card, PR_TRUE, this);
           PRBool bIsMailList = PR_FALSE;
           card->GetIsMailList(&bIsMailList);
           if (bIsMailList)
           {
-            //to do, get mailing list dir side uri and notify rdf to remove it
+            //to do, get mailing list dir side uri and notify nsIAbManager to remove it
             nsCAutoString listUri(mURI);
             listUri.AppendLiteral("/MailList");
             listUri.AppendInt(rowID);
             if (!listUri.IsEmpty())
             {
               nsresult rv = NS_OK;
-              nsCOMPtr<nsIRDFService> rdfService = 
-                       do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
-
-              if (NS_FAILED(rv))
-                return rv;
 
-              nsCOMPtr<nsIRDFResource> listResource;
-              rv = rdfService->GetResource(listUri,
-                                           getter_AddRefs(listResource));
-              nsCOMPtr<nsIAbDirectory> listDir = do_QueryInterface(listResource, &rv);
-              if (NS_FAILED(rv))
-                return rv;
+              nsCOMPtr<nsIAbManager> abManager =
+                  do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
+              NS_ENSURE_SUCCESS(rv, rv);
+
+              nsCOMPtr<nsIAbDirectory> listDir;
+              rv = abManager->GetDirectory(listUri, getter_AddRefs(listDir));
+              NS_ENSURE_SUCCESS(rv, rv);
 
               PRUint32 dirIndex;
               if (m_AddressList && NS_SUCCEEDED(m_AddressList->IndexOf(0, listDir, &dirIndex)))
                 m_AddressList->RemoveElementAt(dirIndex);
 
               mSubDirectories.RemoveObject(listDir);
 
               if (listDir)
@@ -940,22 +930,23 @@ NS_IMETHODIMP nsAbMDBDirectory::StartSea
   // don't search the subdirectories 
   // if the current directory is a mailing list, it won't have any subdirectories
   // if the current directory is a addressbook, searching both it
   // and the subdirectories (the mailing lists), will yield duplicate results
   // because every entry in a mailing list will be an entry in the parent addressbook
   rv = arguments->SetQuerySubDirectories(PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // Get the directory without the query
-  nsCOMPtr<nsIRDFResource> resource;
-  rv = gRDFService->GetResource(mURINoQuery, getter_AddRefs(resource));
+  nsCOMPtr<nsIAbManager> abManager =
+      do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
+  // Get the directory without the query
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = abManager->GetDirectory(mURINoQuery, getter_AddRefs(directory));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Bug 280232 - something was causing continuous loops in searching. Add a
   // check here for the directory to search not being a query uri as well in
   // the hopes that will at least break us out of the continuous loop even if
   // we don't know how we got into it.
   PRBool isQuery;
   rv = directory->GetIsQuery(&isQuery);
@@ -1017,35 +1008,35 @@ nsresult nsAbMDBDirectory::GetAbDatabase
   if (mDatabase)
     return NS_OK;
 
   nsresult rv;
 
   if (m_IsMailList)
   {
     // Get the database of the parent directory.
-    nsCString parentURI(mURINoQuery);
+    nsCAutoString parentURI(mURINoQuery);
 
     PRInt32 pos = parentURI.RFindChar('/');
 
     // If we didn't find a / something really bad has happened
     if (pos == -1)
       return NS_ERROR_FAILURE;
 
     parentURI = StringHead(parentURI, pos);
 
-    nsCOMPtr<nsIRDFService> rdfService =
-      do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
+    nsCOMPtr<nsIAbManager> abManager =
+        do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIRDFResource> resource;
-    rv = rdfService->GetResource(parentURI, getter_AddRefs(resource));
+    nsCOMPtr<nsIAbDirectory> directory;
+    rv = abManager->GetDirectory(parentURI, getter_AddRefs(directory));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIAbMDBDirectory> mdbDir(do_QueryInterface(resource, &rv));
+    nsCOMPtr<nsIAbMDBDirectory> mdbDir(do_QueryInterface(directory, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = mdbDir->GetDatabase(getter_AddRefs(mDatabase));
   }
   else
     rv = GetDatabase(getter_AddRefs(mDatabase));
 
   if (NS_SUCCEEDED(rv))
--- a/mailnews/addrbook/src/nsAbMDBDirectory.h
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.h
@@ -47,38 +47,36 @@
 #include "nsAbMDBDirProperty.h"  
 #include "nsIAbCard.h"
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 #include "nsDirPrefs.h"
 #include "nsIAbDirectorySearch.h"
 #include "nsIAbDirSearchListener.h"
 #include "nsInterfaceHashtable.h"
-#include "nsAbDirectoryRDFResource.h"
 #include "nsIAddrDBListener.h"
 
 /* 
  * Address Book Directory
  */ 
 
 class nsAbMDBDirectory:
-  public nsAbDirectoryRDFResource, 
   public nsAbMDBDirProperty,	// nsIAbDirectory, nsIAbMDBDirectory
   public nsIAbDirSearchListener,
   public nsIAddrDBListener, 
   public nsIAbDirectorySearch
 {
 public: 
   nsAbMDBDirectory(void);
   virtual ~nsAbMDBDirectory(void);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIADDRDBLISTENER
 
-  // Override nsAbDirectoryRDFResource::Init
+  // Override nsAbMDBDirProperty::Init
   NS_IMETHOD Init(const char *aUri);
 
   // nsIAbMDBDirectory methods
   NS_IMETHOD GetURI(nsACString &aURI);
   NS_IMETHOD ClearDatabase();
   NS_IMETHOD NotifyDirItemAdded(nsISupports *item) { return NotifyItemAdded(item);}
   NS_IMETHOD RemoveElementsFromAddressList();
   NS_IMETHOD RemoveEmailAddressAt(PRUint32 aIndex);
@@ -124,12 +122,13 @@ protected:
 
   nsresult GetAbDatabase();
   nsCOMPtr<nsIAddrDatabase> mDatabase;  
 
   nsCOMArray<nsIAbDirectory> mSubDirectories;
 
   PRInt32 mContext;
   PRBool mPerformingQuery;
+
   nsInterfaceHashtable<nsISupportsHashKey, nsIAbCard> mSearchCache;
 };
 
 #endif
--- a/mailnews/addrbook/src/nsAbManager.cpp
+++ b/mailnews/addrbook/src/nsAbManager.cpp
@@ -45,19 +45,16 @@
 #include "nsIOutputStream.h"
 #include "nsNetUtil.h"
 #include "nsMsgI18N.h"
 #include "nsIStringBundle.h"
 #include "nsMsgUtils.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "plstr.h"
 #include "prmem.h"
-#include "nsIRDFResource.h"
-#include "rdf.h"
-#include "nsIRDFService.h"
 #include "nsIServiceManager.h"
 #include "nsIDOMWindow.h"
 #include "nsIFilePicker.h"
 #include "plbase64.h"
 #include "nsIWindowWatcher.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsVCard.h"
 #include "nsVCardObj.h"
@@ -65,16 +62,19 @@
 #include "nsICommandLine.h"
 #include "nsILocalFile.h"
 #include "nsIMutableArray.h"
 #include "nsArrayUtils.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsIObserverService.h"
 #include "nsDirPrefs.h"
 #include "nsThreadUtils.h"
+#include "nsIAbDirFactory.h"
+#include "nsComponentManagerUtils.h"
+#include "nsIIOService.h"
 
 struct ExportAttributesTableStruct
 {
   const char* abPropertyName;
   PRUint32 plainTextStringID;
 };
 
 // our schema is not fixed yet, but we still want some sort of objectclass
@@ -148,16 +148,17 @@ const ExportAttributesTableStruct EXPORT
   {kFamilyNameProperty},
 };
 
 //
 // nsAbManager
 //
 nsAbManager::nsAbManager()
 {
+  mAbStore.Init();
 }
 
 nsAbManager::~nsAbManager()
 {
 }
 
 NS_IMPL_THREADSAFE_ADDREF(nsAbManager)
 NS_IMPL_THREADSAFE_RELEASE(nsAbManager)
@@ -226,118 +227,157 @@ NS_IMETHODIMP nsAbManager::Observe(nsISu
 NS_IMETHODIMP nsAbManager::GetDirectories(nsISimpleEnumerator **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
 
   // We cache the top level AB to ensure that nsIAbDirectory items are not
   // created and dumped every time GetDirectories is called. This was causing
   // performance problems, especially with the content policy on messages
   // with lots of urls.
+  nsresult rv;
+  nsCOMPtr<nsIAbDirectory> rootAddressBook;
+  rv = GetRootDirectory(getter_AddRefs(rootAddressBook));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return rootAddressBook->GetChildNodes(aResult);
+}
+
+nsresult
+nsAbManager::GetRootDirectory(nsIAbDirectory **aResult)
+{
+  // We cache the top level AB to ensure that nsIAbDirectory items are not
+  // created and dumped every time GetDirectories is called. This was causing
+  // performance problems, especially with the content policy on messages
+  // with lots of urls.
+  nsresult rv;
+
   if (!mCacheTopLevelAb)
   {
-    nsresult rv;
-    nsCOMPtr<nsIRDFService> rdfService(do_GetService(NS_RDF_CONTRACTID "/rdf-service;1", &rv));
+    nsCOMPtr<nsIAbDirectory> rootAddressBook(do_GetService(NS_ABDIRECTORY_CONTRACTID, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIRDFResource> parentResource;
-    rv = rdfService->GetResource(NS_LITERAL_CSTRING(kAllDirectoryRoot),
-                                 getter_AddRefs(parentResource));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    mCacheTopLevelAb = do_QueryInterface(parentResource, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
+    mCacheTopLevelAb = rootAddressBook;
   }
 
-  return mCacheTopLevelAb->GetChildNodes(aResult);
+  NS_IF_ADDREF(*aResult = mCacheTopLevelAb);
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsAbManager::GetDirectory(const nsACString &aURI,
                                         nsIAbDirectory **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
 
   nsresult rv;
-  nsCOMPtr<nsIRDFService> rdfService(do_GetService(NS_RDF_CONTRACTID "/rdf-service;1", &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIAbDirectory> directory;
+
+  // Was the directory root requested?
+  if (aURI.Equals(NS_LITERAL_CSTRING(kAllDirectoryRoot)))
+  {
+    rv = GetRootDirectory(getter_AddRefs(directory));
+    NS_ENSURE_SUCCESS(rv, rv);
+    NS_IF_ADDREF(*aResult = directory);
+    return NS_OK;
+  }
+
+  // Do we have a copy of this directory already within our look-up table?
+  if (!mAbStore.Get(aURI, getter_AddRefs(directory)))
+  {
+    // The directory wasn't in our look-up table, so we need to instantiate
+    // it. First, extract the scheme from the URI...
+
+    nsCAutoString scheme;
+
+    PRInt32 colon = aURI.FindChar(':');
+    if (colon <= 0)
+      return NS_ERROR_MALFORMED_URI;
+    scheme = Substring(aURI, 0, colon);
 
-  nsCOMPtr<nsIRDFResource> dirResource;
-  rv = rdfService->GetResource(aURI, getter_AddRefs(dirResource));
-  NS_ENSURE_SUCCESS(rv, rv);
+    // Construct the appropriate nsIAbDirectory...
+    nsCAutoString contractID;
+    contractID.AssignLiteral(NS_AB_DIRECTORY_TYPE_CONTRACTID_PREFIX);
+    contractID.Append(scheme);
+    directory = do_CreateInstance(contractID.get(), &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    // Init it with the URI
+    const nsAFlatCString& flatURI = PromiseFlatCString(aURI);
+
+    rv = directory->Init(flatURI.get());
+    NS_ENSURE_SUCCESS(rv, rv);
 
-  return CallQueryInterface(dirResource, aResult);
+    // Check if this directory was initiated with a search query.  If so,
+    // we don't cache it.
+    PRBool isQuery = PR_FALSE;
+    rv = directory->GetIsQuery(&isQuery);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (!isQuery)
+      mAbStore.Put(aURI, directory);
+  }
+  NS_IF_ADDREF(*aResult = directory);
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsAbManager::NewAddressBook(const nsAString &aDirName,
                                             const nsACString &aURI,
                                             const PRUint32 aType,
                                             const nsACString &aPrefName,
                                             nsACString &aResult)
 {
   nsresult rv;
 
-  nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
+  nsCOMPtr<nsIAbDirectory> parentDir;
+  rv = GetRootDirectory(getter_AddRefs(parentDir));
   NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIRDFResource> parentResource;
-  rv = rdfService->GetResource(NS_LITERAL_CSTRING(kAllDirectoryRoot),
-                               getter_AddRefs(parentResource));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIAbDirectory> parentDir = do_QueryInterface(parentResource, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   return parentDir->CreateNewDirectory(aDirName, aURI, aType, aPrefName, aResult);
 }
 
 NS_IMETHODIMP nsAbManager::DeleteAddressBook(const nsACString &aURI)
 {
   // Find the address book
   nsresult rv;
 
-  nsCOMPtr<nsIRDFService> rdfService =
-    do_GetService(NS_RDF_CONTRACTID "/rdf-service;1", &rv);
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = GetDirectory(aURI, getter_AddRefs(directory));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIRDFResource> directoryResource;
-  rv = rdfService->GetResource(aURI, getter_AddRefs(directoryResource));
+  nsCOMPtr<nsIAbDirectory> rootDirectory;
+  rv = GetRootDirectory(getter_AddRefs(rootDirectory));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIAbDirectory> directory = do_QueryInterface(directoryResource, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // Now find the parent directory
-  PRBool isMailList;
-  rv = directory->GetIsMailList(&isMailList);
+  // Go through each of the children of the address book
+  // (so, the mailing lists) and remove their entries from
+  // the look up table.
+  nsCOMPtr<nsISimpleEnumerator> enumerator;
+  rv = directory->GetChildNodes(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCString uriToUse;
-  if (!isMailList)
-    // We only accept one layer of address books at the moment.
-    uriToUse.AppendLiteral(kAllDirectoryRoot);
-  else
+  nsCOMPtr<nsISupports> item;
+  nsCOMPtr<nsIAbDirectory> childDirectory;
+  PRBool hasMore = PR_FALSE;
+  while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore)
   {
-    uriToUse.Append(aURI);
+    rv = enumerator->GetNext(getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
 
-    PRInt32 pos = uriToUse.RFindChar('/');
+    childDirectory = do_QueryInterface(item, &rv);
+    if (NS_SUCCEEDED(rv))
+    {
+      nsCString childURI;
+      rv = childDirectory->GetURI(childURI);
+      NS_ENSURE_SUCCESS(rv, rv);
 
-    // If we didn't find a / something really bad has happened
-    if (pos == -1)
-      return NS_ERROR_FAILURE;
-
-    uriToUse = StringHead(uriToUse, pos);
+      mAbStore.Remove(childURI);
+    }
   }
 
-  nsCOMPtr<nsIRDFResource> parentResource;
-  rv = rdfService->GetResource(uriToUse, getter_AddRefs(parentResource));
-  NS_ENSURE_SUCCESS(rv, rv);
+  mAbStore.Remove(aURI);
 
-  nsCOMPtr<nsIAbDirectory> parentDir(do_QueryInterface(parentResource, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return parentDir->DeleteDirectory(directory);
+  return rootDirectory->DeleteDirectory(directory);
 }
 
 NS_IMETHODIMP nsAbManager::AddAddressBookListener(nsIAbListener *aListener,
                                                   abListenerNotifyFlagValue aNotifyFlags)
 {
   NS_ENSURE_ARG_POINTER(aListener);
 
   abListener newListener(aListener, aNotifyFlags);
@@ -408,34 +448,24 @@ NS_IMETHODIMP nsAbManager::GetUserProfil
   rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return CallQueryInterface(profileDir, userDir);
 }
 
 NS_IMETHODIMP nsAbManager::MailListNameExists(const PRUnichar *name, PRBool *exist)
 {
+  nsresult rv;
   NS_ENSURE_ARG_POINTER(exist);
 
   *exist = PR_FALSE;
 
-  // Get the rdf service
-    nsresult rv;
-  nsCOMPtr<nsIRDFService> rdfService =
-    do_GetService(NS_RDF_CONTRACTID "/rdf-service;1", &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
   // now get the top-level book
-    nsCOMPtr<nsIRDFResource> resource;
-  rv = rdfService->GetResource(NS_LITERAL_CSTRING("moz-abdirectory://"),
-                                     getter_AddRefs(resource));
-        NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIAbDirectory> topDirectory(do_QueryInterface(resource, &rv));
-        NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIAbDirectory> topDirectory;
+  rv = GetRootDirectory(getter_AddRefs(topDirectory));
 
   // now go through the address books
   nsCOMPtr<nsISimpleEnumerator> enumerator;
   rv = topDirectory->GetChildNodes(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISupports> item;
   nsCOMPtr<nsIAbMDBDirectory> directory;
@@ -953,28 +983,22 @@ nsresult nsAbManager::AppendLDIFForMailL
 
   rv = aCard->GetPropertyAsAString(kNotesProperty, attrValue);
   if (NS_SUCCEEDED(rv) && !attrValue.IsEmpty()) {
     rv = AppendProperty(ldapAttributeName.get(), attrValue.get(), aResult);
     NS_ENSURE_SUCCESS(rv,rv);
     aResult += MSG_LINEBREAK;
   }
 
-  nsCOMPtr<nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-
   nsCString mailListURI;
   rv = aCard->GetMailListURI(getter_Copies(mailListURI));
-  NS_ENSURE_SUCCESS(rv,rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr <nsIRDFResource> resource;
-  rv = rdfService->GetResource(mailListURI, getter_AddRefs(resource));
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  nsCOMPtr <nsIAbDirectory> mailList = do_QueryInterface(resource, &rv);
+  nsCOMPtr <nsIAbDirectory> mailList;
+  rv = GetDirectory(mailListURI, getter_AddRefs(mailList));
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsCOMPtr<nsIMutableArray> addresses;
   rv = mailList->GetAddressLists(getter_AddRefs(addresses));
   if (addresses) {
     PRUint32 total = 0;
     addresses->GetLength(&total);
     if (total) {
--- a/mailnews/addrbook/src/nsAbManager.h
+++ b/mailnews/addrbook/src/nsAbManager.h
@@ -38,18 +38,20 @@
 #ifndef __nsAbManager_h
 #define __nsAbManager_h
  
 #include "nsIAbManager.h"
 #include "nsTObserverArray.h"
 #include "nsCOMPtr.h"
 #include "nsICommandLineHandler.h"
 #include "nsIObserver.h"
+#include "nsInterfaceHashtable.h"
+#include "nsIAbDirFactoryService.h"
+#include "nsIAbDirectory.h"
 
-class nsIAbDirectory;
 class nsIAbLDAPAttributeMap;
 
 class nsAbManager : public nsIAbManager,
                     public nsICommandLineHandler,
                     public nsIObserver
 {
   
 public:
@@ -59,16 +61,17 @@ public:
 	NS_DECL_ISUPPORTS
  	NS_DECL_NSIABMANAGER
   NS_DECL_NSIOBSERVER
   NS_DECL_NSICOMMANDLINEHANDLER
 
   nsresult Init();
 
 private:
+  nsresult GetRootDirectory(nsIAbDirectory **aResult);
   nsresult ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const char *aDelim, PRUint32 aDelimLen, nsILocalFile *aLocalFile);
   nsresult ExportDirectoryToLDIF(nsIAbDirectory *aDirectory, nsILocalFile *aLocalFile);
   nsresult AppendLDIFForMailList(nsIAbCard *aCard, nsIAbLDAPAttributeMap *aAttrMap, nsACString &aResult);
   nsresult AppendDNForCard(const char *aProperty, nsIAbCard *aCard, nsIAbLDAPAttributeMap *aAttrMap, nsACString &aResult);
   nsresult AppendBasicLDIFForCard(nsIAbCard *aCard, nsIAbLDAPAttributeMap *aAttrMap, nsACString &aResult);
   nsresult AppendProperty(const char *aProperty, const PRUnichar *aValue, nsACString &aResult);
   PRBool IsSafeLDIFString(const PRUnichar *aStr);
 
@@ -87,11 +90,12 @@ private:
     }
     int operator==(const abListener &aListener) const {
       return mListener == aListener.mListener;
     }
   };
 
   nsTObserverArray<abListener> mListeners;
   nsCOMPtr<nsIAbDirectory> mCacheTopLevelAb;
+  nsInterfaceHashtable<nsCStringHashKey, nsIAbDirectory> mAbStore;
 };
 
 #endif
--- a/mailnews/addrbook/src/nsAbOSXCard.h
+++ b/mailnews/addrbook/src/nsAbOSXCard.h
@@ -36,43 +36,44 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsAbOSXCard_h___
 #define nsAbOSXCard_h___
 
 #include "nsAbCardProperty.h"
-#include "nsRDFResource.h"
 
 #define NS_ABOSXCARD_URI_PREFIX NS_ABOSXCARD_PREFIX "://"
 
 #define NS_IABOSXCARD_IID \
   { 0xa7e5b697, 0x772d, 0x4fb5, \
     { 0x81, 0x16, 0x23, 0xb7, 0x5a, 0xac, 0x94, 0x56 } }
 
 class nsIAbOSXCard : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IABOSXCARD_IID)
 
+  virtual nsresult Init(const char *aUri) = 0;
   virtual nsresult Update(PRBool aNotify) = 0;
+  virtual nsresult GetURI(nsACString &aURI) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIAbOSXCard, NS_IABOSXCARD_IID)
 
-class nsAbOSXCard : public nsRDFResource, 
-                    public nsAbCardProperty,
+class nsAbOSXCard : public nsAbCardProperty,
                     public nsIAbOSXCard
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
     
-  // nsIRDFResource method
-  NS_IMETHOD Init(const char *aUri);
-
   nsresult Update(PRBool aNotify);
-
+  nsresult GetURI(nsACString &aURI);
+  nsresult Init(const char *aUri);
   // this is needed so nsAbOSXUtils.mm can get at nsAbCardProperty
   friend class nsAbOSXUtils;
+private:
+  nsCString mURI;
+
 };
 
 #endif // nsAbOSXCard_h___
--- a/mailnews/addrbook/src/nsAbOSXCard.mm
+++ b/mailnews/addrbook/src/nsAbOSXCard.mm
@@ -50,19 +50,18 @@
 #define kABShowAsCompany (0)
 #define kABNameOrderingMask (0)
 #define kABDefaultNameOrdering (-1)
 #define kABFirstNameFirst (-1)
 #define kABOtherDatesProperty nil
 #define kABAnniversaryLabel nil
 #endif
 
-NS_IMPL_ISUPPORTS_INHERITED2(nsAbOSXCard,
-                             nsRDFResource,
-                             nsIAbCard,
+NS_IMPL_ISUPPORTS_INHERITED1(nsAbOSXCard,
+                             nsAbCardProperty,
                              nsIAbOSXCard)
 
 #ifdef DEBUG
 static ABPropertyType
 GetPropertType(ABRecord *aCard, NSString *aProperty)
 {
   ABPropertyType propertyType = kABErrorInProperty;
   if ([aCard isKindOfClass:[ABPerson class]])
@@ -83,18 +82,19 @@ SetStringProperty(nsAbOSXCard *aCard, co
   if (NS_FAILED(rv))
     oldValue.Truncate();
 
   if (!aNotify) {
     aCard->SetPropertyAsAString(aMemberName, aValue);
   }
   else if (!oldValue.Equals(aValue)) {
     aCard->SetPropertyAsAString(aMemberName, aValue);
-    
-    nsISupports *supports = NS_ISUPPORTS_CAST(nsRDFResource*, aCard);
+
+    nsISupports *supports = NS_ISUPPORTS_CAST(nsAbCardProperty*, aCard);
+
     aAbManager->NotifyItemPropertyChanged(supports, aMemberName,
                                           oldValue.get(), aValue.get());
   }
 }
 
 static void
 SetStringProperty(nsAbOSXCard *aCard, NSString *aValue, const char *aMemberName,
                   PRBool aNotify, nsIAbManager *aAbManager)
@@ -172,32 +172,41 @@ MapMultiValue(nsAbOSXCard *aCard, ABReco
   }
   // String wasn't found, set value of card to empty if it was set previously
   SetStringProperty(aCard, EmptyString(), aMap.mPropertyName, aNotify,
                     aAbManager);
   
   return PR_FALSE;
 }
 
-NS_IMETHODIMP
+nsresult
 nsAbOSXCard::Init(const char *aUri)
 {
   if (strncmp(aUri, NS_ABOSXCARD_URI_PREFIX,
               sizeof(NS_ABOSXCARD_URI_PREFIX) - 1) != 0)
     return NS_ERROR_FAILURE;
-  
-  nsresult rv = nsRDFResource::Init(aUri);
-  NS_ENSURE_SUCCESS(rv, rv);
-  
+
+  mURI = aUri;
+
   SetLocalId(nsDependentCString(aUri));
 
   return Update(PR_FALSE);
 }
 
 nsresult
+nsAbOSXCard::GetURI(nsACString &aURI)
+{
+  if (mURI.IsEmpty())
+    return NS_ERROR_NOT_INITIALIZED;
+
+  aURI = mURI;
+  return NS_OK;
+}
+
+nsresult
 nsAbOSXCard::Update(PRBool aNotify)
 {
   ABAddressBook *addressBook = [ABAddressBook sharedAddressBook];
 
   const char *uid = &((mURI.get())[16]);
   ABRecord *card = [addressBook recordForUniqueId:[NSString stringWithUTF8String:uid]];
   NS_ENSURE_TRUE(card, NS_ERROR_FAILURE);
 
--- a/mailnews/addrbook/src/nsAbOSXDirectory.h
+++ b/mailnews/addrbook/src/nsAbOSXDirectory.h
@@ -35,24 +35,27 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsAbOSXDirectory_h___
 #define nsAbOSXDirectory_h___
 
+#include "nsISupports.h"
 #include "nsAbBaseCID.h"
-#include "nsAbDirectoryRDFResource.h"
 #include "nsAbDirProperty.h"
 #include "nsIAbDirectoryQuery.h"
 #include "nsIAbDirectorySearch.h"
 #include "nsIAbDirSearchListener.h"
 #include "nsIMutableArray.h"
+#include "nsInterfaceHashtable.h"
+#include "nsAbOSXCard.h"
 
+#include <CoreFoundation/CoreFoundation.h>
 class nsIAbManager;
 class nsIAbBooleanExpression;
 
 #define NS_ABOSXDIRECTORY_URI_PREFIX NS_ABOSXDIRECTORY_PREFIX "://"
 
 #define NS_IABOSXDIRECTORY_IID \
 { 0x87ee4bd9, 0x8552, 0x498f, \
   { 0x80, 0x85, 0x34, 0xf0, 0x2a, 0xbb, 0x56, 0x16 } }
@@ -69,33 +72,36 @@ public:
   virtual nsresult AssertCard(nsIAbManager *aManager,
                               nsIAbCard *aCard) = 0;
   virtual nsresult UnassertCard(nsIAbManager *aManager,
                                 nsIAbCard *aCard,
                                 nsIMutableArray *aCardList) = 0;
   virtual nsresult UnassertDirectory(nsIAbManager *aManager,
                                      nsIAbDirectory *aDirectory) = 0;
   virtual nsresult DeleteUid(const nsACString &aUid) = 0;
+  virtual nsresult GetURI(nsACString &aURI) = 0;
+  virtual nsresult Init(const char *aUri) = 0;
+  virtual nsresult GetCardByUri(const nsACString &aUri, nsIAbOSXCard **aResult) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIAbOSXDirectory, NS_IABOSXDIRECTORY_IID)
 
-class nsAbOSXDirectory : public nsAbDirectoryRDFResource,
-public nsAbDirProperty,
+class nsAbOSXDirectory : public nsAbDirProperty,
 public nsIAbDirSearchListener,
 public nsIAbOSXDirectory
 {
 public:
+  nsAbOSXDirectory();
   ~nsAbOSXDirectory();
   
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIABDIRSEARCHLISTENER
     
-    // nsAbDirectoryRDFResource method
-    NS_IMETHOD Init(const char *aUri);
+  // nsIAbOSXDirectory method
+  NS_IMETHOD Init(const char *aUri);
   
   // nsAbDirProperty methods
   NS_IMETHOD GetReadOnly(PRBool *aReadOnly);
   NS_IMETHOD GetChildCards(nsISimpleEnumerator **aCards);
   NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes);
   NS_IMETHOD GetIsQuery(PRBool *aResult);
   NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard);
   NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory);
@@ -121,26 +127,33 @@ public:
                         nsIAbCard *aCard,
                         nsIMutableArray *aCardList);
   nsresult UnassertDirectory(nsIAbManager *aManager,
                              nsIAbDirectory *aDirectory);
   
   nsresult Update();
 
   nsresult DeleteUid(const nsACString &aUid);
+
+  nsresult GetCardByUri(const nsACString &aUri, nsIAbOSXCard **aResult);
+
+  nsresult GetRootOSXDirectory(nsIAbOSXDirectory **aResult);
+
 private:
   nsresult FallbackSearch(nsIAbBooleanExpression *aExpression,
                           nsISimpleEnumerator **aCards);
 
   // This is a list of nsIAbCards, kept separate from m_AddressList because:
   // - nsIAbDirectory items that are mailing lists, must keep a list of
   //   nsIAbCards in m_AddressList, however
   // - nsIAbDirectory items that are address books, must keep a list of
   //   nsIAbDirectory (i.e. mailing lists) in m_AddressList, AND no nsIAbCards.
   //
   // This wasn't too bad for mork, as that just gets a list from its database,
   // but because we store our own copy of the list, we must store a separate
   // list of nsIAbCards here. nsIMutableArray is used, because then it is
   // interchangeable with m_AddressList.
   nsCOMPtr<nsIMutableArray> mCardList;
+  nsInterfaceHashtable<nsCStringHashKey, nsIAbOSXCard> mCardStore;
+  nsCOMPtr<nsIAbOSXDirectory> mCacheTopLevelOSXAb;
 };
 
 #endif // nsAbOSXDirectory_h___
--- a/mailnews/addrbook/src/nsAbOSXDirectory.mm
+++ b/mailnews/addrbook/src/nsAbOSXDirectory.mm
@@ -42,167 +42,215 @@
 #include "nsAbOSXUtils.h"
 #include "nsAbQueryStringToExpression.h"
 #include "nsArrayEnumerator.h"
 #include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsEnumeratorUtils.h"
 #include "nsIAbDirectoryQueryProxy.h"
 #include "nsIAbManager.h"
-#include "nsIRDFService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIMutableArray.h"
 #include "nsArrayUtils.h"
 #include "nsIAbBooleanExpression.h"
 #include "nsComponentManagerUtils.h"
+#include "nsISimpleEnumerator.h"
 
 #include <AddressBook/AddressBook.h>
 #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3)
 #define kABDeletedRecords @"ABDeletedRecords"
 #define kABUpdatedRecords @"ABUpdatedRecords"
 #define kABInsertedRecords @"ABInsertedRecords"
 #elif (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3)
 #define kABDeletedRecords (kABDeletedRecords? kABDeletedRecords : @"ABDeletedRecords")
 #define kABUpdatedRecords (kABUpdatedRecords ? kABUpdatedRecords : @"ABUpdatedRecords")
 #define kABInsertedRecords (kABInsertedRecords ? kABInsertedRecords : @"ABInsertedRecords")
 #endif
 
+/* Each nsAbOSXDirectory contains a lookup table for their respective
+ * nsAbOSXCard's.  We set the initial size of that lookup table here.
+ */
+#define OSX_CARD_STORE_INIT 100
+
 static nsresult
-ConvertToGroupResource(nsIRDFService *aRDFService, NSString *aUid,
-                       nsIAbDirectory **aResult)
+GetOrCreateGroup(NSString *aUid, nsIAbDirectory **aResult)
 {
   NS_ASSERTION(aUid, "No UID for group!.");
-  
-  *aResult = nsnull;
-  
+
   nsCAutoString uri(NS_ABOSXDIRECTORY_URI_PREFIX);
   AppendToCString(aUid, uri);
-  
-  nsCOMPtr<nsIRDFResource> resource;
-  nsresult rv = aRDFService->GetResource(uri, getter_AddRefs(resource));
+
+  nsresult rv;
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
-  
-  return CallQueryInterface(resource, aResult);
+
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = abManager->GetDirectory(uri, getter_AddRefs(directory));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  NS_IF_ADDREF(*aResult = directory);
+  return NS_OK;
 }
 
 static nsresult
-ConvertToCard(nsIRDFService *aRDFService, ABRecord *aRecord,
-              nsIAbCard **aResult)
+GetCard(ABRecord *aRecord, nsIAbCard **aResult, nsIAbOSXDirectory *osxDirectory)
 {
-  *aResult = nsnull;
-  
   NSString *uid = [aRecord uniqueId];
   NS_ASSERTION(uid, "No UID for card!.");
   if (!uid)
     return NS_ERROR_FAILURE;
-  
+
   nsCAutoString uri(NS_ABOSXCARD_URI_PREFIX);
   AppendToCString(uid, uri);
-  
-  nsCOMPtr<nsIRDFResource> resource;
-  nsresult rv = aRDFService->GetResource(uri, getter_AddRefs(resource));
+  nsCOMPtr<nsIAbOSXCard> osxCard;
+  nsresult rv = osxDirectory->GetCardByUri(uri, getter_AddRefs(osxCard));
   NS_ENSURE_SUCCESS(rv, rv);
-  
-  return CallQueryInterface(resource, aResult);
+
+  nsCOMPtr<nsIAbCard> card = do_QueryInterface(osxCard, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  NS_IF_ADDREF(*aResult = card);
+  return NS_OK;
 }
 
 static nsresult
-Update(nsIRDFService *aRDFService, NSString *aUid)
+CreateCard(ABRecord *aRecord, nsIAbCard **aResult)
+{
+  NSString *uid = [aRecord uniqueId];
+  NS_ASSERTION(uid, "No UID for card!.");
+  if (!uid)
+    return NS_ERROR_FAILURE;
+
+  nsresult rv;
+  nsCOMPtr<nsIAbOSXCard> osxCard = do_CreateInstance(NS_ABOSXCARD_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCAutoString uri(NS_ABOSXCARD_URI_PREFIX);
+  AppendToCString(uid, uri);
+
+  rv = osxCard->Init(uri.get());
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIAbCard> card = do_QueryInterface(osxCard, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  NS_IF_ADDREF(*aResult = card);
+  return NS_OK;
+}
+
+static nsresult
+Sync(NSString *aUid)
 {
   ABAddressBook *addressBook = [ABAddressBook sharedAddressBook];
   ABRecord *card = [addressBook recordForUniqueId:aUid];
-  if ([card isKindOfClass:[ABGroup class]]) {
+  if ([card isKindOfClass:[ABGroup class]])
+  {
     nsCOMPtr<nsIAbDirectory> directory;
-    ConvertToGroupResource(aRDFService, aUid, getter_AddRefs(directory));
+    GetOrCreateGroup(aUid, getter_AddRefs(directory));
     nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
       do_QueryInterface(directory);
     
     osxDirectory->Update();
   }
   else {
     nsCOMPtr<nsIAbCard> abCard;
-    ConvertToCard(aRDFService, card, getter_AddRefs(abCard));
+    nsresult rv;
+
+    nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIAbDirectory> directory;
+    rv = abManager->GetDirectory(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX"/"),
+                                 getter_AddRefs(directory));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
+      do_QueryInterface(directory, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = GetCard(card, getter_AddRefs(abCard), osxDirectory);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     nsCOMPtr<nsIAbOSXCard> osxCard = do_QueryInterface(abCard);
-    
     osxCard->Update(PR_TRUE);
   }
   return NS_OK;
 }
 
 @interface ABChangedMonitor : NSObject
 -(void)ABChanged:(NSNotification *)aNotification;
 @end
 
 @implementation ABChangedMonitor
 -(void)ABChanged:(NSNotification *)aNotification
 {
   NSDictionary *changes = [aNotification userInfo];
   
   nsresult rv;
-  nsCOMPtr<nsIRDFService> rdfService =
-    do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, );
-  
   NSArray *inserted = [changes objectForKey:kABInsertedRecords];
+
   if (inserted) {
-    nsCOMPtr<nsIRDFResource> resource;
-    rv = rdfService->GetResource(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX"/"),
-                                 getter_AddRefs(resource));
+    nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, );
-    
-    nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
-      do_QueryInterface(resource, &rv);
+
+    nsCOMPtr<nsIAbDirectory> directory;
+    rv = abManager->GetDirectory(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX"/"),
+                                 getter_AddRefs(directory));
     NS_ENSURE_SUCCESS(rv, );
-    
-    nsCOMPtr<nsIAbManager> abManager =
-      do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
+
+    nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
+      do_QueryInterface(directory, &rv);
     NS_ENSURE_SUCCESS(rv, );
-    
+
     unsigned int i, count = [inserted count];
     for (i = 0; i < count; ++i) {
       ABAddressBook *addressBook =
       [ABAddressBook sharedAddressBook];
       ABRecord *card =
         [addressBook recordForUniqueId:[inserted objectAtIndex:i]];
       if ([card isKindOfClass:[ABGroup class]]) {
         nsCOMPtr<nsIAbDirectory> directory;
-        ConvertToGroupResource(rdfService, [inserted objectAtIndex:i],
-                               getter_AddRefs(directory));
+        GetOrCreateGroup([inserted objectAtIndex:i],
+                         getter_AddRefs(directory));
         
         rv = osxDirectory->AssertDirectory(abManager, directory);
         NS_ENSURE_SUCCESS(rv, );
       }
       else {
         nsCOMPtr<nsIAbCard> abCard;
-        ConvertToCard(rdfService, card, getter_AddRefs(abCard));
-        
+       // Construct a card
+        nsresult rv = CreateCard(card, getter_AddRefs(abCard));
         rv = osxDirectory->AssertCard(abManager, abCard);
         NS_ENSURE_SUCCESS(rv, );
       }
     }
   }
   
   NSArray *updated = [changes objectForKey:kABUpdatedRecords];
   if (updated) {
     unsigned int i, count = [updated count];
     for (i = 0; i < count; ++i) {
       NSString *uid = [updated objectAtIndex:i];
-      Update(rdfService, uid);
+      Sync(uid);
     }
   }
   
   NSArray *deleted = [changes objectForKey:kABDeletedRecords];
   if (deleted) {
-    nsCOMPtr<nsIRDFResource> resource;
-    rv = rdfService->GetResource(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX"/"),
-                                 getter_AddRefs(resource));
+
+    nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, );
-    
+
+    nsCOMPtr<nsIAbDirectory> directory;
+    rv = abManager->GetDirectory(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX"/"),
+                                 getter_AddRefs(directory));
+    NS_ENSURE_SUCCESS(rv, );
+
     nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
-      do_QueryInterface(resource, &rv);
+      do_QueryInterface(directory, &rv);
     NS_ENSURE_SUCCESS(rv, );
 
     unsigned int i, count = [deleted count];
     for (i = 0; i < count; ++i) {
       NSString *deletedUid = [deleted objectAtIndex:i];
 
       nsCAutoString uid;
       AppendToCString(deletedUid, uid);
@@ -420,102 +468,131 @@ Search(nsIAbBooleanExpression *aExpressi
 {
   PRBool canHandle = PR_FALSE;
   ABSearchElement *searchElement;
   nsresult rv = BuildSearchElements(aExpression, canHandle, &searchElement);
   NS_ENSURE_SUCCESS(rv, PR_FALSE);
   
   if (canHandle)
     *aResult = [[ABAddressBook sharedAddressBook] recordsMatchingSearchElement:searchElement];
-  
+
   return canHandle;
 }
 
 static PRUint32 sObserverCount = 0;
 static ABChangedMonitor *sObserver = nsnull;
 
+nsAbOSXDirectory::nsAbOSXDirectory()
+{
+  mCardStore.Init(OSX_CARD_STORE_INIT);
+}
+
 nsAbOSXDirectory::~nsAbOSXDirectory()
 {
   if (--sObserverCount == 0) {
     [[NSNotificationCenter defaultCenter] removeObserver:sObserver];
     [sObserver release];
   }
 }
 
-NS_IMPL_ISUPPORTS_INHERITED3(nsAbOSXDirectory,
-                             nsAbDirectoryRDFResource,
-                             nsIAbDirectory,
+NS_IMPL_ISUPPORTS_INHERITED2(nsAbOSXDirectory,
+                             nsAbDirProperty,
                              nsIAbOSXDirectory,
                              nsIAbDirSearchListener)
 
 NS_IMETHODIMP
 nsAbOSXDirectory::Init(const char *aUri)
 {
+  nsresult rv;
+  rv = nsAbDirProperty::Init(aUri);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   ABAddressBook *addressBook = [ABAddressBook sharedAddressBook];
   if (sObserverCount == 0) {
     sObserver = [[ABChangedMonitor alloc] init];
     [[NSNotificationCenter defaultCenter] addObserver:(ABChangedMonitor*)sObserver
                                              selector:@selector(ABChanged:)
                                                  name:kABDatabaseChangedExternallyNotification
                                                object:nil];
   }
   ++sObserverCount;
-  
-  nsresult rv = nsAbDirectoryRDFResource::Init(aUri);
-  NS_ENSURE_SUCCESS(rv, rv);
-  
+
   NSArray *cards;
   nsCOMPtr<nsIMutableArray> cardList;
-  if (mURINoQuery.Length() > sizeof(NS_ABOSXDIRECTORY_URI_PREFIX))
-  {
-    nsCAutoString uid(Substring(mURINoQuery, sizeof(NS_ABOSXDIRECTORY_URI_PREFIX) - 1));
-    ABRecord *card = [addressBook recordForUniqueId:[NSString stringWithUTF8String:uid.get()]];
-    NS_ASSERTION([card isKindOfClass:[ABGroup class]], "Huh.");
-    
-    m_IsMailList = PR_TRUE;
-    AppendToString([card valueForProperty:kABGroupNameProperty], m_ListDirName);
+  PRBool isRootOSXDirectory = PR_FALSE;
 
-    ABGroup *group = (ABGroup*)[addressBook recordForUniqueId:[NSString stringWithUTF8String:nsCAutoString(Substring(mURINoQuery, 21)).get()]];
-    cards = [[group members] arrayByAddingObjectsFromArray:[group subgroups]];
-    if (!m_AddressList)
-      m_AddressList = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
-    else
-      rv = m_AddressList->Clear();
-    NS_ENSURE_SUCCESS(rv, rv);
+  if (mURINoQuery.Length() <= sizeof(NS_ABOSXDIRECTORY_URI_PREFIX))
+    isRootOSXDirectory = PR_TRUE;
 
-    cardList = m_AddressList;
-  }
-  else
+  if (isRootOSXDirectory)
   {
     m_DirPrefId.AssignLiteral("ldap_2.servers.osx");
 
     cards = [[addressBook people] arrayByAddingObjectsFromArray:[addressBook groups]];
     if (!mCardList)
       mCardList = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
     else
       rv = mCardList->Clear();
     NS_ENSURE_SUCCESS(rv, rv);
 
     cardList = mCardList;
   }
+  else
+  {
+    nsCAutoString uid(Substring(mURINoQuery, sizeof(NS_ABOSXDIRECTORY_URI_PREFIX) - 1));
+    ABRecord *card = [addressBook recordForUniqueId:[NSString stringWithUTF8String:uid.get()]];
+    NS_ASSERTION([card isKindOfClass:[ABGroup class]], "Huh.");
+
+    m_IsMailList = PR_TRUE;
+    AppendToString([card valueForProperty:kABGroupNameProperty], m_ListDirName);
+
+    ABGroup *group = (ABGroup*)[addressBook recordForUniqueId:[NSString stringWithUTF8String:nsCAutoString(Substring(mURINoQuery, 21)).get()]];
+    cards = [[group members] arrayByAddingObjectsFromArray:[group subgroups]];
+
+    if (!m_AddressList)
+      m_AddressList = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+    else
+      rv = m_AddressList->Clear();
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    cardList = m_AddressList;
+  }
+
 
   nsCAutoString ourUuid;
   GetUuid(ourUuid);
 
   unsigned int nbCards = [cards count];
   nsCOMPtr<nsIAbCard> card;
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIAbOSXDirectory> rootOSXDirectory;
+  if (!isRootOSXDirectory)
+  {
+    rv = GetRootOSXDirectory(getter_AddRefs(rootOSXDirectory));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+
   for (unsigned int i = 0; i < nbCards; ++i)
   {
-    rv = ConvertToCard(gRDFService, [cards objectAtIndex:i],
-                       getter_AddRefs(card));
-    NS_ENSURE_SUCCESS(rv, rv);
+    // If we're a Group, it's likely that the cards we're going
+    // to create were already created in the root nsAbOSXDirectory,
+    if (!isRootOSXDirectory)
+      rv = GetCard([cards objectAtIndex:i], getter_AddRefs(card),
+                   rootOSXDirectory);
+    else
+    {
+      // If we're not a Group, that means we're the root nsAbOSXDirectory,
+      // which means we have to create the cards from scratch.
+      rv = CreateCard([cards objectAtIndex:i], getter_AddRefs(card));
+    }
 
-    card->SetDirectoryId(ourUuid);
-
-    cardList->AppendElement(card, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+    AssertCard(abManager, card);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAbOSXDirectory::GetURI(nsACString &aURI)
 {
@@ -534,23 +611,24 @@ nsAbOSXDirectory::GetReadOnly(PRBool *aR
   *aReadOnly = PR_TRUE;
   return NS_OK;
 }
 
 static PRBool
 CheckRedundantCards(nsIAbManager *aManager, nsIAbDirectory *aDirectory,
                     nsIAbCard *aCard, NSMutableArray *aCardList)
 {
-  nsCOMPtr<nsIRDFResource> resource(do_QueryInterface(aCard));
-  if (!resource)
-    return PR_FALSE;
-  
-  const char* uri;
-  resource->GetValueConst(&uri);
-  NSString *uid = [NSString stringWithUTF8String:(uri + 21)];
+  nsresult rv;
+  nsCOMPtr<nsIAbOSXCard> osxCard = do_QueryInterface(aCard, &rv);
+  NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+  nsCAutoString uri;
+  rv = osxCard->GetURI(uri);
+  NS_ENSURE_SUCCESS(rv, PR_FALSE);
+  NSString *uid = [NSString stringWithUTF8String:(uri.get() + 21)];
   
   unsigned int i, count = [aCardList count];
   for (i = 0; i < count; ++i) {
     if ([[[aCardList objectAtIndex:i] uniqueId] isEqualToString:uid]) {
       [aCardList removeObjectAtIndex:i];
       break;
     }
   }
@@ -559,16 +637,41 @@ CheckRedundantCards(nsIAbManager *aManag
     aManager->NotifyDirectoryItemDeleted(aDirectory, aCard);
     return PR_TRUE;
   }
   
   return PR_FALSE;
 }
 
 nsresult
+nsAbOSXDirectory::GetRootOSXDirectory(nsIAbOSXDirectory **aResult)
+{
+  if (!mCacheTopLevelOSXAb)
+  {
+    // Attempt to get card from the toplevel directories
+    nsresult rv;
+    nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIAbDirectory> directory;
+    rv = abManager->GetDirectory(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX"/"),
+                                 getter_AddRefs(directory));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
+      do_QueryInterface(directory, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+    mCacheTopLevelOSXAb = osxDirectory;
+  }
+
+  NS_IF_ADDREF(*aResult = mCacheTopLevelOSXAb);
+  return NS_OK;
+}
+
+nsresult
 nsAbOSXDirectory::Update()
 {
   nsresult rv;
   nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   
   if (mIsQueryURI) {
     return NS_OK;
@@ -619,40 +722,49 @@ nsAbOSXDirectory::Update()
 
     if (CheckRedundantCards(abManager, this, card, mutableArray))
       cardList->RemoveElementAt(addressCount);
   }
   
   NSEnumerator *enumerator = [mutableArray objectEnumerator];
   ABRecord *card;
   nsCOMPtr<nsIAbCard> abCard;
-  while ((card = [enumerator nextObject])) {
-    rv = ConvertToCard(gRDFService, card, getter_AddRefs(abCard));
+  nsCOMPtr<nsIAbOSXDirectory> rootOSXDirectory;
+  rv = GetRootOSXDirectory(getter_AddRefs(rootOSXDirectory));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  while ((card = [enumerator nextObject]))
+  {
+    rv = GetCard(card, getter_AddRefs(abCard), rootOSXDirectory);
+    if (NS_FAILED(rv))
+      rv = CreateCard(card, getter_AddRefs(abCard));
     NS_ENSURE_SUCCESS(rv, rv);
-
     AssertCard(abManager, abCard);
   }
   
   card = (ABRecord*)[addressBook recordForUniqueId:[NSString stringWithUTF8String:nsCAutoString(Substring(mURINoQuery, 21)).get()]];
   NSString * stringValue = [card valueForProperty:kABGroupNameProperty];
-  if (![stringValue isEqualToString:WrapString(m_ListDirName)]) {
+  if (![stringValue isEqualToString:WrapString(m_ListDirName)])
+  {
     nsAutoString oldValue(m_ListDirName);
     AssignToString(stringValue, m_ListDirName);
-    nsISupports *supports =
-      NS_ISUPPORTS_CAST(nsAbDirectoryRDFResource*, this);
+    nsCOMPtr<nsISupports> supports = do_QueryInterface(static_cast<nsIAbDirectory *>(this), &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
     abManager->NotifyItemPropertyChanged(supports, "DirName",
                                          oldValue.get(), m_ListDirName.get());
   }
   
-  if (groups) {
+  if (groups)
+  {
     mutableArray = [NSMutableArray arrayWithArray:groups];
     nsCOMPtr<nsIAbDirectory> directory;
     // It is ok to use m_AddressList here as only top-level directories have
     // groups, and they will be in m_AddressList
-    if (m_AddressList) {
+    if (m_AddressList)
+    {
       rv = m_AddressList->GetLength(&addressCount);
       NS_ENSURE_SUCCESS(rv, rv);
 
       while (addressCount--)
       {
         directory = do_QueryElementAt(m_AddressList, addressCount, &rv);
         if (NS_FAILED(rv))
           continue;
@@ -673,18 +785,17 @@ nsAbOSXDirectory::Update()
         if (j == arrayCount) {
           UnassertDirectory(abManager, directory);
         }
       }
     }
     
     enumerator = [mutableArray objectEnumerator];
     while ((card = [enumerator nextObject])) {
-      rv = ConvertToGroupResource(gRDFService, [card uniqueId],
-                                  getter_AddRefs(directory));
+      rv = GetOrCreateGroup([card uniqueId], getter_AddRefs(directory));
       NS_ENSURE_SUCCESS(rv, rv);
       
       AssertDirectory(abManager, directory);
     }
   }
   
   return NS_OK;
 }
@@ -708,18 +819,18 @@ nsAbOSXDirectory::AssertChildNodes()
   
   if (count > 0 && !m_AddressList) {
     m_AddressList = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   
   nsCOMPtr<nsIAbDirectory> directory;
   for (i = 0; i < count; ++i) {
-    rv = ConvertToGroupResource(gRDFService, [[groups objectAtIndex:i] uniqueId],
-                                getter_AddRefs(directory));
+    rv = GetOrCreateGroup([[groups objectAtIndex:i] uniqueId],
+                          getter_AddRefs(directory));
     NS_ENSURE_SUCCESS(rv, rv);
     
     rv = AssertDirectory(abManager, directory);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   
   return NS_OK;
 }
@@ -753,16 +864,27 @@ nsAbOSXDirectory::AssertCard(nsIAbManage
   nsCAutoString ourUuid;
   GetUuid(ourUuid);
   aCard->SetDirectoryId(ourUuid);
 
   nsresult rv = m_IsMailList ? m_AddressList->AppendElement(aCard, PR_FALSE) :
                                mCardList->AppendElement(aCard, PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // Get the card's URI and add it to our card store
+  nsCOMPtr<nsIAbOSXCard> osxCard = do_QueryInterface(aCard, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCString uri;
+  rv = osxCard->GetURI(uri);
+
+  nsCOMPtr<nsIAbOSXCard> retrievedCard;
+  if (!mCardStore.Get(uri, getter_AddRefs(retrievedCard)))
+    mCardStore.Put(uri, osxCard);
+
   return aManager->NotifyDirectoryItemAdded(this, aCard);
 }
 
 nsresult
 nsAbOSXDirectory::UnassertCard(nsIAbManager *aManager,
                                nsIAbCard *aCard,
                                nsIMutableArray *aCardList)
 {
@@ -831,20 +953,29 @@ nsAbOSXDirectory::GetChildCards(nsISimpl
     nsCAutoString ourUuid;
     GetUuid(ourUuid);
 
     // Fill the results array and update the card list
     unsigned int nbCards = [cards count];
   
     unsigned int i;
     nsCOMPtr<nsIAbCard> card;
+    nsCOMPtr<nsIAbOSXDirectory> rootOSXDirectory;
+    rv = GetRootOSXDirectory(getter_AddRefs(rootOSXDirectory));
+    NS_ENSURE_SUCCESS(rv, rv);
+
     for (i = 0; i < nbCards; ++i)
     {
-      rv = ConvertToCard(gRDFService, [cards objectAtIndex:i],
-                         getter_AddRefs(card));
+      rv = GetCard([cards objectAtIndex:i], getter_AddRefs(card),
+                   rootOSXDirectory);
+
+      if (NS_FAILED(rv))
+        rv = CreateCard([cards objectAtIndex:i],
+                        getter_AddRefs(card));
+
       NS_ENSURE_SUCCESS(rv, rv);
       card->SetDirectoryId(ourUuid);
 
       mCardList->AppendElement(card, PR_FALSE);
     }
 
     return NS_NewArrayEnumerator(aCards, mCardList);
   }
@@ -857,16 +988,57 @@ nsAbOSXDirectory::GetChildCards(nsISimpl
 NS_IMETHODIMP
 nsAbOSXDirectory::GetIsQuery(PRBool *aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = mIsQueryURI;
   return NS_OK;
 }
 
+/* Recursive method that searches for a child card by URI.  If it cannot find
+ * it within this directory, it checks all subfolders.
+ */
+NS_IMETHODIMP
+nsAbOSXDirectory::GetCardByUri(const nsACString &aUri, nsIAbOSXCard **aResult)
+{
+  nsCOMPtr<nsIAbOSXCard> osxCard;
+
+  // Base Case
+  if (mCardStore.Get(aUri, getter_AddRefs(osxCard)))
+  {
+    NS_IF_ADDREF(*aResult = osxCard);
+    return NS_OK;
+  }
+  // Search children
+  nsCOMPtr<nsISimpleEnumerator> enumerator;
+  nsresult rv = this->GetChildNodes(getter_AddRefs(enumerator));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsISupports> item;
+  PRBool hasMore = PR_FALSE;
+  while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore)
+  {
+    rv = enumerator->GetNext(getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIAbOSXDirectory> childDirectory;
+    childDirectory = do_QueryInterface(item, &rv);
+    if (NS_SUCCEEDED(rv))
+    {
+      rv = childDirectory->GetCardByUri(aUri, getter_AddRefs(osxCard));
+      if (NS_SUCCEEDED(rv))
+      {
+        NS_IF_ADDREF(*aResult = osxCard);
+        return NS_OK;
+      }
+    }
+  }
+  return NS_ERROR_FAILURE;
+}
+
 NS_IMETHODIMP
 nsAbOSXDirectory::GetCardFromProperty(const char *aProperty,
                                       const nsACString &aValue,
                                       PRBool aCaseSensitive,
                                       nsIAbCard **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
 
@@ -1098,23 +1270,23 @@ nsAbOSXDirectory::FallbackSearch(nsIAbBo
   // list, it won't have any subdirectories. If the current directory is an
   // addressbook, searching both it and the subdirectories (the mailing
   // lists), will yield duplicate results because every entry in a mailing
   // list will be an entry in the parent addressbook.
   rv = arguments->SetQuerySubDirectories(PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
   
   // Get the directory without the query
-  nsCOMPtr<nsIRDFResource> resource;
-  rv = gRDFService->GetResource(mURINoQuery, getter_AddRefs(resource));
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
-  
-  nsCOMPtr<nsIAbDirectory> directory = do_QueryInterface(resource, &rv);
+
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = abManager->GetDirectory(nsDependentCString(mURINoQuery), getter_AddRefs(directory));
   NS_ENSURE_SUCCESS(rv, rv);
-  
+
   // Initiate the proxy query with the no query directory
   nsCOMPtr<nsIAbDirectoryQueryProxy> queryProxy = 
     do_CreateInstance(NS_ABDIRECTORYQUERYPROXY_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   
   rv = queryProxy->Initiate();
   NS_ENSURE_SUCCESS(rv, rv);
   
@@ -1147,32 +1319,39 @@ nsresult nsAbOSXDirectory::DeleteUid(con
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCAutoString uri(NS_ABOSXDIRECTORY_URI_PREFIX);
   uri.Append(aUid);
 
   // Iterate backwards in case we remove something
   while (addressCount--)
   {
-    nsCOMPtr<nsIRDFResource> resource(do_QueryElementAt(m_AddressList,
-                                                        addressCount, &rv));
+    nsCOMPtr<nsIAbItem> abItem(do_QueryElementAt(m_AddressList,
+                                                 addressCount, &rv));
+    if (NS_FAILED(rv))
+      continue;
+
+    nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(abItem, &rv));
     if (NS_SUCCEEDED(rv))
     {
-      const char* dirUri;
-      resource->GetValueConst(&dirUri);
+      nsCAutoString dirUri;
+      directory->GetURI(dirUri);
       if (uri.Equals(dirUri))
+        return UnassertDirectory(abManager, directory);
+    } else {
+      nsCOMPtr<nsIAbOSXCard> osxCard(do_QueryInterface(abItem, &rv));
+      if (NS_SUCCEEDED(rv))
       {
-        nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
-        if (NS_SUCCEEDED(rv))
-          // Match found, do the necessary and get out of here.
-          return UnassertDirectory(abManager, directory);
-        else
+        nsCAutoString cardUri;
+        osxCard->GetURI(cardUri);
+        if (uri.Equals(cardUri))
         {
-          nsCOMPtr<nsIAbCard> card(do_QueryInterface(resource, &rv));
-          return UnassertCard(abManager, card, m_AddressList);
+          nsCOMPtr<nsIAbCard> card(do_QueryInterface(osxCard, &rv));
+          if (NS_SUCCEEDED(rv))
+            return UnassertCard(abManager, card, m_AddressList);
         }
       }
     }
   }
 
   // Second, see if it is one of the cards.
   if (!mCardList)
     return NS_ERROR_FAILURE;
@@ -1180,24 +1359,23 @@ nsresult nsAbOSXDirectory::DeleteUid(con
   uri = NS_ABOSXCARD_URI_PREFIX;
   uri.Append(aUid);
 
   rv = mCardList->GetLength(&addressCount);
   NS_ENSURE_SUCCESS(rv, rv);
 
   while (addressCount--)
   {
-    nsCOMPtr<nsIAbCard> card(do_QueryElementAt(mCardList, addressCount, &rv));
+    nsCOMPtr<nsIAbOSXCard> osxCard(do_QueryElementAt(mCardList, addressCount, &rv));
     if (NS_FAILED(rv))
       continue;
 
-    nsCOMPtr<nsIRDFResource> resource(do_QueryInterface(card));
-    if (!resource)
-      continue;
+    nsCAutoString cardUri;
+    osxCard->GetURI(cardUri);
 
-    const char* cardUri;
-    resource->GetValueConst(&cardUri);
-
-    if (uri.Equals(cardUri))
-      return UnassertCard(abManager, card, mCardList);
+    if (uri.Equals(cardUri)) {
+      nsCOMPtr<nsIAbCard> card(do_QueryInterface(osxCard, &rv));
+      if (NS_SUCCEEDED(rv))
+        return UnassertCard(abManager, card, mCardList);
+    }
   }
   return NS_OK;
 }
--- a/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp
+++ b/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp
@@ -34,20 +34,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #include "nsAbOutlookDirFactory.h"
 #include "nsAbWinHelper.h"
 #include "nsIAbDirectory.h"
-
-#include "nsIRDFService.h"
-#include "nsIRDFResource.h"
-#include "nsRDFResource.h"
+#include "nsIAbManager.h"
 #include "nsEnumeratorUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIMutableArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsAbBaseCID.h"
 
 #include "prlog.h"
 
@@ -92,30 +89,31 @@ nsAbOutlookDirFactory::GetDirectories(co
   nsAbWinHelperGuard mapiAddBook(abType);
   nsMapiEntryArray folders;
   ULONG nbFolders = 0;
   nsCOMPtr<nsIMutableArray> directories(do_CreateInstance(NS_ARRAY_CONTRACTID));
   NS_ENSURE_SUCCESS(rv, rv);
   if (!mapiAddBook->IsOK() || !mapiAddBook->GetFolders(folders)) {
     return NS_ERROR_FAILURE;
   }
-  nsCOMPtr<nsIRDFService> rdf(do_GetService(NS_RDF_CONTRACTID "/rdf-service;1", &rv));
+
+  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
   nsCAutoString entryId;
   nsCAutoString uri;
-  nsCOMPtr<nsIRDFResource> resource;
 
   for (ULONG i = 0; i < folders.mNbEntries; ++i) {
     folders.mEntries[i].ToString(entryId);
     buildAbWinUri(kOutlookDirectoryScheme, abType, uri);
     uri.Append(entryId);
 
-    rv = rdf->GetResource(uri, getter_AddRefs(resource));
+	nsCOMPtr<nsIAbDirectory> directory;
+	rv = abManager->GetDirectory(uri, getter_AddRefs(directory));
     NS_ENSURE_SUCCESS(rv, rv);
-    directories->AppendElement(resource, PR_FALSE);
+    directories->AppendElement(directory, PR_FALSE);
   }
   return NS_NewArrayEnumerator(aDirectories, directories);
 }
 
 // No actual deletion, since you cannot create the address books from Mozilla.
 NS_IMETHODIMP nsAbOutlookDirFactory::DeleteDirectory(nsIAbDirectory *aDirectory)
 {
   return NS_OK;
--- a/mailnews/addrbook/src/nsAbOutlookDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbOutlookDirectory.cpp
@@ -34,18 +34,16 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #include "nsAbOutlookDirectory.h"
 #include "nsAbWinHelper.h"
 
-#include "nsIRDFService.h"
-
 #include "nsAbBaseCID.h"
 #include "nsIAbCard.h"
 #include "nsStringGlue.h"
 #include "nsAbDirectoryQuery.h"
 #include "nsIAbBooleanExpression.h"
 #include "nsIAbManager.h"
 #include "nsIAbMDBDirectory.h"
 #include "nsAbQueryStringToExpression.h"
@@ -65,43 +63,41 @@
 #ifdef PR_LOGGING
 static PRLogModuleInfo* gAbOutlookDirectoryLog
     = PR_NewLogModule("nsAbOutlookDirectoryLog");
 #endif
 
 #define PRINTF(args) PR_LOG(gAbOutlookDirectoryLog, PR_LOG_DEBUG, args)
 
 nsAbOutlookDirectory::nsAbOutlookDirectory(void)
-: nsAbDirectoryRDFResource(), nsAbDirProperty(),
-mCurrentQueryId(0), mSearchContext(-1),
-mAbWinType(nsAbWinType_Unknown), mMapiData(nsnull)
+  : nsAbDirProperty(),
+  mCurrentQueryId(0), mSearchContext(-1),
+  mAbWinType(nsAbWinType_Unknown), mMapiData(nsnull)
 {
     mMapiData = new nsMapiEntry ;
     mProtector = PR_NewLock() ;
 }
 
 nsAbOutlookDirectory::~nsAbOutlookDirectory(void)
 {
     if (mMapiData) { delete mMapiData ; }
     if (mProtector) { PR_DestroyLock(mProtector) ; }
 }
 
-NS_IMPL_ISUPPORTS_INHERITED4(nsAbOutlookDirectory, nsAbDirectoryRDFResource, 
-                             nsIAbDirectory, nsISupportsWeakReference,
+NS_IMPL_ISUPPORTS_INHERITED3(nsAbOutlookDirectory, nsAbDirProperty,
                              nsIAbDirectoryQuery, nsIAbDirectorySearch,
                              nsIAbDirSearchListener)
 
-// nsIRDFResource method
 NS_IMETHODIMP nsAbOutlookDirectory::Init(const char *aUri)
 {
   NS_ENSURE_TRUE(mQueryThreads.Init(), NS_ERROR_FAILURE);
   NS_ENSURE_TRUE(mCardList.Init(), NS_ERROR_FAILURE);
-  nsresult retCode = nsAbDirectoryRDFResource::Init(aUri);
 
-  NS_ENSURE_SUCCESS(retCode, retCode);
+  nsresult rv = nsAbDirProperty::Init(aUri);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCAutoString entry;
   nsCAutoString stub;
 
   mAbWinType = getAbWinType(kOutlookDirectoryScheme, mURINoQuery.get(), stub, entry);
   if (mAbWinType == nsAbWinType_Unknown) {
     PRINTF(("Huge problem URI=%s.\n", mURINoQuery));
     return NS_ERROR_INVALID_ARG;
@@ -177,153 +173,144 @@ NS_IMETHODIMP nsAbOutlookDirectory::GetC
   rv = GetChildNodes(nodeList);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_NewArrayEnumerator(aNodes, nodeList);
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsISimpleEnumerator **aCards)
 {
-    NS_ENSURE_ARG_POINTER(aCards);
-
-    *aCards = nsnull;
+  NS_ENSURE_ARG_POINTER(aCards);
+  *aCards = nsnull;
 
-    nsresult retCode;
-    nsCOMPtr<nsIMutableArray> cardList(do_CreateInstance(NS_ARRAY_CONTRACTID, &retCode));
+  nsresult rv;
+  nsCOMPtr<nsIMutableArray> cardList(do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
+  NS_ENSURE_SUCCESS(rv, rv);
 
-    mCardList.Clear();
+  mCardList.Clear();
 
-    retCode = mIsQueryURI ? StartSearch() : GetChildCards(cardList, nsnull);
+  rv = mIsQueryURI ? StartSearch() : GetChildCards(cardList, nsnull);
 
-    if (NS_SUCCEEDED(retCode)) {
-        if (!m_AddressList)
-        {
-          m_AddressList = do_CreateInstance(NS_ARRAY_CONTRACTID, &retCode);
-          NS_ENSURE_SUCCESS(retCode, retCode);
-        }
+  NS_ENSURE_SUCCESS(rv, rv);
+  if (!m_AddressList)
+  {
+    m_AddressList = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
-        // Fill the results array and update the card list
-        // Also update the address list and notify any changes.
-        PRUint32 nbCards = 0 ;
-        
-        NS_NewArrayEnumerator(aCards, cardList);
-        cardList->GetLength(&nbCards);
+  // Fill the results array and update the card list
+  // Also update the address list and notify any changes.
+  PRUint32 nbCards = 0;
 
-        nsCOMPtr<nsIAbCard> card;
+  NS_NewArrayEnumerator(aCards, cardList);
+  cardList->GetLength(&nbCards);
 
-        for (PRUint32 i = 0; i < nbCards; ++i) {
-            card = do_QueryElementAt(cardList, i, &retCode);
-            if (NS_FAILED(retCode))
-              continue;
+  nsCOMPtr<nsIAbCard> card;
+  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID,
+                                   &rv));
+  NS_ENSURE_SUCCESS(rv, rv);
+
 
-            if (!mCardList.Get(card, nsnull)) {
-                // We are dealing with a new element (probably directly
-                // added from Outlook), we may need to sync m_AddressList
-                mCardList.Put(card, card);
-
-                PRBool isMailList = PR_FALSE ;
+  for (PRUint32 i = 0; i < nbCards; ++i)
+  {
+    card = do_QueryElementAt(cardList, i, &rv);
+    if (NS_FAILED(rv))
+      continue;
 
-                retCode = card->GetIsMailList(&isMailList) ;
-                NS_ENSURE_SUCCESS(retCode, retCode) ;
-                if (isMailList) {
-                    // We can have mailing lists only in folder, 
-                    // we must add the directory to m_AddressList
-                    nsCString mailListUri;
+    if (!mCardList.Get(card, nsnull))
+    {
+      // We are dealing with a new element (probably directly
+      // added from Outlook), we may need to sync m_AddressList
+      mCardList.Put(card, card);
 
-                    retCode = card->GetMailListURI(getter_Copies(mailListUri)) ;
-                    NS_ENSURE_SUCCESS(retCode, retCode) ;
-                    nsCOMPtr<nsIRDFResource> resource ;
+      PRBool isMailList = PR_FALSE;
 
-                    retCode = gRDFService->GetResource(mailListUri, getter_AddRefs(resource)) ;
-                    NS_ENSURE_SUCCESS(retCode, retCode) ;
-                    nsCOMPtr<nsIAbDirectory> mailList(do_QueryInterface(resource, &retCode)) ;
-                    
-                    NS_ENSURE_SUCCESS(retCode, retCode) ;
-                    m_AddressList->AppendElement(mailList, PR_FALSE);
-                    NotifyItemAddition(mailList) ;
-                }
-                else if (m_IsMailList) {
-                    m_AddressList->AppendElement(card, PR_FALSE);
-                    NotifyItemAddition(card) ;
-                }
-            }
-            else
-              NS_WARNING("Card wasn't stored");
-        }
+      rv = card->GetIsMailList(&isMailList);
+      NS_ENSURE_SUCCESS(rv, rv);
+      if (isMailList)
+      {
+        // We can have mailing lists only in folder,
+        // we must add the directory to m_AddressList
+        nsCString mailListUri;
+        rv = card->GetMailListURI(getter_Copies(mailListUri));
+        NS_ENSURE_SUCCESS(rv, rv);
+        nsCOMPtr<nsIAbDirectory> mailList;
+        rv = abManager->GetDirectory(mailListUri, getter_AddRefs(mailList));
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        m_AddressList->AppendElement(mailList, PR_FALSE);
+        NotifyItemAddition(mailList);
+      }
+      else if (m_IsMailList)
+      {
+        m_AddressList->AppendElement(card, PR_FALSE);
+        NotifyItemAddition(card);
+      }
     }
-    return retCode ;
+  }
+  return rv;
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::GetIsQuery(PRBool *aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = mIsQueryURI;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
 {
-    if (!aCard || !aHasCard) { return NS_ERROR_NULL_POINTER ; }
-    *aHasCard = mCardList.Get(aCard, nsnull);
-    return NS_OK ;
+  if (!aCard || !aHasCard)
+    return NS_ERROR_NULL_POINTER;
+
+  *aHasCard = mCardList.Get(aCard, nsnull);
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory)
 {
-    NS_ENSURE_ARG_POINTER(aDirectory);
-    NS_ENSURE_ARG_POINTER(aHasDirectory);
+  NS_ENSURE_ARG_POINTER(aDirectory);
+  NS_ENSURE_ARG_POINTER(aHasDirectory);
+
+  *aHasDirectory = PR_FALSE;
 
-    *aHasDirectory = PR_FALSE;
-    
-    PRUint32 pos;
-    if (m_AddressList && NS_SUCCEEDED(m_AddressList->IndexOf(0, aDirectory, &pos)))
-        *aHasDirectory = PR_TRUE;
+  PRUint32 pos;
+  if (m_AddressList && NS_SUCCEEDED(m_AddressList->IndexOf(0, aDirectory, &pos)))
+      *aHasDirectory = PR_TRUE;
 
-    return NS_OK ;
+  return NS_OK;
 }
 
-static nsresult ExtractEntryFromUri(nsIRDFResource *aResource, nsCString &aEntry,
-                                    const char *aPrefix)
-{
-    aEntry.Truncate() ;
-    if (!aPrefix ) { return NS_ERROR_NULL_POINTER ; }
-    nsCString uri;
-    nsresult retCode = aResource->GetValue(getter_Copies(uri)) ;
-    
-    NS_ENSURE_SUCCESS(retCode, retCode) ;
-    nsCAutoString stub ;
-    nsAbWinType objType = getAbWinType(aPrefix, uri.get(), stub, aEntry) ;
-
-    return NS_OK ;
-}
 
 static nsresult ExtractCardEntry(nsIAbCard *aCard, nsCString& aEntry)
 {
-    aEntry.Truncate() ;
+  aEntry.Truncate();
 
-    nsCString uri;
-    aCard->GetPropertyAsAUTF8String("OutlookEntryURI", uri);
+  nsCString uri;
+  aCard->GetPropertyAsAUTF8String("OutlookEntryURI", uri);
 
-    // If we don't have a URI, uri will be empty. getAbWinType doesn't set
-    // aEntry to anything if uri is empty, so it will be truncated, allowing us
-    // to accept cards not initialized by us.
-    nsCAutoString stub;
-    getAbWinType(kOutlookCardScheme, uri.get(), stub, aEntry);
-    return NS_OK;
+  // If we don't have a URI, uri will be empty. getAbWinType doesn't set
+  // aEntry to anything if uri is empty, so it will be truncated, allowing us
+  // to accept cards not initialized by us.
+  nsCAutoString stub;
+  getAbWinType(kOutlookCardScheme, uri.get(), stub, aEntry);
+  return NS_OK;
 }
 
 static nsresult ExtractDirectoryEntry(nsIAbDirectory *aDirectory, nsCString& aEntry)
 {
-    aEntry.Truncate() ;
-    nsresult retCode = NS_OK ;
-    nsCOMPtr<nsIRDFResource> resource (do_QueryInterface(aDirectory, &retCode)) ;
-    
-    // Receiving a non-RDF directory is accepted
-    if (NS_FAILED(retCode)) { return NS_OK ; }
-    return ExtractEntryFromUri(resource, aEntry, kOutlookDirectoryScheme) ;
+  aEntry.Truncate();
+  nsCString uri;
+  nsresult rv = aDirectory->GetURI(uri);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCAutoString stub;
+  nsAbWinType objType = getAbWinType(kOutlookDirectoryScheme, uri.get(), stub, aEntry);
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsIArray *aCardList)
 {
     if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
     if (!aCardList) { return NS_ERROR_NULL_POINTER ; }
     PRUint32 nbCards = 0 ;
     nsresult retCode = NS_OK ;
@@ -437,65 +424,74 @@ NS_IMETHODIMP nsAbOutlookDirectory::AddC
 NS_IMETHODIMP nsAbOutlookDirectory::DropCard(nsIAbCard *aData, PRBool needToCopyCard)
 {
     nsCOMPtr <nsIAbCard> addedCard;
     return AddCard(aData, getter_AddRefs(addedCard));
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::AddMailList(nsIAbDirectory *aMailList)
 {
-    if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
-    if (!aMailList) { return NS_ERROR_NULL_POINTER ; }
-    if (m_IsMailList) { return NS_OK ; }
-    nsresult retCode = NS_OK ;
-    nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
-    nsCAutoString entryString ;
-    nsMapiEntry newEntry ;
-    PRBool didCopy = PR_FALSE ;
+  if (mIsQueryURI)
+    return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_ARG_POINTER(aMailList);
+  if (m_IsMailList)
+    return NS_OK;
+  nsAbWinHelperGuard mapiAddBook (mAbWinType);
+  nsCAutoString entryString;
+  nsMapiEntry newEntry;
+  PRBool didCopy = PR_FALSE;
 
-    if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
-    retCode = ExtractDirectoryEntry(aMailList, entryString) ;
-    if (NS_SUCCEEDED(retCode) && !entryString.IsEmpty()) {
-        nsMapiEntry sourceEntry ;
+  if (!mapiAddBook->IsOK())
+    return NS_ERROR_FAILURE;
+  nsresult rv = ExtractDirectoryEntry(aMailList, entryString);
+  if (NS_SUCCEEDED(rv) && !entryString.IsEmpty())
+  {
+      nsMapiEntry sourceEntry;
 
-        sourceEntry.Assign(entryString) ;
-        mapiAddBook->CopyEntry(*mMapiData, sourceEntry, newEntry) ;
-    }
-    if (newEntry.mByteCount == 0) {
-        if (!mapiAddBook->CreateDistList(*mMapiData, newEntry)) {
-            return NS_ERROR_FAILURE ; 
-        }
-    }
-    else { didCopy = PR_TRUE ; }
-    newEntry.ToString(entryString) ;
-    nsCAutoString uri ;
+      sourceEntry.Assign(entryString);
+      mapiAddBook->CopyEntry(*mMapiData, sourceEntry, newEntry);
+  }
+  if (newEntry.mByteCount == 0)
+  {
+    if (!mapiAddBook->CreateDistList(*mMapiData, newEntry))
+        return NS_ERROR_FAILURE;
+  }
+  else {
+    didCopy = PR_TRUE;
+  }
+  newEntry.ToString(entryString);
+  nsCAutoString uri;
+
+  buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uri);
+  uri.Append(entryString);
+
+  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID,
+                                   &rv));
+  NS_ENSURE_SUCCESS(rv, rv);
 
-    buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uri) ;
-    uri.Append(entryString) ;
-    nsCOMPtr<nsIRDFResource> resource ;
-    retCode = gRDFService->GetResource(uri, getter_AddRefs(resource)) ;
-    NS_ENSURE_SUCCESS(retCode, retCode) ;
-    nsCOMPtr<nsIAbDirectory> newList(do_QueryInterface(resource, &retCode)) ;
-    
-    NS_ENSURE_SUCCESS(retCode, retCode) ;
-    if (!didCopy) {
-        retCode = newList->CopyMailList(aMailList) ;
-        NS_ENSURE_SUCCESS(retCode, retCode) ;
-        retCode = newList->EditMailListToDatabase(nsnull);
-        NS_ENSURE_SUCCESS(retCode, retCode) ;
-    }
+  nsCOMPtr<nsIAbDirectory> newList;
+  rv = abManager->GetDirectory(uri, getter_AddRefs(newList));
+  NS_ENSURE_SUCCESS(rv, rv);
 
-    if (!m_AddressList)
-    {
-      m_AddressList = do_CreateInstance(NS_ARRAY_CONTRACTID, &retCode);
-      NS_ENSURE_SUCCESS(retCode, retCode);
-    }
-    m_AddressList->AppendElement(newList, PR_FALSE);
-    NotifyItemAddition(newList) ;
-    return retCode ;
+  if (!didCopy)
+  {
+    rv = newList->CopyMailList(aMailList);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = newList->EditMailListToDatabase(nsnull);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+
+  if (!m_AddressList)
+  {
+    m_AddressList = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+  m_AddressList->AppendElement(newList, PR_FALSE);
+  NotifyItemAddition(newList);
+  return rv;
 }
 
 NS_IMETHODIMP nsAbOutlookDirectory::EditMailListToDatabase(nsIAbCard *listCard)
 {
   if (mIsQueryURI)
     return NS_ERROR_NOT_IMPLEMENTED;
 
   nsresult rv;
@@ -1088,48 +1084,52 @@ nsresult nsAbOutlookDirectory::GetChildC
 
     aCards->AppendElement(childCard, PR_FALSE);
   }
   return rv;
 }
 
 nsresult nsAbOutlookDirectory::GetChildNodes(nsIMutableArray* aNodes)
 {
-    NS_ENSURE_ARG_POINTER(aNodes);
+  NS_ENSURE_ARG_POINTER(aNodes);
 
-    aNodes->Clear();
+  aNodes->Clear();
 
-    nsAbWinHelperGuard mapiAddBook(mAbWinType);
-    nsMapiEntryArray nodeEntries;
+  nsAbWinHelperGuard mapiAddBook(mAbWinType);
+  nsMapiEntryArray nodeEntries;
 
-    if (!mapiAddBook->IsOK())
-        return NS_ERROR_FAILURE;
+  if (!mapiAddBook->IsOK())
+      return NS_ERROR_FAILURE;
 
-    if (!mapiAddBook->GetNodes(*mMapiData, nodeEntries)) 
-    {
-        PRINTF(("Cannot get nodes.\n"));
-        return NS_ERROR_FAILURE;
-    }
+  if (!mapiAddBook->GetNodes(*mMapiData, nodeEntries))
+  {
+    PRINTF(("Cannot get nodes.\n"));
+    return NS_ERROR_FAILURE;
+  }
 
-    nsCAutoString entryId;
-    nsCAutoString uriName;
-    nsCOMPtr<nsIRDFResource> resource;
-    nsresult rv = NS_OK;
+  nsCAutoString entryId;
+  nsCAutoString uriName;
+  nsresult rv = NS_OK;
+
+  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
+  NS_ENSURE_SUCCESS(rv, rv);
 
-    for (ULONG node = 0; node < nodeEntries.mNbEntries; ++node) 
-        {
-        nodeEntries.mEntries[node].ToString(entryId);
-        buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uriName);
-        uriName.Append(entryId);
+  for (ULONG node = 0; node < nodeEntries.mNbEntries; ++node)
+  {
+    nodeEntries.mEntries[node].ToString(entryId);
+    buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, uriName);
+    uriName.Append(entryId);
 
-        rv = gRDFService->GetResource(uriName, getter_AddRefs(resource));
-        NS_ENSURE_SUCCESS(rv, rv);
-        aNodes->AppendElement(resource, PR_FALSE);
-    }
-    return rv;
+    nsCOMPtr <nsIAbDirectory> directory;
+    rv = abManager->GetDirectory(uriName, getter_AddRefs(directory));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    aNodes->AppendElement(directory, PR_FALSE);
+  }
+  return rv;
 }
 
 nsresult nsAbOutlookDirectory::NotifyItemDeletion(nsISupports *aItem) 
 {
   nsresult rv;
   nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
 
   if (NS_SUCCEEDED(rv))
@@ -1216,17 +1216,17 @@ nsresult nsAbOutlookDirectory::CreateCar
     *aNewCard = nsnull ;
     nsresult retCode = NS_OK ;
     nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
     nsMapiEntry newEntry ;
     nsCAutoString entryString ;
     PRBool didCopy = PR_FALSE ;
 
     if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
-    // If we get a RDF resource and it maps onto an Outlook card uri,
+    // If we get an nsIAbCard that maps onto an Outlook card uri
     // we simply copy the contents of the Outlook card.
     retCode = ExtractCardEntry(aData, entryString) ;
     if (NS_SUCCEEDED(retCode) && !entryString.IsEmpty()) {
         nsMapiEntry sourceEntry ;
         
         
         sourceEntry.Assign(entryString) ;
         if (m_IsMailList) {
--- a/mailnews/addrbook/src/nsAbOutlookDirectory.h
+++ b/mailnews/addrbook/src/nsAbOutlookDirectory.h
@@ -33,61 +33,59 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #ifndef nsAbOutlookDirectory_h___
 #define nsAbOutlookDirectory_h___
 
-#include "nsAbDirectoryRDFResource.h"
 #include "nsAbDirProperty.h"
 #include "nsIAbDirectoryQuery.h"
 #include "nsIAbDirectorySearch.h"
 #include "nsIAbDirSearchListener.h"
 #include "nsDataHashtable.h"
 #include "nsInterfaceHashtable.h"
 #include "nsIMutableArray.h"
 #include "nsAbWinHelper.h"
 
 struct nsMapiEntry ;
 
-class nsAbOutlookDirectory : public nsAbDirectoryRDFResource, // nsIRDFResource
-                             public nsAbDirProperty, // nsIAbDirectory
+class nsAbOutlookDirectory : public nsAbDirProperty, // nsIAbDirectory
                              public nsIAbDirectoryQuery,
                              public nsIAbDirectorySearch,
                              public nsIAbDirSearchListener,
                              public nsIAbDirectoryQueryResultListener
 {
 public:
-	NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIABDIRSEARCHLISTENER
   NS_DECL_NSIABDIRECTORYQUERYRESULTLISTENER
 
   nsAbOutlookDirectory(void);
   virtual ~nsAbOutlookDirectory(void);
-	
-	// nsAbDirProperty methods
+
+  // nsAbDirProperty methods
   NS_IMETHOD GetDirType(PRInt32 *aDirType);
   NS_IMETHOD GetURI(nsACString &aURI);
   NS_IMETHOD GetChildCards(nsISimpleEnumerator **aCards);
   NS_IMETHOD GetChildNodes(nsISimpleEnumerator **aNodes);
   NS_IMETHOD GetIsQuery(PRBool *aResult);
   NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard);
   NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory);
   NS_IMETHOD DeleteCards(nsIArray *aCardList);
   NS_IMETHOD DeleteDirectory(nsIAbDirectory *aDirectory);
   NS_IMETHOD UseForAutocomplete(const nsACString &aIdentityKey, PRBool *aResult);
   NS_IMETHOD AddCard(nsIAbCard *aData, nsIAbCard **addedCard);
   NS_IMETHOD ModifyCard(nsIAbCard *aModifiedCard);
   NS_IMETHOD DropCard(nsIAbCard *aData, PRBool needToCopyCard);
   NS_IMETHOD AddMailList(nsIAbDirectory *aMailList);
   NS_IMETHOD EditMailListToDatabase(nsIAbCard *listCard);
   
-  // nsAbDirectoryRDFResource method
+  // nsAbDirProperty method
   NS_IMETHOD Init(const char *aUri);
   // nsIAbDirectoryQuery methods
   NS_DECL_NSIABDIRECTORYQUERY
   // nsIAbDirectorySearch methods
   NS_DECL_NSIABDIRECTORYSEARCH
   // Perform a MAPI query (function executed in a separate thread)
   nsresult ExecuteQuery(SRestriction &aRestriction,
                         nsIAbDirSearchListener *aListener,
deleted file mode 100644
--- a/mailnews/addrbook/src/nsAbRDFDataSource.cpp
+++ /dev/null
@@ -1,448 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Pierre Phaneuf <pp@ludusdesign.com>
- *   Mark Banner <mark@standard8.demon.co.uk>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsAbRDFDataSource.h"
-#include "nsAbBaseCID.h"
-#include "nsIAbDirectory.h"
-#include "nsIAbCard.h"
-
-#include "rdf.h"
-#include "nsIRDFService.h"
-#include "nsRDFCID.h"
-#include "nsIRDFNode.h"
-#include "nsEnumeratorUtils.h"
-#include "nsIProxyObjectManager.h"
-
-#include "nsCOMPtr.h"
-#include "nsServiceManagerUtils.h"
-#include "nsComponentManagerUtils.h"
-#include "nsThreadUtils.h"
-#include "nsXPCOMCIDInternal.h"
-
-using namespace mozilla;
-
-// this is used for notification of observers using nsVoidArray
-typedef struct _nsAbRDFNotification {
-  nsIRDFDataSource *datasource;
-  nsIRDFResource *subject;
-  nsIRDFResource *property;
-  nsIRDFNode *object;
-} nsAbRDFNotification;
-
-nsresult nsAbRDFDataSource::createNode(const PRUnichar *str, nsIRDFNode **node)
-{
-  *node = nsnull;
-  nsresult rv;
-  nsCOMPtr<nsIRDFService> rdf(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
-  NS_ENSURE_SUCCESS(rv, rv); // always check this before proceeding
-  nsCOMPtr<nsIRDFLiteral> value;
-  rv = rdf->GetLiteral(str, getter_AddRefs(value));
-  if (NS_SUCCEEDED(rv)) 
-    NS_IF_ADDREF(*node = value);
-  return rv;
-}
-
-nsresult nsAbRDFDataSource::createBlobNode(PRUint8 *value, PRUint32 &length, nsIRDFNode **node, nsIRDFService *rdfService)
-{
-  NS_ENSURE_ARG_POINTER(node);
-  NS_ENSURE_ARG_POINTER(rdfService);
-
-  *node = nsnull;
-  nsCOMPtr<nsIRDFBlob> blob;
-  nsresult rv = rdfService->GetBlobLiteral(value, length, getter_AddRefs(blob));
-  NS_ENSURE_SUCCESS(rv,rv);
-  NS_IF_ADDREF(*node = blob);
-  return rv;
-}
-
-PRBool nsAbRDFDataSource::changeEnumFunc(nsIRDFObserver *aObserver, void *aData)
-{
-  nsAbRDFNotification* note = (nsAbRDFNotification *)aData;
-  aObserver->OnChange(note->datasource,
-                     note->subject,
-                     note->property,
-                     nsnull, note->object);
-  return PR_TRUE;
-}
-
-PRBool nsAbRDFDataSource::assertEnumFunc(nsIRDFObserver *aObserver, void *aData)
-{
-  nsAbRDFNotification *note = (nsAbRDFNotification *)aData;
-  aObserver->OnAssert(note->datasource,
-                     note->subject,
-                     note->property,
-                     note->object);
-  return PR_TRUE;
-}
-
-PRBool nsAbRDFDataSource::unassertEnumFunc(nsIRDFObserver *aObserver, void *aData)
-{
-  nsAbRDFNotification* note = (nsAbRDFNotification *)aData;
-  aObserver->OnUnassert(note->datasource,
-                       note->subject,
-                       note->property,
-                       note->object);
-  return PR_TRUE;
-}
-
-nsresult nsAbRDFDataSource::CreateProxyObserver (nsIRDFObserver* observer,
-  nsIRDFObserver** proxyObserver)
-{
-  nsresult rv;
-
-  // Proxy the observer on the UI thread
-  /*
-   * TODO
-   * Currenly using NS_PROXY_ASYNC, however
-   * this can flood the event queue if
-   * rate of events on the observer is
-   * greater that the time to process the
-   * events.
-   * This causes the UI to pause.
-   */
-   nsCOMPtr<nsIProxyObjectManager> proxyObjMgr = do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
-   NS_ENSURE_SUCCESS(rv, rv);
-
-   rv = proxyObjMgr->GetProxyForObject (
-    NS_PROXY_TO_MAIN_THREAD,
-    NS_GET_IID(nsIRDFObserver),
-    observer,
-    NS_PROXY_ASYNC | NS_PROXY_ALWAYS,
-    (void** )proxyObserver);
-
-  return rv;
-}
-
-nsresult nsAbRDFDataSource::CreateProxyObservers ()
-{
-  nsresult rv = NS_OK;
-
-  PRUint32 nObservers = mObservers.Count();
-
-  PRUint32 nProxyObservers = mProxyObservers.Count();
-
-  /*
-   * For all the outstanding observers that
-   * have not been proxied
-   */
-  for (PRUint32 i = nProxyObservers; i < nObservers; i++)
-  {
-    nsIRDFObserver * observer = mObservers.ObjectAt(i);
-
-    // Create the proxy
-    nsCOMPtr<nsIRDFObserver> proxyObserver;
-    rv = CreateProxyObserver (observer, getter_AddRefs (proxyObserver));
-    NS_ENSURE_SUCCESS(rv, rv);
-    mProxyObservers.AppendObject(proxyObserver);
-  }
-
-  return rv;
-}
-
-nsresult nsAbRDFDataSource::NotifyObservers(nsIRDFResource *subject,
-  nsIRDFResource *property,
-  nsIRDFNode *object,
-  PRBool assert,
-  PRBool change)
-{
-  NS_ASSERTION(!(change && assert),
-                 "Can't change and assert at the same time!\n");
-
-  nsresult rv;
-
-  MutexAutoLock lockGuard (mLock);
-
-  /*
-   * TODO
-   * Is the main thread always guaranteed to be
-   * the UI thread?
-   *
-   * Note that this also binds the data source
-   * to the UI which is supposedly the only
-   * place where it is used, but what about
-   * RDF datasources that are not UI specific
-   * but are used in the UI?
-   */
-  nsCOMArray<nsIRDFObserver> * observers;
-  if (NS_IsMainThread())
-  {
-    /*
-     * Since this is the UI Thread use the
-     * observers list directly for performance
-     */
-    observers = &mObservers;
-  }
-  else
-  {
-    /*
-     * This is a different thread to the UI
-     * thread need to use proxies to the
-     * observers
-     *
-     * Create the proxies
-     */
-    rv = CreateProxyObservers();
-    NS_ENSURE_SUCCESS (rv, rv);
-    observers = &mProxyObservers;
-  }
-
-  nsAbRDFNotification note = { this, subject, property, object };
-  if (change)
-    observers->EnumerateForwards(changeEnumFunc, &note);
-  else if (assert)
-    observers->EnumerateForwards(assertEnumFunc, &note);
-  else
-    observers->EnumerateForwards(unassertEnumFunc, &note);
-
-  return NS_OK;
-}
-
-nsresult nsAbRDFDataSource::NotifyPropertyChanged(nsIRDFResource *resource,
-  nsIRDFResource *propertyResource,
-  const PRUnichar *oldValue,
-  const PRUnichar *newValue)
-{
-  nsCOMPtr<nsIRDFNode> newValueNode;
-  createNode(newValue, getter_AddRefs(newValueNode));
-  NotifyObservers(resource, propertyResource, newValueNode, PR_FALSE, PR_TRUE);
-  return NS_OK;
-}
-
-
-nsAbRDFDataSource::nsAbRDFDataSource():
-  mLock("nsAbRDFDataSource.mLock")
-{
-}
-
-nsAbRDFDataSource::~nsAbRDFDataSource (void)
-{
-}
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsAbRDFDataSource)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsAbRDFDataSource)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mObservers)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mProxyObservers)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsAbRDFDataSource)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mObservers)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mProxyObservers)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAbRDFDataSource)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAbRDFDataSource)
-
-NS_INTERFACE_MAP_BEGIN(nsAbRDFDataSource)
-  NS_INTERFACE_MAP_ENTRY(nsIRDFDataSource)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRDFDataSource)
-  NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsAbRDFDataSource)
-NS_INTERFACE_MAP_END
-
- // nsIRDFDataSource methods
-NS_IMETHODIMP nsAbRDFDataSource::GetURI(char* *uri)
-{
-    NS_NOTREACHED("should be implemented by a subclass");
-    return NS_ERROR_UNEXPECTED;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::GetSource(nsIRDFResource* property,
-                                               nsIRDFNode* target,
-                                               PRBool tv,
-                                               nsIRDFResource** source /* out */)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::GetTarget(nsIRDFResource* source,
-                                               nsIRDFResource* property,
-                                               PRBool tv,
-                                               nsIRDFNode** target)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-
-NS_IMETHODIMP nsAbRDFDataSource::GetSources(nsIRDFResource* property,
-                                                nsIRDFNode* target,
-                                                PRBool tv,
-                                                nsISimpleEnumerator** sources)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::GetTargets(nsIRDFResource* source,
-                                                nsIRDFResource* property,
-                                                PRBool tv,
-                                                nsISimpleEnumerator** targets)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::Assert(nsIRDFResource* source,
-                      nsIRDFResource* property,
-                      nsIRDFNode* target,
-                      PRBool tv)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::Unassert(nsIRDFResource* source,
-                        nsIRDFResource* property,
-                        nsIRDFNode* target)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::Change(nsIRDFResource *aSource,
-                                              nsIRDFResource *aProperty,
-                                              nsIRDFNode *aOldTarget,
-                                              nsIRDFNode *aNewTarget)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::Move(nsIRDFResource *aOldSource,
-                                            nsIRDFResource *aNewSource,
-                                            nsIRDFResource *aProperty,
-                                            nsIRDFNode *aTarget)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-
-NS_IMETHODIMP nsAbRDFDataSource::HasAssertion(nsIRDFResource* source,
-                            nsIRDFResource* property,
-                            nsIRDFNode* target,
-                            PRBool tv,
-                            PRBool* hasAssertion)
-{
-    *hasAssertion = PR_FALSE;
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::AddObserver(nsIRDFObserver* observer)
-{
-  // Lock the whole method
-  MutexAutoLock lockGuard (mLock);
-
-  // Do not add if already present
-  if (mObservers.IndexOf(observer) >= 0)
-    return NS_OK;
-
-  mObservers.AppendObject(observer);
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::RemoveObserver(nsIRDFObserver* observer)
-{
-  // Lock the whole method
-  MutexAutoLock lockGuard (mLock);
-  PRInt32 index = mObservers.IndexOf(observer);
-  if (index >= 0)
-  {
-    mObservers.RemoveObjectAt(index);
-    mProxyObservers.RemoveObjectAt(index);
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAbRDFDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *result)
-{
-  *result = PR_FALSE;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAbRDFDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *result)
-{
-  *result = PR_FALSE;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::ArcLabelsIn(nsIRDFNode* node,
-                                                nsISimpleEnumerator** labels)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::ArcLabelsOut(nsIRDFResource* source,
-                                                 nsISimpleEnumerator** labels)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP
-nsAbRDFDataSource::GetAllCmds(nsIRDFResource* source,
-                                      nsISimpleEnumerator/*<nsIRDFResource>*/** commands)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP
-nsAbRDFDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
-                                        nsIRDFResource*   aCommand,
-                                        nsISupportsArray/*<nsIRDFResource>*/* aArguments,
-                                        PRBool* aResult)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP nsAbRDFDataSource::DoCommand
-(nsISupportsArray * aSources, nsIRDFResource* aCommand, nsISupportsArray * aArguments)
-{
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP
-nsAbRDFDataSource::BeginUpdateBatch()
-{
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAbRDFDataSource::EndUpdateBatch()
-{
-    return NS_OK;
-}
deleted file mode 100644
--- a/mailnews/addrbook/src/nsAbRDFDataSource.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsAbRDFDataSource_h__
-#define nsAbRDFDataSource_h__
-
-#include "nsCOMPtr.h"
-#include "nsIRDFDataSource.h"
-#include "nsIRDFService.h"
-#include "nsCOMArray.h"
-#include "nsStringGlue.h"
-#include "nsCycleCollectionParticipant.h"
-#include "mozilla/Mutex.h"
-
-/**
- * The addressbook data source.
- */
-class nsAbRDFDataSource : public nsIRDFDataSource
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAbRDFDataSource,
-                                           nsIRDFDataSource)
-  NS_DECL_NSIRDFDATASOURCE
-
-  nsAbRDFDataSource();
-  virtual ~nsAbRDFDataSource();
-
-protected:
-
-  nsresult createNode(const PRUnichar *str, nsIRDFNode **node);
-  nsresult createBlobNode(PRUint8 *value, PRUint32 &length, nsIRDFNode **node, nsIRDFService *rdfService);
-
-  nsresult NotifyPropertyChanged(
-    nsIRDFResource *resource,
-    nsIRDFResource *propertyResource,
-    const PRUnichar *oldValue,
-    const PRUnichar *newValue);
-
-  nsresult NotifyObservers(
-    nsIRDFResource *subject,
-    nsIRDFResource *property,
-    nsIRDFNode *object,
-    PRBool assert,
-    PRBool change);
-
-  nsresult CreateProxyObservers ();
-
-  nsresult CreateProxyObserver (
-  nsIRDFObserver* observer,
-  nsIRDFObserver** proxyObserver);
-
-  static PRBool assertEnumFunc(nsIRDFObserver *aObserver, void *aData);
-  static PRBool unassertEnumFunc(nsIRDFObserver *aObserver, void *aData);
-  static PRBool changeEnumFunc(nsIRDFObserver *aObserver, void *aData);
-
-private:
-  nsCOMArray<nsIRDFObserver> mObservers;
-  nsCOMArray<nsIRDFObserver> mProxyObservers;
-  mozilla::Mutex mLock;
-};
-
-#endif
--- a/mailnews/addrbook/src/nsAddrDatabase.cpp
+++ b/mailnews/addrbook/src/nsAddrDatabase.cpp
@@ -38,43 +38,41 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 // this file implements the nsAddrDatabase interface using the MDB Interface.
 
 #include "nsAddrDatabase.h"
 #include "nsStringGlue.h"
 #include "nsAutoPtr.h"
-#include "nsRDFCID.h"
 #include "nsUnicharUtils.h"
 #include "nsAbBaseCID.h"
 #include "nsIAbMDBDirectory.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
-#include "nsRDFCID.h"
 #include "nsMsgUtils.h"
 #include "nsMorkCID.h"
 #include "nsIMdbFactoryFactory.h"
-#include "nsIRDFService.h"
 #include "nsIProxyObjectManager.h"
 #include "nsProxiedService.h"
 #include "prprf.h"
 #include "nsIMutableArray.h"
 #include "nsArrayUtils.h"
 #include "nsIPromptService.h"
 #include "nsIStringBundle.h"
 #include "nsIFile.h"
 #include "nsEmbedCID.h"
 #include "nsXPCOMCIDInternal.h"
 #include "nsIProperty.h"
 #include "nsIVariant.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
+#include "nsIAbManager.h"
 
 #define ID_PAB_TABLE            1
 #define ID_DELETEDCARDS_TABLE           2
 
 // There's two books by default, although Mac may have one more, so set this
 // to three. Its not going to affect much, but will save us a few reallocations
 // when the cache is allocated.
 const PRUint32 kInitialAddrDBCacheSize = 3;
@@ -3192,55 +3190,59 @@ NS_IMETHODIMP nsAddrDatabase::GetCardsFr
       done = PR_TRUE;
   } while (!done);
 
   return NS_NewArrayEnumerator(cards, list);
 }
 
 NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow)
 {
-    nsresult rv = NS_OK;
-
-    static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
-    NS_WITH_PROXIED_SERVICE(nsIRDFService, rdfService, kRDFServiceCID,
-                            NS_PROXY_TO_MAIN_THREAD, &rv);
-    if (NS_SUCCEEDED(rv))
+  nsresult rv = NS_OK;
+
+  NS_WITH_PROXIED_SERVICE(nsIAbManager, abManager, NS_ABMANAGER_CONTRACTID,
+                          NS_PROXY_TO_MAIN_THREAD, &rv);
+
+  if (NS_SUCCEEDED(rv))
+  {
+    nsAutoString parentURI;
+    rv = m_dbName->GetLeafName(parentURI);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    parentURI.Replace(0, 0, NS_LITERAL_STRING(kMDBDirectoryRoot));
+
+    nsCOMPtr<nsIAbDirectory> parentDir;
+    rv = abManager->GetDirectory(NS_ConvertUTF16toUTF8(parentURI),
+                                 getter_AddRefs(parentDir));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIProxyObjectManager> proxyObjMgr =
+        do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
+
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIAbDirectory> proxiedParentDir = nsnull;
+    rv = proxyObjMgr->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
+                                        NS_GET_IID( nsIAbDirectory),
+                                        parentDir,
+                                        NS_PROXY_SYNC | NS_PROXY_ALWAYS,
+                                        getter_AddRefs(proxiedParentDir));
+    if (proxiedParentDir)
     {
-        nsCOMPtr<nsIRDFResource>    parentResource;
-
-        nsAutoString parentURI;
-        rv = m_dbName->GetLeafName(parentURI);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        parentURI.Replace(0, 0, NS_LITERAL_STRING(kMDBDirectoryRoot));
-
-        rv = rdfService->GetResource(NS_ConvertUTF16toUTF8(parentURI), getter_AddRefs(parentResource));
-        nsCOMPtr<nsIAbDirectory> parentDir;
-
-        nsCOMPtr<nsIProxyObjectManager> proxyObjMgr = do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
-        NS_ENSURE_SUCCESS(rv, rv);
-        rv = proxyObjMgr->GetProxyForObject( NS_PROXY_TO_MAIN_THREAD,
-                                   NS_GET_IID( nsIAbDirectory),
-                                   parentResource,
-                                   NS_PROXY_SYNC | NS_PROXY_ALWAYS,
-                                   getter_AddRefs( parentDir));
-        if (parentDir)
-        {
-            m_dbDirectory = do_GetWeakReference(parentDir);
-            nsCOMPtr<nsIAbDirectory> mailList;
-            rv = CreateABList(listRow, getter_AddRefs(mailList));
-            if (mailList)
-            {
-                nsCOMPtr<nsIAbMDBDirectory> dbparentDir(do_QueryInterface(parentDir, &rv));
-                if(NS_SUCCEEDED(rv))
-                    dbparentDir->NotifyDirItemAdded(mailList);
-            }
-        }
+      m_dbDirectory = do_GetWeakReference(parentDir);
+      nsCOMPtr<nsIAbDirectory> mailList;
+      rv = CreateABList(listRow, getter_AddRefs(mailList));
+      if (mailList)
+      {
+        nsCOMPtr<nsIAbMDBDirectory> dbparentDir(do_QueryInterface(parentDir, &rv));
+        if(NS_SUCCEEDED(rv))
+          dbparentDir->NotifyDirItemAdded(mailList);
+      }
     }
-    return rv;
+  }
+  return rv;
 }
 
 NS_IMETHODIMP nsAddrDatabase::FindMailListbyUnicodeName(const PRUnichar *listName, PRBool *exist)
 {
   nsAutoString unicodeString(listName);
   ToLowerCase(unicodeString);
 
   nsCOMPtr <nsIMdbRow> listRow;
deleted file mode 100644
--- a/mailnews/addrbook/src/nsDirectoryDataSource.cpp
+++ /dev/null
@@ -1,690 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Pierre Phaneuf <pp@ludusdesign.com>
- *   Seth Spitzer <sspitzer@netscape.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsDirectoryDataSource.h"
-#include "nsAbBaseCID.h"
-#include "nsIAbDirectory.h"
-#include "nsIAbManager.h"
-#include "nsIAbCard.h"
-#include "nsIMutableArray.h"
-#include "nsArrayUtils.h"
-#include "nsArrayEnumerator.h"
-#include "rdf.h"
-#include "nsIRDFService.h"
-#include "nsRDFCID.h"
-#include "nsIRDFNode.h"
-#include "nsEnumeratorUtils.h"
-#include "nsIObserverService.h"
-
-#include "nsCOMPtr.h"
-#include "nsStringGlue.h"
-
-#include "nsMsgRDFUtils.h"
-#include "nsILocaleService.h"
-#include "nsCollationCID.h"
-#include "prmem.h"
-#include "nsServiceManagerUtils.h"
-#include "nsComponentManagerUtils.h"
-
-#define NC_RDF_DIRNAME              "http://home.netscape.com/NC-rdf#DirName"
-#define NC_RDF_DIRURI               "http://home.netscape.com/NC-rdf#DirUri"
-#define NC_RDF_ISMAILLIST           "http://home.netscape.com/NC-rdf#IsMailList"
-#define NC_RDF_ISREMOTE             "http://home.netscape.com/NC-rdf#IsRemote"
-#define NC_RDF_ISWRITEABLE          "http://home.netscape.com/NC-rdf#IsWriteable"
-#define NC_RDF_DIRTREENAMESORT      "http://home.netscape.com/NC-rdf#DirTreeNameSort"
-#define NC_RDF_SUPPORTSMAILINGLISTS "http://home.netscape.com/NC-rdf#SupportsMailingLists"
-
-////////////////////////////////////////////////////////////////////////
-
-nsAbDirectoryDataSource::nsAbDirectoryDataSource()
-{
-}
-
-nsAbDirectoryDataSource::~nsAbDirectoryDataSource()
-{
-}
-
-nsresult nsAbDirectoryDataSource::Cleanup()
-{
-  nsresult rv;
-  nsCOMPtr <nsIRDFService> rdf = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  rv = rdf->UnregisterDataSource(this);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  rv = abManager->RemoveAddressBookListener(this);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAbDirectoryDataSource::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
-{
-  if (!strcmp(aTopic,NS_XPCOM_SHUTDOWN_OBSERVER_ID))
-    return Cleanup();
-
-  return NS_OK;
-}
-
-nsresult
-nsAbDirectoryDataSource::Init()
-{
-  nsresult rv;
-  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  // this listener cares about all events
-  rv = abManager->AddAddressBookListener(this, nsIAbListener::all);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  nsCOMPtr <nsIRDFService> rdf = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  rv = rdf->RegisterDataSource(this, PR_FALSE);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_CHILD),
-                        getter_AddRefs(kNC_Child));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_DIRNAME),
-                        getter_AddRefs(kNC_DirName));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_DIRURI),
-                        getter_AddRefs(kNC_DirUri));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_ISMAILLIST),
-                        getter_AddRefs(kNC_IsMailList));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_ISREMOTE),
-                        getter_AddRefs(kNC_IsRemote));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_ISSECURE),
-                        getter_AddRefs(kNC_IsSecure));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_ISWRITEABLE),
-                        getter_AddRefs(kNC_IsWriteable));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_DIRTREENAMESORT), getter_AddRefs(kNC_DirTreeNameSort));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_SUPPORTSMAILINGLISTS),
-                        getter_AddRefs(kNC_SupportsMailingLists));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = createNode(NS_LITERAL_STRING("true").get(), getter_AddRefs(kTrueLiteral));
-  NS_ENSURE_SUCCESS(rv,rv);
-  rv = createNode(NS_LITERAL_STRING("false").get(), getter_AddRefs(kFalseLiteral));
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  // since the observer (this) supports weak ref,
-  // and we call AddObserver() with PR_TRUE for ownsWeak
-  // we don't need to remove our observer from the from the observer service
-  rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  return NS_OK;
-}
-
-NS_IMPL_ISUPPORTS_INHERITED3(nsAbDirectoryDataSource, nsAbRDFDataSource, nsIAbListener, nsIObserver, nsISupportsWeakReference)
-
- // nsIRDFDataSource methods
-NS_IMETHODIMP nsAbDirectoryDataSource::GetURI(char* *uri)
-{
-  if ((*uri = strdup("rdf:addressdirectory")) == nsnull)
-    return NS_ERROR_OUT_OF_MEMORY;
-  else
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsAbDirectoryDataSource::GetTarget(nsIRDFResource* source,
-                                               nsIRDFResource* property,
-                                               PRBool tv,
-                                               nsIRDFNode** target)
-{
-  nsresult rv = NS_RDF_NO_VALUE;
-  // we only have positive assertions in the mail data source.
-  if (! tv)
-    return NS_RDF_NO_VALUE;
-
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(source, &rv));
-  if (NS_SUCCEEDED(rv) && directory)
-    rv = createDirectoryNode(directory, property, target);
-  else
-    return NS_RDF_NO_VALUE;
-  return rv;
-}
-
-
-NS_IMETHODIMP nsAbDirectoryDataSource::GetTargets(nsIRDFResource* source,
-                                                  nsIRDFResource* property,
-                                                  PRBool tv,
-                                                  nsISimpleEnumerator** targets)
-{
-  nsresult rv = NS_RDF_NO_VALUE;
-  NS_ENSURE_ARG_POINTER(targets);
-
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(source, &rv));
-  if (NS_SUCCEEDED(rv) && directory)
-  {
-    if ((kNC_Child == property))
-    {
-      return directory->GetChildNodes(targets);
-    }
-    else if((kNC_DirName == property) ||
-      (kNC_DirUri == property) ||
-      (kNC_IsMailList == property) ||
-      (kNC_IsRemote == property) ||
-      (kNC_IsSecure == property) ||
-      (kNC_IsWriteable == property) ||
-      (kNC_DirTreeNameSort == property) ||
-      (kNC_SupportsMailingLists == property))
-    {
-      return NS_NewSingletonEnumerator(targets, property);
-    }
-  }
-  return NS_NewEmptyEnumerator(targets);
-}
-
-NS_IMETHODIMP nsAbDirectoryDataSource::Assert(nsIRDFResource* source,
-                      nsIRDFResource* property,
-                      nsIRDFNode* target,
-                      PRBool tv)
-{
-  nsresult rv;
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(source, &rv));
-  //We don't handle tv = PR_FALSE at the moment.
-  if(NS_SUCCEEDED(rv) && tv)
-    return DoDirectoryAssert(directory, property, target);
-  else
-    return NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP nsAbDirectoryDataSource::HasAssertion(nsIRDFResource* source,
-                            nsIRDFResource* property,
-                            nsIRDFNode* target,
-                            PRBool tv,
-                            PRBool* hasAssertion)
-{
-  nsresult rv;
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(source, &rv));
-  if(NS_SUCCEEDED(rv))
-    return DoDirectoryHasAssertion(directory, property, target, tv, hasAssertion);
-  else
-    *hasAssertion = PR_FALSE;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAbDirectoryDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *result)
-{
-  nsresult rv;
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(aSource, &rv));
-  if (NS_SUCCEEDED(rv)) {
-    *result = (aArc == kNC_DirName ||
-               aArc == kNC_Child ||
-               aArc == kNC_DirUri ||
-               aArc == kNC_IsMailList ||
-               aArc == kNC_IsRemote ||
-               aArc == kNC_IsSecure ||
-               aArc == kNC_IsWriteable ||
-               aArc == kNC_DirTreeNameSort ||
-               aArc == kNC_SupportsMailingLists);
-  }
-  else {
-    *result = PR_FALSE;
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsAbDirectoryDataSource::ArcLabelsOut(nsIRDFResource* source,
-                                                 nsISimpleEnumerator** labels)
-{
-  nsresult rv;
-
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(source, &rv));
-  if (NS_SUCCEEDED(rv)) {
-    // Initialise with the number of items below, to save reallocating on each
-    // addition.
-    nsCOMArray<nsIRDFResource> arcs(9);
-
-    arcs.AppendObject(kNC_DirName);
-    arcs.AppendObject(kNC_Child);
-    arcs.AppendObject(kNC_DirUri);
-    arcs.AppendObject(kNC_IsMailList);
-    arcs.AppendObject(kNC_IsRemote);
-    arcs.AppendObject(kNC_IsSecure);
-    arcs.AppendObject(kNC_IsWriteable);
-    arcs.AppendObject(kNC_DirTreeNameSort);
-    arcs.AppendObject(kNC_SupportsMailingLists);
-
-    return NS_NewArrayEnumerator(labels, arcs);
-  }
-  return NS_NewEmptyEnumerator(labels);
-}
-
-NS_IMETHODIMP nsAbDirectoryDataSource::OnItemAdded(nsISupports *parentDirectory, nsISupports *item)
-{
-  nsresult rv;
-  nsCOMPtr<nsIAbDirectory> directory;
-  nsCOMPtr<nsIRDFResource> parentResource;
-
-  if(NS_SUCCEEDED(parentDirectory->QueryInterface(NS_GET_IID(nsIRDFResource), getter_AddRefs(parentResource))))
-  {
-    //If we are adding a directory
-    if (NS_SUCCEEDED(item->QueryInterface(NS_GET_IID(nsIAbDirectory), getter_AddRefs(directory))))
-    {
-      nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
-      if(NS_SUCCEEDED(rv))
-      {
-        //Notify a directory was added.
-        NotifyObservers(parentResource, kNC_Child, itemNode, PR_TRUE, PR_FALSE);
-      }
-    }
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsAbDirectoryDataSource::OnItemRemoved(nsISupports *parentDirectory, nsISupports *item)
-{
-  nsresult rv;
-  nsCOMPtr<nsIAbDirectory> directory;
-  nsCOMPtr<nsIRDFResource> parentResource;
-
-  if(NS_SUCCEEDED(parentDirectory->QueryInterface(NS_GET_IID(nsIRDFResource), getter_AddRefs(parentResource))))
-  {
-    //If we are removing a directory
-    if (NS_SUCCEEDED(item->QueryInterface(NS_GET_IID(nsIAbDirectory), getter_AddRefs(directory))))
-    {
-      nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
-      if(NS_SUCCEEDED(rv))
-      {
-        //Notify a directory was deleted.
-        NotifyObservers(parentResource, kNC_Child, itemNode, PR_FALSE, PR_FALSE);
-      }
-    }
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsAbDirectoryDataSource::OnItemPropertyChanged(nsISupports *item, const char *property,
-                               const PRUnichar *oldValue, const PRUnichar *newValue)
-
-{
-  nsresult rv;
-  nsCOMPtr<nsIRDFResource> resource(do_QueryInterface(item, &rv));
-
-  if (NS_SUCCEEDED(rv))
-  {
-    if (strcmp("DirName", property) == 0)
-    {
-      NotifyPropertyChanged(resource, kNC_DirName, oldValue, newValue);
-    }
-    else if (strcmp("IsSecure", property) == 0)
-    {
-      NotifyPropertyChanged(resource, kNC_IsSecure, oldValue, newValue);
-    }
-  }
-  return NS_OK;
-}
-
-nsresult nsAbDirectoryDataSource::createDirectoryNode(nsIAbDirectory* directory,
-                                                 nsIRDFResource* property,
-                                                 nsIRDFNode** target)
-{
-  nsresult rv = NS_RDF_NO_VALUE;
-
-  if ((kNC_DirName == property))
-    rv = createDirectoryNameNode(directory, target);
-  else if ((kNC_DirUri == property))
-    rv = createDirectoryUriNode(directory, target);
-  else if ((kNC_Child == property))
-    rv = createDirectoryChildNode(directory, target);
-  else if ((kNC_IsMailList == property))
-    rv = createDirectoryIsMailListNode(directory, target);
-  else if ((kNC_IsRemote == property))
-    rv = createDirectoryIsRemoteNode(directory, target);
-  else if ((kNC_IsSecure == property))
-    rv = createDirectoryIsSecureNode(directory, target);
-  else if ((kNC_IsWriteable == property))
-    rv = createDirectoryIsWriteableNode(directory, target);
-  else if ((kNC_DirTreeNameSort == property))
-    rv = createDirectoryTreeNameSortNode(directory, target);
-  else if ((kNC_SupportsMailingLists == property))
-    rv = createDirectorySupportsMailingListsNode(directory, target);
-  return rv;
-}
-
-
-nsresult nsAbDirectoryDataSource::createDirectoryNameNode(nsIAbDirectory *directory,
-                                                     nsIRDFNode **target)
-{
-  nsString name;
-  nsresult rv = directory->GetDirName(name);
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv = createNode(name.get(), target);
-  NS_ENSURE_SUCCESS(rv,rv);
-  return rv;
-}
-
-nsresult nsAbDirectoryDataSource::createDirectoryUriNode(nsIAbDirectory *directory,
-                                                     nsIRDFNode **target)
-{
-  nsCOMPtr<nsIRDFResource> source(do_QueryInterface(directory));
-
-  nsCString uri;
-  nsresult rv = source->GetValue(getter_Copies(uri));
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsAutoString nameString;
-  CopyASCIItoUTF16(uri, nameString);
-  rv = createNode(nameString.get(), target);
-  NS_ENSURE_SUCCESS(rv,rv);
-  return rv;
-}
-
-nsresult
-nsAbDirectoryDataSource::createDirectoryChildNode(nsIAbDirectory *directory,
-                                             nsIRDFNode **target)
-{
-  nsCOMPtr<nsIMutableArray> pAddressLists;
-  directory->GetAddressLists(getter_AddRefs(pAddressLists));
-
-  if (pAddressLists)
-  {
-    PRUint32 total = 0;
-    pAddressLists->GetLength(&total);
-
-    if (total)
-    {
-      PRBool isMailList = PR_FALSE;
-      directory->GetIsMailList(&isMailList);
-      if (!isMailList)
-      {
-        // fetch the last element
-        nsCOMPtr<nsIRDFResource> mailList = do_QueryElementAt(pAddressLists, total - 1);
-        NS_IF_ADDREF(*target = mailList);
-      }
-    } // if total
-  } // if pAddressLists
-
-  return (*target ? NS_OK : NS_RDF_NO_VALUE);
-}
-
-nsresult
-nsAbDirectoryDataSource::createDirectoryIsRemoteNode(nsIAbDirectory* directory,
-                                                     nsIRDFNode **target)
-{
-  PRBool isRemote;
-  nsresult rv = directory->GetIsRemote(&isRemote);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*target = (isRemote ? kTrueLiteral : kFalseLiteral));
-  return NS_OK;
-}
-
-nsresult
-nsAbDirectoryDataSource::createDirectoryIsSecureNode(nsIAbDirectory* directory,
-                                                     nsIRDFNode **target)
-{
-  PRBool IsSecure;
-  nsresult rv = directory->GetIsSecure(&IsSecure);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*target = (IsSecure ? kTrueLiteral : kFalseLiteral));
-  return NS_OK;
-}
-
-nsresult
-nsAbDirectoryDataSource::createDirectoryIsWriteableNode(nsIAbDirectory* directory,
-                                                        nsIRDFNode **target)
-{
-  PRBool isReadOnly;
-  nsresult rv = directory->GetReadOnly(&isReadOnly);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*target = (isReadOnly ? kFalseLiteral : kTrueLiteral));
-  return NS_OK;
-}
-
-nsresult
-nsAbDirectoryDataSource::createDirectoryIsMailListNode(nsIAbDirectory* directory,
-                                                       nsIRDFNode **target)
-{
-  PRBool isMailList;
-  nsresult rv = directory->GetIsMailList(&isMailList);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*target = (isMailList ? kTrueLiteral : kFalseLiteral));
-  return NS_OK;
-}
-
-nsresult
-nsAbDirectoryDataSource::createDirectorySupportsMailingListsNode(nsIAbDirectory* directory,
-                                                                 nsIRDFNode **target)
-{
-  PRBool supportsMailingLists;
-  nsresult rv = directory->GetSupportsMailingLists(&supportsMailingLists);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*target = (supportsMailingLists ? kTrueLiteral : kFalseLiteral));
-  return NS_OK;
-}
-
-nsresult
-nsAbDirectoryDataSource::createDirectoryTreeNameSortNode(nsIAbDirectory* directory, nsIRDFNode **target)
-{
-  nsString name;
-  nsresult rv = directory->GetDirName(name);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  /* sort addressbooks in this order - Personal Addressbook, Collected Addresses, MDB, LDAP -
-   * by prefixing address book names with numbers and using the xul sort service.
-   *
-   *  0Personal Address Book
-   *  1Collected Address Book
-   *  2MAB1
-   *    5MAB1LIST1
-   *    5MAB1LIST2
-   *  2MAB2
-   *    5MAB2LIST1
-   *    5MAB2LIST2
-   *  3LDAP1
-   *  3LDAP2
-   *  4MAPI1
-   *  4MAPI2
-   */
-
-  // Get isMailList
-  PRBool isMailList = PR_FALSE;
-  rv = directory->GetIsMailList(&isMailList);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsAutoString sortString;
-
-  if (isMailList)
-    // Mailing Lists don't need a top level sort position.
-    sortString.AppendInt(5);
-  else
-  {
-    // If its not a mailing list, find out what else we need to know.
-    nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(directory);
-    const char *uri = nsnull;
-    rv = resource->GetValueConst(&uri);
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    // Get directory type.
-    PRInt32 dirType;
-    rv = directory->GetDirType(&dirType);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    PRInt32 position;
-    rv = directory->GetPosition(&position);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // top level sort will be by position. Sort by type under that...
-    sortString.Append((PRUnichar) (position + 'a'));
-
-    if (dirType == PABDirectory)
-    {
-      if (strcmp(uri, kPersonalAddressbookUri) == 0)
-        sortString.AppendInt(0);  // Personal addrbook
-      else if (strcmp(uri, kCollectedAddressbookUri) == 0)
-        sortString.AppendInt(1);  // Collected addrbook
-      else
-        sortString.AppendInt(2);  // Normal addrbook
-    }
-    else if (dirType == LDAPDirectory)
-      sortString.AppendInt(3);    // LDAP addrbook
-    else if (dirType == MAPIDirectory)
-      sortString.AppendInt(4);    // MAPI addrbook
-    else
-      sortString.AppendInt(6);    // everything else comes last
-  }
-
-  sortString += name;
-  PRUint8 *sortKey = nsnull;
-  PRUint32 sortKeyLength;
-  rv = CreateCollationKey(sortString, &sortKey, &sortKeyLength);
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr <nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-  createBlobNode(sortKey, sortKeyLength, target, rdfService);
-  NS_ENSURE_SUCCESS(rv, rv);
-  PR_Free(sortKey);
-
-  return NS_OK;
-
-}
-
-nsresult nsAbDirectoryDataSource::CreateCollationKey(const nsString &aSource,  PRUint8 **aKey, PRUint32 *aLength)
-{
-  NS_ENSURE_ARG_POINTER(aKey);
-  NS_ENSURE_ARG_POINTER(aLength);
-
-  nsresult rv;
-  if (!mCollationKeyGenerator)
-  {
-    nsCOMPtr<nsILocaleService> localeSvc = do_GetService(NS_LOCALESERVICE_CONTRACTID,&rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsILocale> locale;
-    rv = localeSvc->GetApplicationLocale(getter_AddRefs(locale));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr <nsICollationFactory> factory = do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = factory->CreateCollation(locale, getter_AddRefs(mCollationKeyGenerator));
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-
-  return mCollationKeyGenerator->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive, aSource, aKey, aLength);
-}
-
-nsresult nsAbDirectoryDataSource::DoDirectoryAssert(nsIAbDirectory *directory, nsIRDFResource *property, nsIRDFNode *target)
-{
-  return NS_ERROR_FAILURE;
-}
-
-
-nsresult nsAbDirectoryDataSource::DoDirectoryHasAssertion(nsIAbDirectory *directory, nsIRDFResource *property, nsIRDFNode *target,
-                           PRBool tv, PRBool *hasAssertion)
-{
-  nsresult rv = NS_OK;
-  if (!hasAssertion)
-    return NS_ERROR_NULL_POINTER;
-
-  //We're not keeping track of negative assertions on directory.
-  if (!tv)
-  {
-    *hasAssertion = PR_FALSE;
-    return NS_OK;
-  }
-
-  if ((kNC_Child == property))
-  {
-    nsCOMPtr<nsIAbDirectory> newDirectory(do_QueryInterface(target, &rv));
-    if(NS_SUCCEEDED(rv))
-      rv = directory->HasDirectory(newDirectory, hasAssertion);
-  }
-  else if ((kNC_IsMailList == property) || (kNC_IsRemote == property) ||
-            (kNC_IsSecure == property) || (kNC_IsWriteable == property) ||
-            (kNC_SupportsMailingLists == property))
-  {
-    nsCOMPtr<nsIRDFResource> dirResource(do_QueryInterface(directory, &rv));
-    NS_ENSURE_SUCCESS(rv, rv);
-    rv = GetTargetHasAssertion(this, dirResource, property, tv, target, hasAssertion);
-  }
-  else
-    *hasAssertion = PR_FALSE;
-
-  return rv;
-
-}
-
-nsresult nsAbDirectoryDataSource::GetTargetHasAssertion(nsIRDFDataSource *dataSource, nsIRDFResource* dirResource,
-                 nsIRDFResource *property,PRBool tv, nsIRDFNode *target,PRBool* hasAssertion)
-{
-  nsresult rv;
-  if(!hasAssertion)
-    return NS_ERROR_NULL_POINTER;
-
-  nsCOMPtr<nsIRDFNode> currentTarget;
-
-  rv = dataSource->GetTarget(dirResource, property,tv, getter_AddRefs(currentTarget));
-  if(NS_SUCCEEDED(rv))
-  {
-    nsCOMPtr<nsIRDFLiteral> value1(do_QueryInterface(target));
-    nsCOMPtr<nsIRDFLiteral> value2(do_QueryInterface(currentTarget));
-    if(value1 && value2)
-      //If the two values are equal then it has this assertion
-      *hasAssertion = (value1 == value2);
-  }
-  else
-    rv = NS_NOINTERFACE;
-
-  return rv;
-
-}
deleted file mode 100644
--- a/mailnews/addrbook/src/nsDirectoryDataSource.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Seth Spitzer <sspitzer@netscape.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-#ifndef __nsDirectoryDataSource_h
-#define __nsDirectoryDataSource_h
- 
-
-#include "nsAbRDFDataSource.h"
-#include "nsIRDFService.h"
-#include "nsIAbListener.h"
-#include "nsIAbDirectory.h"
-#include "nsDirPrefs.h"
-#include "nsIAbListener.h"
-#include "nsIObserver.h"
-#include "nsWeakReference.h"
-#include "nsICollation.h"
-
-/**
- * The addressbook data source.
- */
-class nsAbDirectoryDataSource : public nsAbRDFDataSource,
-                  public nsIAbListener, public nsIObserver, public nsSupportsWeakReference
-{
-private:
-  PRBool  mInitialized;
-
-public:
-  
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_NSIABLISTENER
-  NS_DECL_NSIOBSERVER
-
-  nsAbDirectoryDataSource(void);
-  virtual ~nsAbDirectoryDataSource (void);
-  virtual nsresult Init();
-
-  // nsIRDFDataSource methods
-  NS_IMETHOD GetURI(char* *uri);
-
-  NS_IMETHOD GetTarget(nsIRDFResource* source,
-             nsIRDFResource* property,
-             PRBool tv,
-             nsIRDFNode** target);
-
-  NS_IMETHOD GetTargets(nsIRDFResource* source,
-            nsIRDFResource* property,    
-            PRBool tv,
-            nsISimpleEnumerator** targets);
-
-  NS_IMETHOD Assert(nsIRDFResource* source,
-          nsIRDFResource* property, 
-          nsIRDFNode* target,
-          PRBool tv);
-
-  NS_IMETHOD HasAssertion(nsIRDFResource* source,
-              nsIRDFResource* property,
-              nsIRDFNode* target,
-              PRBool tv,
-              PRBool* hasAssertion);
-
-  NS_IMETHOD HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *result);
-
-  NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
-              nsISimpleEnumerator** labels); 
-
-protected:
-
-  nsresult createDirectoryNode(nsIAbDirectory* directory, nsIRDFResource* property,
-                                 nsIRDFNode** target);
-  nsresult createDirectoryNameNode(nsIAbDirectory *directory,
-                                     nsIRDFNode **target);
-  nsresult createDirectoryUriNode(nsIAbDirectory *directory,
-                                     nsIRDFNode **target);
-  nsresult createDirectoryChildNode(nsIAbDirectory *directory,
-                                      nsIRDFNode **target);
-  nsresult createDirectoryIsMailListNode(nsIAbDirectory *directory,
-                                      nsIRDFNode **target);
-  nsresult createDirectoryIsRemoteNode(nsIAbDirectory *directory,
-    nsIRDFNode **target);
-  nsresult createDirectoryIsSecureNode(nsIAbDirectory *directory,
-    nsIRDFNode **target);
-  nsresult createDirectoryIsWriteableNode(nsIAbDirectory *directory,
-                                            nsIRDFNode **target);
-  nsresult createDirectorySupportsMailingListsNode(nsIAbDirectory* directory,
-                                                   nsIRDFNode **target);
-  nsresult createDirectoryTreeNameSortNode(nsIAbDirectory *directory,
-                                            nsIRDFNode **target);
-
-  nsresult DoDirectoryAssert(nsIAbDirectory *directory, 
-          nsIRDFResource *property, nsIRDFNode *target);
-  nsresult DoDirectoryHasAssertion(nsIAbDirectory *directory, 
-               nsIRDFResource *property, nsIRDFNode *target,
-               PRBool tv, PRBool *hasAssertion);
-
-  nsresult GetTargetHasAssertion(nsIRDFDataSource *dataSource, nsIRDFResource* dirResource,
-                 nsIRDFResource *property,PRBool tv, nsIRDFNode *target,PRBool* hasAssertion);
-  nsresult CreateCollationKey(const nsString &aSource,  PRUint8 **aKey, PRUint32 *aLength);
-
-  nsCOMPtr<nsIRDFResource> kNC_Child;
-  nsCOMPtr<nsIRDFResource> kNC_DirName;
-  nsCOMPtr<nsIRDFResource> kNC_DirUri;
-  nsCOMPtr<nsIRDFResource> kNC_IsMailList;
-  nsCOMPtr<nsIRDFResource> kNC_IsRemote;
-  nsCOMPtr<nsIRDFResource> kNC_IsSecure;
-  nsCOMPtr<nsIRDFResource> kNC_IsWriteable;
-  nsCOMPtr<nsIRDFResource> kNC_DirTreeNameSort;
-  nsCOMPtr<nsIRDFResource> kNC_SupportsMailingLists;
-  nsCOMPtr<nsICollation> mCollationKeyGenerator;
-
-  //Cached literals
-  nsCOMPtr<nsIRDFNode> kTrueLiteral;
-  nsCOMPtr<nsIRDFNode> kFalseLiteral;
-
-private:
-  nsresult Cleanup();
-};
-
-#endif
--- a/mailnews/addrbook/test/unit/test_nsAbManager2.js
+++ b/mailnews/addrbook/test/unit/test_nsAbManager2.js
@@ -117,17 +117,17 @@ function run_test() {
   for (i = 0; i < numListenerOptions; ++i) {
     gAblSingle[i] = new abL;
     gAbManager.addAddressBookListener(gAblSingle[i], 1 << i);
   }
 
   var expectedABs = [kPABData.URI, kCABData.URI];
 
   // Check the OS X Address Book if available
-  if ("@mozilla.org/rdf/resource-factory;1?name=moz-abosxdirectory" in
+  if ("@mozilla.org/addressbook/directory;1?type=moz-abosxdirectory" in
       Components.classes)
     expectedABs.push(kOSXData.URI);
 
   // Test - Check initial directories
 
   checkDirs(gAbManager.directories, expectedABs);
 
   // Test - Add a directory
--- a/mailnews/base/search/src/nsMsgSearchTerm.cpp
+++ b/mailnews/base/search/src/nsMsgSearchTerm.cpp
@@ -57,30 +57,31 @@
 #include "nsMsgSearchValue.h"
 #include "nsMsgI18N.h"
 #include "nsIMimeConverter.h"
 #include "nsMsgMimeCID.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsIMsgFilterPlugin.h"
 #include "nsILocalFile.h"
-#include "nsIRDFService.h"
 #include "nsISupportsObsolete.h"
 #include "nsNetCID.h"
 #include "nsIFileStreams.h"
 #include "nsUnicharUtils.h"
 #include "nsIAbCard.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsMemory.h"
 #include <ctype.h>
 #include "nsMsgBaseCID.h"
 #include "nsIMsgTagService.h"
 #include "nsMsgMessageFlags.h"
 #include "nsIMsgFilterService.h"
+#include "nsAbBaseCID.h"
+#include "nsIAbManager.h"
 
 //---------------------------------------------------------------------------
 // nsMsgSearchTerm specifies one criterion, e.g. name contains phil
 //---------------------------------------------------------------------------
 
 
 //-----------------------------------------------------------------------------
 //-------------------- Implementation of nsMsgSearchTerm -----------------------
@@ -1026,24 +1027,20 @@ nsresult nsMsgSearchTerm::InitializeAddr
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!uri.Equals(m_value.string))
       // clear out the directory....we are no longer pointing to the right one
       mDirectory = nsnull;
   }
   if (!mDirectory)
   {
-    nsCOMPtr <nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);
+    nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr <nsIRDFResource> resource;
-    rv = rdfService->GetResource(nsDependentCString(m_value.string), getter_AddRefs(resource));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    mDirectory = do_QueryInterface(resource, &rv);
+    rv = abManager->GetDirectory(nsDependentCString(m_value.string), getter_AddRefs(mDirectory));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 nsresult nsMsgSearchTerm::MatchInAddressBook(const char * aAddress, PRBool *pResult)
 {
--- a/mailnews/build/nsMailModule.cpp
+++ b/mailnews/build/nsMailModule.cpp
@@ -148,17 +148,16 @@
 #include "nsMessengerContentHandler.h"
 #include "nsStopwatch.h"
 #include "MailNewsDLF.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 // addrbook includes
 ////////////////////////////////////////////////////////////////////////////////
 #include "nsAbBaseCID.h"
-#include "nsDirectoryDataSource.h"
 #include "nsAbBSDirectory.h"
 #include "nsAbMDBDirectory.h"
 #include "nsAbMDBCard.h"
 #include "nsAbDirFactoryService.h"
 #include "nsAbMDBDirFactory.h"
 #include "nsAddrDatabase.h"
 #include "nsAbManager.h"
 #include "nsAbContentHandler.h"
@@ -185,16 +184,17 @@
 #include "nsAbLDAPReplicationData.h"
 // XXX These files are not being built as they don't work. Bug 311632 should
 // fix them.
 //#include "nsAbLDAPChangeLogQuery.h"
 //#include "nsAbLDAPChangeLogData.h"
 #include "nsLDAPAutoCompleteSession.h"
 #endif
 
+
 #if defined(XP_WIN) && !defined(__MINGW32__)
 #include "nsAbOutlookDirFactory.h"
 #include "nsAbOutlookDirectory.h"
 #endif
 
 #ifdef XP_MACOSX
 #include "nsAbOSXDirectory.h"
 #include "nsAbOSXCard.h"
@@ -459,17 +459,16 @@ NS_DEFINE_NAMED_CID(MAILDIRPROVIDER_CID)
 NS_DEFINE_NAMED_CID(NS_STOPWATCH_CID);
 NS_DEFINE_NAMED_CID(NS_MAILNEWSDLF_CID);
 
 ////////////////////////////////////////////////////////////////////////////////
 // addrbook factories
 ////////////////////////////////////////////////////////////////////////////////
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAbManager,Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbContentHandler)
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAbDirectoryDataSource,Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirProperty)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbCardProperty)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbBSDirectory)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbMDBDirectory)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbMDBCard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddrDatabase)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAbAddressCollector,Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddbookUrl)
@@ -481,45 +480,46 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddbook
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbOutlookDirectory)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbOutlookDirFactory)
 #endif
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirectoryQueryArguments)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbBooleanConditionString)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbBooleanExpression)
 
+
 #if defined(MOZ_LDAP_XPCOM)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPDirectory)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPDirectoryQuery)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPCard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPDirFactory)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPAutoCompFormatter)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPReplicationService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPReplicationQuery)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPProcessReplicationData)
 // XXX These files are not being built as they don't work. Bug 311632 should
 // fix them.
 //NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPChangeLogQuery)
 //NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDAPProcessChangeLogData)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPAutoCompleteSession)
 #endif
 
+
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirectoryQueryProxy)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbView)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgVCardService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbLDIFService)
 
 #ifdef XP_MACOSX
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbOSXDirectory)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbOSXCard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbOSXDirFactory)
 #endif
 
 NS_DEFINE_NAMED_CID(NS_ABMANAGER_CID);
-NS_DEFINE_NAMED_CID(NS_ABDIRECTORYDATASOURCE_CID);
 NS_DEFINE_NAMED_CID(NS_ABDIRECTORY_CID);
 NS_DEFINE_NAMED_CID(NS_ABMDBDIRECTORY_CID);
 NS_DEFINE_NAMED_CID(NS_ABMDBCARD_CID);
 NS_DEFINE_NAMED_CID(NS_ADDRDATABASE_CID);
 NS_DEFINE_NAMED_CID(NS_ABCARDPROPERTY_CID);
 NS_DEFINE_NAMED_CID(NS_ABDIRPROPERTY_CID);
 NS_DEFINE_NAMED_CID(NS_ABADDRESSCOLLECTOR_CID);
 NS_DEFINE_NAMED_CID(NS_ADDBOOKURL_CID);
@@ -529,16 +529,17 @@ NS_DEFINE_NAMED_CID(NS_ABDIRFACTORYSERVI
 NS_DEFINE_NAMED_CID(NS_ABMDBDIRFACTORY_CID);
 NS_DEFINE_NAMED_CID(NS_ABDIRECTORYQUERYARGUMENTS_CID);
 NS_DEFINE_NAMED_CID(NS_BOOLEANCONDITIONSTRING_CID);
 NS_DEFINE_NAMED_CID(NS_BOOLEANEXPRESSION_CID);
 #if defined(XP_WIN) && !defined(__MINGW32__)
 NS_DEFINE_NAMED_CID(NS_ABOUTLOOKDIRECTORY_CID);
 NS_DEFINE_NAMED_CID(NS_ABOUTLOOKDIRFACTORY_CID);
 #endif
+
 #if defined(MOZ_LDAP_XPCOM)
 NS_DEFINE_NAMED_CID(NS_ABLDAPDIRECTORY_CID);
 NS_DEFINE_NAMED_CID(NS_ABLDAPDIRECTORYQUERY_CID);
 NS_DEFINE_NAMED_CID(NS_ABLDAPCARD_CID);
 NS_DEFINE_NAMED_CID(NS_ABLDAPDIRFACTORY_CID);
 NS_DEFINE_NAMED_CID(NS_ABLDAP_REPLICATIONSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_ABLDAP_REPLICATIONQUERY_CID);
 NS_DEFINE_NAMED_CID(NS_ABLDAP_PROCESSREPLICATIONDATA_CID);
@@ -853,17 +854,16 @@ const mozilla::Module::CIDEntry kMailNew
   { &kNS_MESSENGERCONTENTHANDLER_CID, false, NULL, nsMessengerContentHandlerConstructor},
   { &kNS_MSGCONTENTPOLICY_CID, false, NULL, nsMsgContentPolicyConstructor},
   { &kNS_MSGSHUTDOWNSERVICE_CID, false, NULL, nsMsgShutdownServiceConstructor},
   { &kMAILDIRPROVIDER_CID, false, NULL, nsMailDirProviderConstructor},
   { &kNS_STOPWATCH_CID, false, NULL, nsStopwatchConstructor},
   { &kNS_MAILNEWSDLF_CID, false, NULL, MailNewsDLFConstructor},
   // Address Book Entries
   { &kNS_ABMANAGER_CID, false, NULL, nsAbManagerConstructor },
-  { &kNS_ABDIRECTORYDATASOURCE_CID, false, NULL, nsAbDirectoryDataSourceConstructor },
   { &kNS_ABDIRECTORY_CID, false, NULL, nsAbBSDirectoryConstructor },
   { &kNS_ABMDBDIRECTORY_CID, false, NULL, nsAbMDBDirectoryConstructor },
   { &kNS_ABMDBCARD_CID, false, NULL, nsAbMDBCardConstructor },
   { &kNS_ADDRDATABASE_CID, false, NULL, nsAddrDatabaseConstructor },
   { &kNS_ABCARDPROPERTY_CID, false, NULL, nsAbCardPropertyConstructor },
   { &kNS_ABDIRPROPERTY_CID, false, NULL, nsAbDirPropertyConstructor },
   { &kNS_ABADDRESSCOLLECTOR_CID, false, NULL, nsAbAddressCollectorConstructor },
   { &kNS_ADDBOOKURL_CID, false, NULL, nsAddbookUrlConstructor },
@@ -874,16 +874,17 @@ const mozilla::Module::CIDEntry kMailNew
   { &kNS_ABMDBDIRFACTORY_CID, false, NULL, nsAbMDBDirFactoryConstructor },
 #if defined(XP_WIN) && !defined(__MINGW32__)
   { &kNS_ABOUTLOOKDIRECTORY_CID, false, NULL, nsAbOutlookDirectoryConstructor },
   { &kNS_ABOUTLOOKDIRFACTORY_CID, false, NULL, nsAbOutlookDirFactoryConstructor },
 #endif
   { &kNS_ABDIRECTORYQUERYARGUMENTS_CID, false, NULL, nsAbDirectoryQueryArgumentsConstructor },
   { &kNS_BOOLEANCONDITIONSTRING_CID, false, NULL, nsAbBooleanConditionStringConstructor },
   { &kNS_BOOLEANEXPRESSION_CID, false, NULL, nsAbBooleanExpressionConstructor },
+
 #if defined(MOZ_LDAP_XPCOM)
   { &kNS_ABLDAPDIRECTORY_CID, false, NULL, nsAbLDAPDirectoryConstructor },
   { &kNS_ABLDAPDIRECTORYQUERY_CID, false, NULL, nsAbLDAPDirectoryQueryConstructor },
   { &kNS_ABLDAPCARD_CID, false, NULL, nsAbLDAPCardConstructor },
   { &kNS_ABLDAP_REPLICATIONSERVICE_CID, false, NULL, nsAbLDAPReplicationServiceConstructor },
   { &kNS_ABLDAP_REPLICATIONQUERY_CID, false, NULL, nsAbLDAPReplicationQueryConstructor },
   { &kNS_ABLDAP_PROCESSREPLICATIONDATA_CID, false, NULL, nsAbLDAPProcessReplicationDataConstructor },
   { &kNS_ABLDAPDIRFACTORY_CID, false, NULL, nsAbLDAPDirFactoryConstructor },
@@ -1050,17 +1051,16 @@ const mozilla::Module::ContractIDEntry k
   { NS_MSGCONTENTPOLICY_CONTRACTID, &kNS_MSGCONTENTPOLICY_CID },
   { NS_MSGSHUTDOWNSERVICE_CONTRACTID, &kNS_MSGSHUTDOWNSERVICE_CID },
   { NS_MAILDIRPROVIDER_CONTRACTID, &kMAILDIRPROVIDER_CID },
   { NS_STOPWATCH_CONTRACTID, &kNS_STOPWATCH_CID },
   { NS_MAILNEWSDLF_CONTRACTID, &kNS_MAILNEWSDLF_CID },
   // Address Book Entries
   { NS_ABMANAGER_CONTRACTID, &kNS_ABMANAGER_CID },
   { NS_ABMANAGERSTARTUPHANDLER_CONTRACTID, &kNS_ABMANAGER_CID },
-  { NS_ABDIRECTORYDATASOURCE_CONTRACTID, &kNS_ABDIRECTORYDATASOURCE_CID },
   { NS_ABDIRECTORY_CONTRACTID, &kNS_ABDIRECTORY_CID },
   { NS_ABMDBDIRECTORY_CONTRACTID, &kNS_ABMDBDIRECTORY_CID },
   { NS_ABMDBCARD_CONTRACTID, &kNS_ABMDBCARD_CID },
   { NS_ADDRDATABASE_CONTRACTID, &kNS_ADDRDATABASE_CID },
   { NS_ABCARDPROPERTY_CONTRACTID, &kNS_ABCARDPROPERTY_CID },
   { NS_ABDIRPROPERTY_CONTRACTID, &kNS_ABDIRPROPERTY_CID },
   { NS_ABADDRESSCOLLECTOR_CONTRACTID, &kNS_ABADDRESSCOLLECTOR_CID },
   { NS_ADDBOOKURL_CONTRACTID, &kNS_ADDBOOKURL_CID },
@@ -1071,29 +1071,31 @@ const mozilla::Module::ContractIDEntry k
   { NS_ABMDBDIRFACTORY_CONTRACTID, &kNS_ABMDBDIRFACTORY_CID },
 #if defined(XP_WIN) && !defined(__MINGW32__)
   { NS_ABOUTLOOKDIRECTORY_CONTRACTID, &kNS_ABOUTLOOKDIRECTORY_CID },
   { NS_ABOUTLOOKDIRFACTORY_CONTRACTID, &kNS_ABOUTLOOKDIRFACTORY_CID },
 #endif
   { NS_ABDIRECTORYQUERYARGUMENTS_CONTRACTID, &kNS_ABDIRECTORYQUERYARGUMENTS_CID },
   { NS_BOOLEANCONDITIONSTRING_CONTRACTID, &kNS_BOOLEANCONDITIONSTRING_CID },
   { NS_BOOLEANEXPRESSION_CONTRACTID, &kNS_BOOLEANEXPRESSION_CID },
+
 #if defined(MOZ_LDAP_XPCOM)
   { NS_ABLDAPDIRECTORY_CONTRACTID, &kNS_ABLDAPDIRECTORY_CID },
   { NS_ABLDAPDIRECTORYQUERY_CONTRACTID, &kNS_ABLDAPDIRECTORYQUERY_CID },
   { NS_ABLDAPCARD_CONTRACTID, &kNS_ABLDAPCARD_CID },
   { NS_ABLDAPDIRFACTORY_CONTRACTID, &kNS_ABLDAPDIRFACTORY_CID },
   { NS_ABLDAP_REPLICATIONSERVICE_CONTRACTID, &kNS_ABLDAP_REPLICATIONSERVICE_CID },
   { NS_ABLDAP_REPLICATIONQUERY_CONTRACTID, &kNS_ABLDAP_REPLICATIONQUERY_CID },
   { NS_ABLDAP_PROCESSREPLICATIONDATA_CONTRACTID, &kNS_ABLDAP_PROCESSREPLICATIONDATA_CID },
   { NS_ABLDAPACDIRFACTORY_CONTRACTID, &kNS_ABLDAPDIRFACTORY_CID },
   { NS_ABLDAPSACDIRFACTORY_CONTRACTID, &kNS_ABLDAPDIRFACTORY_CID },
   { NS_ABLDAPAUTOCOMPFORMATTER_CONTRACTID, &kNS_ABLDAPAUTOCOMPFORMATTER_CID },
   { "@mozilla.org/autocompleteSession;1?type=ldap", &kNS_LDAPAUTOCOMPLETESESSION_CID },
 #endif
+
   { NS_ABDIRECTORYQUERYPROXY_CONTRACTID, &kNS_ABDIRECTORYQUERYPROXY_CID },
 #ifdef XP_MACOSX
   { NS_ABOSXDIRECTORY_CONTRACTID, &kNS_ABOSXDIRECTORY_CID },
   { NS_ABOSXCARD_CONTRACTID, &kNS_ABOSXCARD_CID },
   { NS_ABOSXDIRFACTORY_CONTRACTID, &kNS_ABOSXDIRFACTORY_CID },
 #endif
   { NS_ABVIEW_CONTRACTID, &kNS_ABVIEW_CID },
   { NS_MSGVCARDSERVICE_CONTRACTID, &kNS_MSGVCARDSERVICE_CID },
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -108,16 +108,17 @@
 #include "nsIMsgProgress.h"
 #include "nsMsgFolderFlags.h"
 #include "nsIMsgDatabase.h"
 #include "nsStringStream.h"
 #include "nsIMutableArray.h"
 #include "nsArrayUtils.h"
 #include "nsIMsgWindow.h"
 #include "nsITextToSubURI.h"
+#include "nsIAbManager.h"
 
 static void GetReplyHeaderInfo(PRInt32* reply_header_type,
                                nsString& reply_header_locale,
                                nsString& reply_header_authorwrote,
                                nsString& reply_header_ondate,
                                nsString& reply_header_separator,
                                nsString& reply_header_colon,
                                nsString& reply_header_originalmessage)
@@ -4466,30 +4467,28 @@ nsresult nsMsgCompose::AttachmentPrettyN
   }
   if (MsgLowerCaseEqualsLiteral(StringHead(scheme, 5), "http:"))
     _retval.Cut(0, 7);
 
   return NS_OK;
 }
 
 nsresult nsMsgCompose::GetABDirectories(const nsACString& aDirUri,
-                                        nsIRDFService *aRDFService,
                                         nsCOMArray<nsIAbDirectory> &aDirArray)
 {
   static PRBool collectedAddressbookFound;
   if (aDirUri.EqualsLiteral(kMDBDirectoryRoot))
     collectedAddressbookFound = PR_FALSE;
 
   nsresult rv;
-  nsCOMPtr<nsIRDFResource> resource;
-  rv = aRDFService->GetResource(aDirUri, getter_AddRefs(resource));
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // query interface
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = abManager->GetDirectory(aDirUri, getter_AddRefs(directory));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISimpleEnumerator> subDirectories;
   if (NS_SUCCEEDED(directory->GetChildNodes(getter_AddRefs(subDirectories))) && subDirectories)
   {
     nsCOMPtr<nsISupports> item;
     PRBool hasMore;
     while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore)
@@ -4525,17 +4524,17 @@ nsresult nsMsgCompose::GetABDirectories(
               if (collectedAddressbookFound && count > 1)
                 pos = count - 1;
               else
                 pos = count;
             }
           }
 
           aDirArray.InsertObjectAt(directory, pos);
-          rv = GetABDirectories(uri, aRDFService, aDirArray);
+          rv = GetABDirectories(uri, aDirArray);
         }
       }
     }
   }
   return rv;
 }
 
 nsresult nsMsgCompose::BuildMailListArray(nsIAbDirectory* parentDir,
@@ -4661,21 +4660,18 @@ nsMsgCompose::CheckAndPopulateRecipients
   PRBool stillNeedToSearch = PR_TRUE;
   nsCOMPtr<nsIAbDirectory> abDirectory;
   nsCOMPtr<nsIAbCard> existingCard;
   nsCOMPtr<nsIMutableArray> mailListAddresses;
   nsCOMPtr<nsIMsgHeaderParser> parser(do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID));
   nsCOMPtr<nsISupportsArray> mailListArray(do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIRDFService> rdfService(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMArray<nsIAbDirectory> addrbookDirArray;
-  rv = GetABDirectories(NS_LITERAL_CSTRING(kAllDirectoryRoot), rdfService,
+  rv = GetABDirectories(NS_LITERAL_CSTRING(kAllDirectoryRoot),
                         addrbookDirArray);
   if (NS_SUCCEEDED(rv))
   {
     nsString dirPath;
     PRUint32 nbrAddressbook = addrbookDirArray.Count();
 
     for (k = 0; k < nbrAddressbook && stillNeedToSearch; ++k)
     {
--- a/mailnews/compose/src/nsMsgCompose.h
+++ b/mailnews/compose/src/nsMsgCompose.h
@@ -104,17 +104,16 @@ private:
   //m_folderName to store the value of the saved drafts folder.
   nsCString                     m_folderName;
 
  private:
   nsresult _SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *identity, const char *accountKey, PRBool entityConversionDone);
   nsresult CreateMessage(const char * originalMsgURI, MSG_ComposeType type, nsIMsgCompFields* compFields);
   void CleanUpRecipients(nsString& recipients);
   nsresult GetABDirectories(const nsACString& aDirUri,
-                            nsIRDFService *aRDFService,
                             nsCOMArray<nsIAbDirectory> &aDirArray);
   nsresult BuildMailListArray(nsIAbDirectory* parentDir,
                               nsISupportsArray* array);
   nsresult GetMailListAddresses(nsString& name, nsISupportsArray* mailListArray, nsIMutableArray** addresses);
   nsresult TagConvertible(nsIDOMNode *node,  PRInt32 *_retval);
   nsresult _BodyConvertible(nsIDOMNode *node, PRInt32 *_retval);
 
   PRBool IsLastWindow();
--- a/mailnews/import/src/nsImportAddressBooks.cpp
+++ b/mailnews/import/src/nsImportAddressBooks.cpp
@@ -44,31 +44,31 @@
 #include "nsISupportsPrimitives.h"
 #include "nsIImportABDescriptor.h"
 #include "nsIImportFieldMap.h"
 #include "nsStringGlue.h"
 #include "nsILocalFile.h"
 #include "nsIAddrDatabase.h"
 #include "nsIAbManager.h"
 #include "nsIAbLDIFService.h"
-#include "nsIRDFService.h"
-#include "nsRDFCID.h"
 #include "nsAbBaseCID.h"
 #include "nsIStringBundle.h"
 #include "nsImportStringBundle.h"
 #include "nsTextFormatter.h"
 #include "nsIProxyObjectManager.h"
 #include "nsServiceManagerUtils.h"
 #include "msgCore.h"
 #include "ImportDebug.h"
 #include "nsIAbMDBDirectory.h"
 #include "nsComponentManagerUtils.h"
 #include "nsXPCOMCIDInternal.h"
+#include "nsISupportsArray.h"
+#include "nsProxiedService.h"
+#include "nsCOMArray.h"
 
-static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
 static void ImportAddressThread( void *stuff);
 
 
 class AddressThreadData;
 
 class nsImportGenericAddressBooks : public nsIImportGeneric
 {
 public:
@@ -102,17 +102,18 @@ private:
 
 public:
   static void  SetLogs( nsString& success, nsString& error, nsISupportsString *pSuccess, nsISupportsString *pError);
   static void ReportError(const PRUnichar *pName, nsString *pStream,
                           nsIStringBundle *aBundle);
 
 private:
   nsIImportAddressBooks *    m_pInterface;
-  nsISupportsArray *      m_pBooks;
+  nsISupportsArray *m_pBooks;
+  nsCOMArray<nsIAddrDatabase> m_DBs;
   nsCOMPtr <nsIFile>              m_pLocation;
   nsIImportFieldMap *      m_pFieldMap;
   PRBool            m_autoFind;
   PRUnichar *          m_description;
   PRBool            m_gotLocation;
   PRBool            m_found;
   PRBool            m_userVerify;
   nsISupportsString *    m_pSuccessLog;
@@ -128,16 +129,17 @@ class AddressThreadData {
 public:
   PRBool            driverAlive;
   PRBool            threadAlive;
   PRBool            abort;
   PRBool            fatalError;
   PRUint32          currentTotal;
   PRUint32          currentSize;
   nsISupportsArray *      books;
+  nsCOMArray<nsIAddrDatabase>* dBs;
   nsIAbLDIFService *ldifService;
   nsIImportAddressBooks *    addressImport;
   nsIImportFieldMap *      fieldMap;
   nsISupportsString *    successLog;
   nsISupportsString *    errorLog;
   char *            pDestinationUri;
     nsIStringBundle*            stringBundle;
 
@@ -527,16 +529,123 @@ void nsImportGenericAddressBooks::SetLog
   }
   if (pError) {
     pError->GetData(str);
         str.Append(error);
         pError->SetData(error);
   }
 }
 
+already_AddRefed<nsIAddrDatabase> GetAddressBookFromUri(const char *pUri)
+{
+  if (!pUri)
+    return nsnull;
+
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID);
+  if (!abManager)
+    return nsnull;
+
+  nsCOMPtr<nsIAbDirectory> directory;
+  abManager->GetDirectory(nsDependentCString(pUri),
+                          getter_AddRefs(directory));
+  if (!directory)
+    return nsnull;
+
+  nsCOMPtr<nsIAbMDBDirectory> mdbDirectory = do_QueryInterface(directory);
+  if (!mdbDirectory)
+    return nsnull;
+
+  nsIAddrDatabase *pDatabase = nsnull;
+  mdbDirectory->GetDatabase(&pDatabase);
+  return pDatabase;
+}
+
+already_AddRefed<nsIAddrDatabase> GetAddressBook(const PRUnichar *name,
+                                                 PRBool makeNew)
+{
+  if (!makeNew) {
+    // FIXME: How do I get the list of address books and look for a
+    // specific name.  Major bogosity!
+    // For now, assume we didn't find anything with that name
+  }
+
+  IMPORT_LOG0( "In GetAddressBook\n");
+
+  nsresult rv;
+  nsIAddrDatabase *pDatabase = nsnull;
+  nsCOMPtr<nsILocalFile> dbPath;
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
+  if (NS_SUCCEEDED(rv))
+  {
+    /* Get the profile directory */
+    rv = abManager->GetUserProfileDirectory(getter_AddRefs(dbPath));
+    if (NS_SUCCEEDED(rv))
+    {
+      // Create a new address book file - we don't care what the file
+      // name is, as long as it's unique
+      rv = dbPath->Append(NS_LITERAL_STRING("impab.mab"));
+      if (NS_SUCCEEDED(rv))
+      {
+        rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
+
+        if (NS_SUCCEEDED(rv))
+        {
+          IMPORT_LOG0( "Getting the address database factory\n");
+
+          nsCOMPtr<nsIAddrDatabase> addrDBFactory =
+            do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
+          if (NS_FAILED(rv))
+            return nsnull;
+
+          IMPORT_LOG0( "Opening the new address book\n");
+          rv = addrDBFactory->Open(dbPath, PR_TRUE, PR_TRUE,
+                                   &pDatabase);
+        }
+      }
+    }
+  }
+  if (NS_FAILED(rv))
+  {
+    IMPORT_LOG0( "Failed to get the user profile directory from the address book session\n");
+  }
+
+  if (pDatabase && dbPath)
+  {
+    // We made a database, add it to the UI?!?!?!?!?!?!
+    // This is major bogosity again!  Why doesn't the address book
+    // just handle this properly for me?  Uggggg...
+
+    nsCOMPtr<nsIAbDirectory> parentDir;
+    abManager->GetDirectory(NS_LITERAL_CSTRING(kAllDirectoryRoot),
+                            getter_AddRefs(parentDir));
+    if (parentDir)
+    {
+      nsCAutoString URI("moz-abmdbdirectory://");
+      nsCAutoString leafName;
+      rv = dbPath->GetNativeLeafName(leafName);
+      if (NS_FAILED(rv))
+        IMPORT_LOG0( "*** Error: Unable to get name of database file\n");
+      else
+      {
+        URI.Append(leafName);
+        rv = parentDir->CreateDirectoryByURI(nsDependentString(name), URI);
+        if (NS_FAILED(rv))
+          IMPORT_LOG0( "*** Error: Unable to create address book directory\n");
+      }
+    }
+
+    if (NS_SUCCEEDED(rv))
+      IMPORT_LOG0( "Added new address book to the UI\n");
+    else
+      IMPORT_LOG0( "*** Error: An error occurred while adding the address book to the UI\n");
+  }
+
+  return pDatabase;
+}
+
 NS_IMETHODIMP nsImportGenericAddressBooks::BeginImport(nsISupportsString *successLog, nsISupportsString *errorLog, PRBool *_retval)
 {
   NS_PRECONDITION(_retval != nsnull, "null ptr");
     if (!_retval)
         return NS_ERROR_NULL_POINTER;
 
   nsString  success;
   nsString  error;
@@ -591,16 +700,38 @@ NS_IMETHODIMP nsImportGenericAddressBook
   NS_IF_ADDREF( m_pFieldMap);
   m_pThreadData->errorLog = m_pErrorLog;
   NS_IF_ADDREF( m_pErrorLog);
   m_pThreadData->successLog = m_pSuccessLog;
   NS_IF_ADDREF( m_pSuccessLog);
   if (m_pDestinationUri)
     m_pThreadData->pDestinationUri = strdup( m_pDestinationUri);
 
+  PRUint32 count = 0;
+  m_pBooks->Count(&count);
+  // Create/obtain any address books that we need here, so that we don't need
+  // to do so inside the import thread which would just proxy the create
+  // operations back to the main thread anyway.
+  nsCOMPtr<nsIAddrDatabase> db = GetAddressBookFromUri(m_pDestinationUri);
+  for (PRUint32 i = 0; i < count; ++i)
+  {
+    nsCOMPtr<nsIImportABDescriptor> book = do_QueryElementAt(m_pBooks, i);
+    if (book)
+    {
+      if (!db)
+      {
+        nsString name;
+        book->GetPreferredName(name);
+        db = GetAddressBook(name.get(), PR_TRUE);
+      }
+      m_DBs.AppendObject(db);
+    }
+  }
+  m_pThreadData->dBs = &m_DBs;
+
   NS_IF_ADDREF(m_pThreadData->stringBundle = m_stringBundle);
 
   nsresult rv;
   nsCOMPtr<nsIAbLDIFService> ldifService(do_GetService(NS_ABLDIFSERVICE_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIProxyObjectManager> proxyObjectManager =
     do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
@@ -755,182 +886,16 @@ void AddressThreadData::DriverAbort()
     // FIXME: Do whatever is necessary to abort what has already been imported!
   }
   else
     abort = PR_TRUE;
   DriverDelete();
 }
 
 
-already_AddRefed<nsIAddrDatabase> GetAddressBookFromUri(const char *pUri)
-{
-  nsIAddrDatabase *  pDatabase = nsnull;
-  if (pUri) {
-    nsresult rv;
-    nsCOMPtr<nsIProxyObjectManager> proxyObjectManager =
-      do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
-    if (NS_FAILED(rv))
-      return nsnull;
-
-    nsCOMPtr<nsIRDFService> mainRdfService =
-      do_GetService(kRDFServiceCID, &rv);
-    if (NS_FAILED(rv))
-      return nsnull;
-
-    nsIRDFService *rdfService = nsnull;
-    rv = proxyObjectManager->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
-                                               NS_GET_IID(nsIRDFService),
-                                               mainRdfService,
-                                               NS_PROXY_SYNC,
-                                               (void**)&rdfService);
-    if (NS_SUCCEEDED(rv) && rdfService)
-    {
-      nsCOMPtr<nsIRDFResource> resource;
-      rv = rdfService->GetResource(nsDependentCString(pUri),
-                                        getter_AddRefs(resource));
-      if (NS_SUCCEEDED(rv))
-      {
-        nsCOMPtr<nsIAbMDBDirectory> directory = do_QueryInterface(resource, &rv);
-        if (NS_SUCCEEDED(rv))
-          directory->GetDatabase(&pDatabase);
-      }
-    }
-  }
-
-  return pDatabase;
-}
-
-already_AddRefed<nsIAddrDatabase> GetAddressBook(const PRUnichar *name,
-                                                 PRBool makeNew)
-{
-  nsresult      rv = NS_OK;
-
-  if (!makeNew) {
-    // FIXME: How do I get the list of address books and look for a
-    // specific name.  Major bogosity!
-    // For now, assume we didn't find anything with that name
-  }
-
-  IMPORT_LOG0( "In GetAddressBook\n");
-
-  nsIAddrDatabase *  pDatabase = nsnull;
-
-  /* Get the profile directory */
-  nsCOMPtr<nsILocalFile> dbPath;
-
-  nsCOMPtr<nsIProxyObjectManager> proxyObjectManager =
-    do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
-  if (NS_FAILED(rv))
-    return nsnull;
-
-  nsCOMPtr<nsIAbManager> abMan = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
-  if (NS_FAILED(rv))
-    return nsnull;
-
-  nsCOMPtr<nsIAbManager> abManager;
-  rv = proxyObjectManager->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
-                                             NS_GET_IID(nsIAbManager),
-                                             abMan,
-                                             NS_PROXY_SYNC,
-                                             getter_AddRefs(abManager));
-
-  if (NS_SUCCEEDED(rv))
-    rv = abManager->GetUserProfileDirectory(getter_AddRefs(dbPath));
-  if (NS_SUCCEEDED(rv)) {
-    // Create a new address book file - we don't care what the file
-    // name is, as long as it's unique
-    rv = dbPath->Append(NS_LITERAL_STRING("impab.mab"));
-        if (NS_SUCCEEDED(rv)) {
-          rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
-
-          if (NS_SUCCEEDED(rv)) {
-            IMPORT_LOG0( "Getting the address database factory\n");
-
-            nsCOMPtr<nsIAddrDatabase> addrDatabaseFactory =
-              do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
-            if (NS_FAILED(rv))
-              return nsnull;
-
-            nsCOMPtr<nsIAddrDatabase> addrDBFactory;
-            rv = proxyObjectManager->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
-                                                       NS_GET_IID(nsIAddrDatabase),
-                                                       addrDatabaseFactory,
-                                                       NS_PROXY_SYNC,
-                                                       getter_AddRefs(addrDBFactory));
-            if (NS_SUCCEEDED(rv) && addrDBFactory) {
-              IMPORT_LOG0( "Opening the new address book\n");
-              nsCOMPtr<nsIAddrDatabase> nonProxyDatabase;
-              rv = addrDBFactory->Open(dbPath, PR_TRUE, PR_TRUE,
-                                       getter_AddRefs(nonProxyDatabase));
-              if (nonProxyDatabase)
-                rv = proxyObjectManager->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
-                                                           NS_GET_IID(nsIAddrDatabase),
-                                                           nonProxyDatabase,
-                                                           NS_PROXY_SYNC,
-                                                           (void**)&pDatabase);
-                
-            }
-          }
-        }
-  }
-  if (NS_FAILED(rv)) {
-    IMPORT_LOG0( "Failed to get the user profile directory from the address book session\n");
-  }
-
-
-  if (pDatabase) {
-    // We made a database, add it to the UI?!?!?!?!?!?!
-    // This is major bogosity again!  Why doesn't the address book
-    // just handle this properly for me?  Uggggg...
-
-    nsCOMPtr<nsIAbDirectory> nonProxyParentDir;
-    abManager->GetDirectory(NS_LITERAL_CSTRING(kAllDirectoryRoot),
-                            getter_AddRefs(nonProxyParentDir));
-    nsCOMPtr<nsIAbDirectory> parentDir;
-    /*
-     * TODO
-     * This may not be required in the future since the
-     * primary listeners of the nsIAbDirectory will be
-     * RDF directory datasource which propagates events to
-     * RDF Observers. In the future the RDF directory datasource
-     * will proxy the observers because asynchronous directory
-     * implementations, such as LDAP, will assert results from
-     * a thread other than the UI thread.
-     *
-     */
-    rv = proxyObjectManager->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
-                                               NS_GET_IID(nsIAbDirectory),
-                                               nonProxyParentDir,
-                                               NS_PROXY_SYNC | NS_PROXY_ALWAYS,
-                                               getter_AddRefs(parentDir));
-    if (parentDir)
-    {
-      nsCAutoString URI("moz-abmdbdirectory://");
-      nsCAutoString leafName;
-      rv = dbPath->GetNativeLeafName(leafName);
-      if (NS_FAILED(rv))
-        IMPORT_LOG0( "*** Error: Unable to get name of database file\n");
-      else
-      {
-        URI.Append(leafName);
-        rv = parentDir->CreateDirectoryByURI(nsDependentString(name), URI);
-        if (NS_FAILED(rv))
-          IMPORT_LOG0( "*** Error: Unable to create address book directory\n");
-      }
-    }
-
-    if (NS_SUCCEEDED(rv))
-      IMPORT_LOG0( "Added new address book to the UI\n");
-    else
-      IMPORT_LOG0( "*** Error: An error occurred while adding the address book to the UI\n");
-  }
-
-  return pDatabase;
-}
-
 void nsImportGenericAddressBooks::ReportError(const PRUnichar *pName,
                                               nsString *pStream,
                                               nsIStringBundle* aBundle)
 {
   if (!pStream)
     return;
   // load the error string
   PRUnichar *pFmt = nsImportStringBundle::GetStringByID( IMPORT_ERROR_GETABOOK, aBundle);
@@ -943,22 +908,19 @@ void nsImportGenericAddressBooks::Report
 
 static void ImportAddressThread( void *stuff)
 {
   IMPORT_LOG0( "In Begin ImportAddressThread\n");
 
   AddressThreadData *pData = (AddressThreadData *)stuff;
   PRUint32  count = 0;
   nsresult   rv = pData->books->Count( &count);
-
   PRUint32          i;
   PRBool            import;
   PRUint32          size;
-  nsCOMPtr<nsIAddrDatabase>  destDB( getter_AddRefs( GetAddressBookFromUri( pData->pDestinationUri)));
-  nsCOMPtr<nsIAddrDatabase> pDestDB;
 
   nsString          success;
   nsString          error;
 
     nsCOMPtr<nsIStringBundle> pBundle;
     rv = nsImportStringBundle::GetStringBundleProxy(pData->stringBundle, getter_AddRefs(pBundle));
     if (NS_FAILED(rv))
     {
@@ -974,32 +936,28 @@ static void ImportAddressThread( void *s
       size = 0;
       rv = book->GetImport( &import);
       if (import)
         rv = book->GetSize( &size);
 
       if (size && import) {
         nsString name;
         book->GetPreferredName(name);
-        if (destDB) {
-          pDestDB = destDB;
-        }
-        else {
-          pDestDB = GetAddressBook(name.get(), PR_TRUE);
-        }
+
+        nsCOMPtr<nsIAddrDatabase> db = pData->dBs->ObjectAt(i);
 
         nsCOMPtr<nsIProxyObjectManager> proxyObjectManager =
           do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv);
         if (NS_FAILED(rv))
           return;
 
         nsCOMPtr<nsIAddrDatabase> proxyAddrDatabase;
         rv = proxyObjectManager->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
                                                    NS_GET_IID(nsIAddrDatabase),
-                                                   pDestDB,
+                                                   db,
                                                    NS_PROXY_SYNC | NS_PROXY_ALWAYS,
                                                    getter_AddRefs(proxyAddrDatabase));
         if (NS_FAILED(rv))
           return;
 
 
         PRBool fatalError = PR_FALSE;
         pData->currentSize = size;
@@ -1050,20 +1008,16 @@ static void ImportAddressThread( void *s
         }
 
         if (fatalError) {
           pData->fatalError = PR_TRUE;
           break;
         }
       }
     }
-
-    if (destDB) {
-      destDB->Close( PR_TRUE);
-    }
   }
 
 
   nsImportGenericAddressBooks::SetLogs( success, error, pData->successLog, pData->errorLog);
 
   if (pData->abort || pData->fatalError) {
     // FIXME: do what is necessary to get rid of what has been imported so far.
     // Nothing if we went into an existing address book!  Otherwise, delete