Bug 1614265 - Reinstate Mac OS, Outlook, and LDAP directory types. r=mkmelin

This required some adjustment in the C++ implementation of these types.

The Outlook directory factory interface has been repurposed to do the minimum
required - talk to the MAPI code and find directories.

Differential Revision: https://phabricator.services.mozilla.com/D62395

--HG--
rename : mailnews/addrbook/src/nsAbOutlookDirFactory.cpp => mailnews/addrbook/src/nsAbOutlookInterface.cpp
rename : mailnews/addrbook/src/nsAbOutlookDirFactory.h => mailnews/addrbook/src/nsAbOutlookInterface.h
extra : moz-landing-system : lando
This commit is contained in:
Geoff Lankow 2020-02-18 08:27:05 +00:00
Родитель 8434c4f284
Коммит f1c5b9dcc9
15 изменённых файлов: 247 добавлений и 142 удалений

Просмотреть файл

@ -820,22 +820,22 @@ var MailMigrator = {
let profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
for (let name of Services.prefs.getChildList("ldap_2.servers.")) {
try {
if (
name.endsWith(".uri") &&
Services.prefs.getStringPref(name).startsWith("ldap://")
) {
let prefName = name.substring(0, name.length - 4);
let fileName = Services.prefs.getStringPref(
`${prefName}.filename`,
""
);
if (fileName.endsWith(".mab")) {
fileName = fileName.replace(/\.mab$/, "");
Services.prefs.setStringPref(
if (name.endsWith(".uri")) {
let uri = Services.prefs.getStringPref(name);
if (uri.startsWith("ldap://") || uri.startsWith("ldaps://")) {
let prefName = name.substring(0, name.length - 4);
let fileName = Services.prefs.getStringPref(
`${prefName}.filename`,
`${fileName}.sqlite`
""
);
await migrateBook(fileName);
if (fileName.endsWith(".mab")) {
fileName = fileName.replace(/\.mab$/, "");
Services.prefs.setStringPref(
`${prefName}.filename`,
`${fileName}.sqlite`
);
await migrateBook(fileName);
}
}
} else if (
name.endsWith(".dirType") &&

Просмотреть файл

@ -32,7 +32,7 @@ function getDirectoryValue(aDir, aKey) {
if (aDir._directory.URI == kCollectedAddressbookURI) {
return "cab";
}
if (aDir._directory.dirType == DIRTYPE_JS) {
if (aDir._directory.URI.startsWith("jsaddrbook://")) {
return "js";
}
if (aDir._directory instanceof Ci.nsIAbLDAPDirectory) {

Просмотреть файл

@ -12,6 +12,5 @@ prefs =
subsuite = thunderbird
[browser_ldap_search.js]
fail-if = true
support-files = ../../../../../mailnews/addrbook/test/unit/data/ldap_contacts.json
[browser_mailing_lists.js]

Просмотреть файл

@ -25,6 +25,16 @@ ChromeUtils.defineModuleGetter(
"resource:///modules/AddrBookUtils.jsm"
);
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyServiceGetter(
this,
"env",
"@mozilla.org/process/environment;1",
"nsIEnvironment"
);
/** Directory type constants, as defined in nsDirPrefs.h. */
const LDAP_DIRECTORY_TYPE = 0;
const MAPI_DIRECTORY_TYPE = 3;
@ -89,14 +99,48 @@ function ensureInitialized() {
store = new Map();
for (let pref of Services.prefs.getChildList("ldap_2.servers.")) {
if (pref.endsWith(".dirType")) {
let prefName = pref.substring(0, pref.length - 8);
let dirType = Services.prefs.getIntPref(pref);
let fileName = Services.prefs.getStringPref(`${prefName}.filename`, "");
if (dirType == JS_DIRECTORY_TYPE && fileName) {
let uri = `jsaddrbook://${fileName}`;
createDirectoryObject(uri, true);
try {
if (pref.endsWith(".uri")) {
let uri = Services.prefs.getStringPref(pref);
if (uri.startsWith("ldap://") || uri.startsWith("ldaps://")) {
let prefName = pref.substring(0, pref.length - 4);
uri = `moz-abldapdirectory://${prefName}`;
createDirectoryObject(uri, true);
}
} else if (pref.endsWith(".dirType")) {
let prefName = pref.substring(0, pref.length - 8);
let dirType = Services.prefs.getIntPref(pref);
let fileName = Services.prefs.getStringPref(`${prefName}.filename`, "");
let uri = Services.prefs.getStringPref(`${prefName}.uri`, "");
switch (dirType) {
case MAPI_DIRECTORY_TYPE:
if (env.exists("MOZ_AUTOMATION")) {
break;
}
if (AppConstants.platform == "macosx") {
createDirectoryObject(uri, true);
} else if (AppConstants.platform == "win") {
let outlookInterface = Cc[
"@mozilla.org/addressbook/outlookinterface;1"
].getService(Ci.nsIAbOutlookInterface);
for (let folderURI of outlookInterface.getFolderURIs(uri)) {
let dir = createDirectoryObject(folderURI, true);
store.set(folderURI, dir);
}
}
break;
case JS_DIRECTORY_TYPE:
if (fileName) {
let uri = `jsaddrbook://${fileName}`;
createDirectoryObject(uri, true);
}
break;
}
}
} catch (ex) {
Cu.reportError(ex);
}
}
}
@ -139,8 +183,8 @@ AddrBookManager.prototype = {
if (!uriParts) {
throw Cr.NS_ERROR_UNEXPECTED;
}
let [, , , tail] = uriParts;
if (tail) {
let [, scheme, , tail] = uriParts;
if (tail && types.includes(scheme)) {
// `tail` could either point to a mailing list or a query.
// Both of these will be handled differently in future.
return createDirectoryObject(uri);
@ -177,21 +221,86 @@ AddrBookManager.prototype = {
ensureInitialized();
let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
file.append("abook.sqlite");
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
file.remove(false);
uri = `jsaddrbook://${file.leafName}`;
switch (type) {
case LDAP_DIRECTORY_TYPE: {
let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
file.append("ldap.sqlite");
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
ensureUniquePrefName();
Services.prefs.setStringPref(`${prefName}.description`, dirName);
Services.prefs.setIntPref(`${prefName}.dirType`, type);
Services.prefs.setStringPref(`${prefName}.filename`, file.leafName);
Services.prefs.setStringPref(`${prefName}.uri`, uri);
ensureUniquePrefName();
Services.prefs.setStringPref(`${prefName}.description`, dirName);
Services.prefs.setStringPref(`${prefName}.filename`, file.leafName);
Services.prefs.setStringPref(`${prefName}.uri`, uri);
uri = `moz-abldapdirectory://${prefName}`;
let dir = createDirectoryObject(uri, true);
this.notifyDirectoryItemAdded(null, dir);
break;
}
case MAPI_DIRECTORY_TYPE: {
if (AppConstants.platform == "macosx") {
uri = "moz-abosxdirectory:///";
if (store.has(uri)) {
throw Cr.NS_ERROR_UNEXPECTED;
}
prefName = "ldap_2.servers.osx";
} else if (AppConstants.platform == "win") {
if (
![
"moz-aboutlookdirectory://oe/",
"moz-aboutlookdirectory://op/",
].includes(uri)
) {
throw Cr.NS_ERROR_UNEXPECTED;
}
if (store.has(uri)) {
throw Cr.NS_ERROR_UNEXPECTED;
}
prefName = "ldap_2.servers.oe";
} else {
throw Cr.NS_ERROR_UNEXPECTED;
}
Services.prefs.setIntPref(`${prefName}.dirType`, MAPI_DIRECTORY_TYPE);
Services.prefs.setStringPref(
`${prefName}.description`,
"chrome://messenger/locale/addressbook/addressBook.properties"
);
Services.prefs.setStringPref(`${prefName}.uri`, uri);
if (AppConstants.platform == "macosx") {
let dir = createDirectoryObject(uri, true);
this.notifyDirectoryItemAdded(null, dir);
} else if (AppConstants.platform == "win") {
let outlookInterface = Cc[
"@mozilla.org/addressbook/outlookinterface;1"
].getService(Ci.nsIAbOutlookInterface);
for (let folderURI of outlookInterface.getFolderURIs(uri)) {
let dir = createDirectoryObject(folderURI, true);
this.notifyDirectoryItemAdded(null, dir);
}
}
break;
}
case JS_DIRECTORY_TYPE: {
let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
file.append("abook.sqlite");
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
ensureUniquePrefName();
Services.prefs.setStringPref(`${prefName}.description`, dirName);
Services.prefs.setIntPref(`${prefName}.dirType`, type);
Services.prefs.setStringPref(`${prefName}.filename`, file.leafName);
uri = `jsaddrbook://${file.leafName}`;
let dir = createDirectoryObject(uri, true);
this.notifyDirectoryItemAdded(null, dir);
break;
}
default:
throw Cr.NS_ERROR_UNEXPECTED;
}
uri = `jsaddrbook://${file.leafName}`;
let dir = createDirectoryObject(uri, true);
this.notifyDirectoryItemAdded(null, dir);
return prefName;
},
deleteAddressBook(uri) {
@ -226,16 +335,20 @@ AddrBookManager.prototype = {
Services.prefs.clearUserPref(`${prefName}.filename`);
Services.prefs.clearUserPref(`${prefName}.uid`);
Services.prefs.clearUserPref(`${prefName}.uri`);
store.delete(`jsaddrbook://${fileName}`);
store.delete(uri);
let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
file.append(fileName);
closeConnectionTo(file).then(() => {
if (file.exists()) {
file.remove(false);
}
if (fileName) {
let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
file.append(fileName);
closeConnectionTo(file).then(() => {
if (file.exists()) {
file.remove(false);
}
this.notifyDirectoryDeleted(null, dir);
});
} else {
this.notifyDirectoryDeleted(null, dir);
});
}
},
exportAddressBook(parentWin, directory) {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;

Просмотреть файл

@ -31,6 +31,11 @@ if CONFIG['MOZ_LDAP_XPCOM']:
'nsIAbLDAPReplicationService.idl',
]
if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_MAPI_SUPPORT']:
XPIDL_SOURCES += [
'nsIAbOutlookInterface.idl',
]
XPIDL_MODULE = 'addrbook'
EXPORTS += [

Просмотреть файл

@ -155,10 +155,10 @@
//
// Outlook directory factory
//
# define NS_ABOUTLOOKDIRFACTORY_CONTRACTID \
NS_AB_DIRECTORY_FACTORY_CONTRACTID_PREFIX "moz-aboutlookdirectory"
# define NS_ABOUTLOOKINTERFACE_CONTRACTID \
"@mozilla.org/addressbook/outlookinterface;1"
# define NS_ABOUTLOOKDIRFACTORY_CID \
# define NS_ABOUTLOOKINTERFACE_CID \
{ \
0x558ccc0f, 0x2681, 0x4dac, { \
0xa0, 0x66, 0xde, 0xbd, 0x8d, 0x26, 0xfa, 0xf6 \

Просмотреть файл

@ -0,0 +1,12 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
[scriptable, uuid(088d3dea-4a6a-41ce-b974-5043d00f1798)]
interface nsIAbOutlookInterface : nsISupports
{
Array<ACString> getFolderURIs(in ACString aURI);
};

Просмотреть файл

@ -31,6 +31,7 @@ SOURCES += [
if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_MAPI_SUPPORT']:
SOURCES += [
'nsAbOutlookDirectory.cpp',
'nsAbOutlookInterface.cpp',
'nsAbWinHelper.cpp',
'nsMapiAddressBook.cpp',
'nsWabAddressBook.cpp',

Просмотреть файл

@ -524,6 +524,10 @@ nsAbOSXDirectory::Init(const char *aUri) {
if (!mIsQueryURI) AssertCard(abManager, card);
}
if (isRootOSXDirectory) {
AssertChildNodes();
}
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;

Просмотреть файл

@ -1,73 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsAbOutlookDirFactory.h"
#include "nsAbWinHelper.h"
#include "nsIAbDirectory.h"
#include "nsIAbManager.h"
#include "nsEnumeratorUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsIMutableArray.h"
#include "nsArrayEnumerator.h"
#include "nsAbBaseCID.h"
#include "mozilla/Logging.h"
NS_IMPL_ISUPPORTS(nsAbOutlookDirFactory, nsIAbDirFactory)
nsAbOutlookDirFactory::nsAbOutlookDirFactory(void) {}
nsAbOutlookDirFactory::~nsAbOutlookDirFactory(void) {}
extern const char *kOutlookDirectoryScheme;
NS_IMETHODIMP
nsAbOutlookDirFactory::GetDirectories(const nsAString &aDirName,
const nsACString &aURI,
const nsACString &aPrefName,
nsISimpleEnumerator **aDirectories) {
NS_ENSURE_ARG_POINTER(aDirectories);
*aDirectories = nullptr;
nsresult rv = NS_OK;
nsCString stub;
nsCString entry;
nsAbWinType abType =
getAbWinType(kOutlookDirectoryScheme, nsCString(aURI).get(), stub, entry);
if (abType == nsAbWinType_Unknown) {
return NS_ERROR_FAILURE;
}
nsAbWinHelperGuard mapiAddBook(abType);
nsMapiEntryArray folders;
nsCOMPtr<nsIMutableArray> directories(do_CreateInstance(NS_ARRAY_CONTRACTID));
NS_ENSURE_SUCCESS(rv, rv);
if (!mapiAddBook->IsOK() || !mapiAddBook->GetFolders(folders)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString entryId;
nsAutoCString uri;
for (ULONG i = 0; i < folders.mNbEntries; ++i) {
folders.mEntries[i].ToString(entryId);
buildAbWinUri(kOutlookDirectoryScheme, abType, uri);
uri.Append(entryId);
nsCOMPtr<nsIAbDirectory> directory;
rv = abManager->GetDirectory(uri, getter_AddRefs(directory));
NS_ENSURE_SUCCESS(rv, rv);
directories->AppendElement(directory);
}
return NS_NewArrayEnumerator(aDirectories, directories,
NS_GET_IID(nsIAbDirectory));
}
// No actual deletion, since you cannot create the address books from Mozilla.
NS_IMETHODIMP nsAbOutlookDirFactory::DeleteDirectory(
nsIAbDirectory *aDirectory) {
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsAbOutlookInterface.h"
#include "nsAbWinHelper.h"
#include "nsComponentManagerUtils.h"
#include "nsAbBaseCID.h"
NS_IMPL_ISUPPORTS(nsAbOutlookInterface, nsIAbOutlookInterface)
nsAbOutlookInterface::nsAbOutlookInterface(void) {}
nsAbOutlookInterface::~nsAbOutlookInterface(void) {}
extern const char *kOutlookDirectoryScheme;
NS_IMETHODIMP
nsAbOutlookInterface::GetFolderURIs(const nsACString &aURI,
nsTArray<nsCString> &uris) {
uris.Clear();
nsresult rv = NS_OK;
nsCString stub;
nsCString entry;
nsAbWinType abType =
getAbWinType(kOutlookDirectoryScheme, nsCString(aURI).get(), stub, entry);
if (abType == nsAbWinType_Unknown) {
return NS_ERROR_FAILURE;
}
nsAbWinHelperGuard mapiAddBook(abType);
nsMapiEntryArray folders;
NS_ENSURE_SUCCESS(rv, rv);
if (!mapiAddBook->IsOK() || !mapiAddBook->GetFolders(folders)) {
return NS_ERROR_FAILURE;
}
uris.SetCapacity(folders.mNbEntries);
nsAutoCString entryId;
nsAutoCString uri;
for (ULONG i = 0; i < folders.mNbEntries; ++i) {
folders.mEntries[i].ToString(entryId);
buildAbWinUri(kOutlookDirectoryScheme, abType, uri);
uri.Append(entryId);
uris.AppendElement(uri);
}
return NS_OK;
}

Просмотреть файл

@ -2,20 +2,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsAbOutlookDirFactory_h___
#define nsAbOutlookDirFactory_h___
#ifndef nsAbOutlookInterface_h___
#define nsAbOutlookInterface_h___
#include "nsIAbDirFactory.h"
#include "nsIAbOutlookInterface.h"
class nsAbOutlookDirFactory : public nsIAbDirFactory {
class nsAbOutlookInterface : public nsIAbOutlookInterface {
public:
nsAbOutlookDirFactory(void);
nsAbOutlookInterface(void);
NS_DECL_ISUPPORTS
NS_DECL_NSIABDIRFACTORY
NS_DECL_NSIABOUTLOOKINTERFACE
private:
virtual ~nsAbOutlookDirFactory(void);
virtual ~nsAbOutlookInterface(void);
};
#endif // nsAbOutlookDirFactory_h___
#endif // nsAbOutlookInterface_h___

Просмотреть файл

@ -7,7 +7,6 @@ support-files = data/*
[test_bug387403.js]
[test_bug448165.js]
[test_bug534822.js]
fail-if = true
[test_bug1522453.js]
[test_cardForEmail.js]
[test_collection.js]
@ -16,13 +15,9 @@ fail-if = true
[test_jsaddrbook.js]
[test_jsaddrbook_inner.js]
[test_ldap1.js]
fail-if = true
[test_ldap2.js]
fail-if = true
[test_ldapOffline.js]
fail-if = true
[test_ldapReplication.js]
fail-if = true
skip-if = debug # Fails for unknown reasons.
[test_mailList1.js]
[test_notifications.js]

Просмотреть файл

@ -10,4 +10,3 @@ support-files = data/*
[test_migration6.js]
[test_migration7.js]
[test_migration8.js]
fail-if = true

Просмотреть файл

@ -139,7 +139,7 @@
#endif
#if defined(MOZ_MAPI_SUPPORT)
# include "nsAbOutlookDirFactory.h"
# include "nsAbOutlookInterface.h"
# include "nsAbOutlookDirectory.h"
#endif
@ -439,7 +439,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAddbookProtocolHandler)
#if defined(MOZ_MAPI_SUPPORT)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbOutlookDirectory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbOutlookDirFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbOutlookInterface)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbDirectoryQueryArguments)
@ -481,7 +481,7 @@ NS_DEFINE_NAMED_CID(NS_BOOLEANCONDITIONSTRING_CID);
NS_DEFINE_NAMED_CID(NS_BOOLEANEXPRESSION_CID);
#if defined(MOZ_MAPI_SUPPORT)
NS_DEFINE_NAMED_CID(NS_ABOUTLOOKDIRECTORY_CID);
NS_DEFINE_NAMED_CID(NS_ABOUTLOOKDIRFACTORY_CID);
NS_DEFINE_NAMED_CID(NS_ABOUTLOOKINTERFACE_CID);
#endif
#if defined(MOZ_LDAP_XPCOM)
@ -892,8 +892,7 @@ const mozilla::Module::CIDEntry kMailNewsCIDs[] = {
{&kNS_ABCONTENTHANDLER_CID, false, NULL, nsAbContentHandlerConstructor},
#if defined(MOZ_MAPI_SUPPORT)
{&kNS_ABOUTLOOKDIRECTORY_CID, false, NULL, nsAbOutlookDirectoryConstructor},
{&kNS_ABOUTLOOKDIRFACTORY_CID, false, NULL,
nsAbOutlookDirFactoryConstructor},
{&kNS_ABOUTLOOKINTERFACE_CID, false, NULL, nsAbOutlookInterfaceConstructor},
#endif
{&kNS_ABDIRECTORYQUERYARGUMENTS_CID, false, NULL,
nsAbDirectoryQueryArgumentsConstructor},
@ -1129,7 +1128,7 @@ const mozilla::Module::ContractIDEntry kMailNewsContracts[] = {
&kNS_ABCONTENTHANDLER_CID},
#if defined(MOZ_MAPI_SUPPORT)
{NS_ABOUTLOOKDIRECTORY_CONTRACTID, &kNS_ABOUTLOOKDIRECTORY_CID},
{NS_ABOUTLOOKDIRFACTORY_CONTRACTID, &kNS_ABOUTLOOKDIRFACTORY_CID},
{NS_ABOUTLOOKINTERFACE_CONTRACTID, &kNS_ABOUTLOOKINTERFACE_CID},
#endif
{NS_ABDIRECTORYQUERYARGUMENTS_CONTRACTID,
&kNS_ABDIRECTORYQUERYARGUMENTS_CID},