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.

380 lines
12 KiB

  1. #include "pch.hxx"
  2. #include "strconst.h"
  3. #include "error.h"
  4. #include "acctutil.h"
  5. #include "inetcfg.h"
  6. #include <icwcfg.h>
  7. #include "impapi.h"
  8. #include <options.h>
  9. #include <shlwapi.h>
  10. #include "shlwapip.h"
  11. #include "regutil.h"
  12. #include <resource.h>
  13. #include "instance.h"
  14. #include <browser.h>
  15. #include <multiusr.h>
  16. #include "demand.h"
  17. ASSERTDATA
  18. void HandleIncompleteAccts(HWND hwnd, BOOL fMail);
  19. DWORD g_dwIcwFlags = 0; //Cleared when switching identities
  20. static const TCHAR c_szSetShellNext[] = TEXT("SetShellNext");
  21. HRESULT GetDefaultNameEmail(BOOL fMail, LPSTR pszName, int cchName, LPSTR pszEmail, int cchEmail)
  22. {
  23. HRESULT hr;
  24. IImnAccount *pAcct;
  25. Assert(pszName != NULL);
  26. Assert(pszEmail != NULL);
  27. pAcct = NULL;
  28. hr = g_pAcctMan->GetDefaultAccount(fMail ? ACCT_MAIL : ACCT_NEWS, &pAcct);
  29. if (FAILED(hr))
  30. {
  31. Assert(pAcct == NULL);
  32. fMail = !fMail;
  33. hr = g_pAcctMan->GetDefaultAccount(fMail ? ACCT_MAIL : ACCT_NEWS, &pAcct);
  34. if (FAILED(hr))
  35. return(E_FAIL);
  36. }
  37. Assert(pAcct != NULL);
  38. *pszName = 0;
  39. *pszEmail = 0;
  40. pAcct->GetPropSz(fMail ? AP_SMTP_DISPLAY_NAME : AP_NNTP_DISPLAY_NAME, pszName, cchName);
  41. pAcct->GetPropSz(fMail ? AP_SMTP_EMAIL_ADDRESS : AP_NNTP_EMAIL_ADDRESS, pszEmail, cchEmail);
  42. pAcct->Release();
  43. return(S_OK);
  44. }
  45. HRESULT NeedToRunICW(LPCSTR pszCmdLine)
  46. {
  47. char *sz;
  48. HINSTANCE hlib;
  49. HRESULT hr;
  50. LONG lRes;
  51. HKEY hkey;
  52. BOOL fRunICW;
  53. PFNCHECKCONNECTIONWIZARD pfnWiz;
  54. PFNSETSHELLNEXT pfnSet;
  55. DWORD dw, cb, dwType;
  56. Assert(pszCmdLine != NULL);
  57. hr = S_FALSE;
  58. g_dwIcwFlags = 0; //re-initialize this in case the user is switching
  59. fRunICW = TRUE;
  60. cb = sizeof(DWORD);
  61. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, ICW_REGPATHSETTINGS, ICW_REGKEYCOMPLETED, &dwType, (LPBYTE)&dw, &cb))
  62. fRunICW = (dw == 0);
  63. if (fRunICW)
  64. {
  65. if (MemAlloc((void **)&sz, MAX_PATH))
  66. {
  67. hlib = LoadLibrary(c_szInetcfgDll);
  68. if (hlib != NULL)
  69. {
  70. pfnWiz = (PFNCHECKCONNECTIONWIZARD)GetProcAddress(hlib, c_szCheckConnWiz);
  71. pfnSet = (PFNSETSHELLNEXT)GetProcAddress(hlib, c_szSetShellNext);
  72. if (pfnWiz != NULL && pfnSet != NULL)
  73. {
  74. if (GetExePath(c_szMainExe, &sz[1], MAX_PATH - 1, FALSE))
  75. {
  76. sz[0] = '"';
  77. cb = lstrlen(sz);
  78. sz[cb] = '"';
  79. cb++;
  80. sz[cb] = 0; // in case we don't append the arg
  81. dw = lstrlen(pszCmdLine);
  82. if (dw > 0 && (dw + cb + 3) <= MAX_PATH)
  83. // room for a space (between exe and arg), escape backslash, and terminating NULL
  84. {
  85. sz[cb] = ' ';
  86. cb++;
  87. if (*pszCmdLine == '/')
  88. {
  89. sz[cb] = '/';
  90. cb++;
  91. }
  92. StrCpyN(&sz[cb], pszCmdLine, (MAX_PATH - cb));
  93. }
  94. dwType = ICW_LAUNCHFULL | ICW_LAUNCHMANUAL;
  95. if (ERROR_SUCCESS == pfnSet(sz))
  96. dwType |= ICW_USE_SHELLNEXT;
  97. if (ERROR_SUCCESS == pfnWiz(dwType, &dw))
  98. {
  99. if (!!(dw & (ICW_LAUNCHEDFULL | ICW_LAUNCHEDMANUAL)))
  100. hr = S_OK;
  101. else
  102. hr = S_FALSE;
  103. }
  104. }
  105. }
  106. FreeLibrary(hlib);
  107. }
  108. MemFree(sz);
  109. }
  110. }
  111. return(hr);
  112. }
  113. void SetStartFolderType(FOLDERTYPE fType)
  114. {
  115. if (fType == FOLDER_LOCAL || fType == FOLDER_IMAP || fType == FOLDER_HTTPMAIL)
  116. g_dwIcwFlags |= ICW_MAIL_START;
  117. else if (fType == FOLDER_NEWS)
  118. g_dwIcwFlags |= ICW_NEWS_START;
  119. else
  120. {
  121. Assert(fType == FOLDER_ROOTNODE);
  122. }
  123. }
  124. BOOL FMailWizardNeeded(VOID)
  125. {
  126. // Locals
  127. ULONG cAccts;
  128. // We better have been initialized
  129. Assert(g_pAcctMan != NULL);
  130. // No SMTP, POP3 or IMAP servers ?
  131. if (!g_pAcctMan || FAILED(g_pAcctMan->GetAccountCount(ACCT_MAIL, &cAccts)))
  132. cAccts = 0;
  133. // No mail servers configured
  134. return(cAccts == 0);
  135. }
  136. // fForce defaults to FALSE, fShowUI defaults to TRUE
  137. HRESULT ProcessICW(HWND hwnd, FOLDERTYPE fType, BOOL fForce, BOOL fShowUI)
  138. {
  139. HRESULT hr;
  140. DWORD dwProp;
  141. FOLDERID id;
  142. BOOL fMail, fBrowse;
  143. DWORD cNewsServers;
  144. TCHAR sz[CCHMAX_DISPLAY_NAME], szT[CCHMAX_ACCOUNT_NAME];
  145. IImnAccount *pAcct;
  146. if (fType == FOLDER_ROOTNODE)
  147. {
  148. // we're at the root
  149. if (!!(g_dwIcwFlags & ICW_MAIL_START))
  150. {
  151. // if we were started up with a mail arg, then we'll behave
  152. // as if we're in a mail folder
  153. fType = FOLDER_LOCAL;
  154. }
  155. else if (!!(g_dwIcwFlags & ICW_NEWS_START))
  156. {
  157. // started with a news arg, so we'll behave as if
  158. // we're in a news folder
  159. fType = FOLDER_NEWS;
  160. }
  161. else
  162. {
  163. // just started at the root, let's assume mail
  164. fType = FOLDER_LOCAL;
  165. }
  166. }
  167. fMail = (fType != FOLDER_NEWS) && ((g_dwAthenaMode & MODE_OUTLOOKNEWS) != MODE_OUTLOOKNEWS);
  168. if (fMail)
  169. {
  170. if (0 == (g_dwIcwFlags & ICW_MAIL_DEF))
  171. {
  172. if (!(g_dwAthenaMode & MODE_NEWSONLY))
  173. {
  174. if (fShowUI)
  175. DoDefaultClientCheck(hwnd, DEFAULT_MAIL);
  176. }
  177. g_dwIcwFlags |= ICW_MAIL_DEF;
  178. }
  179. // if the wizard has already attempted to be run for mail
  180. // or it isn't needed, then we're done
  181. if (((!fForce && DwGetOption(OPT_CHECKEDMAILACCOUNTS)) || !FMailWizardNeeded()))
  182. {
  183. if (fShowUI)
  184. {
  185. DoMigration(hwnd);
  186. SetDwOption(OPT_CHECKEDMAILACCOUNTS, 1, NULL, 0);
  187. }
  188. return(S_OK);
  189. }
  190. }
  191. else
  192. {
  193. if (0 == (g_dwIcwFlags & ICW_NEWS_DEF))
  194. {
  195. if ((g_dwAthenaMode & MODE_OUTLOOKNEWS) == MODE_OUTLOOKNEWS)
  196. DoDefaultClientCheck(hwnd, DEFAULT_NEWS | DEFAULT_OUTNEWS);
  197. else
  198. DoDefaultClientCheck(hwnd, DEFAULT_NEWS);
  199. g_dwIcwFlags |= ICW_NEWS_DEF;
  200. }
  201. // if the wizard has already attempted to be run for news
  202. // or it isn't needed, then we're done
  203. g_pAcctMan->GetAccountCount(ACCT_NEWS, &cNewsServers);
  204. if (cNewsServers || (!fForce && DwGetOption(OPT_CHECKEDNEWSACCOUNTS)))
  205. {
  206. SetDwOption(OPT_CHECKEDNEWSACCOUNTS, 1, NULL, 0);
  207. return(S_OK);
  208. }
  209. }
  210. Assert(g_pAcctMan != NULL);
  211. // We are missing information and need to bring up the ICW,
  212. // but only do so if we are allowed to show UI (some SMAPI codepaths prevent this)
  213. if (!fShowUI || !g_pAcctMan)
  214. {
  215. hr = E_FAIL;
  216. goto exit;
  217. }
  218. fBrowse = FALSE;
  219. id = FOLDERID_INVALID;
  220. hr = g_pAcctMan->CreateAccountObject(fMail ? ACCT_MAIL : ACCT_NEWS, &pAcct);
  221. if (SUCCEEDED(hr))
  222. {
  223. hr = GetDefaultNameEmail(fMail, sz, ARRAYSIZE(sz), szT, ARRAYSIZE(szT));
  224. if (SUCCEEDED(hr))
  225. {
  226. if (*sz != 0)
  227. pAcct->SetPropSz(fMail ? AP_SMTP_DISPLAY_NAME : AP_NNTP_DISPLAY_NAME, sz);
  228. if (*szT != 0)
  229. pAcct->SetPropSz(fMail ? AP_SMTP_EMAIL_ADDRESS : AP_NNTP_EMAIL_ADDRESS, szT);
  230. }
  231. hr = pAcct->DoWizard(hwnd, ACCT_WIZ_MIGRATE | ACCT_WIZ_INTERNETCONNECTION |
  232. ACCT_WIZ_HTTPMAIL | ACCT_WIZ_OE);
  233. // Test g_pBrowser as no need to browse if got here via startup code
  234. if (g_pBrowser &&
  235. hr == S_OK &&
  236. SUCCEEDED(pAcct->GetServerTypes(&dwProp)) &&
  237. 0 == (dwProp & SRV_POP3) &&
  238. SUCCEEDED(pAcct->GetPropSz(AP_ACCOUNT_ID, szT, ARRAYSIZE(szT))) &&
  239. SUCCEEDED(g_pStore->FindServerId(szT, &id)))
  240. {
  241. fBrowse = TRUE;
  242. }
  243. pAcct->Release();
  244. }
  245. if (fMail)
  246. {
  247. SetDwOption(OPT_CHECKEDMAILACCOUNTS, 1, NULL, 0);
  248. DoMigration(hwnd);
  249. }
  250. else
  251. {
  252. SetDwOption(OPT_CHECKEDNEWSACCOUNTS, 1, NULL, 0);
  253. }
  254. if (fBrowse)
  255. {
  256. Assert(id != FOLDERID_INVALID);
  257. g_pBrowser->BrowseObject(id, 0);
  258. }
  259. exit:
  260. return(hr);
  261. }
  262. void ProcessIncompleteAccts(HWND hwnd)
  263. {
  264. if (0 == (g_dwIcwFlags & ICW_INCOMPLETE))
  265. {
  266. HandleIncompleteAccts(hwnd, TRUE);
  267. HandleIncompleteAccts(hwnd, FALSE);
  268. g_dwIcwFlags |= ICW_INCOMPLETE;
  269. }
  270. }
  271. void HandleIncompleteAccts(HWND hwnd, BOOL fMail)
  272. {
  273. HRESULT hr;
  274. char sz[CCHMAX_ACCOUNT_NAME], szT[CCHMAX_ACCOUNT_NAME], szCurr[CCHMAX_ACCOUNT_NAME];
  275. IImnAccount *pAcct;
  276. Assert(g_pAcctMan != NULL);
  277. hr = g_pAcctMan->GetIncompleteAccount(fMail ? ACCT_MAIL : ACCT_NEWS, sz, ARRAYSIZE(sz));
  278. if (hr == S_OK)
  279. {
  280. if (SUCCEEDED(g_pAcctMan->FindAccount(AP_ACCOUNT_ID, sz, &pAcct)))
  281. {
  282. hr = GetDefaultNameEmail(fMail, sz, ARRAYSIZE(sz), szT, ARRAYSIZE(szT));
  283. if (SUCCEEDED(hr))
  284. {
  285. hr = pAcct->GetPropSz(fMail ? AP_SMTP_DISPLAY_NAME : AP_NNTP_DISPLAY_NAME, szCurr, ARRAYSIZE(szCurr));
  286. if (FAILED(hr) && *sz != 0)
  287. pAcct->SetPropSz(fMail ? AP_SMTP_DISPLAY_NAME : AP_NNTP_DISPLAY_NAME, sz);
  288. hr = pAcct->GetPropSz(fMail ? AP_SMTP_EMAIL_ADDRESS : AP_NNTP_EMAIL_ADDRESS, szCurr, ARRAYSIZE(szCurr));
  289. if (FAILED(hr) && *szT != 0)
  290. pAcct->SetPropSz(fMail ? AP_SMTP_EMAIL_ADDRESS : AP_NNTP_EMAIL_ADDRESS, szT);
  291. }
  292. pAcct->DoWizard(hwnd, ACCT_WIZ_INTERNETCONNECTION | ACCT_WIZ_HTTPMAIL | ACCT_WIZ_OE);
  293. pAcct->Release();
  294. }
  295. g_pAcctMan->SetIncompleteAccount(fMail ? ACCT_MAIL : ACCT_NEWS, NULL);
  296. }
  297. }
  298. void DoAcctImport(HWND hwnd, BOOL fMail)
  299. {
  300. IImnAccount *pAcct;
  301. HRESULT hr;
  302. DWORD dwFlags = 0;
  303. hr = g_pAcctMan->CreateAccountObject(fMail ? ACCT_MAIL : ACCT_NEWS, &pAcct);
  304. if (SUCCEEDED(hr))
  305. {
  306. dwFlags = fMail ? ACCT_WIZ_MAILIMPORT : ACCT_WIZ_NEWSIMPORT;
  307. dwFlags |= (ACCT_WIZ_INTERNETCONNECTION | ACCT_WIZ_HTTPMAIL | ACCT_WIZ_OE);
  308. hr = pAcct->DoWizard(hwnd, dwFlags);
  309. pAcct->Release();
  310. if (hr == E_NoAccounts)
  311. AthMessageBoxW(hwnd, MAKEINTRESOURCEW(idsAthena),
  312. MAKEINTRESOURCEW((fMail ? idsNoAccountsFound : idsNoNewsAccountsFound)),
  313. NULL, MB_ICONINFORMATION | MB_OK);
  314. }
  315. }