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.

1042 lines
43 KiB

  1. // --------------------------------------------------------------------------------
  2. // TaskUtil.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #include "pch.hxx"
  7. #include "spoolapi.h"
  8. #include "imnxport.h"
  9. #include "taskutil.h"
  10. #include "strconst.h"
  11. #include "resource.h"
  12. #include "passdlg.h"
  13. #include "xpcomm.h"
  14. #include "timeout.h"
  15. #include "thormsgs.h"
  16. #include "mimeutil.h"
  17. #include "flagconv.h"
  18. #include "ourguid.h"
  19. #include "msgfldr.h"
  20. #include "demand.h"
  21. // --------------------------------------------------------------------------------
  22. // Array of mappings between IXPTYPE and protocol name
  23. // --------------------------------------------------------------------------------
  24. static const LPSTR g_prgszServers[IXP_HTTPMail + 1] = {
  25. "NNTP",
  26. "SMTP",
  27. "POP3",
  28. "IMAP",
  29. "RAS",
  30. "HTTPMail"
  31. };
  32. // --------------------------------------------------------------------------------
  33. // LOGONINFO
  34. // --------------------------------------------------------------------------------
  35. typedef struct tagLOGFONINFO {
  36. LPSTR pszAccount; // Account
  37. LPSTR pszServer; // Server Name
  38. LPSTR pszUserName; // User Name
  39. LPSTR pszPassword; // Passowrd
  40. DWORD fSavePassword; // Save Password
  41. DWORD fAlwaysPromptPassword; // "Always prompt for password"
  42. } LOGONINFO, *LPLOGONINFO;
  43. // --------------------------------------------------------------------------------
  44. // TASKERROR
  45. // --------------------------------------------------------------------------------
  46. static const TASKERROR c_rgTaskErrors[] = {
  47. { SP_E_CANTLOCKUIDLCACHE, idshrLockUidCacheFailed, NULL, TRUE, TASKRESULT_FAILURE },
  48. { IXP_E_TIMEOUT, IDS_IXP_E_TIMEOUT, NULL, FALSE, TASKRESULT_FAILURE },
  49. { IXP_E_WINSOCK_WSASYSNOTREADY, IDS_IXP_E_CONN, NULL, FALSE, TASKRESULT_FAILURE },
  50. { IXP_E_WINSOCK_WSAEINPROGRESS, IDS_IXP_E_WINSOCK_FAILED_WSASTARTUP, NULL, FALSE, TASKRESULT_FAILURE },
  51. { IXP_E_WINSOCK_FAILED_WSASTARTUP, IDS_IXP_E_WINSOCK_FAILED_WSASTARTUP, NULL, FALSE, TASKRESULT_FAILURE },
  52. { IXP_E_WINSOCK_WSAEFAULT, IDS_IXP_E_WINSOCK_FAILED_WSASTARTUP, NULL, FALSE, TASKRESULT_FAILURE },
  53. { IXP_E_WINSOCK_WSAEPROCLIM, IDS_IXP_E_WINSOCK_FAILED_WSASTARTUP, NULL, FALSE, TASKRESULT_FAILURE },
  54. { IXP_E_WINSOCK_WSAVERNOTSUPPORTED, IDS_IXP_E_WINSOCK_FAILED_WSASTARTUP, NULL, FALSE, TASKRESULT_FAILURE },
  55. { IXP_E_LOAD_SICILY_FAILED, IDS_IXP_E_LOAD_SICILY_FAILED, NULL, FALSE, TASKRESULT_FAILURE },
  56. { IXP_E_INVALID_CERT_CN, IDS_IXP_E_INVALID_CERT_CN, NULL, FALSE, TASKRESULT_FAILURE },
  57. { IXP_E_INVALID_CERT_DATE, IDS_IXP_E_INVALID_CERT_DATE, NULL, FALSE, TASKRESULT_FAILURE },
  58. { IXP_E_CONN, IDS_IXP_E_CONN, NULL, FALSE, TASKRESULT_FAILURE },
  59. { IXP_E_CANT_FIND_HOST, IDS_IXP_E_CANT_FIND_HOST, NULL, FALSE, TASKRESULT_FAILURE },
  60. { IXP_E_FAILED_TO_CONNECT, IDS_IXP_E_FAILED_TO_CONNECT, NULL, FALSE, TASKRESULT_FAILURE },
  61. { IXP_E_CONNECTION_DROPPED, IDS_IXP_E_CONNECTION_DROPPED, NULL, FALSE, TASKRESULT_FAILURE },
  62. { IXP_E_CONN_RECV, IDS_IXP_E_SOCKET_READ_ERROR, NULL, FALSE, TASKRESULT_FAILURE },
  63. { IXP_E_SOCKET_READ_ERROR, IDS_IXP_E_SOCKET_READ_ERROR, NULL, FALSE, TASKRESULT_FAILURE },
  64. { IXP_E_CONN_SEND, IDS_IXP_E_SOCKET_WRITE_ERROR, NULL, FALSE, TASKRESULT_FAILURE },
  65. { IXP_E_SOCKET_WRITE_ERROR, IDS_IXP_E_SOCKET_WRITE_ERROR, NULL, FALSE, TASKRESULT_FAILURE },
  66. { IXP_E_SOCKET_INIT_ERROR, IDS_IXP_E_SOCKET_INIT_ERROR, NULL, FALSE, TASKRESULT_FAILURE },
  67. { IXP_E_SOCKET_CONNECT_ERROR, IDS_IXP_E_SOCKET_CONNECT_ERROR, NULL, FALSE, TASKRESULT_FAILURE },
  68. { IXP_E_INVALID_ACCOUNT, IDS_IXP_E_INVALID_ACCOUNT, NULL, FALSE, TASKRESULT_FAILURE },
  69. { IXP_E_USER_CANCEL, IDS_IXP_E_USER_CANCEL, NULL, FALSE, TASKRESULT_FAILURE },
  70. { IXP_E_SICILY_LOGON_FAILED, IDS_IXP_E_SICILY_LOGON_FAILED, NULL, FALSE, TASKRESULT_FAILURE },
  71. { IXP_E_SMTP_RESPONSE_ERROR, IDS_IXP_E_SMTP_RESPONSE_ERROR, NULL, FALSE, TASKRESULT_FAILURE },
  72. { IXP_E_SMTP_UNKNOWN_RESPONSE_CODE, IDS_IXP_E_SMTP_UNKNOWN_RESPONSE_CODE, NULL, FALSE, TASKRESULT_FAILURE },
  73. { IXP_E_SMTP_REJECTED_RECIPIENTS, IDS_IXP_E_SMTP_REJECTED_RECIPIENTS, NULL, FALSE, TASKRESULT_EVENTFAILED },
  74. { IXP_E_SMTP_553_MAILBOX_NAME_SYNTAX, IDS_IXP_E_SMTP_553_MAILBOX_NAME_SYNTAX, NULL, FALSE, TASKRESULT_EVENTFAILED },
  75. { IXP_E_SMTP_NO_SENDER, IDS_IXP_E_SMTP_NO_SENDER, NULL, FALSE, TASKRESULT_EVENTFAILED },
  76. { IXP_E_SMTP_NO_RECIPIENTS, IDS_IXP_E_SMTP_NO_RECIPIENTS, NULL, FALSE, TASKRESULT_EVENTFAILED },
  77. { SP_E_SMTP_CANTOPENMESSAGE, IDS_SP_E_SMTP_CANTOPENMESSAGE, NULL, FALSE, TASKRESULT_EVENTFAILED },
  78. { SP_E_SENDINGSPLITGROUP, IDS_SP_E_SENDINGSPLITGROUP, NULL, FALSE, TASKRESULT_EVENTFAILED },
  79. { IXP_E_SMTP_REJECTED_SENDER, IDS_IXP_E_SMTP_REJECTED_SENDER, NULL, FALSE, TASKRESULT_EVENTFAILED },
  80. { IXP_E_POP3_RESPONSE_ERROR, IDS_IXP_E_POP3_RESPONSE_ERROR, NULL, FALSE, TASKRESULT_EVENTFAILED },
  81. { IXP_E_POP3_INVALID_USER_NAME, IDS_IXP_E_POP3_INVALID_USER_NAME, NULL, FALSE, TASKRESULT_FAILURE },
  82. { IXP_E_POP3_INVALID_PASSWORD, IDS_IXP_E_POP3_INVALID_PASSWORD, NULL, FALSE, TASKRESULT_FAILURE },
  83. { SP_E_CANTLEAVEONSERVER, idshrCantLeaveOnServer, NULL, FALSE, TASKRESULT_FAILURE },
  84. { E_OUTOFMEMORY, IDS_E_OUTOFMEMORY, NULL, FALSE, TASKRESULT_FAILURE },
  85. { ERROR_NOT_ENOUGH_MEMORY, IDS_E_OUTOFMEMORY, NULL, FALSE, TASKRESULT_FAILURE },
  86. { ERROR_OUTOFMEMORY, IDS_E_OUTOFMEMORY, NULL, FALSE, TASKRESULT_FAILURE },
  87. { hrDiskFull, idsDiskFull, NULL, FALSE, TASKRESULT_FAILURE },
  88. { ERROR_DISK_FULL, idsDiskFull, NULL, FALSE, TASKRESULT_FAILURE },
  89. { DB_E_DISKFULL, idsDiskFull, NULL, FALSE, TASKRESULT_FAILURE },
  90. { DB_E_ACCESSDENIED, idsDBAccessDenied, NULL, FALSE, TASKRESULT_FAILURE },
  91. { SP_E_POP3_RETR, IDS_SP_E_RETRFAILED, NULL, FALSE, TASKRESULT_EVENTFAILED },
  92. { IXP_E_SMTP_552_STORAGE_OVERFLOW, IDS_IXP_E_SMTP_552_STORAGE_OVERFLOW, NULL, FALSE, TASKRESULT_EVENTFAILED },
  93. { SP_E_CANT_MOVETO_SENTITEMS, IDS_SP_E_CANT_MOVETO_SENTITEMS, NULL, FALSE, TASKRESULT_EVENTFAILED },
  94. { IXP_E_NNTP_RESPONSE_ERROR, idsNNTPErrUnknownResponse, NULL, FALSE, TASKRESULT_FAILURE },
  95. { IXP_E_NNTP_NEWGROUPS_FAILED, idsNNTPErrNewgroupsFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  96. { IXP_E_NNTP_LIST_FAILED, idsNNTPErrListFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  97. { IXP_E_NNTP_LISTGROUP_FAILED, idsNNTPErrListGroupFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  98. { IXP_E_NNTP_GROUP_FAILED, idsNNTPErrGroupFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  99. { IXP_E_NNTP_GROUP_NOTFOUND, idsNNTPErrGroupNotFound, NULL, FALSE, TASKRESULT_EVENTFAILED },
  100. { IXP_E_NNTP_ARTICLE_FAILED, idsNNTPErrArticleFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  101. { IXP_E_NNTP_HEAD_FAILED, idsNNTPErrHeadFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  102. { IXP_E_NNTP_BODY_FAILED, idsNNTPErrBodyFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  103. { IXP_E_NNTP_POST_FAILED, idsNNTPErrPostFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  104. { IXP_E_NNTP_NEXT_FAILED, idsNNTPErrNextFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  105. { IXP_E_NNTP_DATE_FAILED, idsNNTPErrDateFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  106. { IXP_E_NNTP_HEADERS_FAILED, idsNNTPErrHeadersFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  107. { IXP_E_NNTP_XHDR_FAILED, idsNNTPErrXhdrFailed, NULL, FALSE, TASKRESULT_EVENTFAILED },
  108. { IXP_E_NNTP_INVALID_USERPASS, idsNNTPErrPasswordFailed, NULL, FALSE, TASKRESULT_FAILURE },
  109. { IXP_E_SECURE_CONNECT_FAILED, idsFailedToConnectSecurely, NULL, FALSE, TASKRESULT_FAILURE },
  110. { IXP_E_HTTP_USE_PROXY, IDS_IXP_E_HTTP_USE_PROXY, NULL, FALSE, TASKRESULT_FAILURE },
  111. { IXP_E_HTTP_BAD_REQUEST, IDS_IXP_E_HTTP_BAD_REQUEST, NULL, FALSE, TASKRESULT_EVENTFAILED },
  112. { IXP_E_HTTP_UNAUTHORIZED, IDS_IXP_E_HTTP_UNAUTHORIZED, NULL, FALSE, TASKRESULT_FAILURE },
  113. { IXP_E_HTTP_FORBIDDEN, IDS_IXP_E_HTTP_FORBIDDEN, NULL, FALSE, TASKRESULT_FAILURE },
  114. { IXP_E_HTTP_NOT_FOUND, IDS_IXP_E_HTTP_NOT_FOUND, NULL, FALSE, TASKRESULT_EVENTFAILED },
  115. { IXP_E_HTTP_METHOD_NOT_ALLOW, IDS_IXP_E_HTTP_METHOD_NOT_ALLOW, NULL, FALSE, TASKRESULT_FAILURE },
  116. { IXP_E_HTTP_NOT_ACCEPTABLE, IDS_IXP_E_HTTP_NOT_ACCEPTABLE, NULL, FALSE, TASKRESULT_FAILURE },
  117. { IXP_E_HTTP_PROXY_AUTH_REQ, IDS_IXP_E_HTTP_PROXY_AUTH_REQ, NULL, FALSE, TASKRESULT_FAILURE },
  118. { IXP_E_HTTP_REQUEST_TIMEOUT, IDS_IXP_E_HTTP_REQUEST_TIMEOUT, NULL, FALSE, TASKRESULT_EVENTFAILED },
  119. { IXP_E_HTTP_CONFLICT, IDS_IXP_E_HTTP_CONFLICT, NULL, FALSE, TASKRESULT_EVENTFAILED },
  120. { IXP_E_HTTP_GONE, IDS_IXP_E_HTTP_GONE, NULL, FALSE, TASKRESULT_EVENTFAILED },
  121. { IXP_E_HTTP_LENGTH_REQUIRED, IDS_IXP_E_HTTP_LENGTH_REQUIRED, NULL, FALSE, TASKRESULT_FAILURE },
  122. { IXP_E_HTTP_PRECOND_FAILED, IDS_IXP_E_HTTP_PRECOND_FAILED, NULL, FALSE, TASKRESULT_FAILURE },
  123. { IXP_E_HTTP_INTERNAL_ERROR, IDS_IXP_E_HTTP_INTERNAL_ERROR, NULL, FALSE, TASKRESULT_FAILURE },
  124. { IXP_E_HTTP_NOT_IMPLEMENTED, IDS_IXP_E_HTTP_NOT_IMPLEMENTED, NULL, FALSE, TASKRESULT_FAILURE },
  125. { IXP_E_HTTP_BAD_GATEWAY, IDS_IXP_E_HTTP_BAD_GATEWAY, NULL, FALSE, TASKRESULT_FAILURE },
  126. { IXP_E_HTTP_SERVICE_UNAVAIL, IDS_IXP_E_HTTP_SERVICE_UNAVAIL, NULL, FALSE, TASKRESULT_FAILURE },
  127. { IXP_E_HTTP_GATEWAY_TIMEOUT, IDS_IXP_E_HTTP_GATEWAY_TIMEOUT, NULL, FALSE, TASKRESULT_EVENTFAILED },
  128. { IXP_E_HTTP_VERS_NOT_SUP, IDS_IXP_E_HTTP_VERS_NOT_SUP, NULL, FALSE, TASKRESULT_FAILURE },
  129. { SP_E_HTTP_NOSENDMSGURL, idsHttpNoSendMsgUrl, NULL, FALSE, TASKRESULT_FAILURE },
  130. { SP_E_HTTP_SERVICEDOESNTWORK, idsHttpServiceDoesntWork, NULL, FALSE, TASKRESULT_FAILURE },
  131. { SP_E_HTTP_NODELETESUPPORT, idsHttpNoDeleteSupport, NULL, FALSE, TASKRESULT_FAILURE },
  132. { SP_E_HTTP_CANTMODIFYMSNFOLDER, idsCantModifyMsnFolder, NULL, FALSE, TASKRESULT_EVENTFAILED },
  133. { IXP_E_HTTP_INSUFFICIENT_STORAGE, idsHttpNoSpaceOnServer, NULL, FALSE, TASKRESULT_FAILURE },
  134. { STORE_E_IMAP_HC_NOSLASH, idsIMAPHC_NoSlash, NULL, FALSE, TASKRESULT_FAILURE },
  135. { STORE_E_IMAP_HC_NOBACKSLASH, idsIMAPHC_NoBackSlash, NULL, FALSE, TASKRESULT_FAILURE },
  136. { STORE_E_IMAP_HC_NODOT, idsIMAPHC_NoDot, NULL, FALSE, TASKRESULT_FAILURE },
  137. { STORE_E_IMAP_HC_NOHC, idsIMAPHC_NoHC, NULL, FALSE, TASKRESULT_FAILURE },
  138. { STORE_E_NOTRANSLATION, idsIMAPNoTranslatableInferiors, NULL, FALSE, TASKRESULT_FAILURE },
  139. { IXP_E_SMTP_530_STARTTLS_REQUIRED, idsSMTPSTARTTLSRequired, NULL, FALSE, TASKRESULT_FAILURE },
  140. { IXP_E_SMTP_NO_STARTTLS_SUPPORT, idsSMTPNoSTARTTLSSupport, NULL, FALSE, TASKRESULT_FAILURE },
  141. { IXP_E_SMTP_454_STARTTLS_FAILED, idsSMTPSTARTTLSFailed, NULL, FALSE, TASKRESULT_FAILURE },
  142. };
  143. // --------------------------------------------------------------------------------
  144. // TaskUtil_LogonPromptDlgProc
  145. // --------------------------------------------------------------------------------
  146. INT_PTR CALLBACK TaskUtil_LogonPromptDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  147. INT_PTR CALLBACK TaskUtil_TimeoutPromptDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  148. // --------------------------------------------------------------------------------
  149. // TaskUtil_HrWriteQuoted
  150. // --------------------------------------------------------------------------------
  151. HRESULT TaskUtil_HrWriteQuoted(IStream *pStream, LPCSTR pszName, LPCSTR pszData, BOOL fQuoted,
  152. LPCSTR *ppszSep)
  153. {
  154. // Locals
  155. HRESULT hr=S_OK;
  156. // Write - Separator
  157. CHECKHR(hr = pStream->Write(*ppszSep, lstrlen(*ppszSep), NULL));
  158. // Change Separator
  159. *ppszSep = g_szCommaSpace;
  160. // Write - 'Account Name:'
  161. CHECKHR(hr = pStream->Write(pszName, lstrlen(pszName), NULL));
  162. // Write Space
  163. CHECKHR(hr = pStream->Write(g_szSpace, lstrlen(g_szSpace), NULL));
  164. // Write single quote
  165. if (fQuoted)
  166. CHECKHR(hr = pStream->Write(g_szQuote, lstrlen(g_szQuote), NULL));
  167. // Write Data
  168. CHECKHR(hr = pStream->Write(pszData, lstrlen(pszData), NULL));
  169. // Write End Quote
  170. if (fQuoted)
  171. CHECKHR(hr = pStream->Write(g_szQuote, lstrlen(g_szQuote), NULL));
  172. exit:
  173. // Done
  174. return hr;
  175. }
  176. // --------------------------------------------------------------------------------
  177. // TaskUtil_HrBuildErrorInfoString
  178. // --------------------------------------------------------------------------------
  179. HRESULT TaskUtil_HrBuildErrorInfoString(LPCSTR pszProblem, IXPTYPE ixptype, LPIXPRESULT pResult,
  180. LPINETSERVER pServer, LPCSTR pszSubject, LPSTR *ppszInfo, ULONG *pcchInfo)
  181. {
  182. // Locals
  183. HRESULT hr=S_OK;
  184. CHAR szRes[255];
  185. CHAR szNumber[50];
  186. LPCSTR pszSep=c_szEmpty;
  187. CByteStream cStream;
  188. // Init
  189. *ppszInfo = NULL;
  190. *pcchInfo = 0;
  191. // Write out the problem
  192. AssertSz(NULL != pszProblem, "Hey, what's your problem, buddy?");
  193. if (pszProblem) {
  194. CHECKHR(hr = cStream.Write(pszProblem, lstrlen(pszProblem), NULL));
  195. CHECKHR(hr = cStream.Write(g_szSpace, lstrlen(g_szSpace), NULL));
  196. }
  197. // Subject: 'Subject'
  198. if (pszSubject)
  199. {
  200. LOADSTRING(idsSubject, szRes);
  201. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, pszSubject, TRUE, &pszSep));
  202. }
  203. // Account: 'Account Name'
  204. if (!FIsEmptyA(pServer->szAccount))
  205. {
  206. LOADSTRING(idsDetail_Account, szRes);
  207. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, pServer->szAccount, TRUE, &pszSep));
  208. }
  209. // Server: 'Server Name'
  210. if (!FIsEmptyA(pServer->szServerName))
  211. {
  212. LOADSTRING(idsDetail_Server, szRes);
  213. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, pServer->szServerName, TRUE, &pszSep));
  214. }
  215. // Protocol: 'SMTP'
  216. LOADSTRING(idsDetail_Protocol, szRes);
  217. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, g_prgszServers[ixptype], FALSE, &pszSep));
  218. // Server Response: 'Text'
  219. if (pResult->pszResponse)
  220. {
  221. LOADSTRING(idsDetail_ServerResponse, szRes);
  222. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, pResult->pszResponse, TRUE, &pszSep));
  223. }
  224. // Port: 'Port'
  225. LOADSTRING(idsDetail_Port, szRes);
  226. wnsprintf(szNumber, ARRAYSIZE(szNumber), "%d", pServer->dwPort);
  227. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, szNumber, FALSE, &pszSep));
  228. // Secure: 'Yes or No'
  229. LOADSTRING(idsDetail_Secure, szRes);
  230. if (pServer->fSSL)
  231. LOADSTRING(idsOui, szNumber);
  232. else
  233. LOADSTRING(idsNon, szNumber);
  234. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, szNumber, FALSE, &pszSep));
  235. // Server Error: 'number'
  236. if (pResult->uiServerError)
  237. {
  238. LOADSTRING(idsServerErrorNumber, szRes);
  239. wnsprintf(szNumber, ARRAYSIZE(szNumber), "%d", pResult->uiServerError);
  240. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, szNumber, FALSE, &pszSep));
  241. }
  242. // Server Error: '0x00000000'
  243. else if (pResult->hrServerError)
  244. {
  245. LOADSTRING(idsServerErrorNumber, szRes);
  246. wnsprintf(szNumber, ARRAYSIZE(szNumber), "0x%0X", pResult->hrServerError);
  247. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, szNumber, FALSE, &pszSep));
  248. }
  249. // Socket Error: 'number'
  250. if (pResult->dwSocketError)
  251. {
  252. LOADSTRING(idsSocketErrorNumber, szRes);
  253. wnsprintf(szNumber, ARRAYSIZE(szNumber), "%d", pResult->dwSocketError);
  254. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, szNumber, FALSE, &pszSep));
  255. }
  256. // Error Number: 'Text'
  257. if (pResult->hrResult)
  258. {
  259. LOADSTRING(idsDetail_ErrorNumber, szRes);
  260. wnsprintf(szNumber, ARRAYSIZE(szNumber), "0x%0X", pResult->hrResult);
  261. CHECKHR(hr = TaskUtil_HrWriteQuoted(&cStream, szRes, szNumber, FALSE, &pszSep));
  262. }
  263. // Acquire the string from cStream
  264. CHECKHR(hr = cStream.HrAcquireStringA(pcchInfo, ppszInfo, ACQ_DISPLACE));
  265. exit:
  266. if (FAILED(hr)) {
  267. // If we failed, just return the pszProblem string (duped), if possible
  268. *ppszInfo = StringDup(pszProblem);
  269. if (NULL != *ppszInfo) {
  270. *pcchInfo = lstrlen(*ppszInfo);
  271. hr = S_FALSE;
  272. }
  273. else {
  274. *pcchInfo = 0;
  275. hr = E_OUTOFMEMORY;
  276. }
  277. }
  278. // Done
  279. return hr;
  280. }
  281. // --------------------------------------------------------------------------------
  282. // PTaskUtil_GetError
  283. // --------------------------------------------------------------------------------
  284. LPCTASKERROR PTaskUtil_GetError(HRESULT hrResult, ULONG *piError)
  285. {
  286. // Look for the hresult
  287. for (ULONG i=0; i<ARRAYSIZE(c_rgTaskErrors); i++)
  288. {
  289. // Is this It
  290. if (hrResult == c_rgTaskErrors[i].hrResult)
  291. {
  292. // Done
  293. if (piError)
  294. *piError = i;
  295. return(&c_rgTaskErrors[i]);
  296. }
  297. }
  298. // Done
  299. return(NULL);
  300. }
  301. // --------------------------------------------------------------------------------
  302. // TaskUtil_SplitStoreError
  303. // --------------------------------------------------------------------------------
  304. void TaskUtil_SplitStoreError(IXPRESULT *pixpResult, INETSERVER *pInetServer,
  305. STOREERROR *pErrorInfo)
  306. {
  307. if (NULL == pixpResult || NULL == pInetServer || NULL == pErrorInfo)
  308. {
  309. Assert(FALSE);
  310. return;
  311. }
  312. // Fill out IXPRESULT from STOREERROR
  313. ZeroMemory(pixpResult, sizeof(*pixpResult));
  314. pixpResult->hrResult = pErrorInfo->hrResult;
  315. pixpResult->pszResponse = pErrorInfo->pszDetails;
  316. pixpResult->uiServerError = pErrorInfo->uiServerError;
  317. pixpResult->hrServerError = pErrorInfo->hrServerError;
  318. pixpResult->dwSocketError = pErrorInfo->dwSocketError;
  319. pixpResult->pszProblem = pErrorInfo->pszProblem;
  320. // Fill out INETSERVER structure from STOREERROR
  321. ZeroMemory(pInetServer, sizeof(*pInetServer));
  322. if (NULL != pErrorInfo->pszAccount)
  323. StrCpyN(pInetServer->szAccount, pErrorInfo->pszAccount, ARRAYSIZE(pInetServer->szAccount));
  324. if (NULL != pErrorInfo->pszUserName)
  325. StrCpyN(pInetServer->szUserName, pErrorInfo->pszUserName, ARRAYSIZE(pInetServer->szUserName));
  326. pInetServer->szPassword[0] = '\0';
  327. if (NULL != pErrorInfo->pszServer)
  328. StrCpyN(pInetServer->szServerName, pErrorInfo->pszServer, ARRAYSIZE(pInetServer->szServerName));
  329. if (NULL != pErrorInfo->pszConnectoid)
  330. StrCpyN(pInetServer->szConnectoid, pErrorInfo->pszConnectoid, ARRAYSIZE(pInetServer->szConnectoid));
  331. pInetServer->rasconntype = pErrorInfo->rasconntype;
  332. pInetServer->dwPort = pErrorInfo->dwPort;
  333. pInetServer->fSSL = pErrorInfo->fSSL;
  334. pInetServer->fTrySicily = pErrorInfo->fTrySicily;
  335. pInetServer->dwTimeout = 30; // Whatever, I don't think it's used
  336. pInetServer->dwFlags = 0;
  337. }
  338. TASKRESULTTYPE TaskUtil_InsertTransportError(BOOL fCanShowUI, ISpoolerUI *pUI, EVENTID eidCurrent,
  339. STOREERROR *pErrorInfo, LPSTR pszOpDescription,
  340. LPSTR pszSubject)
  341. {
  342. char szBuf[CCHMAX_STRINGRES * 2];
  343. LPSTR pszEnd; // Points to end of string being constructed in szBuf
  344. IXPRESULT ixpResult;
  345. INETSERVER rServer;
  346. HWND hwndParent;
  347. if (NULL == pErrorInfo)
  348. {
  349. Assert(FALSE);
  350. return TASKRESULT_FAILURE;
  351. }
  352. // If operation description is provided, copy it first
  353. szBuf[0] = '\0';
  354. pszEnd = szBuf;
  355. if (NULL != pszOpDescription)
  356. {
  357. if (0 == HIWORD(pszOpDescription))
  358. pszEnd += LoadString(g_hLocRes, LOWORD(pszOpDescription), szBuf, sizeof(szBuf));
  359. else
  360. {
  361. StrCpyN(szBuf, pszOpDescription, ARRAYSIZE(szBuf));
  362. pszEnd += lstrlen(szBuf);
  363. }
  364. }
  365. // Append the transport error description to our error string buffer
  366. if ((pszEnd - szBuf) < (sizeof(szBuf) - 1))
  367. {
  368. *pszEnd = ' ';
  369. pszEnd += 1;
  370. *pszEnd = '\0';
  371. }
  372. if ((NULL != pErrorInfo->pszProblem) && ((ARRAYSIZE(szBuf)) > ((int)(pszEnd - szBuf))))
  373. StrCpyN(pszEnd, pErrorInfo->pszProblem, ARRAYSIZE(szBuf) - (int) (pszEnd - szBuf));
  374. // Now generate and insert the full error information
  375. TaskUtil_SplitStoreError(&ixpResult, &rServer, pErrorInfo);
  376. ixpResult.pszProblem = szBuf;
  377. // Get Window
  378. if (NULL == pUI || FAILED(pUI->GetWindow(&hwndParent)))
  379. hwndParent = NULL;
  380. return TaskUtil_FBaseTransportError(pErrorInfo->ixpType, eidCurrent, &ixpResult,
  381. &rServer, pszSubject, pUI, fCanShowUI, hwndParent);
  382. } // TaskUtil_InsertTransportError
  383. // --------------------------------------------------------------------------------
  384. // TaskUtil_FBaseTransportError
  385. // --------------------------------------------------------------------------------
  386. TASKRESULTTYPE TaskUtil_FBaseTransportError(IXPTYPE ixptype, EVENTID idEvent, LPIXPRESULT pResult,
  387. LPINETSERVER pServer, LPCSTR pszSubject, ISpoolerUI *pUI, BOOL fCanShowUI, HWND hwndParent)
  388. {
  389. // Locals
  390. HRESULT hr=S_OK;
  391. LPCTASKERROR pError=NULL;
  392. TASKRESULTTYPE taskresult=TASKRESULT_FAILURE;
  393. CHAR szRes[255];
  394. LPSTR pszInfo=NULL;
  395. ULONG cchInfo;
  396. LPSTR pszError=NULL;
  397. LPSTR pszFull=NULL;
  398. BOOL fShowUI=FALSE;
  399. LPSTR pszTempProb=pResult->pszProblem;
  400. ULONG i;
  401. // Invalid Arg
  402. Assert(pResult && FAILED(pResult->hrResult) && pServer && ixptype <= IXP_HTTPMail);
  403. // Find the Error
  404. pError = PTaskUtil_GetError(pResult->hrResult, &i);
  405. // Found it
  406. if (pError)
  407. {
  408. // If I have hard-coded a string
  409. if (pError->pszError)
  410. {
  411. // Just copy the string
  412. StrCpyN(szRes, pError->pszError, ARRAYSIZE(szRes));
  413. // Set pszError
  414. pszError = szRes;
  415. }
  416. // Rejected Recips or Rejected Sender
  417. else if (IXP_E_SMTP_REJECTED_RECIPIENTS == pError->hrResult || IXP_E_SMTP_REJECTED_SENDER == pError->hrResult)
  418. {
  419. // Locals
  420. CHAR szMessage[1024];
  421. // Better Succeed
  422. SideAssert(LoadString(g_hLocRes, pError->ulStringId, szRes, ARRAYSIZE(szRes)) > 0);
  423. // Format the message
  424. if (pResult->pszProblem && '\0' != *pResult->pszProblem)
  425. {
  426. // Use pszProblem, it probably contains the email address, I hope
  427. wnsprintf(szMessage, ARRAYSIZE(szMessage), szRes, pResult->pszProblem);
  428. // Temporarily NULL it out so that we don't use it later
  429. pResult->pszProblem = NULL;
  430. }
  431. else
  432. {
  433. // Locals
  434. CHAR szUnknown[255];
  435. // Load '<Unknown>'
  436. SideAssert(LoadString(g_hLocRes, idsUnknown, szUnknown, ARRAYSIZE(szUnknown)) > 0);
  437. // Format the error
  438. wnsprintf(szMessage, ARRAYSIZE(szMessage), szRes, szUnknown);
  439. }
  440. // Set pszError
  441. pszError = szMessage;
  442. }
  443. // Otherwise, load the string
  444. else
  445. {
  446. // Better Succeed
  447. SideAssert(LoadString(g_hLocRes, pError->ulStringId, szRes, ARRAYSIZE(szRes)) > 0);
  448. // Set pszError
  449. pszError = szRes;
  450. }
  451. // Set the task result type
  452. taskresult = c_rgTaskErrors[i].tyResult;
  453. // Show UI
  454. fShowUI = pError->fShowUI;
  455. }
  456. // Otherwise, default
  457. else
  458. {
  459. // Load the unknwon string
  460. SideAssert(LoadString(g_hLocRes, IDS_IXP_E_UNKNOWN, szRes, ARRAYSIZE(szRes)) > 0);
  461. // Set the Error source
  462. pszError = szRes;
  463. }
  464. // No Error
  465. if (NULL == pszError)
  466. goto exit;
  467. // If there is a pszProblem, use it
  468. if (pResult->pszProblem)
  469. pszError = pResult->pszProblem;
  470. // Get the error information part
  471. CHECKHR(hr = TaskUtil_HrBuildErrorInfoString(pszError, ixptype, pResult, pServer, pszSubject, &pszInfo, &cchInfo));
  472. // Log into spooler ui
  473. if (pUI)
  474. {
  475. // Insert the Error
  476. CHECKHR(hr = pUI->InsertError(idEvent, pszInfo));
  477. }
  478. // Show in a message box ?
  479. if (fShowUI && fCanShowUI)
  480. {
  481. // Locals
  482. INETMAILERROR rError;
  483. // Zero Init
  484. ZeroMemory(&rError, sizeof(INETMAILERROR));
  485. // Setup the Error Structure
  486. rError.dwErrorNumber = pResult->hrResult;
  487. rError.hrError = pResult->hrServerError;
  488. rError.pszServer = pServer->szServerName;
  489. rError.pszAccount = pServer->szAccount;
  490. rError.pszMessage = pszError;
  491. rError.pszUserName = pServer->szUserName;
  492. rError.pszProtocol = g_prgszServers[ixptype];
  493. rError.pszDetails = pResult->pszResponse;
  494. rError.dwPort = pServer->dwPort;
  495. rError.fSecure = pServer->fSSL;
  496. // Beep
  497. MessageBeep(MB_OK);
  498. // Show the error
  499. DialogBoxParam(g_hLocRes, MAKEINTRESOURCE(iddInetMailError), hwndParent, InetMailErrorDlgProc, (LPARAM)&rError);
  500. }
  501. exit:
  502. // Cleanup
  503. SafeMemFree(pszInfo);
  504. SafeMemFree(pszFull);
  505. // Reset pszProblem
  506. pResult->pszProblem = pszTempProb;
  507. // Done
  508. return taskresult;
  509. }
  510. // ------------------------------------------------------------------------------------
  511. // TaskUtil_OnLogonPrompt - Returns S_FALSE if user cancels, otherwise S_OK
  512. // ------------------------------------------------------------------------------------
  513. HRESULT TaskUtil_OnLogonPrompt(IImnAccount *pAccount, ISpoolerUI *pUI, HWND hwndParent,
  514. LPINETSERVER pServer, DWORD apidUserName, DWORD apidPassword, DWORD apidPromptPwd, BOOL fSaveChanges)
  515. {
  516. // Locals
  517. HRESULT hr=S_FALSE;
  518. LOGONINFO rLogon;
  519. DWORD cb, type, dw;
  520. // Check Params
  521. Assert(pAccount && pServer);
  522. if (SUCCEEDED(pAccount->GetPropDw(AP_HTTPMAIL_DOMAIN_MSN, &dw)) && dw)
  523. {
  524. if(HideHotmail())
  525. return(hr);
  526. }
  527. // Use current account, blah
  528. rLogon.pszAccount = pServer->szAccount;
  529. rLogon.pszPassword = pServer->szPassword;
  530. rLogon.pszUserName = pServer->szUserName;
  531. rLogon.pszServer = pServer->szServerName;
  532. rLogon.fSavePassword = !ISFLAGSET(pServer->dwFlags, ISF_ALWAYSPROMPTFORPASSWORD);
  533. cb = sizeof(DWORD);
  534. if (ERROR_SUCCESS == SHGetValue(HKEY_LOCAL_MACHINE, c_szRegFlat, c_szRegValNoModifyAccts, &type, &dw, &cb) &&
  535. dw == 0)
  536. rLogon.fAlwaysPromptPassword = TRUE;
  537. else
  538. rLogon.fAlwaysPromptPassword = FALSE;
  539. // No Parent
  540. if (NULL == hwndParent && NULL != pUI)
  541. {
  542. // Get the window parent
  543. if (FAILED(pUI->GetWindow(&hwndParent)))
  544. hwndParent = NULL;
  545. // Set foreground
  546. if (hwndParent)
  547. SetForegroundWindow(hwndParent);
  548. }
  549. // Do the Dialog Box
  550. if (DialogBoxParam(g_hLocRes, MAKEINTRESOURCE(iddPassword), hwndParent, TaskUtil_LogonPromptDlgProc, (LPARAM)&rLogon) == IDCANCEL)
  551. goto exit;
  552. // Set User Name
  553. pAccount->SetPropSz(apidUserName, pServer->szUserName);
  554. // Save Password
  555. if (rLogon.fSavePassword)
  556. pAccount->SetPropSz(apidPassword, pServer->szPassword);
  557. else
  558. pAccount->SetProp(apidPassword, NULL, 0);
  559. if (rLogon.fAlwaysPromptPassword && apidPromptPwd)
  560. pAccount->SetPropDw(apidPromptPwd, !rLogon.fSavePassword);
  561. // Save Changes
  562. if (fSaveChanges)
  563. pAccount->SaveChanges();
  564. // Everything is good
  565. hr = S_OK;
  566. exit:
  567. // Done
  568. return hr;
  569. }
  570. // ------------------------------------------------------------------------------------
  571. // TaskUtil_LogonPromptDlgProc
  572. // ------------------------------------------------------------------------------------
  573. INT_PTR CALLBACK TaskUtil_LogonPromptDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  574. {
  575. // Locals
  576. LPLOGONINFO pLogon=(LPLOGONINFO)GetWndThisPtr(hwnd);
  577. CHAR szRes[CCHMAX_RES];
  578. CHAR szTitle[CCHMAX_RES + CCHMAX_ACCOUNT_NAME];
  579. // Handle Message
  580. switch (uMsg)
  581. {
  582. case WM_INITDIALOG:
  583. // Get the pointer
  584. pLogon = (LPLOGONINFO)lParam;
  585. Assert(pLogon);
  586. // AddRef the pointer
  587. Assert(pLogon->pszAccount);
  588. Assert(pLogon->pszServer);
  589. Assert(pLogon->pszUserName);
  590. Assert(pLogon->pszPassword);
  591. // Center remember location
  592. CenterDialog(hwnd);
  593. // Limit Text
  594. Edit_LimitText(GetDlgItem(hwnd, IDE_ACCOUNT), CCHMAX_USERNAME-1);
  595. Edit_LimitText(GetDlgItem(hwnd, IDE_PASSWORD), CCHMAX_PASSWORD-1);
  596. // Set Window Title
  597. if (!FIsEmptyA(pLogon->pszAccount))
  598. {
  599. GetWindowText(hwnd, szRes, sizeof(szRes)/sizeof(TCHAR));
  600. wnsprintf(szTitle, ARRAYSIZE(szTitle), "%s - %s", szRes, pLogon->pszAccount);
  601. SetWindowText(hwnd, szTitle);
  602. }
  603. // Set Server
  604. if (!FIsEmptyA(pLogon->pszServer))
  605. Edit_SetText(GetDlgItem(hwnd, IDS_SERVER), pLogon->pszServer);
  606. // Set User Name
  607. if (!FIsEmptyA(pLogon->pszUserName))
  608. {
  609. Edit_SetText(GetDlgItem(hwnd, IDE_ACCOUNT), pLogon->pszUserName);
  610. SetFocus(GetDlgItem(hwnd, IDE_PASSWORD));
  611. }
  612. else
  613. SetFocus(GetDlgItem(hwnd, IDE_ACCOUNT));
  614. // Set Password
  615. if (!FIsEmptyA(pLogon->pszPassword))
  616. Edit_SetText(GetDlgItem(hwnd, IDE_PASSWORD), pLogon->pszPassword);
  617. // Remember Password
  618. CheckDlgButton(hwnd, IDCH_REMEMBER, pLogon->fSavePassword);
  619. if (!pLogon->fAlwaysPromptPassword)
  620. EnableWindow(GetDlgItem(hwnd, IDCH_REMEMBER), FALSE);
  621. // Save the pointer
  622. SetWndThisPtr(hwnd, pLogon);
  623. return FALSE;
  624. case WM_COMMAND:
  625. switch(GET_WM_COMMAND_ID(wParam,lParam))
  626. {
  627. case IDCANCEL:
  628. EndDialog(hwnd, IDCANCEL);
  629. return 1;
  630. case IDOK:
  631. Assert(pLogon);
  632. if (pLogon)
  633. {
  634. // Pray
  635. Assert(pLogon->pszUserName);
  636. Assert(pLogon->pszPassword);
  637. // User Name
  638. if (pLogon->pszUserName)
  639. Edit_GetText(GetDlgItem(hwnd, IDE_ACCOUNT), pLogon->pszUserName, CCHMAX_USERNAME);
  640. // Password
  641. if (pLogon->pszPassword)
  642. Edit_GetText(GetDlgItem(hwnd, IDE_PASSWORD), pLogon->pszPassword, CCHMAX_PASSWORD);
  643. // Save Password
  644. pLogon->fSavePassword = IsDlgButtonChecked(hwnd, IDCH_REMEMBER);
  645. }
  646. EndDialog(hwnd, IDOK);
  647. return 1;
  648. }
  649. break;
  650. case WM_DESTROY:
  651. SetWndThisPtr(hwnd, NULL);
  652. return 0;
  653. }
  654. // Done
  655. return 0;
  656. }
  657. // ------------------------------------------------------------------------------------
  658. // TaskUtil_HwndOnTimeout
  659. // ------------------------------------------------------------------------------------
  660. HWND TaskUtil_HwndOnTimeout(LPCSTR pszServer, LPCSTR pszAccount, LPCSTR pszProtocol, DWORD dwTimeout,
  661. ITimeoutCallback *pCallback)
  662. {
  663. // Locals
  664. TIMEOUTINFO rTimeout;
  665. // Init
  666. ZeroMemory(&rTimeout, sizeof(TIMEOUTINFO));
  667. rTimeout.pszProtocol = pszProtocol;
  668. rTimeout.pszServer = pszServer;
  669. rTimeout.pszAccount = pszAccount;
  670. rTimeout.dwTimeout = dwTimeout;
  671. rTimeout.pCallback = pCallback;
  672. // Modeless Dialog
  673. HWND hwnd = CreateDialogParam(g_hLocRes, MAKEINTRESOURCE(iddTimeout), NULL, TaskUtil_TimeoutPromptDlgProc, (LPARAM)&rTimeout);
  674. // Failure
  675. if (hwnd)
  676. SetForegroundWindow(hwnd);
  677. // Done
  678. return hwnd;
  679. }
  680. // ------------------------------------------------------------------------------------
  681. // TaskUtil_TimeoutPromptDlgProc
  682. // ------------------------------------------------------------------------------------
  683. INT_PTR CALLBACK TaskUtil_TimeoutPromptDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  684. {
  685. // Locals
  686. ITimeoutCallback *pCallback=(ITimeoutCallback *)GetWndThisPtr(hwnd);
  687. // Handle Message
  688. switch (uMsg)
  689. {
  690. case WM_INITDIALOG:
  691. // Get the pointer
  692. {
  693. LPTIMEOUTINFO pTimeout = (LPTIMEOUTINFO)lParam;
  694. Assert(pTimeout);
  695. // Validate pIn
  696. Assert(pTimeout->pszServer && pTimeout->pszAccount && pTimeout->pszProtocol && pTimeout->pCallback);
  697. // Center remember location
  698. CenterDialog(hwnd);
  699. // Get the text from the static
  700. CHAR szText[CCHMAX_RES + CCHMAX_RES];
  701. Edit_GetText(GetDlgItem(hwnd, IDC_TIMEOUT), szText, ARRAYSIZE(szText));
  702. // Format the message
  703. CHAR szAccount[CCHMAX_ACCOUNT_NAME];
  704. CHAR szWarning[CCHMAX_RES + CCHMAX_RES + CCHMAX_ACCOUNT_NAME + CCHMAX_SERVER_NAME];
  705. PszEscapeMenuStringA(pTimeout->pszAccount, szAccount, ARRAYSIZE(szAccount));
  706. wnsprintf(szWarning, ARRAYSIZE(szWarning), szText, pTimeout->pszProtocol, pTimeout->dwTimeout, pTimeout->dwTimeout, szAccount, pTimeout->pszServer);
  707. // Set the Text
  708. Edit_SetText(GetDlgItem(hwnd, IDC_TIMEOUT), szWarning);
  709. // AddRef the Task
  710. pTimeout->pCallback->AddRef();
  711. // Save the pointer
  712. SetWndThisPtr(hwnd, pTimeout->pCallback);
  713. }
  714. return FALSE;
  715. case WM_COMMAND:
  716. switch(GET_WM_COMMAND_ID(wParam,lParam))
  717. {
  718. case IDCANCEL:
  719. Assert(pCallback);
  720. if (pCallback)
  721. {
  722. // IMAP's OnTimeoutResponse blocks on modal error dlg when disconnecting
  723. // during cmd in progress. Hide us to avoid confusion
  724. ShowWindow(hwnd, SW_HIDE);
  725. pCallback->OnTimeoutResponse(TIMEOUT_RESPONSE_STOP);
  726. }
  727. DestroyWindow(hwnd);
  728. return 1;
  729. case IDOK:
  730. Assert(pCallback);
  731. if (pCallback)
  732. pCallback->OnTimeoutResponse(TIMEOUT_RESPONSE_WAIT);
  733. DestroyWindow(hwnd);
  734. return 1;
  735. }
  736. break;
  737. case WM_DESTROY:
  738. Assert(pCallback);
  739. SafeRelease(pCallback);
  740. SetWndThisPtr(hwnd, NULL);
  741. return 0;
  742. }
  743. // Done
  744. return 0;
  745. }
  746. // ------------------------------------------------------------------------------------
  747. // TaskUtil_CheckForPasswordPrompt
  748. //
  749. // Purpose: This function checks if the given account is set to always prompt for a
  750. // a password, and we do not have a password cached for this account. If both are
  751. // true, we make the spooler window visible so that we may prompt the user
  752. // for his password. This function should be called immediately after a spooler
  753. // event has been successfully registered. This function should not be called if
  754. // the caller already has AP_*_PROMPT_PASSWORD, AP_*_PORT and AP_*_SERVER properties:
  755. // in this case, the caller can call GetPassword to see if the password is cached.
  756. //
  757. // Arguments:
  758. // IImnAccount *pAccount [in] - the account associated with a successfully registered
  759. // spooler event.
  760. // DWORD dwSrvType [in] - the SRV_* type of this server, eg, SRV_IMAP or SRV_SMTP.
  761. // ISpoolerUI *pUI [in] - used to show the spooler window if this account matches
  762. // the criteria.
  763. // ------------------------------------------------------------------------------------
  764. #if 0 // Nobody seems to use this right now
  765. void TaskUtil_CheckForPasswordPrompt(IImnAccount *pAccount, DWORD dwSrvType,
  766. ISpoolerUI *pUI)
  767. {
  768. DWORD dwPromptPassPropID, dwPortPropID, dwServerPropID;
  769. DWORD fAlwaysPromptPassword, dwPort;
  770. char szServerName[CCHMAX_SERVER_NAME];
  771. HRESULT hrResult;
  772. Assert(SRV_IMAP == dwSrvType || SRV_NNTP == dwSrvType ||
  773. SRV_POP3 == dwSrvType || SRV_SMTP == dwSrvType);
  774. // Resolve property ID's
  775. switch (dwSrvType) {
  776. case SRV_IMAP:
  777. dwPromptPassPropID = AP_IMAP_PROMPT_PASSWORD;
  778. dwPortPropID = AP_IMAP_PORT;
  779. dwServerPropID = AP_IMAP_SERVER;
  780. break;
  781. case SRV_NNTP:
  782. dwPromptPassPropID = AP_NNTP_PROMPT_PASSWORD;
  783. dwPortPropID = AP_NNTP_PORT;
  784. dwServerPropID = AP_NNTP_SERVER;
  785. break;
  786. case SRV_POP3:
  787. dwPromptPassPropID = AP_POP3_PROMPT_PASSWORD;
  788. dwPortPropID = AP_POP3_PORT;
  789. dwServerPropID = AP_POP3_SERVER;
  790. break;
  791. case SRV_SMTP:
  792. dwPromptPassPropID = AP_SMTP_PROMPT_PASSWORD;
  793. dwPortPropID = AP_SMTP_PORT;
  794. dwServerPropID = AP_SMTP_SERVER;
  795. break;
  796. default:
  797. return; // We can't help you, buddy
  798. } // switch
  799. // If this account is set to always prompt for password and password isn't
  800. // already cached, show UI so we can prompt user for password
  801. hrResult = pAccount->GetPropDw(dwPromptPassPropID, &fAlwaysPromptPassword);
  802. if (FAILED(hrResult) || !fAlwaysPromptPassword)
  803. return;
  804. hrResult = pAccount->GetPropDw(dwPortPropID, &dwPort);
  805. if (FAILED(hrResult))
  806. return;
  807. hrResult = pAccount->GetPropSz(dwServerPropID, szServerName, sizeof(szServerName));
  808. if (FAILED(hrResult))
  809. return;
  810. hrResult = GetPassword(dwPort, szServerName, NULL, 0);
  811. if (FAILED(hrResult))
  812. // No cached password! Go ahead and make the spooler window visible
  813. pUI->ShowWindow(SW_SHOW);
  814. } // TaskUtil_CheckForPasswordPrompt
  815. #endif // 0
  816. // ------------------------------------------------------------------------------------
  817. // TaskUtil_OpenSentItemsFolder
  818. //
  819. // 1. If pAccount is a POP3 Account, then return the Local Store Sent Items.
  820. // 2. If pAccount is a NEWS Account, then return the default mail account sent items.
  821. // 3. Otherwise, return the sent items folder for the account (IMAP or HotMail).
  822. // ------------------------------------------------------------------------------------
  823. HRESULT TaskUtil_OpenSentItemsFolder(IImnAccount *pAccount, IMessageFolder **ppFolder)
  824. {
  825. // Locals
  826. HRESULT hr=S_OK;
  827. FOLDERID idServer;
  828. CHAR szAccountId[CCHMAX_ACCOUNT_NAME];
  829. IImnAccount *pDefault=NULL;
  830. DWORD dwServers;
  831. // Invalid Args
  832. Assert(pAccount && ppFolder);
  833. // Trace
  834. TraceCall("TaskUtil_OpenSentItemsFolder");
  835. // Get Sever Types
  836. IF_FAILEXIT(hr = pAccount->GetServerTypes(&dwServers));
  837. // If News Server, use default mail account instead...
  838. if (ISFLAGSET(dwServers, SRV_NNTP))
  839. {
  840. // Try to get the default mail account
  841. if (SUCCEEDED(g_pAcctMan->GetDefaultAccount(ACCT_MAIL, &pDefault)))
  842. {
  843. // Reset pAccount
  844. pAccount = pDefault;
  845. // Get Sever Types
  846. IF_FAILEXIT(hr = pAccount->GetServerTypes(&dwServers));
  847. }
  848. // Otherwise, use local store
  849. else
  850. dwServers = SRV_POP3;
  851. }
  852. // If pop3...
  853. if (ISFLAGSET(dwServers, SRV_POP3))
  854. {
  855. // Local Store
  856. idServer = FOLDERID_LOCAL_STORE;
  857. }
  858. // Otherwise...
  859. else
  860. {
  861. // Can't be new
  862. Assert(!ISFLAGSET(dwServers, SRV_NNTP));
  863. // Get the Account ID for pAccount
  864. IF_FAILEXIT(hr = pAccount->GetPropSz(AP_ACCOUNT_ID, szAccountId, ARRAYSIZE(szAccountId)));
  865. // Find the Server Id
  866. IF_FAILEXIT(hr = g_pStore->FindServerId(szAccountId, &idServer));
  867. }
  868. // Open Local Store
  869. IF_FAILEXIT(hr = g_pStore->OpenSpecialFolder(idServer, NULL, FOLDER_SENT, ppFolder));
  870. exit:
  871. // If failed, try to open local store special
  872. if (FAILED(hr))
  873. hr = g_pStore->OpenSpecialFolder(FOLDERID_LOCAL_STORE, NULL, FOLDER_SENT, ppFolder);
  874. // Cleanup
  875. SafeRelease(pDefault);
  876. // Done
  877. return(hr);
  878. }