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.

1273 lines
36 KiB

  1. // --------------------------------------------------------------------------------
  2. // Main.cpp
  3. // --------------------------------------------------------------------------------
  4. #define INITGUID
  5. #include "pch.h"
  6. #include "windowsx.h"
  7. #include <initguid.h>
  8. #include "imnxport.h"
  9. #include "smtpcall.h"
  10. #include "pop3call.h"
  11. #include "nntpcall.h"
  12. #include "iconsole.h"
  13. #include "rascall.h"
  14. #include "httpcall.h"
  15. // Globals
  16. IImnAccountManager *g_pAcctMan=NULL;
  17. ISMTPTransport *g_pSMTP=NULL;
  18. IPOP3Transport *g_pPOP3=NULL;
  19. IRASTransport *g_pRAS=NULL;
  20. INNTPTransport *g_pNNTP=NULL;
  21. IHTTPMailTransport *g_pHTTPMail=NULL;
  22. UINT g_msgSMTP=0;
  23. UINT g_msgPOP3=0;
  24. UINT g_msgRAS=0;
  25. UINT g_msgNNTP=0;
  26. UINT g_msgHTTPMail=0;
  27. // Prototypes
  28. void ImnxportCommandShell(LPSTR pszShell);
  29. void SMTPCommandShell(void);
  30. void POP3CommandShell(void);
  31. void NNTPCommandShell(void);
  32. void IMAPCommandShell(void);
  33. void RASCommandShell(void);
  34. void HTTPMailCommandShell(void);
  35. void ConnectToSMTPTransport(LPINETSERVER pServer);
  36. void WaitForCompletion(UINT uiMsg, DWORD wparam);
  37. void __cdecl main(int argc, char *argv[])
  38. {
  39. // Locals
  40. HRESULT hr;
  41. // OLE Init
  42. hr = CoInitialize(NULL);
  43. if (FAILED(hr))
  44. {
  45. printf("CoInitialize - FAILED\n");
  46. exit(1);
  47. }
  48. // Register completion message
  49. g_msgSMTP = RegisterWindowMessage("SMTPTransport_Notify");
  50. g_msgPOP3 = RegisterWindowMessage("POP3Transport_Notify");
  51. g_msgRAS = RegisterWindowMessage("RASTransport_Notify");
  52. g_msgNNTP = RegisterWindowMessage("NNTPTransport_Notify");
  53. g_msgHTTPMail = RegisterWindowMessage("HTTPMailTransport_Notify");
  54. // Load the account manager
  55. hr = CoCreateInstance(CLSID_ImnAccountManager, NULL, CLSCTX_INPROC_SERVER, IID_IImnAccountManager, (LPVOID *)&g_pAcctMan);
  56. if (FAILED(hr))
  57. {
  58. printf("Unable to load the IMN Account Manager.\n");
  59. goto exit;
  60. }
  61. // Init the account manager
  62. hr = g_pAcctMan->Init(NULL);
  63. if (FAILED(hr))
  64. {
  65. printf("Unable to initialize the IMN Account Manager.\n");
  66. goto exit;
  67. }
  68. // Create smtp transport
  69. hr = HrCreateSMTPTransport(&g_pSMTP);
  70. if (FAILED(hr))
  71. goto exit;
  72. // Create pop3 transport
  73. hr = HrCreatePOP3Transport(&g_pPOP3);
  74. if (FAILED(hr))
  75. goto exit;
  76. // Create ras transport
  77. hr = HrCreateRASTransport(&g_pRAS);
  78. if (FAILED(hr))
  79. goto exit;
  80. // Create NNTP transport
  81. hr = HrCreateNNTPTransport(&g_pNNTP);
  82. if (FAILED(hr))
  83. goto exit;
  84. hr = HrCreateHTTPMailTransport(&g_pHTTPMail);
  85. if (FAILED(hr))
  86. goto exit;
  87. // Our console IO manager
  88. if (argc == 2)
  89. ImnxportCommandShell(argv[1]);
  90. else
  91. ImnxportCommandShell(NULL);
  92. exit:
  93. // Cleanup
  94. if (g_pSMTP)
  95. g_pSMTP->Release();
  96. if (g_pPOP3)
  97. g_pPOP3->Release();
  98. if (g_pRAS)
  99. g_pRAS->Release();
  100. if (g_pNNTP)
  101. g_pNNTP->Release();
  102. if (g_pHTTPMail)
  103. g_pHTTPMail->Release();
  104. if (g_pAcctMan)
  105. g_pAcctMan->Release();
  106. // CoUninitialize
  107. CoUninitialize();
  108. // Done
  109. exit(1);
  110. }
  111. // --------------------------------------------------------------------------------
  112. // HrByteToStream
  113. // --------------------------------------------------------------------------------
  114. HRESULT HrByteToStream(LPSTREAM *lppstm, LPBYTE lpb, ULONG cb)
  115. {
  116. // Locals
  117. HRESULT hr=S_OK;
  118. LARGE_INTEGER liOrigin = {0,0};
  119. // Create H Global Stream
  120. hr = CreateStreamOnHGlobal (NULL, TRUE, lppstm);
  121. if (FAILED(hr))
  122. goto exit;
  123. // Write String
  124. hr = (*lppstm)->Write (lpb, cb, NULL);
  125. if (FAILED(hr))
  126. goto exit;
  127. // Rewind the steam
  128. hr = (*lppstm)->Seek(liOrigin, STREAM_SEEK_SET, NULL);
  129. if (FAILED(hr))
  130. goto exit;
  131. exit:
  132. // Done
  133. return hr;
  134. }
  135. void ImnxportCommandShellHelp(void)
  136. {
  137. printf("Valid commands:\nSMTP\nPOP3\nNNTP\nIMAP\nRAS\nHTTPMail\nEXIT\n\n");
  138. }
  139. // Main command handler
  140. void ImnxportCommandShell(LPSTR pszShell)
  141. {
  142. // Locals
  143. char szCommand[50];
  144. // Title
  145. printf("\nMicrosoft(R) Internet Mail and News Command Shell.\n");
  146. printf("(C) Copyright 1985-1996 Microsoft Corp.\n");
  147. printf("Type ? for help.\n\n");
  148. IMNXPORTPrompt:
  149. if (!pszShell)
  150. {
  151. // Prompt
  152. printf("Internet> ");
  153. scanf("%s", szCommand);
  154. fflush(stdin);
  155. }
  156. else
  157. lstrcpy(szCommand, pszShell);
  158. printf("\n");
  159. // Handle Prompt
  160. if (lstrcmpi(szCommand, "SMTP") == 0)
  161. SMTPCommandShell();
  162. else if (lstrcmpi(szCommand, "POP3") == 0)
  163. POP3CommandShell();
  164. else if (lstrcmpi(szCommand, "IMAP") == 0)
  165. IMAPCommandShell();
  166. else if (lstrcmpi(szCommand, "NNTP") == 0)
  167. NNTPCommandShell();
  168. else if (lstrcmpi(szCommand, "RAS") == 0)
  169. RASCommandShell();
  170. else if (lstrcmpi(szCommand, "HTTPMail") == 0 || lstrcmpi(szCommand, "HTTP") == 0)
  171. HTTPMailCommandShell();
  172. else if (lstrcmpi(szCommand, "EXIT") == 0)
  173. return;
  174. else
  175. ImnxportCommandShellHelp();
  176. // RePrompt
  177. pszShell = NULL;
  178. goto IMNXPORTPrompt;
  179. }
  180. // SMTP Command Help
  181. void SMTPCommandShellHelp(void)
  182. {
  183. printf("Valid commands:\nACCOUNTS\nCONNECT\nQUIT\nRSET\nSENDMESSAGE\nEHLO\nHELO\nMAIL\nRCPT\nDATA\nSTREAM\nCUSTOM\nEXIT\n\n");
  184. }
  185. // SMTP Command Handler
  186. void SMTPCommandShell(void)
  187. {
  188. // Locals
  189. INETSERVER rServer;
  190. IImnAccount *pAccount=NULL;
  191. char szCommand[50];
  192. // Title
  193. printf("Microsoft(R) SMTP Command Shell.\n");
  194. printf("Type ? for help.\n\n");
  195. // Show command
  196. SMTPPrompt:
  197. printf("SMTP>");
  198. scanf("%s", szCommand);
  199. fflush(stdin);
  200. if (lstrcmpi(szCommand, "ACCOUNTS") == 0)
  201. g_pAcctMan->AccountListDialog(NULL, NULL);
  202. else if (lstrcmpi(szCommand, "CONNECT") == 0)
  203. {
  204. char szAccount[CCHMAX_ACCOUNT_NAME];
  205. printf("Enter Account Name>");
  206. scanf("%s", szAccount);
  207. fflush(stdin);
  208. if (FAILED(g_pAcctMan->FindAccount(AP_ACCOUNT_NAME, szAccount, &pAccount)))
  209. {
  210. printf("Invalid Account Name: '%s'\n\n", szAccount);
  211. goto SMTPPrompt;
  212. }
  213. if (FAILED(g_pSMTP->InetServerFromAccount(pAccount, &rServer)))
  214. {
  215. pAccount->Release();
  216. printf("IInternetTransport::InetServerFromAccount failed\n");
  217. goto SMTPPrompt;
  218. }
  219. if (FAILED(g_pSMTP->Connect(&rServer, TRUE, TRUE)))
  220. {
  221. pAccount->Release();
  222. printf("IInternetTransport::Connect failed\n");
  223. goto SMTPPrompt;
  224. }
  225. // Wait for completion
  226. WaitForCompletion(g_msgSMTP, SMTP_CONNECTED);
  227. // Done
  228. pAccount->Release();
  229. }
  230. else if (lstrcmpi(szCommand, "EHLO") == 0)
  231. {
  232. if (FAILED(g_pSMTP->CommandEHLO()))
  233. {
  234. printf("ISMTPTransport::CommandEHLO failed.\n");
  235. goto SMTPPrompt;
  236. }
  237. WaitForCompletion(g_msgSMTP, SMTP_EHLO);
  238. }
  239. else if (lstrcmpi(szCommand, "DOT") == 0)
  240. {
  241. if (FAILED(g_pSMTP->CommandDOT()))
  242. {
  243. printf("ISMTPTransport::CommandDOT failed.\n");
  244. goto SMTPPrompt;
  245. }
  246. WaitForCompletion(g_msgSMTP, SMTP_DOT);
  247. }
  248. else if (lstrcmpi(szCommand, "DATA") == 0)
  249. {
  250. if (FAILED(g_pSMTP->CommandDATA()))
  251. {
  252. printf("ISMTPTransport::CommandDATA failed.\n");
  253. goto SMTPPrompt;
  254. }
  255. WaitForCompletion(g_msgSMTP, SMTP_DATA);
  256. }
  257. else if (lstrcmpi(szCommand, "HELO") == 0)
  258. {
  259. if (FAILED(g_pSMTP->CommandHELO()))
  260. {
  261. printf("ISMTPTransport::CommandHELO failed.\n");
  262. goto SMTPPrompt;
  263. }
  264. WaitForCompletion(g_msgSMTP, SMTP_HELO);
  265. }
  266. else if (lstrcmpi(szCommand, "QUIT") == 0)
  267. {
  268. if (FAILED(g_pSMTP->CommandQUIT()))
  269. {
  270. printf("ISMTPTransport::CommandQUIT failed.\n");
  271. goto SMTPPrompt;
  272. }
  273. WaitForCompletion(g_msgSMTP, SMTP_QUIT);
  274. }
  275. else if (lstrcmpi(szCommand, "RSET") == 0)
  276. {
  277. if (FAILED(g_pSMTP->CommandRSET()))
  278. {
  279. printf("ISMTPTransport::CommandRSET failed.\n");
  280. goto SMTPPrompt;
  281. }
  282. WaitForCompletion(g_msgSMTP, SMTP_RSET);
  283. }
  284. else if (lstrcmpi(szCommand, "MAIL") == 0)
  285. {
  286. char szEmail[CCHMAX_EMAIL_ADDRESS];
  287. printf("Enter Sender Email Address>");
  288. scanf("%s", szEmail);
  289. fflush(stdin);
  290. if (FAILED(g_pSMTP->CommandMAIL(szEmail)))
  291. {
  292. printf("ISMTPTransport::CommandMAIL failed.\n");
  293. goto SMTPPrompt;
  294. }
  295. WaitForCompletion(g_msgSMTP, SMTP_MAIL);
  296. }
  297. else if (lstrcmpi(szCommand, "RCPT") == 0)
  298. {
  299. char szEmail[CCHMAX_EMAIL_ADDRESS];
  300. while(1)
  301. {
  302. printf("Enter Recipient Email ('Done')>");
  303. scanf("%s", szEmail);
  304. fflush(stdin);
  305. if (lstrcmpi(szEmail, "DONE") == 0)
  306. break;
  307. if (FAILED(g_pSMTP->CommandRCPT(szEmail)))
  308. {
  309. printf("ISMTPTransport::CommandRCPT failed.\n");
  310. goto SMTPPrompt;
  311. }
  312. WaitForCompletion(g_msgSMTP, SMTP_RCPT);
  313. }
  314. }
  315. else if (lstrcmpi(szCommand, "SENDMESSAGE") == 0)
  316. {
  317. INETADDR rgAddress[11];
  318. SMTPMESSAGE rMessage;
  319. CHAR szText[1024];
  320. ZeroMemory(&rgAddress, sizeof(rgAddress));
  321. ZeroMemory(&rMessage, sizeof(rMessage));
  322. printf("Enter Sender Email Address>");
  323. rgAddress[0].addrtype = ADDR_FROM;
  324. scanf("%s", rgAddress[0].szEmail);
  325. fflush(stdin);
  326. rMessage.rAddressList.prgAddress = rgAddress;
  327. rMessage.rAddressList.cAddress = 1;
  328. while(rMessage.rAddressList.cAddress < 11)
  329. {
  330. INT i = rMessage.rAddressList.cAddress;
  331. printf("(%d of 10) Enter Recipient Email ('Done')>", i);
  332. rgAddress[i].addrtype = ADDR_TO;
  333. scanf("%s", rgAddress[i].szEmail);
  334. fflush(stdin);
  335. if (lstrcmpi(rgAddress[i].szEmail, "DONE") == 0)
  336. break;
  337. rMessage.rAddressList.cAddress++;
  338. }
  339. printf("Enter Message Text, end with pressing RETURN:\n");
  340. scanf("%s", szText);
  341. fflush(stdin);
  342. rMessage.cbSize = lstrlen(szText);
  343. if (FAILED(HrByteToStream(&rMessage.pstmMsg, (LPBYTE)szText, rMessage.cbSize + 1)))
  344. {
  345. printf("HrByteToStream failed.\n");
  346. goto SMTPPrompt;
  347. }
  348. if (FAILED(g_pSMTP->SendMessage(&rMessage)))
  349. {
  350. rMessage.pstmMsg->Release();
  351. printf("ISMTPTransport::SendMessage failed.\n");
  352. goto SMTPPrompt;
  353. }
  354. WaitForCompletion(g_msgSMTP, SMTP_SEND_MESSAGE);
  355. rMessage.pstmMsg->Release();
  356. }
  357. else if (lstrcmpi(szCommand, "EXIT") == 0)
  358. return;
  359. else
  360. SMTPCommandShellHelp();
  361. // Go back to the prompt
  362. goto SMTPPrompt;
  363. }
  364. // POP3 Command Help
  365. void POP3CommandShellHelp(void)
  366. {
  367. printf("Valid commands:\nACCOUNTS\nCONNECT\nQUIT\nSTAT\nLIST\nUIDL\nTOP\nRETR\nMARK\n\n");
  368. }
  369. POP3CMDTYPE GetCommandType(LPDWORD pdwPopId)
  370. {
  371. INT i;
  372. *pdwPopId = 0;
  373. printf("(1) - POP3CMD_GET_POPID\n(2) - POP3CMD_GET_MARKED\n(3) - POP3CMD_GET_ALL\nSelect Command Type>");
  374. scanf("%d", &i);
  375. fflush(stdin);
  376. if (i == 1)
  377. {
  378. printf("Enter PopId>");
  379. scanf("%d", pdwPopId);
  380. return POP3CMD_GET_POPID;
  381. }
  382. else if (i == 2)
  383. return POP3CMD_GET_MARKED;
  384. return POP3CMD_GET_ALL;
  385. }
  386. // POP3 Command Shell
  387. void POP3CommandShell(void)
  388. {
  389. // Locals
  390. DWORD dwPopId;
  391. POP3CMDTYPE cmdtype;
  392. INETSERVER rServer;
  393. IImnAccount *pAccount=NULL;
  394. char szCommand[50];
  395. // Title
  396. printf("Microsoft(R) POP3 Command Shell.\n");
  397. printf("Type ? for help.\n\n");
  398. // Show command
  399. POP3Prompt:
  400. printf("POP3>");
  401. scanf("%s", szCommand);
  402. fflush(stdin);
  403. if (lstrcmpi(szCommand, "ACCOUNTS") == 0)
  404. g_pAcctMan->AccountListDialog(NULL, NULL);
  405. else if (lstrcmpi(szCommand, "CONNECT") == 0)
  406. {
  407. char szAccount[CCHMAX_ACCOUNT_NAME];
  408. printf("Enter Account Name>");
  409. scanf("%s", szAccount);
  410. fflush(stdin);
  411. if (FAILED(g_pAcctMan->FindAccount(AP_ACCOUNT_NAME, szAccount, &pAccount)))
  412. {
  413. printf("Invalid Account Name: '%s'\n\n", szAccount);
  414. goto POP3Prompt;
  415. }
  416. if (FAILED(g_pPOP3->InetServerFromAccount(pAccount, &rServer)))
  417. {
  418. pAccount->Release();
  419. printf("IInternetTransport::InetServerFromAccount failed\n");
  420. goto POP3Prompt;
  421. }
  422. if (FAILED(g_pPOP3->Connect(&rServer, TRUE, TRUE)))
  423. {
  424. pAccount->Release();
  425. printf("IInternetTransport::Connect failed\n");
  426. goto POP3Prompt;
  427. }
  428. // Wait for completion
  429. WaitForCompletion(g_msgPOP3, POP3_CONNECTED);
  430. // Done
  431. pAccount->Release();
  432. }
  433. else if (lstrcmpi(szCommand, "QUIT") == 0)
  434. {
  435. if (FAILED(g_pPOP3->CommandQUIT()))
  436. {
  437. printf("IPOP3Transport::CommandQUIT failed.\n");
  438. goto POP3Prompt;
  439. }
  440. WaitForCompletion(g_msgPOP3, POP3_QUIT);
  441. }
  442. else if (lstrcmpi(szCommand, "STAT") == 0)
  443. {
  444. if (FAILED(g_pPOP3->CommandSTAT()))
  445. {
  446. printf("IPOP3Transport::CommandSTAT failed.\n");
  447. goto POP3Prompt;
  448. }
  449. WaitForCompletion(g_msgPOP3, POP3_STAT);
  450. }
  451. else if (lstrcmpi(szCommand, "LIST") == 0)
  452. {
  453. cmdtype = GetCommandType(&dwPopId);
  454. if (FAILED(g_pPOP3->CommandLIST(cmdtype, dwPopId)))
  455. {
  456. printf("IPOP3Transport::CommandLIST failed.\n");
  457. goto POP3Prompt;
  458. }
  459. WaitForCompletion(g_msgPOP3, POP3_LIST);
  460. }
  461. else if (lstrcmpi(szCommand, "UIDL") == 0)
  462. {
  463. cmdtype = GetCommandType(&dwPopId);
  464. if (FAILED(g_pPOP3->CommandUIDL(cmdtype, dwPopId)))
  465. {
  466. printf("IPOP3Transport::CommandUIDL failed.\n");
  467. goto POP3Prompt;
  468. }
  469. WaitForCompletion(g_msgPOP3, POP3_UIDL);
  470. }
  471. else if (lstrcmpi(szCommand, "DELE") == 0)
  472. {
  473. cmdtype = GetCommandType(&dwPopId);
  474. if (FAILED(g_pPOP3->CommandDELE(cmdtype, dwPopId)))
  475. {
  476. printf("IPOP3Transport::CommandDELE failed.\n");
  477. goto POP3Prompt;
  478. }
  479. WaitForCompletion(g_msgPOP3, POP3_DELE);
  480. }
  481. else if (lstrcmpi(szCommand, "TOP") == 0)
  482. {
  483. INT cLines;
  484. cmdtype = GetCommandType(&dwPopId);
  485. printf("Number of Lines to Preview>");
  486. scanf("%d", &cLines);
  487. fflush(stdin);
  488. if (FAILED(g_pPOP3->CommandTOP(cmdtype, dwPopId, cLines)))
  489. {
  490. printf("IPOP3Transport::CommandTOP failed.\n");
  491. goto POP3Prompt;
  492. }
  493. WaitForCompletion(g_msgPOP3, POP3_TOP);
  494. }
  495. else if (lstrcmpi(szCommand, "RETR") == 0)
  496. {
  497. cmdtype = GetCommandType(&dwPopId);
  498. if (FAILED(g_pPOP3->CommandRETR(cmdtype, dwPopId)))
  499. {
  500. printf("IPOP3Transport::CommandRETR failed.\n");
  501. goto POP3Prompt;
  502. }
  503. WaitForCompletion(g_msgPOP3, POP3_RETR);
  504. }
  505. else if (lstrcmpi(szCommand, "MARK") == 0)
  506. {
  507. INT type, popid, flag;
  508. POP3MARKTYPE marktype;
  509. printf("(1) - POP3_MARK_FOR_TOP\n");
  510. printf("(2) - POP3_MARK_FOR_RETR\n");
  511. printf("(3) - POP3_MARK_FOR_DELE\n");
  512. printf("(4) - POP3_MARK_FOR_UIDL\n");
  513. printf("(5) - POP3_MARK_FOR_LIST\n");
  514. printf("Select MarkItem Type>");
  515. scanf("%d", &type);
  516. fflush(stdin);
  517. printf("Enter PopId>");
  518. scanf("%d", &popid);
  519. fflush(stdin);
  520. printf("Enable or Disable Marked Item (1 = Enable, 0 = Disable)>");
  521. scanf("%d", &flag);
  522. fflush(stdin);
  523. if (1 == type) marktype = POP3_MARK_FOR_TOP;
  524. else if (2 == type) marktype = POP3_MARK_FOR_RETR;
  525. else if (3 == type) marktype = POP3_MARK_FOR_DELE;
  526. else if (4 == type) marktype = POP3_MARK_FOR_UIDL;
  527. else if (5 == type) marktype = POP3_MARK_FOR_LIST;
  528. else
  529. {
  530. printf("Invalid MarkItemType!\n");
  531. goto POP3Prompt;
  532. }
  533. if (FAILED(g_pPOP3->MarkItem(marktype, popid, flag)))
  534. {
  535. printf("IPOP3Transport::MarkItem failed!\n");
  536. goto POP3Prompt;
  537. }
  538. }
  539. else if (lstrcmpi(szCommand, "EXIT") == 0)
  540. return;
  541. else
  542. POP3CommandShellHelp();
  543. // Go back to the prompt
  544. goto POP3Prompt;
  545. }
  546. // NNTP Command Help
  547. void NNTPCommandShellHelp(void)
  548. {
  549. printf("Valid commands:\nACCOUNTS\nCONNECT\nGROUP\nNEXT\nLAST\n"
  550. "STAT\nLIST\nMODE\nDATE\nARTICLE\nHEAD\nBODY\nHEADERS\nXHDR\n"
  551. "POST\nQUIT\n\n");
  552. }
  553. void NNTPCommandShell(void)
  554. {
  555. // Locals
  556. INETSERVER rServer;
  557. IImnAccount *pAccount=NULL;
  558. char szCommand[50];
  559. // Title
  560. printf("Microsoft(R) NNTP Command Shell.\n");
  561. printf("Type ? for help.\n\n");
  562. // Show command
  563. NNTPPrompt:
  564. printf("NNTP> ");
  565. scanf("%s", szCommand);
  566. fflush(stdin);
  567. if (lstrcmpi(szCommand, "ACCOUNTS") == 0)
  568. g_pAcctMan->AccountListDialog(GetDesktopWindow(), NULL);
  569. else if (lstrcmpi(szCommand, "CONNECT") == 0)
  570. {
  571. char szAccount[CCHMAX_ACCOUNT_NAME];
  572. printf("Enter Account Name> ");
  573. scanf("%s", szAccount);
  574. fflush(stdin);
  575. if (FAILED(g_pAcctMan->FindAccount(AP_ACCOUNT_NAME, szAccount, &pAccount)))
  576. {
  577. printf("Invalid Account Name: '%s'\n\n", szAccount);
  578. goto NNTPPrompt;
  579. }
  580. if (FAILED(g_pNNTP->InetServerFromAccount(pAccount, &rServer)))
  581. {
  582. pAccount->Release();
  583. printf("IInternetTransport::InetServerFromAccount failed\n");
  584. goto NNTPPrompt;
  585. }
  586. if (FAILED(g_pNNTP->Connect(&rServer, TRUE, TRUE)))
  587. {
  588. pAccount->Release();
  589. printf("IInternetTransport::Connect failed\n");
  590. goto NNTPPrompt;
  591. }
  592. // Wait for completion
  593. WaitForCompletion(g_msgNNTP, 0);
  594. // Done
  595. pAccount->Release();
  596. }
  597. else if (lstrcmpi(szCommand, "QUIT") == 0)
  598. {
  599. if (FAILED(g_pNNTP->CommandQUIT()))
  600. {
  601. printf("INNTPTransport::CommandQUIT failed.\n");
  602. goto NNTPPrompt;
  603. }
  604. WaitForCompletion(g_msgNNTP, NS_DISCONNECTED);
  605. }
  606. else if (lstrcmpi(szCommand, "AUTHINFO") == 0)
  607. {
  608. DWORD dwType;
  609. char szUserName[256];
  610. char szPassword[256];
  611. NNTPAUTHINFO authinfo;
  612. printf("(1) AUTHINFO USER/PASS\n");
  613. printf("(2) AUTHINFO SIMPLE\n");
  614. printf("(3) AUTHINFO TRANSACT\n");
  615. printf("Select type > ");
  616. scanf("%d", &dwType);
  617. fflush(stdin);
  618. authinfo.authtype = (dwType == 1) ? AUTHTYPE_USERPASS : ((dwType == 2) ? AUTHTYPE_SIMPLE : AUTHTYPE_SASL);
  619. if (dwType < 3)
  620. {
  621. printf("User Name > ");
  622. scanf("%s", &szUserName);
  623. fflush(stdin);
  624. printf("Password > ");
  625. scanf("%s", &szPassword);
  626. authinfo.pszUser = szUserName;
  627. authinfo.pszPass = szPassword;
  628. }
  629. if (FAILED(g_pNNTP->CommandAUTHINFO(&authinfo)))
  630. {
  631. printf("INNTPTransport::CommandAUTHINFO() failed\n");
  632. goto NNTPPrompt;
  633. }
  634. WaitForCompletion(g_msgNNTP, 0);
  635. }
  636. else if (lstrcmpi(szCommand, "GROUP") == 0)
  637. {
  638. char szGroup[256];
  639. printf("Enter Group Name> ");
  640. scanf("%s", szGroup);
  641. fflush(stdin);
  642. if (FAILED(g_pNNTP->CommandGROUP(szGroup)))
  643. {
  644. printf("INNTPTransport::CommandGROUP failed.\n");
  645. goto NNTPPrompt;
  646. }
  647. WaitForCompletion(g_msgNNTP, NS_GROUP);
  648. }
  649. else if (lstrcmpi(szCommand, "NEXT") == 0)
  650. {
  651. if (FAILED(g_pNNTP->CommandNEXT()))
  652. {
  653. printf("INNTPTransport::CommandNEXT failed.\n");
  654. goto NNTPPrompt;
  655. }
  656. WaitForCompletion(g_msgNNTP, NS_NEXT);
  657. }
  658. else if (lstrcmpi(szCommand, "LAST") == 0)
  659. {
  660. if (FAILED(g_pNNTP->CommandLAST()))
  661. {
  662. printf("INNTPTransport::CommandLAST failed.\n");
  663. goto NNTPPrompt;
  664. }
  665. WaitForCompletion(g_msgNNTP, NS_LAST);
  666. }
  667. else if (lstrcmpi(szCommand, "STAT") == 0)
  668. {
  669. char szStat[256];
  670. ARTICLEID aid;
  671. ZeroMemory(szStat, sizeof(szStat));
  672. ZeroMemory(&aid, sizeof(aid));
  673. printf("Enter article> ");
  674. scanf("%s", szStat);
  675. fflush(stdin);
  676. if (0 == sscanf(szStat, "%d", &aid.dwArticleNum))
  677. {
  678. aid.idType = AID_MSGID;
  679. aid.pszMessageId = szStat;
  680. }
  681. else
  682. aid.idType = AID_ARTICLENUM;
  683. if (FAILED(g_pNNTP->CommandSTAT(*szStat ? &aid : NULL)))
  684. {
  685. printf("INNTPTransport::CommandSTAT failed.\n");
  686. goto NNTPPrompt;
  687. }
  688. WaitForCompletion(g_msgNNTP, NS_STAT);
  689. }
  690. else if (lstrcmpi(szCommand, "LIST") == 0)
  691. {
  692. if (FAILED(g_pNNTP->CommandLIST(NULL)))
  693. {
  694. printf("INNTPTransport::CommandLIST failed.\n");
  695. goto NNTPPrompt;
  696. }
  697. WaitForCompletion(g_msgNNTP, 0);
  698. }
  699. else if (lstrcmpi(szCommand, "LISTGROUP") == 0)
  700. {
  701. char szGroup[256];
  702. printf("Enter Group Name> ");
  703. scanf("%s", szGroup);
  704. fflush(stdin);
  705. if (FAILED(g_pNNTP->CommandLISTGROUP(szGroup)))
  706. {
  707. printf("INNTPTransport::CommandLISTGROUP failed.\n");
  708. goto NNTPPrompt;
  709. }
  710. WaitForCompletion(g_msgNNTP, 0);
  711. }
  712. else if (lstrcmpi(szCommand, "LISTARG") == 0)
  713. {
  714. char szArg[256];
  715. ZeroMemory(szArg, 256);
  716. printf("Enter Arguments> ");
  717. scanf("%s", szArg);
  718. fflush(stdin);
  719. if (FAILED(g_pNNTP->CommandLIST(szArg)))
  720. {
  721. printf("INNTPTransport::CommandLIST failed.\n");
  722. goto NNTPPrompt;
  723. }
  724. WaitForCompletion(g_msgNNTP, 0);
  725. }
  726. else if (lstrcmpi(szCommand, "DATE") == 0)
  727. {
  728. if (FAILED(g_pNNTP->CommandDATE()))
  729. {
  730. printf("INNTPTransport::CommandDATE failed.\n");
  731. goto NNTPPrompt;
  732. }
  733. WaitForCompletion(g_msgNNTP, NS_DATE);
  734. }
  735. else if (lstrcmpi(szCommand, "MODE") == 0)
  736. {
  737. char szArg[256];
  738. ZeroMemory(szArg, 256);
  739. printf("Enter Arguments> ");
  740. scanf("%s", szArg);
  741. fflush(stdin);
  742. if (FAILED(g_pNNTP->CommandMODE(szArg)))
  743. {
  744. printf("INNTPTransport::CommandMODE failed.\n");
  745. goto NNTPPrompt;
  746. }
  747. WaitForCompletion(g_msgNNTP, NS_MODE);
  748. }
  749. else if (lstrcmpi(szCommand, "NEWGROUPS") == 0)
  750. {
  751. SYSTEMTIME st = {1996, 11, 0, 1, 0, 0, 0, 0};
  752. if (FAILED(g_pNNTP->CommandNEWGROUPS(&st, "<alt>")))
  753. {
  754. printf("INNTPTransport::CommandNEWGROUPS failed.\n");
  755. goto NNTPPrompt;
  756. }
  757. WaitForCompletion(g_msgNNTP, 0);
  758. }
  759. else if (lstrcmpi(szCommand, "ARTICLE") == 0)
  760. {
  761. char szArg[256];
  762. ARTICLEID aid;
  763. ZeroMemory(szArg, 256);
  764. printf("Enter article number> ");
  765. scanf("%s", szArg);
  766. fflush(stdin);
  767. if (0 == sscanf(szArg, "%d", &aid.dwArticleNum))
  768. {
  769. aid.idType = AID_MSGID;
  770. aid.pszMessageId = szArg;
  771. }
  772. else
  773. aid.idType = AID_ARTICLENUM;
  774. if (FAILED(g_pNNTP->CommandARTICLE(&aid)))
  775. {
  776. printf("INNTPTransport::CommandARTICLE failed.\n");
  777. goto NNTPPrompt;
  778. }
  779. WaitForCompletion(g_msgNNTP, 0);
  780. }
  781. else if (lstrcmpi(szCommand, "HEAD") == 0)
  782. {
  783. char szArg[256];
  784. ARTICLEID aid;
  785. ZeroMemory(szArg, 256);
  786. printf("Enter article number> ");
  787. scanf("%s", szArg);
  788. fflush(stdin);
  789. if (0 == sscanf(szArg, "%d", &aid.dwArticleNum))
  790. {
  791. aid.idType = AID_MSGID;
  792. aid.pszMessageId = szArg;
  793. }
  794. else
  795. aid.idType = AID_ARTICLENUM;
  796. if (FAILED(g_pNNTP->CommandHEAD(&aid)))
  797. {
  798. printf("INNTPTransport::CommandHEAD failed.\n");
  799. goto NNTPPrompt;
  800. }
  801. WaitForCompletion(g_msgNNTP, 0);
  802. }
  803. else if (lstrcmpi(szCommand, "BODY") == 0)
  804. {
  805. char szArg[256];
  806. ARTICLEID aid;
  807. ZeroMemory(szArg, 256);
  808. printf("Enter article number> ");
  809. scanf("%s", szArg);
  810. fflush(stdin);
  811. if (0 == sscanf(szArg, "%d", &aid.dwArticleNum))
  812. {
  813. aid.idType = AID_MSGID;
  814. aid.pszMessageId = szArg;
  815. }
  816. else
  817. aid.idType = AID_ARTICLENUM;
  818. if (FAILED(g_pNNTP->CommandBODY(&aid)))
  819. {
  820. printf("INNTPTransport::CommandBODY failed.\n");
  821. goto NNTPPrompt;
  822. }
  823. WaitForCompletion(g_msgNNTP, 0);
  824. }
  825. else if (lstrcmpi(szCommand, "HEADERS") == 0)
  826. {
  827. char szArg1[30], szArg2[30];
  828. RANGE range;
  829. printf("Enter starting article number> ");
  830. scanf("%s", szArg1);
  831. fflush(stdin);
  832. printf("Enter ending article number (0 for a single article)> ");
  833. scanf("%s", szArg2);
  834. fflush(stdin);
  835. range.idType = (atol(szArg2) == 0 ? RT_SINGLE : RT_RANGE);
  836. range.dwFirst = atol(szArg1);
  837. range.dwLast = atol(szArg2);
  838. if (FAILED(g_pNNTP->GetHeaders(&range)))
  839. {
  840. printf("INNTPTransport::GetHeaders() failed.\n");
  841. goto NNTPPrompt;
  842. }
  843. WaitForCompletion(g_msgNNTP, 0);
  844. }
  845. else if (lstrcmpi(szCommand, "XHDR") == 0)
  846. {
  847. char szHdr[256];
  848. char szArg1[30], szArg2[30];
  849. RANGE range;
  850. HRESULT hr;
  851. // I tested this scenario as well -- SteveSer
  852. // hr = g_pNNTP->CommandXHDR("Subject", NULL, "<01bb9b7a$7767b020$ff22369d@a-dmay>");
  853. printf("Enter header> ");
  854. scanf("%s", szHdr);
  855. printf("Enter starting article number (0 for the current article)> ");
  856. scanf("%s", szArg1);
  857. fflush(stdin);
  858. if (atol(szArg1) != 0)
  859. {
  860. printf("Enter ending article number (0 for a single article)> ");
  861. scanf("%s", szArg2);
  862. fflush(stdin);
  863. }
  864. if (atol(szArg1) == 0)
  865. hr = g_pNNTP->CommandXHDR(szHdr, NULL, NULL);
  866. else
  867. {
  868. range.idType = (atol(szArg2) == 0 ? RT_SINGLE : RT_RANGE);
  869. range.dwFirst = atol(szArg1);
  870. range.dwLast = atol(szArg2);
  871. hr = g_pNNTP->CommandXHDR(szHdr, &range, NULL);
  872. }
  873. if (FAILED(hr))
  874. {
  875. printf("INNTPTransport::CommandXHDR() failed.\n");
  876. goto NNTPPrompt;
  877. }
  878. WaitForCompletion(g_msgNNTP, 0);
  879. }
  880. else if (lstrcmpi(szCommand, "POST") == 0)
  881. {
  882. char szMessage[] = "From: \"Steve Serdy\" <[email protected]>\r\n"
  883. "Newsgroups: alt.test\r\n"
  884. "Subject: Test Message\r\n"
  885. "\r\nTest\r\n";
  886. NNTPMESSAGE rMessage;
  887. LPSTREAM pStream = 0;
  888. HRESULT hr;
  889. if (SUCCEEDED(CreateStreamOnHGlobal(NULL, TRUE, &pStream)))
  890. {
  891. pStream->Write((void const*) szMessage, lstrlen(szMessage) + 1, NULL);
  892. rMessage.cbSize = lstrlen(szMessage);
  893. rMessage.pstmMsg = pStream;
  894. hr = g_pNNTP->CommandPOST(&rMessage);
  895. pStream->Release();
  896. if (FAILED(hr))
  897. {
  898. printf("INNTPTransport::CommandPOST() failed.\n");
  899. goto NNTPPrompt;
  900. }
  901. WaitForCompletion(g_msgNNTP, 0);
  902. }
  903. }
  904. else if (lstrcmpi(szCommand, "EXIT") == 0)
  905. return;
  906. else
  907. NNTPCommandShellHelp();
  908. // Go back to the prompt
  909. goto NNTPPrompt;
  910. }
  911. void IMAPCommandShell(void)
  912. {
  913. printf("Not yet implemented.\n\n");
  914. }
  915. void RASCommandShellHelp(void)
  916. {
  917. printf("Valid commands:\nCONNECT\nDISCONNECT\nEXIT\n\n");
  918. }
  919. void RASCommandShell(void)
  920. {
  921. char szCommand[50];
  922. IImnAccount *pAccount=NULL;
  923. INETSERVER rServer;
  924. // Title
  925. printf("Microsoft(R) RAS Command Shell.\n");
  926. printf("Type ? for help.\n\n");
  927. // Show command
  928. RASPrompt:
  929. printf("RAS>");
  930. scanf("%s", szCommand);
  931. fflush(stdin);
  932. if (lstrcmpi(szCommand, "CONNECT") == 0)
  933. {
  934. char szAccount[CCHMAX_ACCOUNT_NAME];
  935. printf("Enter Account Name>");
  936. scanf("%s", szAccount);
  937. fflush(stdin);
  938. if (FAILED(g_pAcctMan->FindAccount(AP_ACCOUNT_NAME, szAccount, &pAccount)))
  939. {
  940. printf("Invalid Account Name: '%s'\n\n", szAccount);
  941. goto RASPrompt;
  942. }
  943. if (FAILED(g_pPOP3->InetServerFromAccount(pAccount, &rServer)))
  944. {
  945. pAccount->Release();
  946. printf("IInternetTransport::InetServerFromAccount failed\n");
  947. goto RASPrompt;
  948. }
  949. if (RAS_CONNECT_RAS != rServer.rasconntype)
  950. {
  951. pAccount->Release();
  952. printf("Account is not using RAS.\n");
  953. goto RASPrompt;
  954. }
  955. if (FAILED(g_pRAS->Connect(&rServer, TRUE, TRUE)))
  956. {
  957. pAccount->Release();
  958. printf("IInternetTransport::Connect failed\n");
  959. goto RASPrompt;
  960. }
  961. // Wait for completion
  962. WaitForCompletion(g_msgRAS, RAS_CONNECT);
  963. // Done
  964. pAccount->Release();
  965. }
  966. else if (lstrcmpi(szCommand, "DISCONNECT") == 0)
  967. {
  968. g_pRAS->Disconnect();
  969. }
  970. else if (lstrcmpi(szCommand, "EXIT") == 0)
  971. return;
  972. else
  973. RASCommandShellHelp();
  974. // Go back to the prompt
  975. goto RASPrompt;
  976. }
  977. void HTTPMailCommandShellHelp(void)
  978. {
  979. printf("Valid commands:\nCONNECT\nDISCONNECT\nGET\nGETROOTPROP\nLISTFOLDERS\nPUT\nPROPFIND\nEXIT\n\n");
  980. }
  981. void HTTPMailCommandShell(void)
  982. {
  983. INETSERVER rServer;
  984. char szCommand[50];
  985. // Title
  986. printf("Microsoft(R) HTTPMail Command Shell.\n");
  987. printf("Type ? for help.\n\n");
  988. HTTPMailPrompt:
  989. printf("HTTPMail> ");
  990. scanf("%s", szCommand);
  991. fflush(stdin);
  992. if (lstrcmpi(szCommand, "CONNECT") == 0)
  993. {
  994. ZeroMemory(&rServer, sizeof(rServer));
  995. printf("Enter server> ");
  996. scanf("%s", rServer.szServerName);
  997. fflush(stdin);
  998. printf("Enter login ('*' for anonymous)> ");
  999. scanf("%s", rServer.szUserName);
  1000. fflush(stdin);
  1001. if ('*' == rServer.szUserName[0])
  1002. rServer.szUserName[0] = '\0';
  1003. else
  1004. {
  1005. printf("Enter password> ");
  1006. scanf("%s", rServer.szPassword);
  1007. }
  1008. if (FAILED(g_pHTTPMail->Connect(&rServer, FALSE, TRUE)))
  1009. {
  1010. printf("IHTTMPMailTransport::Connect failed\n");
  1011. goto HTTPMailPrompt;
  1012. }
  1013. WaitForCompletion(g_msgHTTPMail, HTTPMAIL_CONNECTED);
  1014. goto HTTPMailPrompt;
  1015. }
  1016. else if (lstrcmpi(szCommand, "GET") == 0)
  1017. {
  1018. char szPath[1024];
  1019. printf("Enter path ('/' for root)> ");
  1020. scanf("%s", szPath);
  1021. fflush(stdin);
  1022. g_pHTTPMail->CommandGET(szPath, 0);
  1023. WaitForCompletion(g_msgHTTPMail, HTTPMAIL_GET);
  1024. goto HTTPMailPrompt;
  1025. }
  1026. else if (lstrcmpi(szCommand, "GETROOTPROP") == 0)
  1027. {
  1028. int iSelection;
  1029. HTTPMAILROOTPROPTYPE proptype;
  1030. printf("Select a property to retrieve:\n");
  1031. printf("\t(1) Adbar\n\t(2) Contacts\n\t(3) Inbox\n\t(4) Outbox\n\t(5) SentItems");
  1032. printf("\n\t(6) DeletedItems\n\t(7) Drafts\n\t(8) MsgFolderRoot\n\t(9) Sig");
  1033. printf("\nSelection> ");
  1034. scanf("%d", &iSelection);
  1035. fflush(stdin);
  1036. if (iSelection < 1 || iSelection > 9)
  1037. {
  1038. printf("Invalid Selection\n");
  1039. goto HTTPMailPrompt;
  1040. }
  1041. HTTPMAILROOTPROPTYPE rgProps[] =
  1042. {
  1043. HTTPMAIL_ROOTPROP_ADBAR,
  1044. HTTPMAIL_ROOTPROP_CONTACTS,
  1045. HTTPMAIL_ROOTPROP_INBOX,
  1046. HTTPMAIL_ROOTPROP_OUTBOX,
  1047. HTTPMAIL_ROOTPROP_SENTITEMS,
  1048. HTTPMAIL_ROOTPROP_DELETEDITEMS,
  1049. HTTPMAIL_ROOTPROP_DRAFTS,
  1050. HTTPMAIL_ROOTPROP_MSGFOLDERROOT,
  1051. HTTPMAIL_ROOTPROP_SIG
  1052. };
  1053. LPSTR pszProp = NULL;
  1054. if (SUCCEEDED(g_pHTTPMail->GetRootProperty(rgProps[iSelection - 1], &pszProp)))
  1055. {
  1056. if (pszProp)
  1057. printf("Result: %s\n", pszProp);
  1058. }
  1059. goto HTTPMailPrompt;
  1060. }
  1061. else if (lstrcmpi(szCommand, "LISTFOLDERS") == 0)
  1062. {
  1063. g_pHTTPMail->ListFolders(0);
  1064. WaitForCompletion(g_msgHTTPMail, HTTPMAIL_LISTFOLDERS);
  1065. }
  1066. else if (lstrcmpi(szCommand, "PUT") == 0)
  1067. {
  1068. char szPath[1024];
  1069. char *lpszData = "Outlook Express PUT test";
  1070. printf("Enter path ('/' for root)> ");
  1071. scanf("%s", szPath);
  1072. fflush(stdin);
  1073. g_pHTTPMail->CommandPUT(szPath, lpszData, strlen(lpszData), 0);
  1074. }
  1075. else if (lstrcmpi(szCommand, "POST") == 0)
  1076. {
  1077. char szPath[1024];
  1078. char *lpszData = "Outlook Express POST test";
  1079. printf("Enter path ('/' for root)> ");
  1080. scanf("%s", szPath);
  1081. fflush(stdin);
  1082. g_pHTTPMail->CommandPOST(szPath, lpszData, strlen(lpszData), 0);
  1083. }
  1084. else if (lstrcmpi(szCommand, "PROPFIND") == 0)
  1085. {
  1086. char szPath[1024];
  1087. printf("Enter path ('/' for root)> ");
  1088. scanf("%s", szPath);
  1089. fflush(stdin);
  1090. g_pHTTPMail->CommandPROPFIND(szPath, NULL, 0, 0);
  1091. WaitForCompletion(g_msgHTTPMail, HTTPMAIL_PROPFIND);
  1092. goto HTTPMailPrompt;
  1093. }
  1094. else if (lstrcmpi(szCommand, "DISCONNECT") == 0)
  1095. {
  1096. g_pHTTPMail->Disconnect();
  1097. }
  1098. else if (lstrcmpi(szCommand, "EXIT") == 0)
  1099. return;
  1100. else
  1101. HTTPMailCommandShellHelp();
  1102. // Go back to the prompt
  1103. goto HTTPMailPrompt;
  1104. }
  1105. void WaitForCompletion(UINT uiMsg, DWORD wparam)
  1106. {
  1107. MSG msg;
  1108. while(GetMessage(&msg, NULL, 0, 0))
  1109. {
  1110. if (msg.message == uiMsg && msg.wParam == wparam || msg.wParam == IXP_DISCONNECTED)
  1111. break;
  1112. TranslateMessage(&msg);
  1113. DispatchMessage(&msg);
  1114. }
  1115. }