Source code of Windows XP (NT5)
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.

248 lines
6.7 KiB

  1. // oe.cpp
  2. //
  3. #include "oe.h"
  4. /*
  5. HRESULT GetServerAndPort(IN INETSERVER & rServer, OUT CHost & host, OUT DWORD & dwPort)
  6. {
  7. #ifdef UNICODE
  8. TCHAR wcsServer[128];
  9. mbstowcs(wcsServer, rServer.szServerName, 128);
  10. host.SetHost(wcsServer);
  11. #else
  12. host.SetHost(rServer.szServerName);
  13. #endif
  14. dwPort = (long)rServer.dwPort;
  15. return S_OK;
  16. }
  17. */
  18. enum MAIL_TYPE
  19. {
  20. MAIL_NONE,
  21. MAIL_SMTP,
  22. MAIL_SMTP2,
  23. MAIL_IMAP,
  24. MAIL_POP3,
  25. MAIL_HTTP,
  26. };
  27. HRESULT GetDefaultOutBoundMailServer2(IN IImnAccount * pIImnAccount,
  28. OUT INETSERVER & rServer,
  29. OUT DWORD & dwMailType)
  30. {
  31. ISMTPTransport *pSMTPTransport;
  32. ISMTPTransport2 *pSMTPTransport2;
  33. HRESULT hr;
  34. // Create the SMTP transport object
  35. //
  36. hr = CoCreateInstance(CLSID_ISMTPTransport, NULL, CLSCTX_INPROC_SERVER, IID_ISMTPTransport, (LPVOID *)&pSMTPTransport);
  37. if( SUCCEEDED(hr) )
  38. {
  39. // Get the SMTP server information
  40. //
  41. hr = pSMTPTransport->InetServerFromAccount(pIImnAccount, &rServer);
  42. dwMailType = MAIL_SMTP;
  43. pSMTPTransport->Release();
  44. }
  45. if( FAILED(hr) )
  46. {
  47. // Unable to get SMTP server info, lets try and get SMTP transport 2 server information
  48. //
  49. hr = CoCreateInstance(CLSID_ISMTPTransport, NULL, CLSCTX_INPROC_SERVER, IID_ISMTPTransport2, (LPVOID *)&pSMTPTransport2);
  50. if( SUCCEEDED(hr) )
  51. {
  52. // Get SMTP2 server info
  53. //
  54. hr = pSMTPTransport2->InetServerFromAccount(pIImnAccount, &rServer);
  55. dwMailType = MAIL_SMTP2;
  56. pSMTPTransport->Release();
  57. }
  58. }
  59. if( FAILED(hr) )
  60. {
  61. // Make sure to clear the struct
  62. //
  63. memset(&rServer,0,sizeof(rServer));
  64. dwMailType = MAIL_NONE;
  65. }
  66. return hr;
  67. }
  68. HRESULT GetDefaultInBoundMailServer2(IN IImnAccount * pIImnAccount,
  69. OUT INETSERVER & rServer,
  70. OUT DWORD & dwMailType)
  71. {
  72. IPOP3Transport *pPOP3Transport;
  73. IIMAPTransport *pIMAPTransport;
  74. IHTTPMailTransport *pHTTPTransport;
  75. HRESULT hr;
  76. // Create the HTTP transport object
  77. //
  78. hr = CoCreateInstance(CLSID_IHTTPMailTransport, NULL, CLSCTX_INPROC_SERVER, IID_IHTTPMailTransport, (LPVOID *)&pHTTPTransport);
  79. if( SUCCEEDED(hr) )
  80. {
  81. // Get the HTTP server information
  82. //
  83. hr = pHTTPTransport->InetServerFromAccount(pIImnAccount, &rServer);
  84. dwMailType = MAIL_HTTP;
  85. pHTTPTransport->Release();
  86. }
  87. if( FAILED(hr) )
  88. {
  89. // Create the POP3 transport object
  90. //
  91. hr = CoCreateInstance(CLSID_IPOP3Transport, NULL, CLSCTX_INPROC_SERVER, IID_IPOP3Transport, (LPVOID *)&pPOP3Transport);
  92. if( SUCCEEDED(hr) )
  93. {
  94. // Get the POP3 server information
  95. //
  96. hr = pPOP3Transport->InetServerFromAccount(pIImnAccount, &rServer);
  97. dwMailType = MAIL_POP3;
  98. pPOP3Transport->Release();
  99. }
  100. }
  101. if( FAILED(hr) )
  102. {
  103. // Create the SMTP transport object
  104. //
  105. hr = CoCreateInstance(CLSID_IIMAPTransport, NULL, CLSCTX_INPROC_SERVER, IID_IIMAPTransport, (LPVOID *)&pIMAPTransport);
  106. if( SUCCEEDED(hr) )
  107. {
  108. // Get the SMTP server information
  109. //
  110. hr = pIMAPTransport->InetServerFromAccount(pIImnAccount, &rServer);
  111. dwMailType = MAIL_IMAP;
  112. pIMAPTransport->Release();
  113. }
  114. }
  115. if( FAILED(hr) )
  116. {
  117. memset(&rServer,0,sizeof(rServer));
  118. dwMailType = MAIL_NONE;
  119. }
  120. return hr;
  121. }
  122. HRESULT GetOEDefaultMailServer2(OUT INETSERVER & rInBoundServer,
  123. OUT DWORD & dwInBoundMailType,
  124. OUT INETSERVER & rOutBoundServer,
  125. OUT DWORD & dwOutBoundMailType)
  126. {
  127. IImnAccountManager2 *pIImnAccountManager2 = NULL;
  128. IImnAccountManager *pIImnAccountManager = NULL;
  129. IImnAccount *pIImnAccount = NULL;
  130. HRESULT hr;
  131. hr = CoCreateInstance(CLSID_ImnAccountManager, NULL, CLSCTX_INPROC_SERVER, IID_IImnAccountManager, (void**)&pIImnAccountManager);
  132. if( SUCCEEDED(hr) )
  133. {
  134. hr = pIImnAccountManager->QueryInterface(__uuidof(IImnAccountManager2), (void**)&pIImnAccountManager2);
  135. if(SUCCEEDED(hr))
  136. {
  137. hr = pIImnAccountManager2->InitUser(NULL, (GUID)UID_GIBC_DEFAULT_USER, 0);
  138. }
  139. if(SUCCEEDED(hr))
  140. {
  141. hr = pIImnAccountManager->Init(NULL);
  142. }
  143. if( SUCCEEDED(hr) )
  144. {
  145. hr = pIImnAccountManager->GetDefaultAccount(ACCT_MAIL, &pIImnAccount);
  146. if( SUCCEEDED(hr) )
  147. {
  148. HRESULT hr2, hr3;
  149. hr = E_FAIL;
  150. hr2 = GetDefaultInBoundMailServer2(pIImnAccount,rInBoundServer,dwInBoundMailType);
  151. hr3 = GetDefaultOutBoundMailServer2(pIImnAccount,rOutBoundServer,dwOutBoundMailType);
  152. if( SUCCEEDED(hr2) || SUCCEEDED(hr3) )
  153. {
  154. hr = S_OK;
  155. }
  156. pIImnAccount->Release();
  157. }
  158. }
  159. pIImnAccountManager->Release();
  160. if( pIImnAccountManager2 )
  161. {
  162. pIImnAccountManager2->Release();
  163. }
  164. }
  165. return hr;
  166. }
  167. HRESULT GetOEDefaultNewsServer2(OUT INETSERVER & rNewsServer)
  168. {
  169. IImnAccountManager2 *pIImnAccountManager2 = NULL;
  170. IImnAccountManager *pIImnAccountManager = NULL;
  171. IImnAccount *pIImnAccount = NULL;
  172. INNTPTransport *pNNTPTransport;
  173. HRESULT hr;
  174. hr = CoCreateInstance(CLSID_ImnAccountManager, NULL, CLSCTX_INPROC_SERVER, IID_IImnAccountManager, (void**)&pIImnAccountManager);
  175. if( SUCCEEDED(hr) )
  176. {
  177. hr = pIImnAccountManager->QueryInterface(__uuidof(IImnAccountManager2), (void**)&pIImnAccountManager2);
  178. if(SUCCEEDED(hr))
  179. {
  180. hr = pIImnAccountManager2->InitUser(NULL, (GUID)UID_GIBC_DEFAULT_USER, 0);
  181. }
  182. if(SUCCEEDED(hr))
  183. {
  184. hr = pIImnAccountManager->Init(NULL);
  185. }
  186. if( SUCCEEDED(hr) )
  187. {
  188. hr = pIImnAccountManager->GetDefaultAccount(ACCT_NEWS, &pIImnAccount);
  189. if( SUCCEEDED(hr) )
  190. {
  191. hr = CoCreateInstance(CLSID_INNTPTransport, NULL, CLSCTX_INPROC_SERVER, IID_INNTPTransport, (LPVOID *)&pNNTPTransport);
  192. if(SUCCEEDED(hr))
  193. {
  194. hr = pNNTPTransport->InetServerFromAccount(pIImnAccount, &rNewsServer);
  195. pIImnAccount->Release();
  196. }
  197. }
  198. }
  199. pIImnAccountManager->Release();
  200. if( pIImnAccountManager2 )
  201. {
  202. pIImnAccountManager2->Release();
  203. }
  204. }
  205. return hr;
  206. }