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.

1781 lines
68 KiB

  1. #include "pch.hxx"
  2. #include <prsht.h>
  3. #include <msident.h>
  4. #include "acctman.h"
  5. #include <icwacct.h>
  6. #include <strconst.h>
  7. #include "dllmain.h"
  8. #include "acctui.h"
  9. #include "server.h"
  10. #include <shlwapi.h>
  11. #include "acctimp.h"
  12. #include <icwwiz.h>
  13. #include <wininet.h>
  14. #include "resource.h"
  15. #include "demand.h"
  16. ASSERTDATA
  17. enum
  18. {
  19. NNTP = 0,
  20. POP3,
  21. IMAP,
  22. HTTP,
  23. LDAP
  24. };
  25. HRESULT HandleIdentity(LPCSTR pszSection, LPCSTR pszFile, CONNECTINFO *pci, DWORD dwFlags, IUserIdentityManager *pIdMan);
  26. HRESULT HandleGlobalSettings(LPCSTR lpFile);
  27. HRESULT CreateMailAccount(CAccountManager *pAcctMgr, LPCSTR szFile, LPCSTR szMailSection, CONNECTINFO *pci, HKEY hkey, LPSTR pszAcctId, DWORD cchSizeAcctID, DWORD dwFlags);
  28. HRESULT CreateNewsAccount(CAccountManager *pAcctMgr, LPCSTR szFile, LPCSTR szNewsSection, LPCSTR szMailSection, CONNECTINFO *pci, HKEY hkey, IUserIdentity *pId, LPSTR pszAcctId, DWORD cchSizeAcctId, DWORD dwFlags);
  29. HRESULT CreateLDAPAccount(CAccountManager *pAcctMgr, LPCSTR szFile, LPCSTR szLDAPSection, CONNECTINFO *pci);
  30. HRESULT GetAccount(DWORD type, CAccountManager *pAcctMgr, LPCSTR szSection, LPCSTR szFile, IImnAccount **ppAcct);
  31. HRESULT DeleteAccount(DWORD type, CAccountManager *pAcctMgr, LPCSTR szSection, LPCSTR szFile);
  32. void HandleMultipleAccounts(ACCTTYPE type, CAccountManager *pAcctMgr, LPCSTR pszFile, LPCSTR szSection, CONNECTINFO *pci, HKEY hkey, IUserIdentity *pId, DWORD dwFlags);
  33. void SetSignature(LPCSTR szMailSigSection, LPCSTR szNewsSigSection, LPCSTR pszMailId, LPCSTR pszNewsId, LPCSTR szFile, HKEY hkey, CAccountManager *pAcctMgr);
  34. void DoDefaultClient(LPCSTR szFile, BOOL fMail);
  35. void DoMailBranding(LPCSTR szFile, LPCSTR szMailSection, HKEY hkey);
  36. void DoNewsBranding(LPCSTR szFile, LPCSTR szNewsSection, HKEY hkey);
  37. void DoBranding(LPCSTR szFile, LPCSTR szOESection, HKEY hkey);
  38. void SetHelp(LPCSTR szFile, LPCSTR szURLSection, HKEY hkey);
  39. void SubscribeNewsgroups(IImnAccount *pAcct, LPCSTR szSection, LPCSTR szFile, HKEY hkey);
  40. void SetRegDw(LPCSTR szFile, LPCSTR szSection, LPCSTR szValue, HKEY hkey, LPCSTR szRegValue);
  41. void SetRegProp(LPCSTR szFile, LPCSTR szSection, LPCSTR szValue, HKEY hkey, LPCSTR szRegValue);
  42. void SetRegLockPropLM(LPCSTR szFile, LPCSTR szSection, LPCSTR szValue, HKEY hkeyLM, LPCSTR szRegValue, HKEY hkeyCU);
  43. BOOL GetSectionNames(LPSTR psz, DWORD cch, char chSep, DWORD *pcNames);
  44. static const char c_sz1[] = "1";
  45. static const char c_szRegRootMail[] = STR_REG_PATH_ROOT "\\Mail";
  46. static const char c_szRegRootNews[] = STR_REG_PATH_ROOT "\\News";
  47. static const char c_szRegRootRules[] = STR_REG_PATH_ROOT "\\Rules";
  48. static const char c_szRegRootSigs[] = STR_REG_PATH_ROOT "\\Signatures";
  49. ///////////////////////////////////////////////////////////////////////////////
  50. // INS file section names
  51. static const char c_szIdentitySection[] = "Identities";
  52. static const char c_szMailSection[] = "Internet_Mail";
  53. static const char c_szNewsSection[] = "Internet_News";
  54. static const char c_szLDAPSection[] = "LDAP";
  55. static const char c_szMailSigSection[] = "Mail_Signature";
  56. static const char c_szNewsSigSection[] = "Signature";
  57. static const char c_szURLSection[] = "URL";
  58. static const char c_szOESection[] = "Outlook_Express";
  59. static const char c_szGlobalSection[] = "Outlook_Express_Global";
  60. //
  61. ///////////////////////////////////////////////////////////////////////////////
  62. static const char c_szAcctName[] = "Account_Name";
  63. static const char c_szReplyAddr[] = "Reply_To_Address";
  64. static const char c_szIEConnect[] = "Use_IE_Connection";
  65. static const char c_szUseSSL[] = "Use_SSL";
  66. static const char c_szOldServer[] = "Server_Old";
  67. static const char c_szMultiAccounts[] = "Multiple_Accounts";
  68. static const char c_szNone[] = "none";
  69. static const char c_szBase64[] = "base 64";
  70. static const char c_szQuotedPrintable[] = "quoted printable";
  71. static const char c_szMime[] = "mime";
  72. static const char c_szUuencode[] = "uuencode";
  73. static const char c_szDeleteAccount[] = "Delete_Account";
  74. ///////////////////////////////////////////////////////////////////////////////
  75. // identity values
  76. static const char c_szGUID[] = "GUID";
  77. static const char c_szUserName[] = "User_Name";
  78. static const char c_szRegInsGUID[] = "INS File GUID";
  79. //
  80. ///////////////////////////////////////////////////////////////////////////////
  81. ///////////////////////////////////////////////////////////////////////////////
  82. // [URL] section values
  83. static const char c_szHelpPage[] = "Help_Page";
  84. //
  85. ///////////////////////////////////////////////////////////////////////////////
  86. ///////////////////////////////////////////////////////////////////////////////
  87. // [Internet_Mail] section values
  88. static const char c_szMailName[] = "Email_Name";
  89. static const char c_szMailAddr[] = "Email_Address";
  90. static const char c_szPopServer[] = "POP_Server";
  91. static const char c_szPopPort[] = "POP_Server_Port_Number";
  92. static const char c_szMailLogon[] = "POP_Logon_Name";
  93. static const char c_szMailPassword[] = "POP_Logon_Password";
  94. static const char c_szPopLeaveOnServer[] = "POP_Leave_On_Server";
  95. static const char c_szPopRemoveOnDelete[] = "POP_Remove_When_Deleted";
  96. static const char c_szSmtpServer[] = "SMTP_Server";
  97. static const char c_szSmtpPort[] = "SMTP_Server_Port_Number";
  98. static const char c_szSmtpUseSSL[] = "Use_SSL_Send";
  99. static const char c_szSmtpLogonReq[] = "SMTP_Logon_Required";
  100. static const char c_szSmtpLogon[] = "SMTP_Logon_Name";
  101. static const char c_szSmtpPassword[] = "SMTP_Logon_Password";
  102. static const char c_szSmtpLogonUsingSPA[] = "SMTP_Logon_Using_SPA";
  103. static const char c_szLogonUsingSPA[] = "Logon_Using_SPA";
  104. static const char c_szUseImap[] = "Use_IMAP";
  105. static const char c_szImapServer[] = "IMAP_Server";
  106. static const char c_szImapPort[] = "IMAP_Server_Port_Number";
  107. static const char c_szImapLogon[] = "IMAP_Logon_Name";
  108. static const char c_szImapPassword[] = "IMAP_Logon_Password";
  109. static const char c_szImapRoot[] = "IMAP_Root_Folder";
  110. static const char c_szImapSentItems[] = "IMAP_Sent_Items";
  111. static const char c_szImapDrafts[] = "IMAP_Drafts";
  112. static const char c_szImapPoll[] = "Poll_Subscribed_Folders";
  113. static const char c_szService[] = "Service";
  114. static const char c_szHttpUrl[] = "HTTP_Mail_Root_URL";
  115. static const char c_szHttpLogon[] = "HTTP_Mail_Logon_Name";
  116. static const char c_szHttpPassword[] = "HTTP_Mail_Logon_Password";
  117. static const char c_szHttpPoll[] = "HTTP_Poll_Folders";
  118. static const char c_szMsnCom[] = "MSN_COM";
  119. static const char c_szWinTitle[] = "Window_Title";
  120. static const char c_szInfopane[] = "Infopane";
  121. static const char c_szWelcomeMsg[] = "Welcome_Message";
  122. static const char c_szProfWelcomeName[] = "Welcome_Name";
  123. static const char c_szProfWelcomeEmail[] = "Welcome_Address";
  124. static const char c_szPollTime[] = "PollTime";
  125. static const char c_szStartAtInbox[] = "Start_at_Inbox";
  126. static const char c_szJunkMail[] = "Junk_Mail_Filtering";
  127. static const char c_szHTMLMsgs[] = "HTML_Msgs";
  128. //
  129. ///////////////////////////////////////////////////////////////////////////////
  130. ///////////////////////////////////////////////////////////////////////////////
  131. // [Internet_News] section values
  132. static const char c_szNewsName[] = "News_Name";
  133. static const char c_szNewsAddr[] = "News_Address";
  134. static const char c_szNewsServer[] = "NNTP_Server";
  135. static const char c_szNewsPort[] = "NNTP_Server_Port_Number";
  136. static const char c_szNewsLogon[] = "NNTP_Logon_Name";
  137. static const char c_szNewsPassword[] = "NNTP_Logon_Password";
  138. static const char c_szNewsLogonRequired[] = "Logon_Required";
  139. static const char c_szNewsgroups[] = "Newsgroups";
  140. //
  141. ///////////////////////////////////////////////////////////////////////////////
  142. ///////////////////////////////////////////////////////////////////////////////
  143. // [LDAP] section values
  144. static const char c_szLDAPServer[] = "Server";
  145. static const char c_szLDAPFriendlyName[] = "FriendlyName";
  146. static const char c_szLDAPHomePage[] = "HomePage";
  147. static const char c_szLDAPSearchBase[] = "SearchBase";
  148. static const char c_szLDAPAuthType[] = "AuthType";
  149. static const char c_szLDAPCheckNames[] = "CheckNames";
  150. static const char c_szLDAPUserName[] = "UserName";
  151. static const char c_szLDAPPassword[] = "Password";
  152. static const char c_szLDAPLogo[] = "Bitmap";
  153. static const char c_szLDAPPort[] = "LDAP_Server_Port_Number";
  154. static const char c_szLDAPResults[] = "Maximum_Results";
  155. static const char c_szLDAPTimeout[] = "Search_Timeout";
  156. //
  157. ///////////////////////////////////////////////////////////////////////////////
  158. ///////////////////////////////////////////////////////////////////////////////
  159. // [Outlook_Express] section values
  160. static const char c_szFolderBar[] = "Folder_Bar";
  161. static const char c_szFolderList[] = "Folder_List";
  162. static const char c_szOutlookBar[] = "Outlook_Bar";
  163. static const char c_szStatusBar[] = "Status_Bar";
  164. static const char c_szContacts[] = "Contacts";
  165. static const char c_szTipOfTheDay[] = "Tip_Day";
  166. static const char c_szToolbar[] = "Toolbar";
  167. static const char c_szToolbarText[] = "Show_Toolbar_Text";
  168. static const char c_szPreviewPane[] = "Preview_Pane";
  169. static const char c_szPreviewHeader[] = "Show_Preview_Header";
  170. static const char c_szPreviewSide[] = "Show_Preview_Beside_Msgs";
  171. static const char c_szMigration[] = "Migration";
  172. static const char c_szSecZone[] = "Security_Zone";
  173. static const char c_szSecZoneLocked[] = "Security_Zone_Locked";
  174. static const char c_szMapiWarn[] = "Warn_on_Mapi_Send";
  175. static const char c_szMapiWarnLocked[] = "Warn_on_Mapi_Send_Locked";
  176. static const char c_szSafeAttach[] = "Safe_Attachments";
  177. static const char c_szSafeAttachLocked[] = "Safe_Attachments_Locked";
  178. static const char c_szSendEncoding[] = "Send_Language_Encoding";
  179. static const char c_szReadEncoding[] = "Read_Language_Encoding";
  180. static const char c_szMailEncoding[] = "HTML_Mail_Encoding";
  181. static const char c_szNewsEncoding[] = "HTML_News_Encoding";
  182. static const char c_szMailEnglishHeader[] = "HTML_Mail_Allow_English_Mail_Headers";
  183. static const char c_szNewsEnglishHeader[] = "HTML_News_Allow_English_Mail_Headers";
  184. static const char c_szMailPlainEncoding[] = "Plain_Text_Mail_Encoding";
  185. static const char c_szNewsPlainEncoding[] = "Plain_Text_News_Encoding";
  186. static const char c_szMailPlainEnglishHeader[] = "Plain_Text_Allow_English_Mail_Headers";
  187. static const char c_szNewsPlainEnglishHeader[] = "Plain_Text_Allow_English_News_Headers";
  188. static const char c_szRequestReadReceipts[] = "Request_read_receipts";
  189. static const char c_szReadReceiptResponse[] = "Read_receipt_response";
  190. static const char c_szSendReceiptsToList[] = "Send_receipts_to_list";
  191. static const char c_szRequestReadReceiptsLocked[] = "Request_read_receipts_locked";
  192. static const char c_szReadReceiptResponseLocked[] = "Read_receipt_response_locked";
  193. static const char c_szSendReceiptsToListLocked[] = "Send_receipts_to_list_locked";
  194. //
  195. ///////////////////////////////////////////////////////////////////////////////
  196. ///////////////////////////////////////////////////////////////////////////////
  197. // [Outlook_Express_Global] section values
  198. static const char c_szReadOnlyAccts[] = "Read_Only";
  199. static const char c_szDisableAccts[] = "Disable_Account_Access";
  200. static const char c_szInsHideMessenger[] = "Hide_Messenger";
  201. static const char c_szHideMSN[] = "Hide_MSN";
  202. static const char c_szServiceName[] = "Service_Name";
  203. static const char c_szServiceURL[] = "Service_URL";
  204. static const char c_szAccountNumber[] = "Account_Number";
  205. static const char c_szInsEnableHttpmail[] = "Enable_HTTPMail";
  206. //
  207. ///////////////////////////////////////////////////////////////////////////////
  208. static const char c_szUseSig[] = "Use_Signature";
  209. static const char c_szProfSigText[] = "Signature_Text";
  210. static const char c_szUseMailForNews[] = "Use_Mail_For_News";
  211. static const char c_szMailSigKey[] = "MailIEAK";
  212. static const char c_szNewsSigKey[] = "NewsIEAK";
  213. static const char c_szDefClient[] = "Default_Client";
  214. static const char c_szRegProfile[] = "InternetProfile";
  215. #define CBPROFILEBUF 0x07fff
  216. // From mailnews\inc\goptions.h
  217. #define SIGFLAG_AUTONEW 0x0001 // automatically add sig to new messages
  218. #define SIGFLAG_AUTOREPLY 0x0002 // automatically add sig to reply/forward messages
  219. HRESULT WINAPI CreateAccountsFromFile(LPSTR lpFile, DWORD dwFlags)
  220. {
  221. return(CreateAccountsFromFileEx(lpFile, NULL, dwFlags));
  222. }
  223. HRESULT WINAPI CreateAccountsFromFileEx(LPSTR lpFile, CONNECTINFO *pci, DWORD dwFlags)
  224. {
  225. GUID guid;
  226. IUserIdentityManager *pIdMan;
  227. IUserIdentity *pId;
  228. HKEY hkey;
  229. CAccountManager *pAcctMgr;
  230. LPSTR sz, psz;
  231. LPCSTR pszMailSig, pszNewsSig;
  232. CONNECTINFO ci;
  233. DWORD cch, type, dw, cb, i;
  234. HRESULT hr;
  235. char szMailId[CCHMAX_ACCOUNT_NAME], szNewsId[CCHMAX_ACCOUNT_NAME];
  236. hr = CoInitialize(NULL);
  237. if (SUCCEEDED(hr))
  238. {
  239. if (!g_pMalloc || !MemAlloc((void **)&sz, CBPROFILEBUF))
  240. {
  241. hr = E_OUTOFMEMORY;
  242. }
  243. else
  244. {
  245. hr = CoCreateInstance(CLSID_UserIdentityManager, NULL, CLSCTX_INPROC_SERVER, IID_IUserIdentityManager, (LPVOID *)&pIdMan);
  246. if (SUCCEEDED(hr))
  247. {
  248. if (!!(dwFlags & CAFF_USE_AUTODIAL))
  249. {
  250. cb = sizeof(DWORD);
  251. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, c_szEnableAutoDialPath, c_RegKeyEnableAutoDial, &type, &dw, &cb) &&
  252. !!dw &&
  253. #pragma prefast(suppress:282, "the value of cb has to be changed between the first and second calls to SHGetValue")
  254. (cb = sizeof(ci.szConnectoid)) &&
  255. ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, c_szDefConnPath, c_szRegProfile, &type, ci.szConnectoid, &cb) &&
  256. !FIsEmpty(ci.szConnectoid))
  257. {
  258. ci.cbSize = sizeof(CONNECTINFO);
  259. ci.type = CONNECT_RAS;
  260. pci = &ci;
  261. }
  262. }
  263. cch = GetPrivateProfileSection(c_szIdentitySection, sz, CBPROFILEBUF, lpFile);
  264. if ((cch != 0) && (cch != (CBPROFILEBUF - 2)))
  265. {
  266. if (GetSectionNames(sz, cch, 0, &dw))
  267. {
  268. for (i = 0, psz = sz; i < dw; i++)
  269. {
  270. HandleIdentity(psz, lpFile, pci, dwFlags, pIdMan);
  271. psz += (lstrlen(psz) + 1);
  272. }
  273. }
  274. }
  275. else
  276. {
  277. cch = GetPrivateProfileSectionNames(sz, CBPROFILEBUF, lpFile);
  278. if (cch != 0)
  279. {
  280. if (!!(dwFlags & CAFF_CURRENT_USER))
  281. guid = UID_GIBC_CURRENT_USER;
  282. else
  283. guid = UID_GIBC_DEFAULT_USER;
  284. hr = pIdMan->GetIdentityByCookie(&guid, &pId);
  285. if (SUCCEEDED(hr))
  286. {
  287. hr = pId->OpenIdentityRegKey(KEY_READ | KEY_WRITE, &hkey);
  288. if (SUCCEEDED(hr))
  289. {
  290. hr = HrCreateAccountManager((IImnAccountManager **)&pAcctMgr);
  291. if (SUCCEEDED(hr))
  292. {
  293. hr = pAcctMgr->InitUser(NULL, guid, 0);
  294. if (SUCCEEDED(hr))
  295. {
  296. *szMailId = 0;
  297. *szNewsId = 0;
  298. pszMailSig = NULL;
  299. pszNewsSig = NULL;
  300. psz = sz;
  301. while (*psz != 0)
  302. {
  303. if (0 == lstrcmpi(psz, c_szMailSection))
  304. {
  305. CreateMailAccount(pAcctMgr, lpFile, c_szMailSection, pci, hkey, szMailId, ARRAYSIZE(szMailId), dwFlags);
  306. DoMailBranding(lpFile, c_szMailSection, hkey);
  307. HandleMultipleAccounts(ACCT_MAIL, pAcctMgr, lpFile, c_szMailSection, pci, hkey, pId, dwFlags);
  308. }
  309. else if (0 == lstrcmpi(psz, c_szNewsSection))
  310. {
  311. CreateNewsAccount(pAcctMgr, lpFile, c_szNewsSection, c_szMailSection, pci, hkey, pId, szNewsId, ARRAYSIZE(szNewsId), dwFlags);
  312. DoNewsBranding(lpFile, c_szNewsSection, hkey);
  313. HandleMultipleAccounts(ACCT_NEWS, pAcctMgr, lpFile, c_szNewsSection, pci, hkey, pId, dwFlags);
  314. }
  315. else if (0 == lstrcmpi(psz, c_szLDAPSection))
  316. {
  317. CreateLDAPAccount(pAcctMgr, lpFile, c_szLDAPSection, pci);
  318. HandleMultipleAccounts(ACCT_DIR_SERV, pAcctMgr, lpFile, c_szLDAPSection, pci, hkey, pId, dwFlags);
  319. }
  320. else if (0 == lstrcmpi(psz, c_szURLSection))
  321. {
  322. SetHelp(lpFile, c_szURLSection, hkey);
  323. }
  324. else if (0 == lstrcmpi(psz, c_szOESection))
  325. {
  326. DoBranding(lpFile, c_szOESection, hkey);
  327. }
  328. else if (0 == lstrcmpi(psz, c_szMailSigSection))
  329. {
  330. pszMailSig = c_szMailSigSection;
  331. }
  332. else if (0 == lstrcmpi(psz, c_szNewsSigSection))
  333. {
  334. pszNewsSig = c_szNewsSigSection;
  335. }
  336. psz += (lstrlen(psz) + 1);
  337. }
  338. SetSignature(pszMailSig, pszNewsSig, (*szMailId != 0) ? szMailId : NULL,
  339. (*szNewsId != 0) ? szNewsId : NULL, lpFile, hkey, pAcctMgr);
  340. }
  341. pAcctMgr->Release();
  342. }
  343. RegCloseKey(hkey);
  344. }
  345. pId->Release();
  346. }
  347. }
  348. }
  349. HandleGlobalSettings(lpFile);
  350. DoDefaultClient(lpFile, TRUE);
  351. DoDefaultClient(lpFile, FALSE);
  352. pIdMan->Release();
  353. }
  354. MemFree(sz);
  355. }
  356. CoUninitialize();
  357. }
  358. return(hr);
  359. }
  360. HRESULT HandleGlobalSettings(LPCSTR lpFile)
  361. {
  362. HKEY hkey;
  363. HRESULT hr;
  364. DWORD dw, disp, cb;
  365. char sz[512], szT[512], szKey[MAX_PATH];
  366. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, c_szRegFlat, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw))
  367. {
  368. SetRegProp(lpFile, c_szGlobalSection, c_szDisableAccts, hkey, c_szRegValNoModifyAccts);
  369. dw = GetPrivateProfileString(c_szGlobalSection, c_szInsEnableHttpmail, c_szEmpty, sz, ARRAYSIZE(sz), lpFile);
  370. if (dw > 0)
  371. {
  372. dw = (0 == lstrcmpi(sz, c_szYes) || 0 == lstrcmpi(sz, c_sz1));
  373. RegSetValueEx(hkey, c_szEnableHTTPMail, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  374. }
  375. RegCloseKey(hkey);
  376. }
  377. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, c_szRegFlat, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &dw))
  378. {
  379. SetRegDw(lpFile, c_szGlobalSection, c_szInsHideMessenger, hkey, c_szHideMessenger);
  380. SetRegProp(lpFile, c_szGlobalSection, c_szHideMSN, hkey, c_szRegDisableHotmail);
  381. RegCloseKey(hkey);
  382. }
  383. dw = GetPrivateProfileString(c_szGlobalSection, c_szServiceURL, c_szEmpty, sz, ARRAYSIZE(sz), lpFile);
  384. if (dw > 0)
  385. {
  386. cb = ARRAYSIZE(szT);
  387. hr = UrlGetPart(sz, szT, &cb, URL_PART_HOSTNAME, 0);
  388. if (FAILED(hr))
  389. StrCpyN(szT, sz, ARRAYSIZE(szT));
  390. wnsprintf(szKey, ARRAYSIZE(szKey), c_szPathFileFmt, c_szHTTPMailServiceRoot, szT);
  391. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp))
  392. {
  393. RegSetValueEx(hkey, c_szHTTPMailSignUp, 0, REG_SZ, (LPBYTE)sz, dw + 1);
  394. dw = GetPrivateProfileString(c_szGlobalSection, c_szServiceName, c_szEmpty, sz, ARRAYSIZE(sz), lpFile);
  395. if (dw > 0)
  396. RegSetValueEx(hkey, c_szHTTPMailServiceName, 0, REG_SZ, (LPBYTE)sz, dw + 1);
  397. SetRegDw(lpFile, c_szGlobalSection, c_szAccountNumber, hkey, c_szHTTPMailAcctNumber);
  398. RegCloseKey(hkey);
  399. }
  400. }
  401. return(S_OK);
  402. }
  403. void HandleConnectInfo(IImnAccount *pAcct, CONNECTINFO *pci, BOOL fUseIEConnection)
  404. {
  405. DWORD type;
  406. Assert(pAcct != NULL);
  407. if (fUseIEConnection)
  408. {
  409. pAcct->SetPropDw(AP_RAS_CONNECTION_TYPE, CONNECTION_TYPE_INETSETTINGS);
  410. return;
  411. }
  412. if (pci != NULL)
  413. type = pci->type;
  414. else
  415. type = CONNECT_LAN;
  416. pAcct->SetPropDw(AP_RAS_CONNECTION_TYPE, type);
  417. if (type == CONNECT_RAS)
  418. {
  419. Assert(pci != NULL);
  420. pAcct->SetPropSz(AP_RAS_CONNECTOID, pci->szConnectoid);
  421. }
  422. }
  423. void GetPropSz(LPCSTR szSection, LPCSTR szValue, LPCSTR szSection2, LPCSTR szValue2, LPCSTR szFile, IImnAccount *pAcct, DWORD prop, BOOL *pfComplete)
  424. {
  425. char sz[512];
  426. DWORD dw;
  427. HRESULT hr;
  428. Assert(szSection != NULL);
  429. Assert(szValue != NULL);
  430. Assert(szFile != NULL);
  431. Assert(pAcct != NULL);
  432. dw = GetPrivateProfileString(szSection, szValue, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  433. if (dw == 0 && szSection2 != NULL)
  434. {
  435. Assert(szValue2 != NULL);
  436. dw = GetPrivateProfileString(szSection2, szValue2, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  437. }
  438. if (dw > 0)
  439. {
  440. pAcct->SetPropSz(prop, sz);
  441. }
  442. else if (pfComplete != NULL)
  443. {
  444. dw = 0;
  445. hr = pAcct->GetProp(prop, NULL, &dw);
  446. if (dw == 0)
  447. *pfComplete = FALSE;
  448. }
  449. }
  450. void GetPropDw(LPCSTR szSection, LPCSTR szValue, LPCSTR szFile, IImnAccount *pAcct, DWORD prop)
  451. {
  452. DWORD dw;
  453. dw = GetPrivateProfileInt(szSection, szValue, -1, szFile);
  454. if (dw != -1)
  455. pAcct->SetPropDw(prop, dw);
  456. }
  457. void GetPropBool(LPCSTR szSection, LPCSTR szValue, LPCSTR szFile, IImnAccount *pAcct, DWORD prop)
  458. {
  459. DWORD dw;
  460. char sz[512];
  461. dw = GetPrivateProfileString(szSection, szValue, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  462. if (dw > 0)
  463. {
  464. dw = (0 == lstrcmpi(sz, c_szYes) || 0 == lstrcmpi(sz, c_sz1));
  465. pAcct->SetPropDw(prop, dw);
  466. }
  467. }
  468. BOOL GetBool(LPCSTR szSection, LPCSTR szValue, LPCSTR szFile)
  469. {
  470. DWORD dw;
  471. char sz[512];
  472. dw = GetPrivateProfileString(szSection, szValue, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  473. return(dw > 0 && (0 == lstrcmpi(sz, c_szYes) || 0 == lstrcmpi(sz, c_sz1)));
  474. }
  475. void SetRegProp(LPCSTR szFile, LPCSTR szSection, LPCSTR szValue, HKEY hkey, LPCSTR szRegValue)
  476. {
  477. char sz[16];
  478. DWORD dw;
  479. dw = GetPrivateProfileString(szSection, szValue, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  480. if (dw > 0)
  481. {
  482. dw = (0 == lstrcmpi(sz, c_szYes) || 0 == lstrcmpi(sz, c_sz1));
  483. RegSetValueEx(hkey, szRegValue, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  484. }
  485. }
  486. void SetRegDw(LPCSTR szFile, LPCSTR szSection, LPCSTR szValue, HKEY hkey, LPCSTR szRegValue)
  487. {
  488. DWORD dw;
  489. dw = GetPrivateProfileInt(szSection, szValue, -1, szFile);
  490. if (dw != -1)
  491. RegSetValueEx(hkey, szRegValue, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  492. }
  493. HRESULT CreateMailAccount(CAccountManager *pAcctMgr, LPCSTR szFile, LPCSTR szMailSection, CONNECTINFO *pci, HKEY hkey, LPSTR pszAcctId, DWORD cchSizeAcctID, DWORD dwFlags)
  494. {
  495. IImnAccount *pAcct;
  496. HRESULT hr;
  497. DWORD dw;
  498. char sz[512];
  499. int type;
  500. BOOL fSicily, fDelete, fComplete = TRUE;
  501. Assert(pAcctMgr != NULL);
  502. Assert(szFile != NULL);
  503. if (GetBool(szMailSection, c_szUseImap, szFile))
  504. type = IMAP;
  505. else if (GetPrivateProfileString(szMailSection, c_szHttpUrl, c_szEmpty, sz, ARRAYSIZE(sz), szFile) > 0)
  506. type = HTTP;
  507. else
  508. type = POP3;
  509. fDelete = (BOOL)GetPrivateProfileInt(szMailSection, c_szDeleteAccount, 0, szFile);
  510. if (fDelete)
  511. {
  512. DeleteAccount(type, pAcctMgr, szMailSection, szFile);
  513. return(S_OK);
  514. }
  515. if (SUCCEEDED(hr = GetAccount(type, pAcctMgr, szMailSection, szFile, &pAcct)))
  516. {
  517. Assert(pAcct != NULL);
  518. if (type == POP3)
  519. {
  520. GetPropDw(szMailSection, c_szPopPort, szFile, pAcct, AP_POP3_PORT);
  521. GetPropBool(szMailSection, c_szUseSSL, szFile, pAcct, AP_POP3_SSL);
  522. GetPropBool(szMailSection, c_szPopLeaveOnServer, szFile, pAcct, AP_POP3_LEAVE_ON_SERVER);
  523. GetPropBool(szMailSection, c_szPopRemoveOnDelete, szFile, pAcct, AP_POP3_REMOVE_DELETED);
  524. fSicily = GetBool(szMailSection, c_szLogonUsingSPA, szFile);
  525. pAcct->SetPropDw(AP_POP3_USE_SICILY, fSicily);
  526. // IE5 Bug #65821: Even if SPA (Sicily) is turned on, we store the account name and password
  527. GetPropSz(szMailSection, c_szMailLogon, NULL, NULL, szFile, pAcct, AP_POP3_USERNAME, &fComplete);
  528. GetPropSz(szMailSection, c_szMailPassword, NULL, NULL, szFile, pAcct, AP_POP3_PASSWORD, NULL);
  529. }
  530. else if (type == IMAP)
  531. {
  532. GetPropDw(szMailSection, c_szImapPort, szFile, pAcct, AP_IMAP_PORT);
  533. GetPropBool(szMailSection, c_szUseSSL, szFile, pAcct, AP_IMAP_SSL);
  534. GetPropSz(szMailSection, c_szImapRoot, NULL, NULL, szFile, pAcct, AP_IMAP_ROOT_FOLDER, NULL);
  535. GetPropSz(szMailSection, c_szImapSentItems, NULL, NULL, szFile, pAcct, AP_IMAP_SENTITEMSFLDR, NULL);
  536. GetPropSz(szMailSection, c_szImapDrafts, NULL, NULL, szFile, pAcct, AP_IMAP_DRAFTSFLDR, NULL);
  537. GetPropBool(szMailSection, c_szImapPoll, szFile, pAcct, AP_IMAP_POLL);
  538. fSicily = GetBool(szMailSection, c_szLogonUsingSPA, szFile);
  539. pAcct->SetPropDw(AP_IMAP_USE_SICILY, fSicily);
  540. // IE5 Bug #65821: Even if SPA (Sicily) is turned on, we store the account name and password
  541. GetPropSz(szMailSection, c_szImapLogon, NULL, NULL, szFile, pAcct, AP_IMAP_USERNAME, &fComplete);
  542. GetPropSz(szMailSection, c_szImapPassword, NULL, NULL, szFile, pAcct, AP_IMAP_PASSWORD, NULL);
  543. }
  544. else
  545. {
  546. fSicily = GetBool(szMailSection, c_szLogonUsingSPA, szFile);
  547. pAcct->SetPropDw(AP_HTTPMAIL_USE_SICILY, fSicily);
  548. // IE5 Bug #65821: Even if SPA (Sicily) is turned on, we store the account name and password
  549. GetPropSz(szMailSection, c_szHttpLogon, NULL, NULL, szFile, pAcct, AP_HTTPMAIL_USERNAME, &fComplete);
  550. GetPropSz(szMailSection, c_szHttpPassword, NULL, NULL, szFile, pAcct, AP_HTTPMAIL_PASSWORD, NULL);
  551. GetPropBool(c_szMailSection, c_szHttpPoll, szFile, pAcct, AP_HTTPMAIL_POLL);
  552. GetPropBool(szMailSection, c_szMsnCom, szFile, pAcct, AP_HTTPMAIL_DOMAIN_MSN);
  553. }
  554. GetPropSz(szMailSection, c_szMailName, NULL, NULL, szFile, pAcct, AP_SMTP_DISPLAY_NAME, &fComplete);
  555. GetPropSz(szMailSection, c_szMailAddr, NULL, NULL, szFile, pAcct, AP_SMTP_EMAIL_ADDRESS, &fComplete);
  556. GetPropSz(szMailSection, c_szReplyAddr, NULL, NULL, szFile, pAcct, AP_SMTP_REPLY_EMAIL_ADDRESS, NULL);
  557. if (type != HTTP)
  558. {
  559. GetPropSz(szMailSection, c_szSmtpServer, NULL, NULL, szFile, pAcct, AP_SMTP_SERVER, &fComplete);
  560. GetPropDw(szMailSection, c_szSmtpPort, szFile, pAcct, AP_SMTP_PORT);
  561. GetPropBool(szMailSection, c_szSmtpUseSSL, szFile, pAcct, AP_SMTP_SSL);
  562. dw = GetPrivateProfileString(szMailSection, c_szSmtpLogonReq, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  563. if (dw > 0)
  564. {
  565. if (0 == lstrcmpi(sz, c_szYes) || 0 == lstrcmpi(sz, c_sz1))
  566. {
  567. // IE5 Bug #67153: If SMTP logon required, but SPA not set, assume username/pass is provided
  568. fSicily = GetBool(szMailSection, c_szSmtpLogonUsingSPA, szFile);
  569. pAcct->SetPropDw(AP_SMTP_USE_SICILY, fSicily ?
  570. SMTP_AUTH_SICILY : SMTP_AUTH_USE_SMTP_SETTINGS);
  571. // IE5 Bug #67153: Even if SPA (Sicily) is turned on, we store the account name and password
  572. GetPropSz(szMailSection, c_szSmtpLogon, NULL, NULL, szFile, pAcct, AP_SMTP_USERNAME, NULL);
  573. GetPropSz(szMailSection, c_szSmtpPassword, NULL, NULL, szFile, pAcct, AP_SMTP_PASSWORD, NULL);
  574. }
  575. else
  576. {
  577. pAcct->SetPropDw(AP_SMTP_USE_SICILY, SMTP_AUTH_NONE);
  578. pAcct->SetPropSz(AP_SMTP_USERNAME, NULL);
  579. pAcct->SetPropSz(AP_SMTP_PASSWORD, NULL);
  580. }
  581. }
  582. }
  583. GetPropSz(szMailSection, c_szService, NULL, NULL, szFile, pAcct, AP_SERVICE, NULL);
  584. GetPropDw(c_szGlobalSection, c_szReadOnlyAccts, szFile, pAcct, AP_SERVER_READ_ONLY);
  585. HandleConnectInfo(pAcct, pci, GetBool(szMailSection, c_szIEConnect, szFile));
  586. hr = pAcct->SaveChanges();
  587. if (SUCCEEDED(hr))
  588. {
  589. if (0 == (dwFlags & CAFF_NO_SET_DEFAULT))
  590. pAcct->SetAsDefault();
  591. if (SUCCEEDED(pAcct->GetPropSz(AP_ACCOUNT_ID, sz, ARRAYSIZE(sz))))
  592. {
  593. if (pszAcctId != NULL)
  594. StrCpyN(pszAcctId, sz, cchSizeAcctID);
  595. if (!fComplete)
  596. pAcctMgr->SetIncompleteAccount(ACCT_MAIL, sz);
  597. }
  598. }
  599. pAcct->Release();
  600. }
  601. return(hr);
  602. }
  603. HRESULT CreateNewsAccount(CAccountManager *pAcctMgr, LPCSTR szFile, LPCSTR szNewsSection, LPCSTR szMailSection, CONNECTINFO *pci, HKEY hkey, IUserIdentity *pId, LPSTR pszAcctId, DWORD cchSizeAcctId, DWORD dwFlags)
  604. {
  605. IImnAccount *pAcct;
  606. HRESULT hr;
  607. DWORD dw;
  608. char sz[512];
  609. BOOL fSPA, fDelete, fComplete = TRUE;
  610. Assert(pAcctMgr != NULL);
  611. Assert(szFile != NULL);
  612. fDelete = (BOOL)GetPrivateProfileInt(szNewsSection, c_szDeleteAccount, 0, szFile);
  613. if (fDelete)
  614. {
  615. DeleteAccount(NNTP, pAcctMgr, szNewsSection, szFile);
  616. return(S_OK);
  617. }
  618. if (SUCCEEDED(hr = GetAccount(NNTP, pAcctMgr, szNewsSection, szFile, &pAcct)))
  619. {
  620. Assert(pAcct != NULL);
  621. GetPropSz(szNewsSection, c_szNewsName, szMailSection, c_szMailName, szFile, pAcct,
  622. AP_NNTP_DISPLAY_NAME, &fComplete);
  623. GetPropSz(szNewsSection, c_szNewsAddr, szMailSection, c_szMailAddr, szFile, pAcct,
  624. AP_NNTP_EMAIL_ADDRESS, &fComplete);
  625. GetPropSz(szNewsSection, c_szReplyAddr, szMailSection, c_szReplyAddr, szFile, pAcct,
  626. AP_NNTP_REPLY_EMAIL_ADDRESS, NULL);
  627. GetPropDw(szNewsSection, c_szNewsPort, szFile, pAcct, AP_NNTP_PORT);
  628. GetPropBool(szNewsSection, c_szUseSSL, szFile, pAcct, AP_NNTP_SSL);
  629. fSPA = FALSE;
  630. if (GetBool(szNewsSection, c_szNewsLogonRequired, szFile))
  631. {
  632. fSPA = GetBool(szNewsSection, c_szLogonUsingSPA, szFile);
  633. // IE5 Bug #65821: Even if SPA (Sicily) is turned on, we store the account name and password
  634. GetPropSz(szNewsSection, c_szNewsLogon, NULL, NULL, szFile, pAcct, AP_NNTP_USERNAME, &fComplete);
  635. GetPropSz(szNewsSection, c_szNewsPassword, NULL, NULL, szFile, pAcct, AP_NNTP_PASSWORD, NULL);
  636. }
  637. pAcct->SetPropDw(AP_NNTP_USE_SICILY, fSPA);
  638. GetPropDw(c_szGlobalSection, c_szReadOnlyAccts, szFile, pAcct, AP_SERVER_READ_ONLY);
  639. HandleConnectInfo(pAcct, pci, GetBool(szNewsSection, c_szIEConnect, szFile));
  640. hr = pAcct->SaveChanges();
  641. if (SUCCEEDED(hr))
  642. {
  643. if (0 == (dwFlags & CAFF_NO_SET_DEFAULT))
  644. pAcct->SetAsDefault();
  645. if (SUCCEEDED(pAcct->GetPropSz(AP_ACCOUNT_ID, sz, ARRAYSIZE(sz))))
  646. {
  647. if (pszAcctId != NULL)
  648. StrCpyN(pszAcctId, sz, cchSizeAcctId);
  649. if (!fComplete)
  650. pAcctMgr->SetIncompleteAccount(ACCT_NEWS, sz);
  651. }
  652. dw = GetPrivateProfileString(szNewsSection, c_szNewsgroups, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  653. if (dw > 0)
  654. SubscribeNewsgroups(pAcct, sz, szFile, hkey);
  655. }
  656. pAcct->Release();
  657. }
  658. return(hr);
  659. }
  660. HRESULT CreateLDAPAccount(CAccountManager *pAcctMgr, LPCSTR szFile, LPCSTR szLDAPSection, CONNECTINFO *pci)
  661. {
  662. IImnAccount *pAcct;
  663. HRESULT hr;
  664. int i;
  665. char sz[512];
  666. DWORD dw;
  667. BOOL fDelete;
  668. Assert(pAcctMgr != NULL);
  669. Assert(szFile != NULL);
  670. fDelete = (BOOL)GetPrivateProfileInt(szLDAPSection, c_szDeleteAccount, 0, szFile);
  671. if (fDelete)
  672. {
  673. DeleteAccount(LDAP, pAcctMgr, szLDAPSection, szFile);
  674. return(S_OK);
  675. }
  676. if (SUCCEEDED(hr = GetAccount(LDAP, pAcctMgr, szLDAPSection, szFile, &pAcct)))
  677. {
  678. Assert(pAcct != NULL);
  679. GetPropSz(szLDAPSection, c_szLDAPSearchBase, NULL, NULL, szFile, pAcct, AP_LDAP_SEARCH_BASE, NULL);
  680. GetPropSz(szLDAPSection, c_szLDAPHomePage, NULL, NULL, szFile, pAcct, AP_LDAP_URL, NULL);
  681. GetPropSz(szLDAPSection, c_szLDAPLogo, NULL, NULL, szFile, pAcct, AP_LDAP_LOGO, NULL);
  682. GetPropDw(szLDAPSection, c_szLDAPPort, szFile, pAcct, AP_LDAP_PORT);
  683. GetPropBool(szLDAPSection, c_szUseSSL, szFile, pAcct, AP_LDAP_SSL);
  684. GetPropDw(szLDAPSection, c_szLDAPResults, szFile, pAcct, AP_LDAP_SEARCH_RETURN);
  685. GetPropDw(szLDAPSection, c_szLDAPTimeout, szFile, pAcct, AP_LDAP_TIMEOUT);
  686. dw = GetBool(szLDAPSection, c_szLDAPCheckNames, szFile);
  687. pAcct->SetPropDw(AP_LDAP_RESOLVE_FLAG, dw);
  688. i = GetPrivateProfileInt(szLDAPSection, c_szLDAPAuthType, -1, szFile);
  689. if (i >= LDAP_AUTH_ANONYMOUS && i <= LDAP_AUTH_MAX)
  690. {
  691. if (i > LDAP_AUTH_ANONYMOUS)
  692. {
  693. GetPropSz(szLDAPSection, c_szLDAPUserName, NULL, NULL, szFile, pAcct, AP_LDAP_USERNAME, NULL);
  694. GetPropSz(szLDAPSection, c_szLDAPPassword, NULL, NULL, szFile, pAcct, AP_LDAP_PASSWORD, NULL);
  695. }
  696. pAcct->SetPropDw(AP_LDAP_AUTHENTICATION, (DWORD)i);
  697. }
  698. GetPropDw(c_szGlobalSection, c_szReadOnlyAccts, szFile, pAcct, AP_SERVER_READ_ONLY);
  699. hr = pAcct->SaveChanges();
  700. pAcct->Release();
  701. }
  702. return(hr);
  703. }
  704. typedef struct tagACCTPROPS
  705. {
  706. ACCTTYPE type;
  707. DWORD dwSrv;
  708. DWORD dwPropSrv;
  709. LPCSTR szSrv;
  710. DWORD dwMatch;
  711. LPCSTR szMatch;
  712. } ACCTPROPS;
  713. static const ACCTPROPS g_rgProps[LDAP + 1] = {
  714. {
  715. ACCT_NEWS,
  716. SRV_NNTP,
  717. AP_NNTP_SERVER,
  718. c_szNewsServer,
  719. AP_NNTP_USERNAME,
  720. c_szNewsLogon
  721. },
  722. {
  723. ACCT_MAIL,
  724. SRV_POP3,
  725. AP_POP3_SERVER,
  726. c_szPopServer,
  727. AP_SMTP_EMAIL_ADDRESS,
  728. c_szMailAddr,
  729. },
  730. {
  731. ACCT_MAIL,
  732. SRV_IMAP,
  733. AP_IMAP_SERVER,
  734. c_szImapServer,
  735. AP_SMTP_EMAIL_ADDRESS,
  736. c_szMailAddr,
  737. },
  738. {
  739. ACCT_MAIL,
  740. SRV_HTTPMAIL,
  741. AP_HTTPMAIL_SERVER,
  742. c_szHttpUrl,
  743. AP_SMTP_EMAIL_ADDRESS,
  744. c_szMailAddr,
  745. },
  746. {
  747. ACCT_DIR_SERV,
  748. SRV_LDAP,
  749. AP_LDAP_SERVER,
  750. c_szLDAPServer,
  751. AP_LDAP_USERNAME,
  752. c_szLDAPUserName,
  753. }
  754. };
  755. HRESULT GetAccount(DWORD type, CAccountManager *pAcctMgr, LPCSTR szSection, LPCSTR szFile, IImnAccount **ppAcct)
  756. {
  757. IImnEnumAccounts *pEnum;
  758. HRESULT hr;
  759. DWORD dw;
  760. BOOL fOldSrv;
  761. const ACCTPROPS *pProps;
  762. IImnAccount *pAcct;
  763. char szSrv[CCHMAX_SERVER_NAME], szMatch[CCHMAX_ACCT_PROP_SZ], sz[CCHMAX_ACCT_PROP_SZ], szOldSrv[CCHMAX_SERVER_NAME];
  764. LPSTR pszSrv;
  765. Assert(pAcctMgr != NULL);
  766. Assert(szSection != NULL);
  767. Assert(szFile != NULL);
  768. Assert(ppAcct != NULL);
  769. *ppAcct = NULL;
  770. pProps = &g_rgProps[type];
  771. *szSrv = 0;
  772. dw = GetPrivateProfileString(szSection, pProps->szSrv, c_szEmpty, szSrv, ARRAYSIZE(szSrv), szFile);
  773. if (*szSrv == 0)
  774. return(E_FAIL);
  775. *szOldSrv = 0;
  776. dw = GetPrivateProfileString(szSection, c_szOldServer, c_szEmpty, szOldSrv, ARRAYSIZE(szOldSrv), szFile);
  777. if (fOldSrv = (*szOldSrv != 0))
  778. pszSrv = szOldSrv;
  779. else
  780. pszSrv = szSrv;
  781. *szMatch = 0;
  782. dw = GetPrivateProfileString(szSection, pProps->szMatch, c_szEmpty, szMatch, ARRAYSIZE(szMatch), szFile);
  783. hr = S_FALSE;
  784. if (S_OK == pAcctMgr->Enumerate(pProps->dwSrv, &pEnum))
  785. {
  786. Assert(pEnum != NULL);
  787. // try to find a duplicate account
  788. while (S_OK == pEnum->GetNext(&pAcct))
  789. {
  790. Assert(pAcct != NULL);
  791. *sz = 0;
  792. pAcct->GetPropSz(pProps->dwPropSrv, sz, ARRAYSIZE(sz));
  793. if (0 == lstrcmpi(sz, pszSrv))
  794. {
  795. // the servers are the same for the accounts so this may be a match
  796. *sz = 0;
  797. pAcct->GetPropSz(pProps->dwMatch, sz, ARRAYSIZE(sz));
  798. if (fOldSrv)
  799. {
  800. hr = S_OK;
  801. }
  802. else if (*szMatch != 0 && *sz != 0)
  803. {
  804. if (0 == lstrcmpi(sz, szMatch))
  805. hr = S_OK;
  806. }
  807. else if (*szMatch == 0)
  808. {
  809. if (*sz == 0)
  810. hr = S_OK;
  811. else
  812. hr = E_FAIL;
  813. }
  814. else
  815. {
  816. Assert(*sz == 0);
  817. hr = S_OK;
  818. }
  819. }
  820. if (hr == S_OK)
  821. {
  822. *ppAcct = pAcct;
  823. break;
  824. }
  825. pAcct->Release();
  826. if (hr != S_FALSE)
  827. break;
  828. }
  829. pEnum->Release();
  830. }
  831. if (hr == S_FALSE)
  832. {
  833. Assert(*ppAcct == NULL);
  834. if (SUCCEEDED(hr = pAcctMgr->CreateAccountObject(pProps->type, &pAcct)))
  835. {
  836. pAcct->SetPropSz(pProps->dwPropSrv, szSrv);
  837. dw = GetPrivateProfileString(szSection, (type == LDAP) ? c_szLDAPFriendlyName : c_szAcctName,
  838. c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  839. if (dw == 0)
  840. StrCpyN(sz, szSrv, ARRAYSIZE(sz));
  841. hr = pAcctMgr->GetUniqueAccountName(sz, ARRAYSIZE(sz));
  842. if (SUCCEEDED(hr))
  843. {
  844. pAcct->SetPropSz(AP_ACCOUNT_NAME, sz);
  845. *ppAcct = pAcct;
  846. }
  847. }
  848. }
  849. else if (hr == S_OK)
  850. {
  851. Assert(pAcct != NULL);
  852. if (fOldSrv)
  853. pAcct->SetPropSz(pProps->dwPropSrv, szSrv);
  854. dw = GetPrivateProfileString(szSection, (type == LDAP) ? c_szLDAPFriendlyName : c_szAcctName,
  855. c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  856. if (dw > 0)
  857. {
  858. if (SUCCEEDED(pAcct->GetPropSz(AP_ACCOUNT_NAME, szMatch, ARRAYSIZE(szMatch))))
  859. {
  860. if (0 != lstrcmp(sz, szMatch))
  861. {
  862. if (SUCCEEDED(pAcctMgr->GetUniqueAccountName(sz, ARRAYSIZE(sz))))
  863. pAcct->SetPropSz(AP_ACCOUNT_NAME, sz);
  864. }
  865. }
  866. }
  867. }
  868. return(hr);
  869. }
  870. HRESULT DeleteAccount(DWORD type, CAccountManager *pAcctMgr, LPCSTR szSection, LPCSTR szFile)
  871. {
  872. IImnEnumAccounts *pEnum;
  873. DWORD dw;
  874. const ACCTPROPS *pProps;
  875. IImnAccount *pAcct;
  876. char szSrv[CCHMAX_SERVER_NAME], sz[CCHMAX_ACCT_PROP_SZ];
  877. Assert(pAcctMgr != NULL);
  878. Assert(szSection != NULL);
  879. Assert(szFile != NULL);
  880. pProps = &g_rgProps[type];
  881. *szSrv = 0;
  882. dw = GetPrivateProfileString(szSection, pProps->szSrv, c_szEmpty, szSrv, ARRAYSIZE(szSrv), szFile);
  883. if (*szSrv == 0)
  884. return(E_FAIL);
  885. if (S_OK == pAcctMgr->Enumerate(pProps->dwSrv, &pEnum))
  886. {
  887. Assert(pEnum != NULL);
  888. // try to find a duplicate account
  889. while (S_OK == pEnum->GetNext(&pAcct))
  890. {
  891. Assert(pAcct != NULL);
  892. *sz = 0;
  893. pAcct->GetPropSz(pProps->dwPropSrv, sz, ARRAYSIZE(sz));
  894. if (0 == lstrcmpi(sz, szSrv))
  895. {
  896. pAcct->Delete();
  897. }
  898. pAcct->Release();
  899. }
  900. pEnum->Release();
  901. }
  902. return(S_OK);
  903. }
  904. void FixSignature(LPSTR psz)
  905. {
  906. Assert(psz != NULL);
  907. while (*psz != 0)
  908. {
  909. if (!IsDBCSLeadByte(*psz) && *psz == '\\' && *(psz + 1) == 'n')
  910. {
  911. *psz = 0x0d;
  912. psz++;
  913. *psz = 0x0a;
  914. psz++;
  915. }
  916. else
  917. {
  918. psz = CharNextA(psz);
  919. }
  920. }
  921. }
  922. void SetSignature(LPCSTR szMailSigSection, LPCSTR szNewsSigSection, LPCSTR pszMailId, LPCSTR pszNewsId, LPCSTR szFile, HKEY hkey, CAccountManager *pAcctMgr)
  923. {
  924. BOOL fMailForNews;
  925. HKEY hkeyT;
  926. IImnAccount *pAcct;
  927. char sz[1024], szKey[MAX_PATH], szT[CCHMAX_STRINGRES];
  928. DWORD dw, cb;
  929. if (szMailSigSection != NULL)
  930. {
  931. if (GetBool(szMailSigSection, c_szUseSig, szFile))
  932. {
  933. dw = GetPrivateProfileString(szMailSigSection, c_szProfSigText, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  934. if (dw > 0)
  935. {
  936. FixSignature(sz);
  937. fMailForNews = GetBool(szMailSigSection, c_szUseMailForNews, szFile);
  938. wnsprintf(szKey, ARRAYSIZE(szKey), c_szPathFileFmt, c_szRegRootSigs, c_szMailSigKey);
  939. if (ERROR_SUCCESS == RegCreateKeyEx(hkey, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeyT, &dw))
  940. {
  941. LoadString(g_hInstRes, idsMailSignature, szT, ARRAYSIZE(szT));
  942. RegSetValueEx(hkeyT, c_szSigName, 0, REG_SZ, (LPBYTE)szT, lstrlen(szT) + 1);
  943. RegSetValueEx(hkeyT, c_szSigText, 0, REG_SZ, (LPBYTE)sz, lstrlen(sz) + 1);
  944. dw = 1;
  945. RegSetValueEx(hkeyT, c_szSigType, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  946. RegCloseKey(hkeyT);
  947. if (fMailForNews)
  948. {
  949. SHSetValue(hkey, c_szRegRootSigs, c_szRegDefSig, REG_SZ, (LPBYTE)c_szMailSigKey, lstrlen(c_szMailSigKey) + 1);
  950. }
  951. else if (pszMailId != NULL)
  952. {
  953. if (SUCCEEDED(pAcctMgr->FindAccount(AP_ACCOUNT_ID, pszMailId, &pAcct)))
  954. {
  955. pAcct->SetPropSz(AP_SMTP_SIGNATURE, (LPSTR)c_szMailSigKey);
  956. pAcct->SaveChanges();
  957. pAcct->Release();
  958. }
  959. }
  960. }
  961. if (fMailForNews)
  962. {
  963. // Turn on "Add signatures to all outgoing messages"
  964. if (ERROR_SUCCESS == RegCreateKeyEx(hkey, c_szRegRoot, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &hkeyT, &dw))
  965. {
  966. dw = 0;
  967. // Read any existing value
  968. cb = sizeof(dw);
  969. RegQueryValueEx(hkeyT, c_szSigFlags, 0, NULL, (LPBYTE)&dw, &cb);
  970. // Turn on checkbox
  971. dw |= SIGFLAG_AUTONEW;
  972. // Write back new value
  973. RegSetValueEx(hkeyT, c_szSigFlags, 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw));
  974. RegCloseKey(hkeyT);
  975. }
  976. // Per spec, don't even worry about News Sig section
  977. return;
  978. }
  979. }
  980. }
  981. }
  982. if (szNewsSigSection != NULL)
  983. {
  984. if (GetBool(szNewsSigSection, c_szUseSig, szFile))
  985. {
  986. dw = GetPrivateProfileString(szNewsSigSection, c_szProfSigText, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  987. if (dw > 0)
  988. {
  989. FixSignature(sz);
  990. wnsprintf(szKey, ARRAYSIZE(szKey), c_szPathFileFmt, c_szRegRootSigs, c_szNewsSigKey);
  991. if (ERROR_SUCCESS == RegCreateKeyEx(hkey, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeyT, &dw))
  992. {
  993. LoadString(g_hInstRes, idsNewsSignature, szT, ARRAYSIZE(szT));
  994. RegSetValueEx(hkeyT, c_szSigName, 0, REG_SZ, (LPBYTE)szT, lstrlen(szT) + 1);
  995. RegSetValueEx(hkeyT, c_szSigText, 0, REG_SZ, (LPBYTE)sz, lstrlen(sz) + 1);
  996. dw = 1;
  997. RegSetValueEx(hkeyT, c_szSigType, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  998. RegCloseKey(hkeyT);
  999. if (pszNewsId != NULL)
  1000. {
  1001. if (SUCCEEDED(pAcctMgr->FindAccount(AP_ACCOUNT_ID, pszNewsId, &pAcct)))
  1002. {
  1003. pAcct->SetPropSz(AP_NNTP_SIGNATURE, (LPSTR)c_szNewsSigKey);
  1004. pAcct->SaveChanges();
  1005. pAcct->Release();
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. }
  1012. }
  1013. static const char c_szRegClient[] = "Software\\Clients\\Mail\\Outlook Express";
  1014. static const char c_szDllPath[] = "DLLPath";
  1015. static const char c_szSetDefMail[] = "SetDefaultMailHandler";
  1016. static const char c_szSetDefNews[] = "SetDefaultNewsHandler";
  1017. typedef HRESULT (WINAPI *PFN_SETDEFCLIENT)(DWORD);
  1018. void DoDefaultClient(LPCSTR szFile, BOOL fMail)
  1019. {
  1020. HINSTANCE hlib;
  1021. PFN_SETDEFCLIENT pfn;
  1022. char szDll[MAX_PATH];
  1023. DWORD dw, type;
  1024. if (GetBool(fMail ? c_szMailSection : c_szNewsSection, c_szDefClient, szFile))
  1025. {
  1026. dw = sizeof(szDll);
  1027. if (ERROR_SUCCESS == SHGetValue(HKEY_LOCAL_MACHINE, c_szRegClient, c_szDllPath, &type, (LPVOID)szDll, &dw))
  1028. {
  1029. hlib = LoadLibrary(szDll);
  1030. if (hlib != NULL)
  1031. {
  1032. pfn = (PFN_SETDEFCLIENT)GetProcAddress(hlib, fMail ? c_szSetDefMail : c_szSetDefNews);
  1033. if (pfn != NULL)
  1034. pfn(0);
  1035. FreeLibrary(hlib);
  1036. }
  1037. }
  1038. }
  1039. }
  1040. void DoMailBranding(LPCSTR szFile, LPCSTR szMailSection, HKEY hkeyUser)
  1041. {
  1042. HKEY hkey;
  1043. DWORD dw;
  1044. int i;
  1045. char sz[1024];
  1046. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyUser, c_szRegRoot, 0, NULL, REG_OPTION_NON_VOLATILE,
  1047. KEY_WRITE, NULL, &hkey, &dw))
  1048. {
  1049. dw = GetPrivateProfileString(szMailSection, c_szWinTitle, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1050. if (dw > 0 && !FIsEmpty(sz))
  1051. RegSetValueEx(hkey, c_szWindowTitle, 0, REG_SZ, (LPBYTE)sz, dw + 1);
  1052. dw = GetPrivateProfileString(szMailSection, c_szInfopane, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1053. if (dw > 0 && !FIsEmpty(sz))
  1054. {
  1055. RegSetValueEx(hkey, c_szRegBodyBarPath, 0, REG_SZ, (LPBYTE)sz, dw + 1);
  1056. dw = 1;
  1057. RegSetValueEx(hkey, c_szShowBodyBar, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  1058. }
  1059. SetRegProp(szFile, szMailSection, c_szStartAtInbox, hkey, c_szRegLaunchInbox);
  1060. RegCloseKey(hkey);
  1061. }
  1062. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyUser, c_szRegRootMail, 0, NULL, REG_OPTION_NON_VOLATILE,
  1063. KEY_WRITE, NULL, &hkey, &dw))
  1064. {
  1065. dw = GetPrivateProfileString(szMailSection, c_szWelcomeMsg, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1066. if (dw > 0 && !FIsEmpty(sz))
  1067. {
  1068. RegSetValueEx(hkey, c_szWelcomeHtm, 0, REG_SZ, (LPBYTE)sz, dw + 1);
  1069. dw = GetPrivateProfileString(szMailSection, c_szProfWelcomeName, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1070. if (dw > 0 && !FIsEmpty(sz))
  1071. RegSetValueEx(hkey, c_szWelcomeName, 0, REG_SZ, (LPBYTE)sz, dw + 1);
  1072. dw = GetPrivateProfileString(szMailSection, c_szProfWelcomeEmail, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1073. if (dw > 0 && !FIsEmpty(sz))
  1074. RegSetValueEx(hkey, c_szWelcomeEmail, 0, REG_SZ, (LPBYTE)sz, dw + 1);
  1075. // Tell OE we need a welcome msg...
  1076. dw = 1;
  1077. RegSetValueEx(hkey, c_szNeedWelcomeMsg, 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw));
  1078. }
  1079. dw = GetPrivateProfileString(szMailSection, c_szPollTime, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1080. if (dw > 0 && !FIsEmpty(sz))
  1081. {
  1082. i = StrToInt(sz);
  1083. if (i <= 0)
  1084. {
  1085. dw = 0xffffffff;
  1086. }
  1087. else
  1088. {
  1089. if (i > 120)
  1090. i = 120;
  1091. dw = (DWORD)i * 60 * 1000;
  1092. }
  1093. RegSetValueEx(hkey, c_szRegPollForMail, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  1094. }
  1095. // Turn on Sending HTML msgs for Mail?
  1096. SetRegDw(szFile, szMailSection, c_szHTMLMsgs, hkey, c_szMsgSendHtml);
  1097. RegCloseKey(hkey);
  1098. }
  1099. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyUser, c_szRegRootRules, 0, NULL, REG_OPTION_NON_VOLATILE,
  1100. KEY_WRITE, NULL, &hkey, &dw))
  1101. {
  1102. SetRegProp(szFile, szMailSection, c_szJunkMail, hkey, c_szRegFilterJunk);
  1103. RegCloseKey(hkey);
  1104. }
  1105. }
  1106. void DoNewsBranding(LPCSTR szFile, LPCSTR szNewsSection, HKEY hkeyUser)
  1107. {
  1108. HKEY hkey;
  1109. DWORD dw;
  1110. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyUser, c_szRegRootNews, 0, NULL, REG_OPTION_NON_VOLATILE,
  1111. KEY_WRITE, NULL, &hkey, &dw))
  1112. {
  1113. // Turn on Sending HTML msgs for News?
  1114. SetRegDw(szFile, szNewsSection, c_szHTMLMsgs, hkey, c_szMsgSendHtml);
  1115. RegCloseKey(hkey);
  1116. }
  1117. }
  1118. void SubscribeNewsgroups(IImnAccount *pAcct, LPCSTR szSection, LPCSTR szFile, HKEY hkey)
  1119. {
  1120. char *sz, szPath[MAX_PATH], szId[CCHMAX_ACCOUNT_NAME];
  1121. DWORD dw, cGroups, type;
  1122. Assert(pAcct != NULL);
  1123. Assert(szSection != NULL);
  1124. Assert(szFile != NULL);
  1125. if (SUCCEEDED(pAcct->GetPropSz(AP_ACCOUNT_ID, szId, ARRAYSIZE(szId))))
  1126. {
  1127. if (MemAlloc((void **)&sz, CBPROFILEBUF))
  1128. {
  1129. dw = GetPrivateProfileSection(szSection, sz, CBPROFILEBUF, szFile);
  1130. if ((dw > 0) && (dw != (CBPROFILEBUF - 2)))
  1131. {
  1132. if (GetSectionNames(sz, dw, ',', &cGroups) && cGroups > 0)
  1133. {
  1134. wnsprintf(szPath, ARRAYSIZE(szPath), c_szPathFileFmt, c_szRegRootSubscribe, szId);
  1135. RegSetValue(hkey, szPath, REG_SZ, sz, lstrlen(sz) + 1);
  1136. }
  1137. }
  1138. MemFree(sz);
  1139. }
  1140. }
  1141. }
  1142. void SetHelp(LPCSTR szFile, LPCSTR szURLSection, HKEY hkey)
  1143. {
  1144. char sz[INTERNET_MAX_URL_LENGTH];
  1145. DWORD dw;
  1146. dw = GetPrivateProfileString(szURLSection, c_szHelpPage, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1147. if (dw > 0)
  1148. {
  1149. SHSetValue(hkey, c_szRegRoot, c_szRegHelpUrl, REG_SZ, (LPBYTE)sz, lstrlen(sz) + 1);
  1150. }
  1151. }
  1152. HRESULT HandleIdentity(LPCSTR pszSection, LPCSTR pszFile, CONNECTINFO *pci, DWORD dwFlags, IUserIdentityManager *pIdMan)
  1153. {
  1154. HRESULT hr;
  1155. CAccountManager *pAcctMgr;
  1156. IPrivateIdentityManager *pPrivIdMgr;
  1157. IEnumUserIdentity *pEnum;
  1158. IUserIdentity *pId;
  1159. HKEY hkey;
  1160. char sz[256], szT[256], szGuid[256], szMailId[CCHMAX_ACCOUNT_NAME], szNewsId[CCHMAX_ACCOUNT_NAME];
  1161. DWORD dw, dwT, type, cb;
  1162. WCHAR szwUserName[CCH_USERNAME_MAX_LENGTH + 1];
  1163. Assert(pszSection != NULL);
  1164. Assert(pszFile != NULL);
  1165. Assert(pIdMan != NULL);
  1166. dw = GetPrivateProfileString(pszSection, c_szGUID, c_szEmpty, szGuid, ARRAYSIZE(szGuid), pszFile);
  1167. if (dw > 0)
  1168. {
  1169. dw = GetPrivateProfileString(pszSection, c_szUserName, c_szEmpty, sz, ARRAYSIZE(sz), pszFile);
  1170. if (dw > 0)
  1171. {
  1172. // try to find this identity
  1173. hr = pIdMan->EnumIdentities(&pEnum);
  1174. if (FAILED(hr))
  1175. return(hr);
  1176. pId = NULL;
  1177. hkey = NULL;
  1178. while (hr == S_OK)
  1179. {
  1180. hr = pEnum->Next(1, (IUnknown **)&pId, &dw);
  1181. if (hr == S_OK)
  1182. {
  1183. Assert(pId != NULL);
  1184. hr = pId->OpenIdentityRegKey(KEY_READ | KEY_WRITE, &hkey);
  1185. if (SUCCEEDED(hr))
  1186. {
  1187. // check if it matches
  1188. cb = sizeof(szT);
  1189. if (ERROR_SUCCESS == RegQueryValueEx(hkey, c_szRegInsGUID, NULL, &type, (LPBYTE)szT, &cb))
  1190. {
  1191. if (0 == lstrcmp(szT, szGuid))
  1192. break;
  1193. }
  1194. RegCloseKey(hkey);
  1195. hkey = NULL;
  1196. }
  1197. pId->Release();
  1198. pId = NULL;
  1199. }
  1200. }
  1201. pEnum->Release();
  1202. // if we can't find the user, create a new identity
  1203. if (pId == NULL)
  1204. {
  1205. if (MultiByteToWideChar(CP_ACP, 0, sz, -1, szwUserName, CCH_USERNAME_MAX_LENGTH) == 0)
  1206. return(E_FAIL);
  1207. hr = pIdMan->QueryInterface(IID_IPrivateIdentityManager, (void **)&pPrivIdMgr);
  1208. if (FAILED(hr))
  1209. return(hr);
  1210. hr = pPrivIdMgr->CreateIdentity(szwUserName, &pId);
  1211. if (SUCCEEDED(hr))
  1212. {
  1213. hr = pId->OpenIdentityRegKey(KEY_READ | KEY_WRITE, &hkey);
  1214. if (SUCCEEDED(hr))
  1215. RegSetValueEx(hkey, c_szRegInsGUID, 0, REG_SZ, (LPBYTE)szGuid, lstrlen(szGuid) + 1);
  1216. }
  1217. pPrivIdMgr->Release();
  1218. }
  1219. // set values for the identity
  1220. Assert(pId != NULL);
  1221. Assert(hkey != NULL);
  1222. GUID guid;
  1223. hr = HrCreateAccountManager((IImnAccountManager **)&pAcctMgr);
  1224. if (SUCCEEDED(hr) && SUCCEEDED(pId->GetCookie(&guid)))
  1225. {
  1226. hr = pAcctMgr->InitUser(NULL, guid, 0);
  1227. if (SUCCEEDED(hr))
  1228. {
  1229. *szMailId = 0;
  1230. *szNewsId = 0;
  1231. dw = GetPrivateProfileString(pszSection, c_szMailSection, c_szEmpty, sz, ARRAYSIZE(sz), pszFile);
  1232. if (dw > 0)
  1233. {
  1234. CreateMailAccount(pAcctMgr, pszFile, sz, pci, hkey, szMailId, ARRAYSIZE(szMailId), dwFlags);
  1235. DoMailBranding(pszFile, sz, hkey);
  1236. HandleMultipleAccounts(ACCT_MAIL, pAcctMgr, pszFile, sz, pci, hkey, pId, dwFlags);
  1237. }
  1238. dwT = GetPrivateProfileString(pszSection, c_szNewsSection, c_szEmpty, szT, ARRAYSIZE(szT), pszFile);
  1239. if (dwT > 0)
  1240. {
  1241. CreateNewsAccount(pAcctMgr, pszFile, szT, (dw > 0) ? sz : NULL, pci, hkey, pId, szNewsId, ARRAYSIZE(szNewsId), dwFlags);
  1242. HandleMultipleAccounts(ACCT_NEWS, pAcctMgr, pszFile, sz, pci, hkey, pId, dwFlags);
  1243. }
  1244. dw = GetPrivateProfileString(pszSection, c_szLDAPSection, c_szEmpty, sz, ARRAYSIZE(sz), pszFile);
  1245. if (dw > 0)
  1246. {
  1247. CreateLDAPAccount(pAcctMgr, pszFile, sz, pci);
  1248. HandleMultipleAccounts(ACCT_DIR_SERV, pAcctMgr, pszFile, sz, pci, hkey, pId, dwFlags);
  1249. }
  1250. dw = GetPrivateProfileString(pszSection, c_szMailSigSection, c_szEmpty, sz, ARRAYSIZE(sz), pszFile);
  1251. dwT = GetPrivateProfileString(pszSection, c_szNewsSigSection, c_szEmpty, szT, ARRAYSIZE(szT), pszFile);
  1252. SetSignature((dw > 0) ? sz : NULL, (dw > 0) ? szT : NULL, (*szMailId != 0) ? szMailId : NULL,
  1253. (*szNewsId != 0) ? szNewsId : NULL, pszFile, hkey, pAcctMgr);
  1254. SetHelp(pszFile, c_szURLSection, hkey);
  1255. dw = GetPrivateProfileString(pszSection, c_szOESection, c_szEmpty, sz, ARRAYSIZE(sz), pszFile);
  1256. if (dw > 0)
  1257. DoBranding(pszFile, sz, hkey);
  1258. }
  1259. pAcctMgr->Release();
  1260. }
  1261. RegCloseKey(hkey);
  1262. pId->Release();
  1263. }
  1264. }
  1265. return(S_OK);
  1266. }
  1267. void SetHtmlEncoding(LPCSTR szFile, LPCSTR szSection, LPCSTR szValue, HKEY hkey, LPCSTR szRegValue)
  1268. {
  1269. char sz[32];
  1270. DWORD dw;
  1271. dw = GetPrivateProfileString(szSection, szValue, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1272. if (dw > 0)
  1273. {
  1274. dw = 0;
  1275. if (0 == lstrcmpi(sz, c_szNone))
  1276. dw = 4;
  1277. else if (0 == lstrcmpi(sz, c_szBase64))
  1278. dw = 1;
  1279. else if (0 == lstrcmpi(sz, c_szQuotedPrintable))
  1280. dw = 3;
  1281. if (dw != 0)
  1282. RegSetValueEx(hkey, szRegValue, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  1283. }
  1284. }
  1285. void SetPlainEncoding(LPCSTR szFile, LPCSTR szSection, LPCSTR szValue, HKEY hkey, LPCSTR szRegValue)
  1286. {
  1287. char sz[32];
  1288. DWORD dw;
  1289. dw = GetPrivateProfileString(szSection, szValue, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1290. if (dw > 0)
  1291. {
  1292. dw = -1;
  1293. if (0 == lstrcmpi(sz, c_szMime))
  1294. dw = 1;
  1295. else if (0 == lstrcmpi(sz, c_szUuencode))
  1296. dw = 0;
  1297. if (dw != -1)
  1298. RegSetValueEx(hkey, szRegValue, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  1299. }
  1300. }
  1301. void DoBranding(LPCSTR szFile, LPCSTR szOESection, HKEY hkeyUser)
  1302. {
  1303. HKEY hkey;
  1304. DWORD dw;
  1305. int i;
  1306. char sz[1024];
  1307. HKEY hkeyLM;
  1308. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyUser, c_szRegRoot, 0, NULL, REG_OPTION_NON_VOLATILE,
  1309. KEY_WRITE, NULL, &hkey, &dw))
  1310. {
  1311. dw = GetPrivateProfileString(szOESection, c_szFolderBar, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1312. if (dw > 0)
  1313. {
  1314. dw = (0 != lstrcmpi(sz, c_szYes) && 0 != lstrcmpi(sz, c_sz1));
  1315. RegSetValueEx(hkey, c_szRegHideFolderBar, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  1316. }
  1317. SetRegProp(szFile, szOESection, c_szFolderList, hkey, c_szShowTree);
  1318. SetRegProp(szFile, szOESection, c_szOutlookBar, hkey, c_szRegShowOutlookBar);
  1319. SetRegProp(szFile, szOESection, c_szStatusBar, hkey, c_szShowStatus);
  1320. SetRegProp(szFile, szOESection, c_szContacts, hkey, c_szRegShowContacts);
  1321. SetRegProp(szFile, szOESection, c_szTipOfTheDay, hkey, c_szRegTipOfTheDay);
  1322. SetRegProp(szFile, szOESection, c_szToolbar, hkey, c_szShowToolbarIEAK);
  1323. SetRegProp(szFile, szOESection, c_szMigration, hkey, c_szMigrationPerformed);
  1324. //Keys for Return Receipts admin
  1325. SetRegProp(szFile, szOESection, c_szRequestReadReceipts, hkey, c_szRequestMDN);
  1326. SetRegProp(szFile, szOESection, c_szReadReceiptResponse, hkey, c_szSendMDN);
  1327. SetRegProp(szFile, szOESection, c_szSendReceiptsToList, hkey, c_szSendReceiptToList);
  1328. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, STR_REG_PATH_POLICY, 0, NULL, REG_OPTION_NON_VOLATILE,
  1329. KEY_WRITE, NULL, &hkeyLM, &dw))
  1330. {
  1331. //Lock Keys for Return Receipts admin
  1332. SetRegLockPropLM(szFile, szOESection, c_szReadReceiptResponseLocked, hkeyLM, c_szSendMDNLocked, hkey);
  1333. SetRegLockPropLM(szFile, szOESection, c_szSendReceiptsToListLocked, hkeyLM, c_szSendReceiptToListLocked, hkey);
  1334. SetRegLockPropLM(szFile, szOESection, c_szRequestReadReceiptsLocked, hkeyLM, c_szRequestMDNLocked, hkey);
  1335. RegCloseKey(hkeyLM);
  1336. }
  1337. dw = GetPrivateProfileInt(szOESection, c_szToolbarText, 666, szFile);
  1338. if (dw == 0 || dw == 1)
  1339. {
  1340. if (dw == 0)
  1341. dw = 2;
  1342. RegSetValueEx(hkey, c_szRegToolbarText, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  1343. }
  1344. dw = GetPrivateProfileInt(szOESection, c_szSecZone, 666, szFile);
  1345. if (dw == 0 || dw == 1)
  1346. {
  1347. dw += 3;
  1348. RegSetValueEx(hkey, c_szRegSecurityZone, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  1349. }
  1350. dw = GetPrivateProfileInt(szOESection, c_szSecZoneLocked, 666, szFile);
  1351. if (dw == 0 || dw == 1)
  1352. RegSetValueEx(hkey, c_szRegSecurityZoneLocked, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD));
  1353. RegCloseKey(hkey);
  1354. }
  1355. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyUser, c_szRegRootMail, 0, NULL, REG_OPTION_NON_VOLATILE,
  1356. KEY_WRITE, NULL, &hkey, &dw))
  1357. {
  1358. SetRegProp(szFile, szOESection, c_szPreviewPane, hkey, c_szRegShowHybrid);
  1359. SetRegProp(szFile, szOESection, c_szPreviewHeader, hkey, c_szMailShowHeaderInfo);
  1360. SetRegProp(szFile, szOESection, c_szPreviewSide, hkey, c_szRegSplitDir);
  1361. SetRegDw(szFile, szOESection, c_szSendEncoding, hkey, c_szDefaultCodePage);
  1362. SetHtmlEncoding(szFile, szOESection, c_szMailEncoding, hkey, c_szMsgHTMLEncoding);
  1363. SetRegProp(szFile, szOESection, c_szMailEnglishHeader, hkey, c_szMsgHTMLAllow8bit);
  1364. SetPlainEncoding(szFile, szOESection, c_szMailPlainEncoding, hkey, c_szMsgPlainMime);
  1365. SetRegProp(szFile, szOESection, c_szMailPlainEnglishHeader, hkey, c_szMsgPlainAllow8bit);
  1366. SetRegProp(szFile, szOESection, c_szMapiWarn, hkey, c_szRegAppSend);
  1367. SetRegProp(szFile, szOESection, c_szMapiWarnLocked, hkey, c_szRegAppSendLocked);
  1368. SetRegProp(szFile, szOESection, c_szSafeAttach, hkey, c_szRegSafeAttachments);
  1369. SetRegProp(szFile, szOESection, c_szSafeAttachLocked, hkey, c_szRegSafeAttachmentsLocked);
  1370. RegCloseKey(hkey);
  1371. }
  1372. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyUser, c_szRegRootNews, 0, NULL, REG_OPTION_NON_VOLATILE,
  1373. KEY_WRITE, NULL, &hkey, &dw))
  1374. {
  1375. SetRegProp(szFile, szOESection, c_szPreviewPane, hkey, c_szRegShowHybrid);
  1376. SetRegProp(szFile, szOESection, c_szPreviewHeader, hkey, c_szNewsShowHeaderInfo);
  1377. SetRegProp(szFile, szOESection, c_szPreviewSide, hkey, c_szRegSplitDir);
  1378. SetHtmlEncoding(szFile, szOESection, c_szNewsEncoding, hkey, c_szMsgHTMLEncoding);
  1379. SetRegProp(szFile, szOESection, c_szNewsEnglishHeader, hkey, c_szMsgHTMLAllow8bit);
  1380. SetPlainEncoding(szFile, szOESection, c_szNewsPlainEncoding, hkey, c_szMsgPlainMime);
  1381. SetRegProp(szFile, szOESection, c_szNewsPlainEnglishHeader, hkey, c_szMsgPlainAllow8bit);
  1382. RegCloseKey(hkey);
  1383. }
  1384. if (ERROR_SUCCESS == RegCreateKeyEx(hkeyUser, c_szRegInternational, 0, NULL, REG_OPTION_NON_VOLATILE,
  1385. KEY_WRITE, NULL, &hkey, &dw))
  1386. {
  1387. SetRegDw(szFile, szOESection, c_szReadEncoding, hkey, c_szDefaultCodePage);
  1388. RegCloseKey(hkey);
  1389. }
  1390. }
  1391. void SetRegLockPropLM(LPCSTR szFile, LPCSTR szSection, LPCSTR szValue, HKEY hkeyLM, LPCSTR szRegValue, HKEY hkeyCU)
  1392. {
  1393. char sz[16];
  1394. DWORD dw;
  1395. dw = GetPrivateProfileString(szSection, szValue, c_szEmpty, sz, ARRAYSIZE(sz), szFile);
  1396. if (dw > 0)
  1397. {
  1398. dw = (0 == lstrcmpi(sz, c_szYes) || 0 == lstrcmpi(sz, c_sz1));
  1399. if (ERROR_SUCCESS != RegSetValueEx(hkeyLM, szRegValue, 0, REG_DWORD, (LPBYTE)&dw, sizeof(DWORD)))
  1400. {
  1401. //Try to set in HKCU
  1402. SetRegProp(szFile, szSection, szValue, hkeyCU, szRegValue);
  1403. }
  1404. }
  1405. }
  1406. BOOL GetSectionNames(LPSTR psz, DWORD cch, char chSep, DWORD *pcNames)
  1407. {
  1408. LPSTR pszT, pszNames;
  1409. BOOL fEOL;
  1410. Assert(psz != NULL);
  1411. Assert(cch > 0);
  1412. Assert(pcNames != NULL);
  1413. *pcNames = 0;
  1414. pszNames = psz;
  1415. while (*psz != 0)
  1416. {
  1417. pszT = psz;
  1418. while (*psz != 0 && *psz != '=')
  1419. {
  1420. *pszNames = *psz;
  1421. psz++;
  1422. pszNames++;
  1423. }
  1424. fEOL = (*psz == 0);
  1425. if (psz > pszT)
  1426. {
  1427. *pszNames = chSep;
  1428. pszNames++;
  1429. (*pcNames)++;
  1430. }
  1431. if (!fEOL)
  1432. {
  1433. psz++;
  1434. while (*psz != 0)
  1435. psz++;
  1436. }
  1437. psz++;
  1438. }
  1439. *pszNames = 0;
  1440. pszNames++;
  1441. return(*pcNames > 0);
  1442. }
  1443. void HandleMultipleAccounts(ACCTTYPE type, CAccountManager *pAcctMgr, LPCSTR pszFile, LPCSTR szSection, CONNECTINFO *pci, HKEY hkey, IUserIdentity *pId, DWORD dwFlags)
  1444. {
  1445. DWORD dw, cch, i;
  1446. char sz[1024], *psz, *pszT;
  1447. dw = GetPrivateProfileString(szSection, c_szMultiAccounts, c_szEmpty, sz, ARRAYSIZE(sz), pszFile);
  1448. if (dw > 0)
  1449. {
  1450. if (MemAlloc((void **)&psz, CBPROFILEBUF))
  1451. {
  1452. cch = GetPrivateProfileSection(sz, psz, CBPROFILEBUF, pszFile);
  1453. if ((cch != 0) && (cch != (CBPROFILEBUF - 2)))
  1454. {
  1455. if (GetSectionNames(psz, cch, 0, &dw))
  1456. {
  1457. for (i = 0, pszT = psz; i < dw; i++)
  1458. {
  1459. switch (type)
  1460. {
  1461. case ACCT_MAIL:
  1462. CreateMailAccount(pAcctMgr, pszFile, pszT, pci, hkey, NULL, 0, dwFlags);
  1463. break;
  1464. case ACCT_NEWS:
  1465. CreateNewsAccount(pAcctMgr, pszFile, pszT, NULL, pci, hkey, pId, NULL, 0, dwFlags);
  1466. break;
  1467. case ACCT_DIR_SERV:
  1468. CreateLDAPAccount(pAcctMgr, pszFile, pszT, pci);
  1469. break;
  1470. default:
  1471. Assert(FALSE);
  1472. break;
  1473. }
  1474. pszT += (lstrlen(pszT) + 1);
  1475. }
  1476. }
  1477. }
  1478. MemFree(psz);
  1479. }
  1480. }
  1481. }