Bug 666607 - Improve the address book import for Outlook Express. r=sid0. Updated by Siddharth Agarwal <sid.bugzilla@gmail.com>, r=bienvenu
authorSiddharth Agarwal <sid.bugzilla@gmail.com>
Wed, 06 Jul 2011 17:47:40 -0700
changeset 8516 8a25422c9fca5df3703535e54475cc5ccaea356c
parent 8515 b65e94778dbd5d6a1f852bb167da792488a0e6b3
child 8517 cc06bf5d9186e3c5664a212f69a685a344b4307e
push id158
push userbugzilla@standard8.plus.com
push dateTue, 27 Sep 2011 19:18:14 +0000
treeherdercomm-beta@e47b99c61e4d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssid0, bienvenu
bugs666607
Bug 666607 - Improve the address book import for Outlook Express. r=sid0. Updated by Siddharth Agarwal <sid.bugzilla@gmail.com>, r=bienvenu
mailnews/addrbook/src/nsWabAddressBook.cpp
mailnews/import/oexpress/WabObject.cpp
--- a/mailnews/addrbook/src/nsWabAddressBook.cpp
+++ b/mailnews/addrbook/src/nsWabAddressBook.cpp
@@ -30,16 +30,18 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include <tchar.h>
 #include "nsWabAddressBook.h"
 #include "prlog.h"
 
 #ifdef PR_LOGGING
 static PRLogModuleInfo* gWabAddressBookLog
     = PR_NewLogModule("nsWabAddressBookLog");
 #endif
 
@@ -56,20 +58,40 @@ LPADRBOOK nsWabAddressBook::mRootBook = 
 BOOL nsWabAddressBook::LoadWabLibrary(void)
 {
     if (mLibrary) { ++ mLibUsage ; return TRUE ; }
     // We try to fetch the location of the WAB DLL from the registry
     TCHAR wabDLLPath [MAX_PATH] ;
     DWORD keyType = 0 ;
     ULONG byteCount = sizeof(wabDLLPath) ;
     HKEY keyHandle = NULL ;
-    
     wabDLLPath [MAX_PATH - 1] = 0 ;
     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
         RegQueryValueEx(keyHandle, "", NULL, &keyType, (LPBYTE) wabDLLPath, &byteCount) ;
+        if (keyType == REG_EXPAND_SZ) {
+            // Expand the environment variables
+            DWORD bufferSize = ExpandEnvironmentStrings(wabDLLPath, NULL, 0);
+            if (bufferSize && bufferSize < MAX_PATH) {
+                TCHAR tmp[MAX_PATH];
+                ExpandEnvironmentStrings(wabDLLPath, tmp, bufferSize);
+                _tcscpy(wabDLLPath, tmp);
+            }
+            else {
+                return FALSE;
+            }
+        }
+    }
+    else {
+        if (GetSystemDirectory(wabDLLPath, MAX_PATH)) {
+            _tcsncat(wabDLLPath, WAB_DLL_NAME,
+                     NS_MIN(_tcslen(WAB_DLL_NAME), MAX_PATH - _tcslen(wabDLLPath) - 1));
+        }
+        else {
+            return FALSE;
+        }
     }
     if (keyHandle) { RegCloseKey(keyHandle) ; }
     mLibrary = LoadLibrary( (lstrlen(wabDLLPath)) ? wabDLLPath : WAB_DLL_NAME );
     if (!mLibrary) { return FALSE ; }
     ++ mLibUsage ;
     mWABOpen = reinterpret_cast<LPWABOPEN>(GetProcAddress(mLibrary, "WABOpen")) ;
     if (!mWABOpen) { return FALSE ; }
     HRESULT retCode = mWABOpen(&mRootBook, &mRootSession, NULL, 0) ;
--- a/mailnews/import/oexpress/WabObject.cpp
+++ b/mailnews/import/oexpress/WabObject.cpp
@@ -30,16 +30,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include <tchar.h>
 #include "nscore.h"
 #include "wabobject.h"
 
 enum {
     ieidPR_DISPLAY_NAME = 0,
     ieidPR_ENTRYID,
     ieidPR_OBJECT_TYPE,
     ieidMax
@@ -127,18 +128,43 @@ CWAB::CWAB(nsILocalFile *file)
         HKEY hKey = NULL;
 
         *szWABDllPath = '\0';
 
         // First we look under the default WAB DLL path location in the
         // Registry.
         // WAB_DLL_PATH_KEY is defined in wabapi.h
         //
-        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
+        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey)) {
             RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);
+            if (dwType == REG_EXPAND_SZ) {
+                // Expand the environment variables
+                DWORD bufferSize = ExpandEnvironmentStrings(szWABDllPath, NULL, 0);
+                if (bufferSize && bufferSize < MAX_PATH) {
+                    TCHAR tmp[MAX_PATH];
+                    ExpandEnvironmentStrings(szWABDllPath, tmp, bufferSize);
+                    _tcscpy(szWABDllPath, tmp);
+                }
+                else {
+                    // This is an error condition. Nothing else is initialized yet, so simply return.
+                    return;
+                }
+
+            }
+        }
+        else {
+            if (GetSystemDirectory(szWABDllPath, MAX_PATH)) {
+                _tcsncat(szWABDllPath, WAB_DLL_NAME,
+                         NS_MIN(_tcslen(WAB_DLL_NAME), MAX_PATH - _tcslen(szWABDllPath) - 1));
+            }
+            else {
+                // Yet another error condition.
+                return;
+            }
+        }
 
         if(hKey) RegCloseKey(hKey);
 
         // if the Registry came up blank, we do a loadlibrary on the wab32.dll
         // WAB_DLL_NAME is defined in wabapi.h
         //
         m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
     }