diff --git a/lib/native/windows-64/jmsoutlookaddrbook.dll b/lib/native/windows-64/jmsoutlookaddrbook.dll new file mode 100644 index 000000000..406c51d7b Binary files /dev/null and b/lib/native/windows-64/jmsoutlookaddrbook.dll differ diff --git a/lib/native/windows/jmsoutlookaddrbook.dll b/lib/native/windows/jmsoutlookaddrbook.dll new file mode 100644 index 000000000..457be2e16 Binary files /dev/null and b/lib/native/windows/jmsoutlookaddrbook.dll differ diff --git a/src/native/addrbook/msoutlook/Makefile b/src/native/addrbook/msoutlook/Makefile index c36024c8a..2f5362dd0 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 8bacf6ba4..1fcba9252 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 f4d2f324f..14446b0aa 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)) { diff --git a/src/net/java/sip/communicator/plugin/addrbook/AddrBookActivator.java b/src/net/java/sip/communicator/plugin/addrbook/AddrBookActivator.java index ceeeb1cdf..86ad3ee09 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/AddrBookActivator.java +++ b/src/net/java/sip/communicator/plugin/addrbook/AddrBookActivator.java @@ -69,7 +69,17 @@ else if (OSUtils.IS_MAC) else return; - css = (ContactSourceService) Class.forName(cssClassName).newInstance(); + try + { + css + = (ContactSourceService) + Class.forName(cssClassName).newInstance(); + } + catch (Exception ex) + { + logger.error("Failed to instantiate " + cssClassName, ex); + return; + } try { cssServiceRegistration