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.

394 lines
13 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: dsnsink.h
  5. //
  6. // Description: Header file for CDefaultDSNSink - Default DSN Generation Sink
  7. //
  8. // Author: Mike Swafford (MikeSwa)
  9. //
  10. // History:
  11. // 6/30/98 - MikeSwa Created
  12. //
  13. // Copyright (C) 1998 Microsoft Corporation
  14. //
  15. //-----------------------------------------------------------------------------
  16. #ifndef __DSNSINK_H__
  17. #define __DSNSINK_H__
  18. #include <aqintrnl.h>
  19. #include <baseobj.h>
  20. #define DSN_SINK_SIG 'sNSD'
  21. #define DSN_SINK_SIG_FREED 'NSD!'
  22. class CDSNBuffer;
  23. //Limit on the MIME boundary string set by RFC2046
  24. #define MIME_BOUNDARY_RFC2046_LIMIT 70
  25. //RFCs 2045-2048 suggests that we inlcude "=_" somewhere in the MIME Boundry
  26. #define MIME_BOUNDARY_CONSTANT "9B095B5ADSN=_"
  27. #define MIME_BOUNDARY_START_TIME_SIZE 16*sizeof(CHAR) //Size of string with file-time
  28. #define MIME_BOUNDARY_SIZE MIME_BOUNDARY_START_TIME_SIZE + \
  29. sizeof(MIME_BOUNDARY_CONSTANT) + \
  30. 24*sizeof(CHAR) //room for 8 char count and portion of host name
  31. //needs room for "x.xxx.xxx", plus an optional comment
  32. #define MAX_STATUS_COMMENT_SIZE 50
  33. #define STATUS_STRING_SIZE 10+MAX_STATUS_COMMENT_SIZE
  34. //
  35. // The default implementation of the DSN Generation sink
  36. //
  37. class CDefaultDSNSink :
  38. public IDSNGenerationSink
  39. {
  40. public: //IUnknown
  41. STDMETHOD(QueryInterface)(REFIID riid, LPVOID * ppvObj);
  42. //
  43. // This class is allocated as a part of another object. Pass
  44. // AddRef/Release to the parent object
  45. //
  46. STDMETHOD_(ULONG, AddRef)(void)
  47. {
  48. return m_pUnk->AddRef();
  49. }
  50. STDMETHOD_(ULONG, Release)(void)
  51. {
  52. return m_pUnk->Release();
  53. }
  54. public: //IDSNGenerationSink
  55. STDMETHOD(OnSyncSinkInit) (
  56. IN DWORD dwVSID);
  57. STDMETHOD(OnSyncGetDSNRecipientIterator) (
  58. IN ISMTPServer *pISMTPServer,
  59. IN IMailMsgProperties *pIMsg,
  60. IN IMailMsgPropertyBag *pDSNProperties,
  61. IN DWORD dwStartDomain,
  62. IN DWORD dwDSNActions,
  63. IN IDSNRecipientIterator *pRecipIterIN,
  64. OUT IDSNRecipientIterator **ppRecipIterOUT);
  65. STDMETHOD(OnSyncGenerateDSN) (
  66. IN ISMTPServer *pISMTPServer,
  67. IN IDSNSubmission *pIDSNSubmission,
  68. IN IMailMsgProperties *pIMsg,
  69. IN IMailMsgPropertyBag *pDSNProperties,
  70. IN IDSNRecipientIterator *pRecipIter);
  71. STDMETHOD(OnSyncPostGenerateDSN) (
  72. IN ISMTPServer *pISMTPServer,
  73. IN IMailMsgProperties *pIMsgOrig,
  74. IN DWORD dwDSNAction,
  75. IN DWORD cRecipsDSNd,
  76. IN IMailMsgProperties *pIMsgDSN,
  77. IN IMailMsgPropertyBag *pDSNProperties)
  78. {
  79. return E_NOTIMPL;
  80. }
  81. #define SIGNATURE_CDEFAULTDSNSINK (DWORD)'NSDC'
  82. #define SIGNATURE_CDEFAULTDSNSINK_INVALID (DWORD)'NSDX'
  83. CDefaultDSNSink(IUnknown *pUnk);
  84. ~CDefaultDSNSink()
  85. {
  86. _ASSERT(m_dwSig == SIGNATURE_CDEFAULTDSNSINK);
  87. m_dwSig = SIGNATURE_CDEFAULTDSNSINK_INVALID;
  88. }
  89. HRESULT HrInitialize();
  90. private:
  91. HRESULT HrGenerateDSNInternal(
  92. ISMTPServer *pISMTPServer,
  93. IMailMsgProperties *pIMailMsgProperties,
  94. IDSNRecipientIterator *pIRecipIter,
  95. IDSNSubmission *pIDSNSubmission,
  96. DWORD dwDSNActions,
  97. DWORD dwRFC821Status,
  98. HRESULT hrStatus,
  99. LPSTR szDefaultDomain,
  100. DWORD cbDefaultDomain,
  101. LPSTR szReportingMTA,
  102. DWORD cbReportingMTA,
  103. LPSTR szReportingMTAType,
  104. DWORD cbReportingMTAType,
  105. LPSTR szDSNContext,
  106. DWORD cbDSNContext,
  107. DWORD dwPreferredLangId,
  108. DWORD dwDSNOptions,
  109. LPSTR szCopyNDRTo,
  110. DWORD cbCopyNDRTo,
  111. FILETIME *pftExpireTime,
  112. LPSTR szHRTopCustomText,
  113. LPWSTR wszHRTopCustomText,
  114. LPSTR szHRBottomCustomText,
  115. LPWSTR wszHRBottomCustomText,
  116. IMailMsgProperties **ppIMailMsgPropertiesDSN,
  117. DWORD *pdwDSNTypesGenerated,
  118. DWORD *pcRecipsDSNd,
  119. DWORD *pcIterationsLeft,
  120. DWORD dwDSNRetType,
  121. HRESULT hrContentFailure);
  122. //Used to mark all recipient flags, when there is no per recip processing
  123. //happening (like NDR of DSN).
  124. HRESULT HrMarkAllRecipFlags(
  125. IN DWORD dwDSNActions,
  126. IN IDSNRecipientIterator *pIRecipIter);
  127. VOID GetCurrentIterationsDSNAction(
  128. IN OUT DWORD *pdwActualDSNAction,
  129. IN OUT DWORD *pcIterationsLeft);
  130. //Writes global DSN P1 Properties to IMailMsgProperties and P2 headers to content
  131. HRESULT HrWriteDSNP1AndP2Headers(
  132. IN DWORD dwDSNAction,
  133. IN IMailMsgProperties *pIMailMsgProperties,
  134. IN IMailMsgProperties *pIMailMsgPropertiesDSN,
  135. IN CDSNBuffer *pdsnbuff,
  136. IN LPSTR szDefaultDomain,
  137. IN DWORD cbDefaultDomain,
  138. IN LPSTR szReportingMTA,
  139. IN DWORD cbReportingMTA,
  140. IN LPSTR szDSNContext,
  141. IN DWORD cbDSNContext,
  142. IN LPSTR szCopyNDRTo,
  143. IN HRESULT hrStatus,
  144. IN LPSTR szMimeBoundary,
  145. IN DWORD cbMimeBoundary,
  146. IN DWORD dwDSNOptions,
  147. IN HRESULT hrContent);
  148. //Write human readable portion of DSN
  149. HRESULT HrWriteDSNHumanReadable(
  150. IN IMailMsgProperties *pIMailMsgProperties,
  151. IN IMailMsgRecipients *pIMailMsgRecipients,
  152. IN IDSNRecipientIterator *pIRecipIter,
  153. IN DWORD dwDSNActions,
  154. IN CDSNBuffer *pdsnbuff,
  155. IN DWORD dwPreferredLangId,
  156. IN LPSTR szMimeBoundary,
  157. IN DWORD cbMimeBoundary,
  158. IN HRESULT hrStatus,
  159. IN LPSTR szHRTopCustomText,
  160. IN LPWSTR wszHRTopCustomText,
  161. IN LPSTR szHRBottomCustomText,
  162. IN LPWSTR wszHRBottomCustomText);
  163. //Write the per-msg portion of the DSN Report
  164. HRESULT HrWriteDSNReportPerMsgProperties(
  165. IN IMailMsgProperties *pIMailMsgProperties,
  166. IN CDSNBuffer *pdsnbuff,
  167. IN LPSTR szReportingMTA,
  168. IN DWORD cbReportingMTA,
  169. IN LPSTR szMimeBoundary,
  170. IN DWORD cbMimeBoundary);
  171. //Write a per-recipient portion of the DSN Report
  172. HRESULT HrWriteDSNReportPreRecipientProperties(
  173. IN IMailMsgRecipients *pIMailMsgRecipients,
  174. IN CDSNBuffer *pdsnbuff,
  175. IN DWORD iRecip,
  176. IN LPSTR szExpireTime,
  177. IN DWORD cbExpireTime,
  178. IN DWORD dwDSNAction,
  179. IN DWORD dwRFC821Status,
  180. IN HRESULT hrStatus);
  181. //Logs events for DSN generation
  182. HRESULT HrLogDSNGenerationEvent(
  183. ISMTPServer *pISMTPServer,
  184. IMailMsgProperties *pIMailMsgProperties,
  185. IN IMailMsgRecipients *pIMailMsgRecipients,
  186. IN DWORD iRecip,
  187. IN DWORD dwDSNAction,
  188. IN DWORD dwRFC821Status,
  189. IN HRESULT hrStatus);
  190. //Writes last mime-headers, flush dsnbuffer, and copy original message
  191. HRESULT HrWriteDSNClosingAndOriginalMessage(
  192. IN IMailMsgProperties *pIMailMsgProperties,
  193. IN IMailMsgProperties *pIMailMsgPropertiesDSN,
  194. IN CDSNBuffer *pdsnbuff,
  195. IN PFIO_CONTEXT pDestFile,
  196. IN DWORD dwDSNAction,
  197. IN LPSTR szMimeBoundary,
  198. IN DWORD cbMimeBoundary,
  199. IN DWORD dwDSNRetType,
  200. IN DWORD dwOrigMsgSize);
  201. void GetCurrentMimeBoundary(
  202. IN LPSTR szReportingMTA,
  203. IN DWORD cbReportingMTA,
  204. IN OUT CHAR szMimeBoundary[MIME_BOUNDARY_SIZE],
  205. OUT DWORD *pcbMimeBoundary);
  206. //Writes the original full message to the third DSN part
  207. HRESULT HrWriteOriginalMessageFull(
  208. IN IMailMsgProperties *pIMailMsgProperties,
  209. IN IMailMsgProperties *pIMailMsgPropertiesDSN,
  210. IN CDSNBuffer *pdsnbuff,
  211. IN PFIO_CONTEXT pDestFile,
  212. IN LPSTR szMimeBoundary,
  213. IN DWORD cbMimeBoundary,
  214. IN DWORD dwOrigMsgSize);
  215. //Write only some headers of the orignal message to the third DSN part
  216. HRESULT HrWriteOriginalMessagePartialHeaders(
  217. IN IMailMsgProperties *pIMailMsgProperties,
  218. IN IMailMsgProperties *pIMailMsgPropertiesDSN,
  219. IN CDSNBuffer *pdsnbuff,
  220. IN PFIO_CONTEXT pDestFile,
  221. IN LPSTR szMimeBoundary,
  222. IN DWORD cbMimeBoundary);
  223. //Write MIME headers to finish message
  224. HRESULT HrWriteMimeClosing(
  225. IN CDSNBuffer *pdsnbuff,
  226. IN LPSTR szMimeBoundary,
  227. IN DWORD cbMimeBoundary,
  228. OUT DWORD *pcbDSNSize);
  229. //Gets the per-recipient DSN status code
  230. HRESULT HrGetStatusCode(
  231. IN IMailMsgRecipients *pIMailMsgRecipients,
  232. IN DWORD iRecip,
  233. IN DWORD dwDSNAction,
  234. IN DWORD dwStatus,
  235. IN HRESULT hrStatus,
  236. IN DWORD cbExtendedStatus,
  237. IN OUT LPSTR szExtendedStatus,
  238. IN OUT CHAR szStatus[STATUS_STRING_SIZE]);
  239. //Parse status code from RFC2034 extended status code string
  240. HRESULT HrGetStatusFromStatus(
  241. IN DWORD cbExtendedStatus,
  242. IN OUT LPSTR szExtendedStatus,
  243. IN OUT CHAR szStatus[STATUS_STRING_SIZE]);
  244. //Determine status based on supplied context information
  245. HRESULT HrGetStatusFromContext(
  246. IN HRESULT hrRecipient,
  247. IN DWORD dwRecipFlags,
  248. IN DWORD dwDSNAction,
  249. IN OUT CHAR szStatus[STATUS_STRING_SIZE]);
  250. HRESULT HrGetStatusFromRFC821Status(
  251. IN DWORD dwRFC821Status,
  252. IN OUT CHAR szStatus[STATUS_STRING_SIZE]);
  253. //Writes a list of recipients being DSN'd... one per line
  254. HRESULT HrWriteHumanReadableListOfRecips(
  255. IN IMailMsgRecipients *pIMailMsgRecipients,
  256. IN IDSNRecipientIterator *pIRecipIter,
  257. IN DWORD dwDSNActionsNeeded,
  258. IN CDSNBuffer *pdsnbuff);
  259. //Get the recipient address and type... checks multple mailmsg props
  260. HRESULT HrGetRecipAddressAndType(
  261. IN IMailMsgRecipients *pIMailMsgRecipients,
  262. IN DWORD iRecip,
  263. IN DWORD cbAddressBuffer,
  264. IN OUT LPSTR szAddressBuffer,
  265. IN DWORD cbAddressType,
  266. IN OUT LPSTR szAddressType);
  267. private:
  268. DWORD m_dwSig;
  269. IUnknown *m_pUnk;
  270. DWORD m_dwVSID;
  271. DWORD m_cDSNsRequested;
  272. BOOL m_fInit;
  273. CHAR m_szPerInstanceMimeBoundary[MIME_BOUNDARY_START_TIME_SIZE + 1];
  274. };
  275. //---[ CDSNGenerator ]-------------------------------------------------------
  276. //
  277. //
  278. // Description:
  279. // Default DSN Generation sink...
  280. // Hungarian:
  281. // dsnsink, pdsnsink
  282. //
  283. //-----------------------------------------------------------------------------
  284. class CDSNGenerator
  285. {
  286. protected:
  287. DWORD m_dwSignature;
  288. public:
  289. CDSNGenerator(IUnknown *pUnk);
  290. ~CDSNGenerator();
  291. HRESULT HrInitialize()
  292. {
  293. return m_CDefaultDSNSink.HrInitialize();
  294. }
  295. public:
  296. STDMETHOD(GenerateDSN)(
  297. IAQServerEvent *pIServerEvent,
  298. DWORD dwVSID,
  299. ISMTPServer *pISMTPServer,
  300. IMailMsgProperties *pIMailMsgProperties,
  301. DWORD dwStartDomain,
  302. DWORD dwDSNActions,
  303. DWORD dwRFC821Status,
  304. HRESULT hrStatus,
  305. LPSTR szDefaultDomain,
  306. LPSTR szReportingMTA,
  307. LPSTR szReportingMTAType,
  308. LPSTR szDSNContext,
  309. DWORD dwPreferredLangId,
  310. DWORD dwDSNOptions,
  311. LPSTR szCopyNDRTo,
  312. FILETIME *pftExpireTime,
  313. IDSNSubmission *pIAQDSNSubmission,
  314. DWORD dwMaxDSNSize);
  315. HRESULT HrTriggerGetDSNRecipientIterator(
  316. IAQServerEvent *pIServerEvent,
  317. DWORD dwVSID,
  318. ISMTPServer *pISMTPServer,
  319. IMailMsgProperties *pIMsg,
  320. IMailMsgPropertyBag *pIDSNProperties,
  321. DWORD dwStartDomain,
  322. DWORD dwDSNActions,
  323. IDSNRecipientIterator **ppIRecipIterator);
  324. HRESULT HrTriggerGenerateDSN(
  325. IAQServerEvent *pIServerEvent,
  326. DWORD dwVSID,
  327. ISMTPServer *pISMTPServer,
  328. IDSNSubmission *pIDSNSubmission,
  329. IMailMsgProperties *pIMsg,
  330. IMailMsgPropertyBag *pIDSNProperties,
  331. IDSNRecipientIterator *pIRecipIterator);
  332. HRESULT HrTriggerPostGenerateDSN(
  333. IAQServerEvent *pIServerEvent,
  334. DWORD dwVSID,
  335. ISMTPServer *pISMTPServer,
  336. IMailMsgProperties *pIMsgOrig,
  337. DWORD dwDSNAction,
  338. DWORD cRecipsDSNd,
  339. IMailMsgProperties *pIMsgDSN,
  340. IMailMsgPropertyBag *pIDSNProperties);
  341. static HRESULT HrStaticInit();
  342. static VOID StaticDeinit();
  343. private:
  344. HRESULT HrSetRetType(
  345. IN DWORD dwMaxDSNSize,
  346. IN IMailMsgProperties *pIMsg,
  347. IN IMailMsgPropertyBag *pDSNProps);
  348. private:
  349. CDefaultDSNSink m_CDefaultDSNSink;
  350. };
  351. #endif //__DSNSINK_H__