Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
8.7 KiB

  1. #include "pch.hxx"
  2. #include <iert.h>
  3. #include <mapi.h>
  4. #include <mapix.h>
  5. #include <impapi.h>
  6. #include <newimp.h>
  7. #include "import.h"
  8. #include "comconv.h"
  9. #include "strconst.h"
  10. #include "demand.h"
  11. extern HRESULT GetCommunicatorDirectory(char *szUser, char *szDir, int cch);
  12. int BrowseCallbackProc(HWND hwnd, UINT msg, LPARAM lParam, LPARAM lpData);
  13. BOOL GetVersion(TCHAR *szFile, DWORD *pdwHigh, DWORD *pdwLow);
  14. HRESULT DispDialog(HWND hwnd, TCHAR *pathname, int cch)
  15. {
  16. BROWSEINFO browse;
  17. BOOL fRet;
  18. TCHAR szBuffer[CCHMAX_STRINGRES], szPath[MAX_PATH];
  19. LPITEMIDLIST lpitemid;
  20. Assert(cch >= MAX_PATH);
  21. LoadString(g_hInstImp, idsBrowseFolderText, szBuffer, ARRAYSIZE(szBuffer));
  22. browse.hwndOwner = hwnd;
  23. browse.pidlRoot = NULL;
  24. browse.pszDisplayName = szPath;
  25. browse.lpszTitle = szBuffer;
  26. browse.ulFlags = BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN;
  27. browse.lpfn = BrowseCallbackProc;
  28. browse.lParam = (*pathname != 0) ? (LPARAM)pathname : NULL;
  29. if ((lpitemid = SHBrowseForFolder(&browse)) == NULL)
  30. return(S_FALSE);
  31. Assert(lpitemid != NULL);
  32. fRet = SHGetPathFromIDList(lpitemid, szPath);
  33. SHFree(lpitemid);
  34. if (!fRet)
  35. return(E_FAIL);
  36. StrCpyN(pathname, szPath, cch);
  37. return(S_OK);
  38. }
  39. int BrowseCallbackProc(HWND hwnd, UINT msg, LPARAM lParam, LPARAM lpData)
  40. {
  41. if (msg == BFFM_INITIALIZED && lpData != NULL)
  42. SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
  43. return(0);
  44. }
  45. HRESULT GetClientDir(char *szDir, int cch, int program)
  46. {
  47. HKEY hkResult;
  48. DWORD cb, dwMs, dwLs, dwType;
  49. HRESULT hr;
  50. char sz[MAX_PATH * 2], szExpanded[MAX_PATH*2], *szT, *pszTok;
  51. Assert(cch >= MAX_PATH);
  52. Assert(program == EUDORA || program == NETSCAPE || program == COMMUNICATOR);
  53. hr = E_FAIL;
  54. pszTok = sz;
  55. switch(program)
  56. {
  57. case EUDORA:
  58. {
  59. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, c_szEudoraCommand, 0, KEY_QUERY_VALUE, &hkResult))
  60. {
  61. cb = sizeof(sz);
  62. if (ERROR_SUCCESS == RegQueryValueEx(hkResult, c_szCurrent, NULL, &dwType, (LPBYTE)sz, &cb))
  63. {
  64. if (REG_EXPAND_SZ == dwType)
  65. {
  66. ExpandEnvironmentStrings(sz, szExpanded, ARRAYSIZE(szExpanded));
  67. pszTok = szExpanded;
  68. }
  69. // TODO: check if user is running version 4 or higher...
  70. szT = StrTokEx(&pszTok, c_szSpace);
  71. if (szT != NULL && GetVersion(szT, &dwMs, &dwLs) && dwMs <= 0x00040000)
  72. {
  73. szT = StrTokEx(&pszTok, c_szSpace);
  74. if (szT != NULL)
  75. {
  76. StrCpyN(szDir, szT, cch);
  77. hr = S_OK;
  78. }
  79. }
  80. }
  81. RegCloseKey(hkResult);
  82. }
  83. break;
  84. }
  85. case NETSCAPE:
  86. {
  87. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, c_szNetscapeKey, 0, KEY_QUERY_VALUE, &hkResult))
  88. {
  89. cb = cch;
  90. if (ERROR_SUCCESS == RegQueryValueEx(hkResult, c_szMailDirectory, NULL, &dwType, (LPBYTE)szDir, &cb))
  91. {
  92. if (REG_EXPAND_SZ == dwType)
  93. {
  94. ExpandEnvironmentStrings(szDir, szExpanded, ARRAYSIZE(szExpanded));
  95. StrCpyN(szDir, szExpanded, cch);
  96. }
  97. // TODO: check if user is running version 4 or higher...
  98. hr = S_OK;
  99. }
  100. RegCloseKey(hkResult);
  101. }
  102. if (hr != S_OK)
  103. {
  104. // try to find 16-bit nscp
  105. cb = GetProfileString(c_szNetscape, c_szIni, c_szEmpty, sz, ARRAYSIZE(sz));
  106. if (cb > 0)
  107. {
  108. cb = GetPrivateProfileString(c_szMail, c_szMailDirectory, c_szEmpty, szDir, cch, sz);
  109. if (cb > 0)
  110. hr = S_OK;
  111. }
  112. }
  113. break;
  114. }
  115. case COMMUNICATOR:
  116. hr = GetCommunicatorDirectory(NULL, szDir, cch);
  117. break;
  118. default:
  119. //We NEVER come here
  120. break;
  121. }
  122. return(hr);
  123. }
  124. BOOL ValidStoreDirectory(TCHAR *szPath, int program)
  125. {
  126. int cch;
  127. HANDLE hnd;
  128. TCHAR *szValid, sz[MAX_PATH];
  129. WIN32_FIND_DATA data;
  130. StrCpyN(sz, szPath, ARRAYSIZE(sz));
  131. cch = lstrlen(sz);
  132. Assert(cch > 0);
  133. if (sz[cch - 1] != '\\')
  134. {
  135. sz[cch] = '\\';
  136. cch++;
  137. sz[cch] = 0;
  138. }
  139. szValid = (program == EUDORA ? (TCHAR *)c_szDescmapPce : (TCHAR *)c_szSnmExt);
  140. StrCpyN(&sz[cch], szValid, ARRAYSIZE(sz)-cch);
  141. hnd = FindFirstFile(sz, &data);
  142. if (hnd != INVALID_HANDLE_VALUE)
  143. FindClose(hnd);
  144. return(hnd == INVALID_HANDLE_VALUE ? FALSE : TRUE);
  145. }
  146. BOOL GetVersion(TCHAR *szFile, DWORD *pdwHigh, DWORD *pdwLow)
  147. {
  148. BOOL fRet;
  149. LPSTR lpInfo;
  150. UINT uLen;
  151. DWORD dwVerInfoSize, dwVerHnd;
  152. VS_FIXEDFILEINFO *pinfo;
  153. Assert(szFile != NULL);
  154. Assert(pdwHigh != NULL);
  155. Assert(pdwLow != NULL);
  156. fRet = FALSE;
  157. if (dwVerInfoSize = GetFileVersionInfoSize(szFile, &dwVerHnd))
  158. {
  159. if (MemAlloc((void **)&lpInfo, dwVerInfoSize))
  160. {
  161. if (GetFileVersionInfo(szFile, dwVerHnd, dwVerInfoSize, lpInfo))
  162. {
  163. if (VerQueryValue(lpInfo, "\\", (LPVOID *)&pinfo, &uLen) &&
  164. uLen == sizeof(VS_FIXEDFILEINFO))
  165. {
  166. *pdwHigh = pinfo->dwProductVersionMS;
  167. *pdwLow = pinfo->dwProductVersionLS;
  168. fRet = TRUE;
  169. }
  170. }
  171. MemFree(lpInfo);
  172. }
  173. }
  174. return(fRet);
  175. }
  176. BOOL GetStorePath(char *szProfile, char *szStorePath, DWORD cchStorePath)
  177. {
  178. char szTemp[MAX_PATH * 2];
  179. char szDirpath[250];
  180. char szLine[1000];
  181. char szCompare[1000];
  182. int nLine = 0;
  183. int nPosition = 0;
  184. HANDLE hJSHandle = NULL;
  185. HANDLE hJSFile = NULL;
  186. ULONG cbJSFile = 0;
  187. BYTE *pBegin = NULL,
  188. *pCurr = NULL,
  189. *pEnd = NULL;
  190. BOOL bFoundEntry = FALSE;
  191. StrCpyN(szTemp, szProfile, ARRAYSIZE(szTemp));
  192. StrCatBuff(szTemp, c_szScriptFile, ARRAYSIZE(szTemp));
  193. hJSHandle = CreateFile( szTemp, GENERIC_READ, FILE_SHARE_READ, NULL,
  194. OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  195. if(hJSHandle == INVALID_HANDLE_VALUE)
  196. return FALSE;
  197. cbJSFile = GetFileSize(hJSHandle, NULL);
  198. hJSFile = CreateFileMapping(hJSHandle, NULL, PAGE_READONLY, 0, 0, NULL);
  199. if(hJSFile == NULL)
  200. {
  201. CloseHandle(hJSHandle);
  202. return FALSE;
  203. }
  204. pBegin = (BYTE *)MapViewOfFile( hJSFile, FILE_MAP_READ, 0, 0, 0);
  205. if(pBegin == NULL)
  206. {
  207. CloseHandle(hJSHandle);
  208. CloseHandle(hJSFile);
  209. return FALSE;
  210. }
  211. pCurr = pBegin;
  212. pEnd = pCurr + cbJSFile;
  213. while (pCurr < pEnd)
  214. {
  215. szLine[nLine] = *pCurr; //keep storing here. will be used for comparing later.
  216. if((pCurr[0] == 0x0D) && (pCurr[1] == 0x0A))
  217. {
  218. if(nLine > lstrlen(c_szUserPref))
  219. {
  220. StrCpyN(szCompare, szLine, (int)(min(lstrlen(c_szUserPref) + 1, ARRAYSIZE(szCompare))));
  221. if(lstrcmp(szCompare, c_szUserPref) == 0)//Found a UserPref for "mail.directory"!
  222. {
  223. //Extract the Mail Store directory.
  224. nPosition = lstrlen(c_szUserPref);
  225. while (((szLine[nPosition] == '"')||(szLine[nPosition] == ' ')||(szLine[nPosition] == ',')) &&(nPosition < nLine))
  226. nPosition++;
  227. StrCpyN(szDirpath, &szLine[nPosition], (int)(min(nLine - nPosition, ARRAYSIZE(szDirpath))));
  228. //Now trim the trailing edge!!!
  229. nPosition = lstrlen(szDirpath) - 1;
  230. while((szDirpath[nPosition] == '"') || (szDirpath[nPosition] == ')')||(szDirpath[nPosition] == ';'))
  231. {
  232. szDirpath[nPosition] = '\0';
  233. nPosition = lstrlen(szDirpath) - 1;
  234. }
  235. // Now replace the double backslashes that Netscape uses
  236. // in the JaveScript files, with a single backslash.
  237. nPosition++; // this now indicates the actual length of the string.
  238. int nPos = 0;
  239. for (int nCount = 0; (nCount < nPosition) && (nPos < (int)cchStorePath); nCount++)
  240. {
  241. if ((szDirpath[nCount - 1] == '\\') && (szDirpath[nCount] == '\\'))
  242. nCount++;
  243. szStorePath[nPos] = szDirpath[nCount];
  244. nPos++;
  245. }
  246. bFoundEntry = TRUE;
  247. break;
  248. }
  249. }
  250. nLine = -1; //the nLine++ that follows will make nLine zero.
  251. pCurr++;
  252. }
  253. pCurr++;
  254. nLine++;
  255. }
  256. if(hJSHandle != INVALID_HANDLE_VALUE)
  257. CloseHandle(hJSHandle);
  258. if(pBegin)
  259. UnmapViewOfFile(pBegin);
  260. if(hJSFile)
  261. CloseHandle(hJSFile);
  262. if(bFoundEntry)
  263. return TRUE;
  264. else
  265. return FALSE;
  266. }