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.

275 lines
14 KiB

  1. // --------------------------------------------------------------------------------
  2. // Smtptask.h
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #ifndef __SMTPTASK_H
  7. #define __SMTPTASK_H
  8. // --------------------------------------------------------------------------------
  9. // Depends
  10. // --------------------------------------------------------------------------------
  11. #include "spoolapi.h"
  12. #include "imnxport.h"
  13. #include "taskutil.h"
  14. #include "storutil.h"
  15. // --------------------------------------------------------------------------------
  16. // Forward Decls
  17. // --------------------------------------------------------------------------------
  18. typedef struct tagMAILMSGHDR *LPMAILMSGHDR;
  19. interface ILogFile;
  20. interface IMimeMessage;
  21. interface IMimeEnumAddressTypes;
  22. // --------------------------------------------------------------------------------
  23. // State
  24. // --------------------------------------------------------------------------------
  25. #define SMTPSTATE_CANCELED FLAG01
  26. #define SMTPSTATE_DEFAULT FLAG02
  27. #define SMTPSTATE_ASKEDDEFAULT FLAG03
  28. #define SMTPSTATE_USEDEFAULT FLAG04
  29. #define SMTPSTATE_EXECUTEFAILED FLAG05
  30. // --------------------------------------------------------------------------------
  31. // SMTPTASKEVENT_xxx Flags
  32. // --------------------------------------------------------------------------------
  33. #define SMTPEVENT_SPLITPART FLAG01 // Sending a split part
  34. #define SMTPEVENT_COMPLETE FLAG02 // The event was completed
  35. // --------------------------------------------------------------------------------
  36. // SMTPEVENTINFO
  37. // --------------------------------------------------------------------------------
  38. typedef struct tagSMTPEVENTINFO {
  39. DWORD dwFlags; // Flags
  40. MESSAGEID idMessage; // Store Information
  41. DWORD cbEvent; // Size of the message
  42. DWORD cbEventSent; // Size of the message
  43. DWORD cbSentTotal; // Where m_cbSent should be after this
  44. DWORD cRecipients; // Recipient
  45. IMimeMessage *pMessage; // Message to send
  46. DWORD iPart; // Part dwPart of cTotalParts
  47. DWORD cParts; // Part dwPart of cTotalParts
  48. DWORD cbParts; // Number of bytes of original message
  49. HRESULT hrResult; // Result of this event
  50. } SMTPEVENTINFO, *LPSMTPEVENTINFO;
  51. // --------------------------------------------------------------------------------
  52. // SMTPEVENTTABLE
  53. // --------------------------------------------------------------------------------
  54. typedef struct tagSMTPEVENTTABLE {
  55. DWORD iEvent; // Current Event
  56. DWORD cCompleted; // Number of events completed
  57. DWORD cEvents; // Number of events in prgEvent
  58. DWORD cAlloc; // Number of items allocated in prgEvent
  59. LPSMTPEVENTINFO prgEvent; // Array of events
  60. } SMTPEVENTTABLE, *LPSMTPEVENTTABLE;
  61. // --------------------------------------------------------------------------------
  62. // CSmtpTask
  63. // --------------------------------------------------------------------------------
  64. class CSmtpTask : public ISpoolerTask,
  65. public ISMTPCallback,
  66. public ITimeoutCallback,
  67. public ITransportCallbackService,
  68. public IStoreCallback
  69. {
  70. public:
  71. // ----------------------------------------------------------------------------
  72. // CSmtpTask
  73. // ----------------------------------------------------------------------------
  74. CSmtpTask(void);
  75. ~CSmtpTask(void);
  76. // ---------------------------------------------------------------------------
  77. // IUnknown members
  78. // ---------------------------------------------------------------------------
  79. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  80. STDMETHODIMP_(ULONG) AddRef(void);
  81. STDMETHODIMP_(ULONG) Release(void);
  82. // ---------------------------------------------------------------------------
  83. // ISpoolerTask
  84. // ---------------------------------------------------------------------------
  85. STDMETHODIMP Init(DWORD dwFlags, ISpoolerBindContext *pBindCtx);
  86. STDMETHODIMP BuildEvents(ISpoolerUI *pSpoolerUI, IImnAccount *pAccount, FOLDERID idFolder);
  87. STDMETHODIMP Execute(EVENTID eid, DWORD_PTR dwTwinkie);
  88. STDMETHODIMP CancelEvent(EVENTID eid, DWORD_PTR dwTwinkie);
  89. STDMETHODIMP ShowProperties(HWND hwndParent, EVENTID eid, DWORD_PTR dwTwinkie) {
  90. return TrapError(E_NOTIMPL); }
  91. STDMETHODIMP GetExtendedDetails(EVENTID eid, DWORD_PTR dwTwinkie, LPSTR *ppszDetails) {
  92. return TrapError(E_NOTIMPL); }
  93. STDMETHODIMP Cancel(void);
  94. STDMETHODIMP IsDialogMessage(LPMSG pMsg);
  95. STDMETHODIMP OnFlagsChanged(DWORD dwFlags);
  96. // --------------------------------------------------------------------------------
  97. // ITransportCallbackService Members
  98. // --------------------------------------------------------------------------------
  99. STDMETHODIMP GetParentWindow(DWORD dwReserved, HWND *phwndParent) {
  100. TraceCall("CSmtpTask::GetParentWindow");
  101. if (ISFLAGSET(m_dwFlags, DELIVER_NOUI))
  102. return TraceResult(E_FAIL);
  103. if (m_pUI)
  104. return m_pUI->GetWindow(phwndParent);
  105. return TraceResult(E_FAIL);
  106. }
  107. STDMETHODIMP GetAccount(LPDWORD pdwServerType, IImnAccount **ppAccount) {
  108. Assert(ppAccount && m_pAccount);
  109. *pdwServerType = SRV_SMTP;
  110. *ppAccount = m_pAccount;
  111. (*ppAccount)->AddRef();
  112. return(S_OK);
  113. }
  114. // --------------------------------------------------------------------------------
  115. // ITransportCallback Members
  116. // --------------------------------------------------------------------------------
  117. STDMETHODIMP OnTimeout(DWORD *pdwTimeout, IInternetTransport *pTransport);
  118. STDMETHODIMP OnLogonPrompt(LPINETSERVER pInetServer, IInternetTransport *pTransport);
  119. STDMETHODIMP_(INT) OnPrompt(HRESULT hrError, LPCTSTR pszText, LPCTSTR pszCaption, UINT uType, IInternetTransport *pTransport);
  120. STDMETHODIMP OnStatus(IXPSTATUS ixpstatus, IInternetTransport *pTransport);
  121. STDMETHODIMP OnError(IXPSTATUS ixpstatus, LPIXPRESULT pResult, IInternetTransport *pTransport);
  122. STDMETHODIMP OnCommand(CMDTYPE cmdtype, LPSTR pszLine, HRESULT hrResponse, IInternetTransport *pTransport);
  123. // --------------------------------------------------------------------------------
  124. // ISMTPCallback
  125. // --------------------------------------------------------------------------------
  126. STDMETHODIMP OnResponse(LPSMTPRESPONSE pResponse);
  127. // --------------------------------------------------------------------------------
  128. // ITimeoutCallback
  129. // --------------------------------------------------------------------------------
  130. STDMETHODIMP OnTimeoutResponse(TIMEOUTRESPONSE eResponse);
  131. // --------------------------------------------------------------------------------
  132. // IStoreCallback Interface
  133. // --------------------------------------------------------------------------------
  134. STDMETHODIMP OnBegin(STOREOPERATIONTYPE tyOperation, STOREOPERATIONINFO *pOpInfo, IOperationCancel *pCancel);
  135. STDMETHODIMP OnProgress(STOREOPERATIONTYPE tyOperation, DWORD dwCurrent, DWORD dwMax, LPCSTR pszStatus);
  136. STDMETHODIMP OnTimeout(LPINETSERVER pServer, LPDWORD pdwTimeout, IXPTYPE ixpServerType);
  137. STDMETHODIMP CanConnect(LPCSTR pszAccountId, DWORD dwFlags);
  138. STDMETHODIMP OnLogonPrompt(LPINETSERVER pServer, IXPTYPE ixpServerType);
  139. STDMETHODIMP OnComplete(STOREOPERATIONTYPE tyOperation, HRESULT hrComplete, LPSTOREOPERATIONINFO pOpInfo, LPSTOREERROR pErrorInfo);
  140. STDMETHODIMP OnPrompt(HRESULT hrError, LPCTSTR pszText, LPCTSTR pszCaption, UINT uType, INT *piUserResponse);
  141. private:
  142. // ---------------------------------------------------------------------------
  143. // Private Methods
  144. // ---------------------------------------------------------------------------
  145. HRESULT _HrAppendOutboxMessage(LPCSTR pszAccount, LPMESSAGEINFO pMsgInfo, BOOL fSplitMsgs, DWORD cbMaxPart);
  146. HRESULT _HrAppendEventTable(LPSMTPEVENTINFO *ppEvent);
  147. HRESULT _HrAppendSplitMessage(LPMESSAGEINFO pMsgInfo, DWORD cbMaxPart);
  148. HRESULT _HrOpenMessage(MESSAGEID dwMsgId, IMimeMessage **ppMessage);
  149. HRESULT _ExecuteSMTP(EVENTID eid, DWORD_PTR dwTwinkie);
  150. HRESULT _ExecuteUpload(EVENTID eid, DWORD_PTR dwTwinkie);
  151. void _FreeEventTableElements(void);
  152. void _ResetObject(BOOL fDeconstruct);
  153. // ---------------------------------------------------------------------------
  154. // Error / Progress Methods
  155. // ---------------------------------------------------------------------------
  156. TASKRESULTTYPE _CatchResult(LPIXPRESULT pResult, INETSERVER *pServer, IXPTYPE ixpType);
  157. TASKRESULTTYPE _CatchResult(HRESULT hrResult, IXPTYPE ixpType);
  158. void _DoProgress(void);
  159. // ---------------------------------------------------------------------------
  160. // Event State Methods
  161. // ---------------------------------------------------------------------------
  162. HRESULT _HrStartCurrentEvent(void);
  163. HRESULT _HrCommandMAIL(void);
  164. HRESULT _HrCommandRCPT(void);
  165. HRESULT _HrSendDataStream(void);
  166. HRESULT _HrFinishCurrentEvent(HRESULT hrResult);
  167. HRESULT _HrStartNextEvent(void);
  168. HRESULT _HrOnConnected(void);
  169. HRESULT _OnDisconnectComplete(void);
  170. void _OnStreamProgress(LPSMTPSTREAM pInfo);
  171. private:
  172. // ---------------------------------------------------------------------------
  173. // Private Data
  174. // ---------------------------------------------------------------------------
  175. DWORD m_cRef; // Reference Coutning
  176. INETSERVER m_rServer; // Server information
  177. DWORD m_dwFlags; // DELIVER_xxx flags
  178. ISpoolerBindContext *m_pSpoolCtx; // Spooler bind contexting
  179. IImnAccount *m_pAccount; // Internet Account
  180. ISMTPTransport *m_pTransport; // SMTP transport
  181. IMessageFolder *m_pOutbox; // The outbox
  182. IMessageFolder *m_pSentItems;
  183. SMTPEVENTTABLE m_rTable; // Event Table
  184. DWORD m_cbTotal; // Total number of bytes to send
  185. DWORD m_cbSent; // Total number of bytes to send
  186. WORD m_wProgress; // Current progress index
  187. EVENTID m_idEvent; // EventId for SMTP message send
  188. EVENTID m_idEventUpload; // EventId for SMTP message send
  189. ISpoolerUI *m_pUI; // SpoolerUI
  190. DWORD m_dwState; // State
  191. IMimeEnumAddressTypes *m_pAdrEnum; // Address Enumerator
  192. HWND m_hwndTimeout; // Handle to timeout window
  193. ILogFile *m_pLogFile; // Logfile
  194. CRITICAL_SECTION m_cs; // Thread Safety
  195. // Callback
  196. MESSAGEIDLIST m_rList;
  197. IOperationCancel *m_pCancel;
  198. STOREOPERATIONTYPE m_tyOperation;
  199. };
  200. // --------------------------------------------------------------------------------
  201. // CMessageIdStream
  202. // --------------------------------------------------------------------------------
  203. class CMessageIdStream : public IStream
  204. {
  205. public:
  206. // -------------------------------------------------------------------------
  207. // Construction
  208. // -------------------------------------------------------------------------
  209. CMessageIdStream(IStream *pStream);
  210. ~CMessageIdStream(void) { m_pStream->Release(); }
  211. // -------------------------------------------------------------------------
  212. // IUnknown
  213. // -------------------------------------------------------------------------
  214. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv) { Assert(FALSE); return E_NOTIMPL; }
  215. STDMETHODIMP_(ULONG) AddRef(void) { return ++m_cRef; }
  216. STDMETHODIMP_(ULONG) Release(void) {
  217. if (0 != --m_cRef)
  218. return m_cRef;
  219. delete this;
  220. return 0;
  221. }
  222. // -------------------------------------------------------------------------
  223. // IStream Not implemented Methods
  224. // -------------------------------------------------------------------------
  225. STDMETHODIMP Stat(STATSTG *, DWORD) { Assert(FALSE); return E_NOTIMPL; }
  226. STDMETHODIMP Write(const void *, ULONG, ULONG *) { Assert(FALSE); return E_NOTIMPL; }
  227. STDMETHODIMP SetSize(ULARGE_INTEGER) { Assert(FALSE); return E_NOTIMPL; }
  228. STDMETHODIMP CopyTo(LPSTREAM, ULARGE_INTEGER, ULARGE_INTEGER *, ULARGE_INTEGER *) { Assert(FALSE); return E_NOTIMPL; }
  229. STDMETHODIMP Commit(DWORD) { Assert(FALSE); return E_NOTIMPL; }
  230. STDMETHODIMP Revert(void) { Assert(FALSE); return E_NOTIMPL; }
  231. STDMETHODIMP LockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { Assert(FALSE); return E_NOTIMPL; }
  232. STDMETHODIMP UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { Assert(FALSE); return E_NOTIMPL; }
  233. STDMETHODIMP Clone(LPSTREAM *) { Assert(FALSE); return E_NOTIMPL; }
  234. STDMETHODIMP Read(LPVOID pv, ULONG cbWanted, ULONG *pcbRead);
  235. STDMETHODIMP Seek(LARGE_INTEGER liMove, DWORD dwOrigin, ULARGE_INTEGER *pulNew);
  236. // -------------------------------------------------------------------------
  237. // CMessageIdStream - Returns the length of the messageid
  238. // -------------------------------------------------------------------------
  239. ULONG CchMessageId(void) { return m_cchMessageId; }
  240. private:
  241. IStream *m_pStream;
  242. CHAR m_szMessageId[512];
  243. ULONG m_cchMessageId;
  244. ULONG m_cbIndex;
  245. ULONG m_cRef;
  246. };
  247. #endif // __SMTPTASK_H