diff options
Diffstat (limited to 'comm/mail/components/search/wsenable')
-rw-r--r-- | comm/mail/components/search/wsenable/Makefile.in | 6 | ||||
-rw-r--r-- | comm/mail/components/search/wsenable/WSEnable.cpp | 141 | ||||
-rw-r--r-- | comm/mail/components/search/wsenable/WSEnable.exe.manifest | 37 | ||||
-rw-r--r-- | comm/mail/components/search/wsenable/WSEnable.rc | 6 | ||||
-rw-r--r-- | comm/mail/components/search/wsenable/module.ver | 1 | ||||
-rw-r--r-- | comm/mail/components/search/wsenable/moz.build | 21 |
6 files changed, 212 insertions, 0 deletions
diff --git a/comm/mail/components/search/wsenable/Makefile.in b/comm/mail/components/search/wsenable/Makefile.in new file mode 100644 index 0000000000..254509ee77 --- /dev/null +++ b/comm/mail/components/search/wsenable/Makefile.in @@ -0,0 +1,6 @@ +# +# 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/. + +MOZ_WINCONSOLE = 0 diff --git a/comm/mail/components/search/wsenable/WSEnable.cpp b/comm/mail/components/search/wsenable/WSEnable.cpp new file mode 100644 index 0000000000..825e0c4fe4 --- /dev/null +++ b/comm/mail/components/search/wsenable/WSEnable.cpp @@ -0,0 +1,141 @@ +/* -*- 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 <SearchAPI.h> +#include <shellapi.h> +#include <objbase.h> +#include <string> + +static const CLSID CLSID_CSearchManager = { + 0x7d096c5f, + 0xac08, + 0x4f1f, + {0xbe, 0xb7, 0x5c, 0x22, 0xc5, 0x17, 0xce, 0x39}}; +static const IID IID_ISearchManager = { + 0xab310581, + 0xac80, + 0x11d1, + {0x8d, 0xf3, 0x00, 0xc0, 0x4f, 0xb6, 0xef, 0x69}}; + +static const WCHAR* const sFoldersToIndex[] = {L"\\Mail\\", L"\\ImapMail\\", + L"\\News\\"}; + +struct RegKey { + HKEY mRoot; + LPCWSTR mSubKey; + LPCWSTR mName; + LPCWSTR mValue; + + RegKey(HKEY aRoot, LPCWSTR aSubKey, LPCWSTR aName, LPCWSTR aValue) + : mRoot(aRoot), mSubKey(aSubKey), mName(aName), mValue(aValue) {} +}; + +static const RegKey* const sRegKeys[] = { + new RegKey(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PropertySystem\\" + L"PropertyHandlers\\.wdseml", + L"", L"{5FA29220-36A1-40f9-89C6-F4B384B7642E}"), + new RegKey(HKEY_CLASSES_ROOT, L".wdseml", L"Content Type", + L"message/rfc822"), + new RegKey(HKEY_CLASSES_ROOT, L".wdseml\\PersistentHandler", L"", + L"{5645c8c4-e277-11cf-8fda-00aa00a14f93}"), + new RegKey(HKEY_CLASSES_ROOT, + L".wdseml\\shellex\\{8895B1C6-B41F-4C1C-A562-0D564250836F}", L"", + L"{b9815375-5d7f-4ce2-9245-c9d4da436930}"), + new RegKey( + HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\KindMap", + L".wdseml", L"email;communication")}; + +HRESULT GetCrawlScopeManager(ISearchCrawlScopeManager** aCrawlScopeManager) { + *aCrawlScopeManager = NULL; + + ISearchManager* searchManager; + HRESULT hr = CoCreateInstance(CLSID_CSearchManager, NULL, CLSCTX_ALL, + IID_ISearchManager, (void**)&searchManager); + if (SUCCEEDED(hr)) { + ISearchCatalogManager* catalogManager; + hr = searchManager->GetCatalog(L"SystemIndex", &catalogManager); + if (SUCCEEDED(hr)) { + hr = catalogManager->GetCrawlScopeManager(aCrawlScopeManager); + catalogManager->Release(); + } + searchManager->Release(); + } + return hr; +} + +LSTATUS SetRegistryKeys() { + LSTATUS rv = ERROR_SUCCESS; + for (uint32_t i = 0; rv == ERROR_SUCCESS && i < _countof(sRegKeys); i++) { + const RegKey* key = sRegKeys[i]; + HKEY subKey; + // Since we're administrator, we should be able to do this just fine + rv = RegCreateKeyExW(key->mRoot, key->mSubKey, 0, NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS | KEY_WOW64_64KEY, NULL, &subKey, NULL); + if (rv == ERROR_SUCCESS) + rv = RegSetValueExW(subKey, key->mName, 0, REG_SZ, (LPBYTE)key->mValue, + (lstrlenW(key->mValue) + 1) * sizeof(WCHAR)); + RegCloseKey(subKey); + } + + return rv; +} + +int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + LPWSTR lpCmdLine, int nCmdShow) { + UNREFERENCED_PARAMETER(lpCmdLine); + + HRESULT hr = + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + if (SUCCEEDED(hr)) { + int argc; + LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc); + if (argc != 2) hr = E_INVALIDARG; + if (SUCCEEDED(hr)) { + ISearchCrawlScopeManager* crawlScopeManager; + hr = GetCrawlScopeManager(&crawlScopeManager); + if (SUCCEEDED(hr)) { + if (*argv[0] == L'1') { + // We first add the required registry entries + LSTATUS rv = SetRegistryKeys(); + if (rv != ERROR_SUCCESS) hr = E_FAIL; + + // Next, we add rules for each of the three folders + for (uint32_t i = 0; SUCCEEDED(hr) && i < _countof(sFoldersToIndex); + i++) { + std::wstring path = L"file:///"; + path.append(argv[1]); + path.append(sFoldersToIndex[i]); + // Add only if the rule isn't already there + BOOL isIncluded = FALSE; + hr = crawlScopeManager->IncludedInCrawlScope(path.c_str(), + &isIncluded); + if (SUCCEEDED(hr) && !isIncluded) + hr = crawlScopeManager->AddUserScopeRule(path.c_str(), TRUE, TRUE, + TRUE); + } + } else if (*argv[0] == L'0') { + // This is simple, we just exclude the profile dir and override + // children + std::wstring path = L"file:///"; + path.append(argv[1]); + hr = crawlScopeManager->AddUserScopeRule(path.c_str(), FALSE, TRUE, + TRUE); + } else + hr = E_INVALIDARG; + + if (SUCCEEDED(hr)) { + hr = crawlScopeManager->SaveAll(); + } + crawlScopeManager->Release(); + } + } + LocalFree(argv); + } + + return hr; +} diff --git a/comm/mail/components/search/wsenable/WSEnable.exe.manifest b/comm/mail/components/search/wsenable/WSEnable.exe.manifest new file mode 100644 index 0000000000..1c5ebf8e57 --- /dev/null +++ b/comm/mail/components/search/wsenable/WSEnable.exe.manifest @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> +<assemblyIdentity + version="1.0.0.0" + processorArchitecture="*" + name="Mozilla.Thunderbird" + type="win32" +/> +<description>Mozilla Thunderbird Windows Search Integration Handler</description> +<dependency> + <dependentAssembly> + <assemblyIdentity + type="win32" + name="Microsoft.Windows.Common-Controls" + version="6.0.0.0" + processorArchitecture="*" + publicKeyToken="6595b64144ccf1df" + language="*" + /> + </dependentAssembly> +</dependency> +<ms_asmv3:trustInfo xmlns:ms_asmv3="urn:schemas-microsoft-com:asm.v3"> + <ms_asmv3:security> + <ms_asmv3:requestedPrivileges> + <ms_asmv3:requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> + </ms_asmv3:requestedPrivileges> + </ms_asmv3:security> +</ms_asmv3:trustInfo> + <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> + <application> + <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> + <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> + <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> + <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> + </application> + </compatibility> +</assembly> diff --git a/comm/mail/components/search/wsenable/WSEnable.rc b/comm/mail/components/search/wsenable/WSEnable.rc new file mode 100644 index 0000000000..857298e160 --- /dev/null +++ b/comm/mail/components/search/wsenable/WSEnable.rc @@ -0,0 +1,6 @@ +/* -*- 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/. */ + +1 24 "WSEnable.exe.manifest" diff --git a/comm/mail/components/search/wsenable/module.ver b/comm/mail/components/search/wsenable/module.ver new file mode 100644 index 0000000000..bd6f7f1c84 --- /dev/null +++ b/comm/mail/components/search/wsenable/module.ver @@ -0,0 +1 @@ +WIN32_MODULE_DESCRIPTION=@MOZ_APP_DISPLAYNAME@ Windows Search Integration Handler diff --git a/comm/mail/components/search/wsenable/moz.build b/comm/mail/components/search/wsenable/moz.build new file mode 100644 index 0000000000..bf9cdab1dc --- /dev/null +++ b/comm/mail/components/search/wsenable/moz.build @@ -0,0 +1,21 @@ +# vim: set filetype=python: +# 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/. + +Program("WSEnable") + +SOURCES += [ + "WSEnable.cpp", +] + +OS_LIBS += [ + "advapi32", + "ole32", + "shell32", +] + +RCINCLUDE = "WSEnable.rc" + +# This isn't XPCOM code, but it wants to use STL so disable STL wrappers +DisableStlWrapping() |