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.

216 lines
7.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // RulesMgr.h
  4. //
  5. ///////////////////////////////////////////////////////////////////////////////
  6. #ifndef _RULESMGR_H_
  7. #define _RULESMGR_H_
  8. // Bring in only once
  9. #if _MSC_VER > 1000
  10. #pragma once
  11. #endif
  12. #include "oerules.h"
  13. typedef struct tagRULENODE
  14. {
  15. RULEID ridRule;
  16. IOERule * pIRule;
  17. struct tagRULENODE * pNext;
  18. } RULENODE, * PRULENODE;
  19. const int CCH_REGKEY_MAX = 4;
  20. const int CCH_RULENAME_MAX = 256;
  21. class CRulesManager : public IOERulesManager
  22. {
  23. private:
  24. enum
  25. {
  26. STATE_LOADED_INIT = 0x00000000,
  27. STATE_LOADED_MAIL = 0x00000001,
  28. STATE_LOADED_NEWS = 0x00000002,
  29. STATE_LOADED_SENDERS = 0x00000004,
  30. STATE_LOADED_JUNK = 0x00000008,
  31. STATE_LOADED_FILTERS = 0x00000010
  32. };
  33. enum
  34. {
  35. RTF_INIT = 0x00000000,
  36. RTF_DISABLED = 0x00000001
  37. };
  38. enum
  39. {
  40. ARTF_PREPEND = 0x00000001,
  41. ARTF_SENDER = 0x00000002
  42. };
  43. private:
  44. LONG m_cRef;
  45. BOOL m_dwState;
  46. RULENODE * m_pMailHead;
  47. RULENODE * m_pNewsHead;
  48. RULENODE * m_pFilterHead;
  49. IOERule * m_pIRuleSenderMail;
  50. IOERule * m_pIRuleSenderNews;
  51. IOERule * m_pIRuleJunk;
  52. CRITICAL_SECTION m_cs;
  53. public:
  54. // Constructor/destructor
  55. CRulesManager();
  56. ~CRulesManager();
  57. // IUnknown members
  58. STDMETHODIMP QueryInterface(REFIID riid, void ** ppvObject);
  59. STDMETHODIMP_(ULONG) AddRef(void);
  60. STDMETHODIMP_(ULONG) Release(void);
  61. // IOERulesManager members
  62. STDMETHODIMP Initialize(DWORD dwFlags);
  63. STDMETHODIMP GetRule(RULEID ridRule, RULE_TYPE type, DWORD dwFlags, IOERule ** ppIRule);
  64. STDMETHODIMP FindRule(LPCSTR pszRuleName, RULE_TYPE type, IOERule ** ppIRule);
  65. STDMETHODIMP GetRules(DWORD dwFlags, RULE_TYPE typeRule, RULEINFO ** ppinfoRule, ULONG * pcpinfoRule);
  66. STDMETHODIMP SetRules(DWORD dwFlags, RULE_TYPE typeRule, RULEINFO * pinfoRule, ULONG cpinfoRule);
  67. STDMETHODIMP EnumRules(DWORD dwFlags, RULE_TYPE type, IOEEnumRules ** ppIEnumRules);
  68. STDMETHODIMP GetState(RULE_TYPE type, DWORD dwFlags, DWORD * pdwState) { return E_NOTIMPL; }
  69. STDMETHODIMP ExecRules(DWORD dwFlags, RULE_TYPE type, IOEExecRules ** ppIExecRules);
  70. STDMETHODIMP ExecuteRules(RULE_TYPE typeRule, DWORD dwFlags, HWND hwndUI,
  71. IOEExecRules * pIExecRules, MESSAGEINFO * pMsgInfo,
  72. IMessageFolder * pFolder, IMimeMessage * pIMMsg);
  73. private:
  74. HRESULT _HrLoadRules(RULE_TYPE type);
  75. HRESULT _HrLoadSenders(VOID);
  76. HRESULT _HrLoadJunk(VOID);
  77. HRESULT _HrSaveRules(RULE_TYPE type);
  78. HRESULT _HrSaveSenders(VOID);
  79. HRESULT _HrSaveJunk(VOID);
  80. HRESULT _HrFreeRules(RULE_TYPE type);
  81. HRESULT _HrAddRule(RULEID ridRule, IOERule * pIRule, RULE_TYPE type);
  82. HRESULT _HrReplaceRule(RULEID ridRule, IOERule * pIRule, RULE_TYPE type);
  83. HRESULT _HrRemoveRule(IOERule * pIRule, RULE_TYPE type);
  84. HRESULT _HrFixupRuleInfo(RULE_TYPE typeRule, RULEINFO * pinfoRule, ULONG cpinfoRule);
  85. };
  86. class CEnumRules : public IOEEnumRules
  87. {
  88. private:
  89. LONG m_cRef;
  90. RULENODE * m_pNodeHead;
  91. RULENODE * m_pNodeCurr;
  92. DWORD m_dwFlags;
  93. RULE_TYPE m_typeRule;
  94. public:
  95. // Constructor/destructor
  96. CEnumRules();
  97. ~CEnumRules();
  98. // IUnknown members
  99. STDMETHODIMP QueryInterface(REFIID riid, void ** ppvObject);
  100. STDMETHODIMP_(ULONG) AddRef(void);
  101. STDMETHODIMP_(ULONG) Release(void);
  102. // IOEEnumRules members
  103. STDMETHODIMP Next(ULONG cpIRule, IOERule ** rgpIRule, ULONG * pcpIRuleFetched);
  104. STDMETHODIMP Skip(ULONG cpIRule);
  105. STDMETHODIMP Reset(void);
  106. STDMETHODIMP Clone(IOEEnumRules ** ppIEnumRules);
  107. HRESULT _HrInitialize(DWORD dwFlags, RULE_TYPE typeRule, RULENODE * pNodeHead);
  108. };
  109. const DWORD ERF_ONLY_ENABLED = 0x00000001;
  110. const DWORD ERF_ONLY_VALID = 0x00000002;
  111. class CExecRules : public IOEExecRules
  112. {
  113. private:
  114. enum
  115. {
  116. RULE_FOLDER_ALLOC = 16
  117. };
  118. struct RULE_FOLDER
  119. {
  120. FOLDERID idFolder;
  121. IMessageFolder * pFolder;
  122. };
  123. enum
  124. {
  125. RULE_FILE_ALLOC = 16
  126. };
  127. struct RULE_FILE
  128. {
  129. LPSTR pszFile;
  130. IStream * pstmFile;
  131. DWORD dwType;
  132. };
  133. enum
  134. {
  135. SND_FILE_ALLOC = 16
  136. };
  137. private:
  138. LONG m_cRef;
  139. RULENODE * m_pNodeHead;
  140. ULONG m_cNode;
  141. DWORD m_dwState;
  142. RULE_FOLDER * m_pRuleFolder;
  143. ULONG m_cRuleFolder;
  144. ULONG m_cRuleFolderAlloc;
  145. RULE_FILE * m_pRuleFile;
  146. ULONG m_cRuleFile;
  147. ULONG m_cRuleFileAlloc;
  148. LPSTR * m_ppszSndFile;
  149. ULONG m_cpszSndFile;
  150. ULONG m_cpszSndFileAlloc;
  151. public:
  152. // Constructor/destructor
  153. CExecRules() : m_cRef(0), m_pNodeHead(NULL), m_cNode(0), m_dwState(RULE_STATE_NULL),
  154. m_pRuleFolder(NULL), m_cRuleFolder(0), m_cRuleFolderAlloc(0),
  155. m_pRuleFile(NULL), m_cRuleFile(0), m_cRuleFileAlloc(0),
  156. m_ppszSndFile(NULL), m_cpszSndFile(0), m_cpszSndFileAlloc(0) {}
  157. ~CExecRules();
  158. // IUnknown members
  159. STDMETHODIMP QueryInterface(REFIID riid, void ** ppvObject);
  160. STDMETHODIMP_(ULONG) AddRef(void);
  161. STDMETHODIMP_(ULONG) Release(void);
  162. // IOEExecRules members
  163. STDMETHODIMP GetState(DWORD * pdwState);
  164. STDMETHODIMP ExecuteRules(DWORD dwFlags, LPCSTR pszAcct, MESSAGEINFO * pMsgInfo,
  165. IMessageFolder * pFolder, IMimePropertySet * pIMPropSet,
  166. IMimeMessage * pIMMsg, ULONG cbMsgSize,
  167. ACT_ITEM ** ppActions, ULONG * pcActions);
  168. STDMETHODIMP ReleaseObjects(VOID);
  169. STDMETHODIMP GetRuleFolder(FOLDERID idFolder, DWORD_PTR * pdwFolder);
  170. STDMETHODIMP GetRuleFile(LPCSTR pszFile, IStream ** pstmFile, DWORD * pdwType);
  171. STDMETHODIMP AddSoundFile(DWORD dwFlags, LPCSTR pszSndFile);
  172. STDMETHODIMP PlaySounds(DWORD dwFlags);
  173. HRESULT _HrInitialize(DWORD dwFlags, RULENODE * pNodeHead);
  174. private:
  175. HRESULT _HrReleaseFolderObjects(VOID);
  176. HRESULT _HrReleaseFileObjects(VOID);
  177. HRESULT _HrReleaseSoundFiles(VOID);
  178. };
  179. #endif // !_RULESMGR_H_