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.

490 lines
13 KiB

  1. #include "pch.hxx"
  2. #include <imnact.h>
  3. #include <acctimp.h>
  4. #include <dllmain.h>
  5. #include <resource.h>
  6. #include "eudora.h"
  7. #include "demand.h"
  8. ASSERTDATA
  9. CEudoraAcctImport::CEudoraAcctImport()
  10. {
  11. m_cRef = 1;
  12. *m_szIni = 0;
  13. m_cInfo = 0;
  14. m_rgInfo = NULL;
  15. }
  16. CEudoraAcctImport::~CEudoraAcctImport()
  17. {
  18. if (m_rgInfo != NULL)
  19. MemFree(m_rgInfo);
  20. }
  21. STDMETHODIMP CEudoraAcctImport::QueryInterface(REFIID riid, LPVOID *ppv)
  22. {
  23. if (ppv == NULL)
  24. return(E_INVALIDARG);
  25. *ppv = NULL;
  26. if (IID_IUnknown == riid)
  27. *ppv = (IAccountImport *)this;
  28. else if (IID_IAccountImport == riid)
  29. *ppv = (IAccountImport *)this;
  30. else if (IID_IAccountImport2 == riid)
  31. *ppv = (IAccountImport2 *)this;
  32. else
  33. return(E_NOINTERFACE);
  34. ((LPUNKNOWN)*ppv)->AddRef();
  35. return(S_OK);
  36. }
  37. STDMETHODIMP_(ULONG) CEudoraAcctImport::AddRef()
  38. {
  39. return(++m_cRef);
  40. }
  41. STDMETHODIMP_(ULONG) CEudoraAcctImport::Release()
  42. {
  43. if (--m_cRef == 0)
  44. {
  45. delete this;
  46. return(0);
  47. }
  48. return(m_cRef);
  49. }
  50. const static char c_szRegEudora[] = "Software\\Qualcomm\\Eudora\\CommandLine";
  51. const static char c_szCmdValue[] = "Current";
  52. HRESULT STDMETHODCALLTYPE CEudoraAcctImport::AutoDetect(DWORD *pcAcct, DWORD dwFlags)
  53. {
  54. HRESULT hr;
  55. HKEY hkey;
  56. char *szCmdLine, *sz, *psz, szExpanded[MAX_PATH];
  57. DWORD type, cb;
  58. if (pcAcct == NULL)
  59. return(E_INVALIDARG);
  60. hr = S_FALSE;
  61. *pcAcct = 0;
  62. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, c_szRegEudora, 0, KEY_ALL_ACCESS, &hkey))
  63. {
  64. if (ERROR_SUCCESS == RegQueryValueEx(hkey, c_szCmdValue, NULL, &type, NULL, &cb) &&
  65. cb > 0 &&
  66. ((type == REG_SZ) || (type == REG_EXPAND_SZ)))
  67. {
  68. if (MemAlloc((void **)&szCmdLine, cb))
  69. {
  70. if (ERROR_SUCCESS == RegQueryValueEx(hkey, c_szCmdValue, NULL, &type, (LPBYTE)szCmdLine, &cb))
  71. {
  72. sz = szCmdLine;
  73. sz = PszSkipWhiteA(sz);
  74. sz = PszScanToWhiteA(sz);
  75. sz = PszSkipWhiteA(sz);
  76. sz = PszScanToWhiteA(sz);
  77. sz = PszSkipWhiteA(sz);
  78. if (REG_EXPAND_SZ == type)
  79. {
  80. DWORD nReturn = ExpandEnvironmentStrings(sz, szExpanded, ARRAYSIZE(szExpanded));
  81. if (nReturn && nReturn <= ARRAYSIZE(szExpanded))
  82. psz = szExpanded;
  83. else
  84. psz = sz;
  85. }
  86. else
  87. psz = sz;
  88. if (*psz != 0 && 0xffffffff != GetFileAttributes(psz))
  89. hr = InitAccounts(psz);
  90. }
  91. MemFree(szCmdLine);
  92. }
  93. else
  94. {
  95. hr = E_OUTOFMEMORY;
  96. }
  97. }
  98. RegCloseKey(hkey);
  99. }
  100. // TODO: if we haven't found the ini file in the reg,
  101. // let's search for it...
  102. if (hr == S_OK)
  103. *pcAcct = m_cInfo;
  104. return(hr);
  105. }
  106. HRESULT STDMETHODCALLTYPE CEudoraAcctImport::EnumerateAccounts(IEnumIMPACCOUNTS **ppEnum)
  107. {
  108. CEnumEUDORAACCTS *penum;
  109. HRESULT hr;
  110. if (ppEnum == NULL)
  111. return(E_INVALIDARG);
  112. *ppEnum = NULL;
  113. if (m_cInfo == 0)
  114. return(S_FALSE);
  115. Assert(m_rgInfo != NULL);
  116. penum = new CEnumEUDORAACCTS;
  117. if (penum == NULL)
  118. return(E_OUTOFMEMORY);
  119. hr = penum->Init(m_rgInfo, m_cInfo);
  120. if (FAILED(hr))
  121. {
  122. penum->Release();
  123. penum = NULL;
  124. }
  125. *ppEnum = penum;
  126. return(hr);
  127. }
  128. HRESULT STDMETHODCALLTYPE CEudoraAcctImport::GetSettings(DWORD_PTR dwCookie, IImnAccount *pAcct)
  129. {
  130. if (pAcct == NULL)
  131. return(E_INVALIDARG);
  132. return(IGetSettings(dwCookie, pAcct, NULL));
  133. }
  134. HRESULT STDMETHODCALLTYPE CEudoraAcctImport::GetSettings2(DWORD_PTR dwCookie, IImnAccount *pAcct, IMPCONNINFO *pInfo)
  135. {
  136. if (pAcct == NULL ||
  137. pInfo == NULL)
  138. return(E_INVALIDARG);
  139. return(IGetSettings(dwCookie, pAcct, pInfo));
  140. }
  141. const static char c_szEmpty[] = "";
  142. const static char c_szRealName[] = "RealName";
  143. const static char c_szSmtpServer[] = "SMTPServer";
  144. const static char c_szReturnAddress[] = "ReturnAddress";
  145. const static char c_szPopAccount[] = "POPAccount";
  146. const static char c_szLeaveMailOnServer[] = "LeaveMailOnServer";
  147. const static char c_szUsesIMAP[] = "UsesIMAP";
  148. const static char c_szUsesPOP[] = "UsesPOP";
  149. const static char c_sz1[] = "1";
  150. const static char c_szConnName[] = "AutoConnectionName";
  151. HRESULT CEudoraAcctImport::IGetSettings(DWORD_PTR dwCookie, IImnAccount *pAcct, IMPCONNINFO *pInfo)
  152. {
  153. BOOL fSMTP, fEmail, fPop;
  154. EUDORAACCTINFO *pinfo;
  155. char sz[512], *szT;
  156. DWORD cb;
  157. HRESULT hr;
  158. Assert(pAcct != NULL);
  159. fSMTP = FALSE;
  160. fEmail = FALSE;
  161. Assert(((int) dwCookie) >= 0 && dwCookie < (DWORD_PTR)m_cInfo);
  162. pinfo = &m_rgInfo[dwCookie];
  163. Assert(pinfo->dwCookie == dwCookie);
  164. hr = pAcct->SetPropSz(AP_ACCOUNT_NAME, pinfo->szDisplay);
  165. if (FAILED(hr))
  166. return(hr);
  167. cb = GetPrivateProfileString(pinfo->szSection, c_szRealName, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  168. if (cb > 0 && !FIsEmpty(sz))
  169. {
  170. hr = pAcct->SetPropSz(AP_SMTP_DISPLAY_NAME, sz);
  171. Assert(!FAILED(hr));
  172. }
  173. cb = GetPrivateProfileString(pinfo->szSection, c_szSmtpServer, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  174. if (cb > 0 && !FIsEmpty(sz))
  175. {
  176. hr = pAcct->SetPropSz(AP_SMTP_SERVER, sz);
  177. Assert(!FAILED(hr));
  178. fSMTP = TRUE;
  179. }
  180. cb = GetPrivateProfileString(pinfo->szSection, c_szReturnAddress, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  181. if (cb > 0 && !FIsEmpty(sz))
  182. {
  183. hr = pAcct->SetPropSz(AP_SMTP_EMAIL_ADDRESS, sz);
  184. Assert(!FAILED(hr));
  185. fEmail = TRUE;
  186. }
  187. fPop = TRUE;
  188. cb = GetPrivateProfileString(pinfo->szSection, c_szUsesPOP, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  189. if (cb == 0 || 0 != lstrcmp(sz, c_sz1))
  190. {
  191. cb = GetPrivateProfileString(pinfo->szSection, c_szUsesIMAP, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  192. if (cb > 0 && 0 == lstrcmp(sz, c_sz1))
  193. fPop = FALSE;
  194. }
  195. cb = GetPrivateProfileString(pinfo->szSection, c_szPopAccount, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  196. if (cb > 0 && !FIsEmpty(sz))
  197. {
  198. if (!fEmail)
  199. {
  200. hr = pAcct->SetPropSz(AP_SMTP_EMAIL_ADDRESS, sz);
  201. Assert(!FAILED(hr));
  202. }
  203. szT = PszScanToCharA(sz, '@');
  204. if (*szT)
  205. {
  206. *szT = 0;
  207. szT++;
  208. hr = pAcct->SetPropSz(fPop ? AP_POP3_USERNAME : AP_IMAP_USERNAME, sz);
  209. Assert(!FAILED(hr));
  210. hr = pAcct->SetPropSz(fPop ? AP_POP3_SERVER : AP_IMAP_SERVER, szT);
  211. Assert(!FAILED(hr));
  212. if (!fSMTP)
  213. {
  214. hr = pAcct->SetPropSz(AP_SMTP_SERVER, szT);
  215. Assert(!FAILED(hr));
  216. }
  217. }
  218. }
  219. if (fPop)
  220. {
  221. cb = GetPrivateProfileString(pinfo->szSection, c_szLeaveMailOnServer, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  222. if (cb > 0 && 0 == lstrcmp(sz, c_sz1))
  223. {
  224. hr = pAcct->SetPropDw(AP_POP3_LEAVE_ON_SERVER, 1);
  225. Assert(!FAILED(hr));
  226. }
  227. }
  228. if (pInfo != NULL)
  229. {
  230. cb = GetPrivateProfileString(pinfo->szSection, c_szConnName, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  231. if (cb > 0 && !FIsEmpty(sz))
  232. {
  233. pInfo->dwConnect = CONN_USE_SETTINGS;
  234. pInfo->dwConnectType = CONNECTION_TYPE_RAS;
  235. StrCpyN(pInfo->szConnectoid, sz, ARRAYSIZE(pInfo->szConnectoid));
  236. }
  237. else
  238. {
  239. // TODO: determine if we need to create a connectoid
  240. pInfo->dwConnect = CONN_USE_DEFAULT;
  241. }
  242. }
  243. return(S_OK);
  244. }
  245. const static char c_szPersona[] = "Personalities";
  246. const static char c_szSettings[] = "Settings";
  247. #define CALLOCINFO 8
  248. #define CALLOCSETTINGS 0x07fff
  249. HRESULT CEudoraAcctImport::InitAccounts(char *szIni)
  250. {
  251. HRESULT hr;
  252. DWORD cch, cInfoBuf;
  253. char *szBuf, *szKey, *szVal;
  254. Assert(m_cInfo == 0);
  255. Assert(m_rgInfo == NULL);
  256. if (!MemAlloc((void **)&szBuf, CALLOCSETTINGS))
  257. return(E_OUTOFMEMORY);
  258. hr = E_FAIL;
  259. cch = GetPrivateProfileSection(c_szSettings, szBuf, 0x07fff, szIni);
  260. if (cch != 0)
  261. {
  262. if (!MemAlloc((void **)&m_rgInfo, CALLOCINFO * sizeof(EUDORAACCTINFO)))
  263. {
  264. hr = E_OUTOFMEMORY;
  265. goto done;
  266. }
  267. cInfoBuf = CALLOCINFO;
  268. m_rgInfo[m_cInfo].dwCookie = m_cInfo;
  269. StrCpyN(m_rgInfo[m_cInfo].szSection, c_szSettings, ARRAYSIZE(m_rgInfo[m_cInfo].szSection));
  270. LoadString(g_hInstRes, idsDefaultAccount, m_rgInfo[m_cInfo].szDisplay, ARRAYSIZE(m_rgInfo[m_cInfo].szDisplay));
  271. m_cInfo++;
  272. cch = GetPrivateProfileSection(c_szPersona, szBuf, 0x07fff, szIni);
  273. if ((cch != 0) && (cch != (0x07fff - 2)))
  274. {
  275. szKey = szBuf;
  276. while (TRUE)
  277. {
  278. if (m_cInfo == cInfoBuf)
  279. {
  280. cInfoBuf += CALLOCINFO;
  281. if (!MemRealloc((void **)&m_rgInfo, cInfoBuf * sizeof(EUDORAACCTINFO)))
  282. {
  283. hr = E_OUTOFMEMORY;
  284. goto done;
  285. }
  286. }
  287. szVal = PszScanToCharA(szKey, '=');
  288. if (*szVal != 0)
  289. {
  290. szVal++;
  291. m_rgInfo[m_cInfo].dwCookie = m_cInfo;
  292. StrCpyN(m_rgInfo[m_cInfo].szSection, szVal, ARRAYSIZE(m_rgInfo[m_cInfo].szSection));
  293. StrCpyN(m_rgInfo[m_cInfo].szDisplay, szVal, ARRAYSIZE(m_rgInfo[m_cInfo].szDisplay));
  294. m_cInfo++;
  295. }
  296. szKey = szVal;
  297. while (*szKey != 0)
  298. szKey++;
  299. szKey++;
  300. if (*szKey == 0)
  301. break;
  302. }
  303. }
  304. StrCpyN(m_szIni, szIni, ARRAYSIZE(m_szIni));
  305. hr = S_OK;
  306. }
  307. done:
  308. MemFree(szBuf);
  309. return(hr);
  310. }
  311. HRESULT STDMETHODCALLTYPE CEudoraAcctImport::InitializeImport(HWND hwnd, DWORD_PTR dwCookie)
  312. {
  313. return(E_NOTIMPL);
  314. }
  315. HRESULT STDMETHODCALLTYPE CEudoraAcctImport::GetNewsGroup(INewsGroupImport *pImp, DWORD dwReserved)
  316. {
  317. return(E_NOTIMPL);
  318. }
  319. CEnumEUDORAACCTS::CEnumEUDORAACCTS()
  320. {
  321. m_cRef = 1;
  322. // m_iInfo
  323. m_cInfo = 0;
  324. m_rgInfo = NULL;
  325. }
  326. CEnumEUDORAACCTS::~CEnumEUDORAACCTS()
  327. {
  328. if (m_rgInfo != NULL)
  329. MemFree(m_rgInfo);
  330. }
  331. STDMETHODIMP CEnumEUDORAACCTS::QueryInterface(REFIID riid, LPVOID *ppv)
  332. {
  333. if (ppv == NULL)
  334. return(E_INVALIDARG);
  335. *ppv = NULL;
  336. if (IID_IUnknown == riid)
  337. *ppv = (IUnknown *)this;
  338. else if (IID_IEnumIMPACCOUNTS == riid)
  339. *ppv = (IEnumIMPACCOUNTS *)this;
  340. if (*ppv != NULL)
  341. ((LPUNKNOWN)*ppv)->AddRef();
  342. else
  343. return(E_NOINTERFACE);
  344. return(S_OK);
  345. }
  346. STDMETHODIMP_(ULONG) CEnumEUDORAACCTS::AddRef()
  347. {
  348. return(++m_cRef);
  349. }
  350. STDMETHODIMP_(ULONG) CEnumEUDORAACCTS::Release()
  351. {
  352. if (--m_cRef == 0)
  353. {
  354. delete this;
  355. return(0);
  356. }
  357. return(m_cRef);
  358. }
  359. HRESULT STDMETHODCALLTYPE CEnumEUDORAACCTS::Next(IMPACCOUNTINFO *pinfo)
  360. {
  361. if (pinfo == NULL)
  362. return(E_INVALIDARG);
  363. m_iInfo++;
  364. if ((UINT)m_iInfo >= m_cInfo)
  365. return(S_FALSE);
  366. Assert(m_rgInfo != NULL);
  367. pinfo->dwCookie = m_rgInfo[m_iInfo].dwCookie;
  368. pinfo->dwReserved = 0;
  369. StrCpyN(pinfo->szDisplay, m_rgInfo[m_iInfo].szDisplay, ARRAYSIZE(pinfo->szDisplay));
  370. return(S_OK);
  371. }
  372. HRESULT STDMETHODCALLTYPE CEnumEUDORAACCTS::Reset()
  373. {
  374. m_iInfo = -1;
  375. return(S_OK);
  376. }
  377. HRESULT CEnumEUDORAACCTS::Init(EUDORAACCTINFO *pinfo, int cinfo)
  378. {
  379. DWORD cb;
  380. Assert(pinfo != NULL);
  381. Assert(cinfo > 0);
  382. cb = cinfo * sizeof(EUDORAACCTINFO);
  383. if (!MemAlloc((void **)&m_rgInfo, cb))
  384. return(E_OUTOFMEMORY);
  385. m_iInfo = -1;
  386. m_cInfo = cinfo;
  387. CopyMemory(m_rgInfo, pinfo, cb);
  388. return(S_OK);
  389. }