aboutsummaryrefslogtreecommitdiffstats
path: root/src/native/addrbook/msoutlook
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2011-01-10 01:05:10 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2011-01-10 01:05:10 +0000
commitc0b0337671672252f723cee43beaebdb3bc09ddb (patch)
tree9a5cab615a066b01b4a2ee6f28c37bfe8c99e0f1 /src/native/addrbook/msoutlook
parent167d74256df976c06fd40c04d6a41ca22c92c38c (diff)
downloadjitsi-c0b0337671672252f723cee43beaebdb3bc09ddb.zip
jitsi-c0b0337671672252f723cee43beaebdb3bc09ddb.tar.gz
jitsi-c0b0337671672252f723cee43beaebdb3bc09ddb.tar.bz2
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.
Diffstat (limited to 'src/native/addrbook/msoutlook')
-rw-r--r--src/native/addrbook/msoutlook/Makefile2
-rw-r--r--src/native/addrbook/msoutlook/MsOutlookMAPI.h3
-rw-r--r--src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx130
3 files changed, 131 insertions, 4 deletions
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 <mapitags.h>
#include <mapix.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
#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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
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))
{