From c0b0337671672252f723cee43beaebdb3bc09ddb Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Mon, 10 Jan 2011 01:05:10 +0000 Subject: Mitigate the following issue with the support for the Address Book of Mac OS X: if Microsoft Office is not installed or a 32-bit version of Microsoft Office is installed on 64-bit Windows and SIP Communicator, a dialog may appear to notify the SIP Communicator user that there is no default e-mail program. --- src/native/addrbook/msoutlook/Makefile | 2 +- src/native/addrbook/msoutlook/MsOutlookMAPI.h | 3 + ...tlook_MsOutlookAddrBookContactSourceService.cxx | 130 ++++++++++++++++++++- 3 files changed, 131 insertions(+), 4 deletions(-) (limited to 'src/native') diff --git a/src/native/addrbook/msoutlook/Makefile b/src/native/addrbook/msoutlook/Makefile index c36024c..2f5362d 100644 --- a/src/native/addrbook/msoutlook/Makefile +++ b/src/native/addrbook/msoutlook/Makefile @@ -11,7 +11,7 @@ endif CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32 -I$(OUTLOOK_MAPI_HEADERS) -I.. LDFLAGS = -shared -Wl,--kill-at -LIBS = -lmapi32 -luuid +LIBS = -lmapi32 -luuid -ladvapi32 TARGET = ../../../../lib/native/windows$(ARCH)/$(TARGET_BASENAME).dll $(TARGET): \ diff --git a/src/native/addrbook/msoutlook/MsOutlookMAPI.h b/src/native/addrbook/msoutlook/MsOutlookMAPI.h index 8bacf6b..1fcba92 100644 --- a/src/native/addrbook/msoutlook/MsOutlookMAPI.h +++ b/src/native/addrbook/msoutlook/MsOutlookMAPI.h @@ -15,4 +15,7 @@ #include #include +#define WIN32_LEAN_AND_MEAN +#include + #endif /* #ifndef _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MSOUTLOOKMAPI_H_ */ diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx index f4d2f32..14446b0 100644 --- a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx +++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx @@ -10,14 +10,138 @@ #include "MsOutlookMAPI.h" #include "MsOutlookMAPIHResultException.h" +#include +#include +#include + JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIInitialize (JNIEnv *jniEnv, jclass clazz, jlong version, jlong flags) { - MAPIINIT_0 mapiInit = { (ULONG) version, (ULONG) flags }; - HRESULT hResult; + HKEY officeKey; + HRESULT hResult = MAPI_E_NO_SUPPORT; + + /* + * In the absence of a default e-mail program, MAPIInitialize may show a + * dialog to notify of the fact. The dialog is undesirable here. Because we + * implement ContactSourceService for Microsoft Outlook, we will try to + * mitigate the problem by implementing an ad-hoc check whether Microsoft + * Outlook is installed. + */ + if (ERROR_SUCCESS + == RegOpenKeyEx( + HKEY_LOCAL_MACHINE, + _TEXT("Software\\Microsoft\\Office"), + 0, + KEY_ENUMERATE_SUB_KEYS, + &officeKey)) + { + DWORD i = 0; + TCHAR installRootKeyName[ + 255 /* The size limit of key name as documented in MSDN */ + + 20 /* \Outlook\InstallRoot */ + + 1 /* The terminating null character */ ]; + + while (1) + { + LONG regEnumKeyEx; + DWORD subkeyNameLength = 255 + 1; + LPTSTR str; + HKEY installRootKey; + DWORD pathValueType; + DWORD pathValueSize; + + regEnumKeyEx + = RegEnumKeyEx( + officeKey, + i, + installRootKeyName, &subkeyNameLength, + NULL, + NULL, NULL, + NULL); + if (ERROR_NO_MORE_ITEMS == regEnumKeyEx) + break; + + i++; + if (ERROR_SUCCESS != regEnumKeyEx) + continue; + + str = installRootKeyName + subkeyNameLength; + memcpy(str, _TEXT("\\Outlook\\InstallRoot"), 20 * sizeof(TCHAR)); + *(str + 20) = 0; + if ((ERROR_SUCCESS + == RegOpenKeyEx( + officeKey, + installRootKeyName, + 0, + KEY_QUERY_VALUE, + &installRootKey)) + && (ERROR_SUCCESS + == RegQueryValueEx( + installRootKey, + _TEXT("Path"), + NULL, + &pathValueType, + NULL, &pathValueSize)) + && (REG_SZ == pathValueType) + && pathValueSize) + { + LPTSTR pathValue; + + /* + * MSDN says "the string may not have been stored with the + * proper terminating null characters." + */ + pathValueSize + += sizeof(TCHAR) + * (12 /* \Outlook.exe */ + + 1 /* The terminating null character */); - hResult = MAPIInitialize(&mapiInit); + if (pathValueSize <= sizeof(installRootKeyName)) + pathValue = installRootKeyName; + else + { + pathValue = (TCHAR *) malloc(pathValueSize); + if (!pathValue) + continue; + } + + if (ERROR_SUCCESS + == RegQueryValueEx( + installRootKey, + _TEXT("Path"), + NULL, + NULL, + (LPBYTE) pathValue, &pathValueSize)) + { + DWORD pathValueLength = pathValueSize / sizeof(TCHAR); + + if (pathValueLength) + { + DWORD fileAttributes; + + str = pathValue + (pathValueLength - 1); + if (*str) + str++; + memcpy(str, "\\Outlook.exe", 12 * sizeof(TCHAR)); + *(str + 12) = 0; + + fileAttributes = GetFileAttributes(pathValue); + if (INVALID_FILE_ATTRIBUTES != fileAttributes) + { + MAPIINIT_0 mapiInit + = { (ULONG) version, (ULONG) flags }; + + hResult = MAPIInitialize(&mapiInit); + } + } + } + + if (pathValue != installRootKeyName) + free(pathValue); + } + } + } if (HR_FAILED(hResult)) { -- cgit v1.1