//---------------------------------------------------------------------------
// OERules.idl
//---------------------------------------------------------------------------

import "objidl.idl";
import "ocidl.idl";
import "mimeole.idl";
import "oestore.idl";

//---------------------------------------------------------------------------
// Interfaces
//---------------------------------------------------------------------------
interface IOERulesManager;
interface IOEEnumRules;
interface IOEExecRules;
interface IOERule;
interface IOECriteria;
interface IOEActions;

// Make sure we only bring in this file only once
cpp_quote("// Bring in only once")
cpp_quote("#if _MSC_VER > 1000")
cpp_quote("#pragma once")
cpp_quote("#endif")
cpp_quote("")

//---------------------------------------------------------------------------
// HRESULT Macros
//---------------------------------------------------------------------------
cpp_quote("#ifndef FACILITY_INTERNET")
cpp_quote("#define FACILITY_INTERNET 12")
cpp_quote("#endif")
cpp_quote("#ifndef HR_E")
cpp_quote("#define HR_E(n) MAKE_SCODE(SEVERITY_ERROR, FACILITY_INTERNET, n)")
cpp_quote("#endif")
cpp_quote("#ifndef HR_S")
cpp_quote("#define HR_S(n) MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_INTERNET, n)")
cpp_quote("#endif")
cpp_quote("#ifndef HR_CODE")
cpp_quote("#define HR_CODE(hr) (INT)(hr & 0xffff)")
cpp_quote("#endif")
cpp_quote("")

typedef struct tagRULEFOLDERDATA
{
    FILETIME    ftStamp;
    FOLDERID    idFolder;
} RULEFOLDERDATA, * PRULEFOLDERDATA;

typedef enum tagRULE_TYPE
{
    RULE_TYPE_MAIL = 0,
    RULE_TYPE_NEWS,
    RULE_TYPE_FILTER,
    RULE_TYPE_MAX
} RULE_TYPE;

typedef DWORD   RULE_SESSION;

typedef enum tagACT_TYPE
{
    ACT_TYPE_NULL = 0,
    ACT_TYPE_COPY,
    ACT_TYPE_FWD,
    ACT_TYPE_NOTIFYMSG,
    ACT_TYPE_NOTIFYSND,
    ACT_TYPE_REPLY,
    ACT_TYPE_MOVE,
    ACT_TYPE_DELETE,
    ACT_TYPE_DELETESERVER,
    ACT_TYPE_DONTDOWNLOAD,
    ACT_TYPE_HIGHLIGHT,
    ACT_TYPE_FLAG,
    ACT_TYPE_STOP,
    ACT_TYPE_READ,
    ACT_TYPE_MARKDOWNLOAD,
    ACT_TYPE_SHOW,
    ACT_TYPE_JUNKMAIL,
    ACT_TYPE_WATCH,
    ACT_TYPE_MAX
} ACT_TYPE;

const DWORD ACT_FLAG_DEFAULT           = 0x00000000;
const DWORD ACT_FLAG_INVERT            = 0x00000001;

typedef struct tagACT_ITEM
{
    ACT_TYPE        type;
    DWORD           dwFlags;
    PROPVARIANT     propvar;
} ACT_ITEM, * PACT_ITEM;

typedef struct tagRULEINFO
{
    RULEID      ridRule;
    IOERule *   pIRule;
} RULEINFO, *PRULEINFO;

//---------------------------------------------------------------------------
// Rules Manager IDs
//---------------------------------------------------------------------------

// For Rules
const RULEID RULEID_JUNK                = (RULEID) -3;
const RULEID RULEID_SENDERS             = (RULEID) -2;

// For Views
const RULEID RULEID_VIEW_ALL           = (RULEID) 0x00000FFA;
const RULEID RULEID_VIEW_UNREAD        = (RULEID) 0x00000FFB;
const RULEID RULEID_VIEW_DOWNLOADED    = (RULEID) 0x00000FFC;
const RULEID RULEID_VIEW_DELETED       = (RULEID) 0x00000FFD;
const RULEID RULEID_VIEW_REPLIES       = (RULEID) 0x00000FFE;
const RULEID RULEID_VIEW_IGNORED       = (RULEID) 0x00000FFF;

//---------------------------------------------------------------------------
// Rules Manager HRESULTs
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// IOERulesManager interface
//---------------------------------------------------------------------------
[
    object,
    uuid(626bafe0-e5d6-11d1-b1dd-006097d503d9),
    pointer_default(unique),
    version(1.0)
]
interface IOERulesManager : IUnknown
{
    const DWORD RULESMGR_VERSION = 0x00050000;
    
    HRESULT Initialize(
        [in]    DWORD   dwFlags);

    HRESULT GetRule(
        [in]    RULEID      ridRule,
        [in]    RULE_TYPE   type,
        [in]    DWORD       dwFlags,
        [out]   IOERule **  ppIRule);

    HRESULT FindRule(
        [in]    LPCSTR      pszRuleName,
        [in]    RULE_TYPE   type,
        [out]   IOERule **  ppIRule);

    const DWORD GETF_ALL        = 0x00000000;
    const DWORD GETF_EDIT       = 0x00000001;
    const DWORD GETF_SENDER     = 0x00000002;
    const DWORD GETF_JUNK       = 0x00000004;
    const DWORD GETF_POP3       = 0x00000008;
    const DWORD GETF_NNTP       = 0x00000010;
    const DWORD GETF_IMAP       = 0x00000020;
    const DWORD GETF_HTTPMAIL   = 0x00000040;
       
    HRESULT GetRules(
        [in]    DWORD       dwFlags,
        [in]    RULE_TYPE   typeRule,
        [in]    RULEINFO ** ppinfoRule,
        [in]    ULONG *     pcpinfoRule);
        
    const DWORD SETF_APPEND  = 0x00000000;
    const DWORD SETF_CLEAR   = 0x00000001;
    const DWORD SETF_SENDER  = 0x00000002;
    const DWORD SETF_JUNK    = 0x00000004;
    const DWORD SETF_REPLACE = 0x00000008;
       
    HRESULT SetRules(
        [in]    DWORD       dwFlags,
        [in]    RULE_TYPE   typeRule,
        [in]    RULEINFO *  pinfoRule,
        [in]    ULONG       cpIRule);
        
    const DWORD ENUMF_ALL       = 0x00000001;
    const DWORD ENUMF_EDIT      = 0x00000002;
    const DWORD ENUMF_SENDER    = 0x00000004;
    const DWORD ENUMF_POP3      = 0x00000008;
    const DWORD ENUMF_NNTP      = 0x00000010;
    const DWORD ENUMF_IMAP      = 0x00000020;
    const DWORD ENUMF_HTTPMAIL  = 0x00000040;
    
    HRESULT EnumRules(
        [in]    DWORD           dwFlags,
        [in]    RULE_TYPE       type,
        [out]   IOEEnumRules ** ppIEnumRules);

    HRESULT GetState(
        [in]    RULE_TYPE   type,
        [in]    DWORD       dwFlags,
        [out]   DWORD *     pdwState);

    const DWORD EXECF_ALL     = 0x00000001;
    const DWORD EXECF_APPLY   = 0x00000002;
    
    HRESULT ExecRules(
        [in]    DWORD           dwFlags,
        [in]    RULE_TYPE       type,
        [out]   IOEExecRules ** ppIExecRules);

    HRESULT ExecuteRules(
        [in]    RULE_TYPE           typeRule,
        [in]    DWORD               dwFlags,
        [in]    HWND                hwndUI,
        [in]    IOEExecRules *      pIExecRules,
        [in]    MESSAGEINFO *       pMsgInfo,
        [in]    IMessageFolder *    pFolder,
        [in]    IMimeMessage *      pIMMsg);
};

//---------------------------------------------------------------------------
// Interface IOEEnumRules
//---------------------------------------------------------------------------
[
    object,
    uuid(626bafe2-e5d6-11d1-b1dd-006097d503d9),
    pointer_default(unique),
    version(1.0)
]
interface IOEEnumRules : IUnknown
{
    typedef [unique] IOEEnumRules *LPENUMRULES;

    HRESULT Next(
        [in]    ULONG       cpIRule,
        [out, size_is(cpIRule), length_is(*pcpIRuleFetched)]
                IOERule ** rgpIRule,
        [out]   ULONG *     pcpIRuleFetched);

    HRESULT Skip(
        [in]    ULONG   cpIRule);

    HRESULT Reset();

    HRESULT Clone(
        [out]   IOEEnumRules ** ppIEnumRules);        
};

//---------------------------------------------------------------------------
// Interface IOEExecRules
//---------------------------------------------------------------------------
[
    object,
    uuid(626bafe4-e5d6-11d1-b1dd-006097d503d9),
    pointer_default(unique),
    version(1.0)
]
interface IOEExecRules : IUnknown
{
    typedef [unique] IOEExecRules *LPEXECRULES;

    HRESULT GetState(
        [out]    DWORD *    pdwState);

    const DWORD ERF_ONLYSERVER      = 0x00000001;
    const DWORD ERF_NOSERVER        = 0x00000002;
    const DWORD ERF_SKIPPARTIALS    = 0x00000004;
    
    HRESULT ExecuteRules(
        [in]        DWORD               dwFlags,
        [in]        LPCSTR              pszAcct,
        [in]        MESSAGEINFO *       pMsgInfo,
        [in]        IMessageFolder *    pFolder,
        [in]        IMimePropertySet *  pIMPropSet,
        [in]        IMimeMessage *      pIMMsg,
        [in]        ULONG               cbMsgSize,
        [out]       ACT_ITEM **         ppActions,
        [out]       ULONG *             pcActions);

    HRESULT ReleaseObjects();

    HRESULT GetRuleFolder(
        [in]        FOLDERID            idfolder,
        [out]       DWORD_PTR *         pdwFolder);

    const DWORD RFT_FILE    = 0x00000000;
    const DWORD RFT_HTML    = 0x00000001;
    const DWORD RFT_TEXT    = 0x00000002;
    const DWORD RFT_MESSAGE = 0x00000003;
    
    HRESULT GetRuleFile(
        [in]        LPCSTR              pszFile,
        [out]       IStream **          ppstmFile,
        [out]       DWORD *             pdwType);

    const DWORD ASF_PLAYIFNEW   = 0x00000001;
    
    HRESULT AddSoundFile(
        [in]        DWORD               dwFlags,
        [in]        LPCSTR              pszSndFile);

    HRESULT PlaySounds(
        [in]        DWORD               dwFlags);
};

//---------------------------------------------------------------------------
// Interface IOERule
//---------------------------------------------------------------------------
[
    object,
    uuid(626bafe6-e5d6-11d1-b1dd-006097d503d9),
    pointer_default(unique),
    version(1.0)
]
interface IOERule : IUnknown
{
    typedef enum tagRULE_PROP
    {
        RULE_PROP_NAME = 0,
        RULE_PROP_DISABLED,
        RULE_PROP_CRITERIA,
        RULE_PROP_ACTIONS,
        RULE_PROP_STATE,
        RULE_PROP_VERSION,
        RULE_PROP_READONLY,
        RULE_PROP_JUNKPCT,
        RULE_PROP_EXCPT_WAB,
        RULE_PROP_MAX
    } RULE_PROP;

    HRESULT Reset();
    
    const DWORD RULE_STATE_NULL     = 0x00000000;
    const DWORD RULE_STATE_HEADER   = 0x00000001;    
    const DWORD RULE_STATE_ALL      = 0x00000002;
        
    HRESULT GetState(
        [out]    DWORD *    pdwState);

    HRESULT Validate(
        [in]     DWORD      dwFlags);
        
    HRESULT GetProp(
        [in]        RULE_PROP       prop,
        [in]        DWORD           dwFlags,
        [in, out]   PROPVARIANT *   pvarResult);

    HRESULT SetProp(
        [in]    RULE_PROP       prop,
        [in]    DWORD           dwFlags,
        [in]    PROPVARIANT *   pvarValue);

    HRESULT Evaluate(
        [in]        LPCSTR              pszAcct,
        [in]        MESSAGEINFO *       pMsgInfo,
        [in]        IMessageFolder *    pFolder,
        [in]        IMimePropertySet *  pIMPropSet,
        [in]        IMimeMessage *      pIMMsg,
        [in]        ULONG               cbMsgSize,
        [out]       ACT_ITEM **         ppActions,
        [out]       ULONG *             pcActions);

    HRESULT LoadReg(
        [in]        LPCSTR      szRegPath);

    HRESULT SaveReg(
        [in]        LPCSTR      szRegPath,
        [in]        BOOL        fClearDirty);
        
    HRESULT Clone(
        [out]   IOERule **      ppIRule);
};

//---------------------------------------------------------------------------
// Interface IOECriteria
//---------------------------------------------------------------------------
[
    object,
    uuid(626bafe8-e5d6-11d1-b1dd-006097d503d9),
    pointer_default(unique),
    version(1.0)
]
interface IOECriteria : IUnknown
{
    typedef enum tagCRIT_TYPE
    {
        CRIT_TYPE_NULL = 0,
        CRIT_TYPE_NEWSGROUP,
        CRIT_TYPE_TOME,
        CRIT_TYPE_CCME,
        CRIT_TYPE_BCCME,
        CRIT_TYPE_TOADDR,
        CRIT_TYPE_CCADDR,
        CRIT_TYPE_FROMADDR,
        CRIT_TYPE_SUBJECT,
        CRIT_TYPE_BODY,
        CRIT_TYPE_TO,
        CRIT_TYPE_CC,
        CRIT_TYPE_FROM,
        CRIT_TYPE_PRIORITY,
        CRIT_TYPE_ATTACH,
        CRIT_TYPE_SIZE,
        CRIT_TYPE_DATE,
        CRIT_TYPE_HEADER,
        CRIT_TYPE_JUNK,
        CRIT_TYPE_ACCOUNT,
        CRIT_TYPE_ALL,
        CRIT_TYPE_TOORCCADDR,
        CRIT_TYPE_TOORCC,
        CRIT_TYPE_SENDER,
        CRIT_TYPE_REPLIES,
        CRIT_TYPE_DOWNLOADED,
        CRIT_TYPE_DELETED,
        CRIT_TYPE_THREADSTATE,
        CRIT_TYPE_READ,
        CRIT_TYPE_LINES,
        CRIT_TYPE_AGE,
        CRIT_TYPE_SECURE,
        CRIT_TYPE_FLAGGED,
        CRIT_TYPE_MAX
    } CRIT_TYPE;
    
    const DWORD CRIT_FLAG_DEFAULT           = 0x00000000;
    const DWORD CRIT_FLAG_INVERT            = 0x00000001;
    const DWORD CRIT_FLAG_MULTIPLEAND       = 0x00000002;

    const DWORD CRIT_DATA_IGNORETHREAD      = 0x00000002;
    const DWORD CRIT_DATA_WATCHTHREAD       = 0x00000001;
    const DWORD CRIT_DATA_NORMALTHREAD      = 0x00000000;
    
    const DWORD CRIT_DATA_HIPRI             = 0x00000002;
    const DWORD CRIT_DATA_LOPRI             = 0x00000001;
    const DWORD CRIT_DATA_NORMALPRI         = 0x00000000;
    
    const DWORD CRIT_DATA_ENCRYPTSECURE     = 0x00000002;
    const DWORD CRIT_DATA_SIGNEDSECURE      = 0x00000001;
    const DWORD CRIT_DATA_NOSECURE          = 0x00000000;
    
    typedef enum tagCRIT_LOGIC
    {
        CRIT_LOGIC_NULL = 0,
        CRIT_LOGIC_OR,
        CRIT_LOGIC_AND,
        CRIT_LOGIC_MAX
    } CRIT_LOGIC;
        
    typedef struct tagCRIT_ITEM
    {
        CRIT_TYPE       type;
        DWORD           dwFlags;
        PROPVARIANT     propvar;
        CRIT_LOGIC      logic;
    } CRIT_ITEM, * PCRIT_ITEM;
        
    HRESULT Reset();

    const DWORD CRIT_STATE_NULL     = 0x00000000;
    const DWORD CRIT_STATE_DIRTY    = 0x00000001;
    const DWORD CRIT_STATE_LOADED   = 0x00000002;
    
    const DWORD CRIT_STATE_HEADER   = 0x00010000;
    const DWORD CRIT_STATE_ALL      = 0x00020000;
    const DWORD CRIT_STATE_MASK     = 0x00FF0000;
    
    HRESULT GetState(
        [out]   DWORD *         pdwState);
        
    HRESULT GetCriteria(
        [in]    DWORD           dwFlags,
        [out]   PCRIT_ITEM *    ppItem,
        [out]   ULONG *         pcItem);

    HRESULT SetCriteria(
        [in]    DWORD           dwFlags,
        [in]    CRIT_ITEM *     pItem,
        [in]    ULONG           cItem);

    HRESULT Validate(
        [in]     DWORD          dwFlags);
    
    HRESULT AppendCriteria(
        [in]    DWORD           dwFlags,
        [in]    CRIT_LOGIC      logic,
        [in]    CRIT_ITEM *     pItem,
        [in]    ULONG           cItem,
        [out]   ULONG *         pcItemAppended);
        
    HRESULT MatchMessage(
        [in]        LPCSTR              pszAcct,
        [in]        MESSAGEINFO *       pMsgInfo,
        [in]        IMessageFolder *    pFolder,
        [in]        IMimePropertySet *  pIMPropSet,
        [in]        IMimeMessage *      pIMMsg,
        [in]        ULONG               cbMsgSize);

    HRESULT LoadReg(
        [in]        LPCSTR      szRegPath);

    HRESULT SaveReg(
        [in]        LPCSTR      szRegPath,
        [in]        BOOL        fClearDirty);
        
    HRESULT Clone(
        [out]   IOECriteria **   ppICriteria);
};

//---------------------------------------------------------------------------
// Interface IOEActions
//---------------------------------------------------------------------------
[
    object,
    uuid(626bafea-e5d6-11d1-b1dd-006097d503d9),
    pointer_default(unique),
    version(1.0)
]
interface IOEActions : IUnknown
{    
    const DWORD ACT_DATA_NULL               = 0x00000000;
    
    const DWORD ACT_DATA_WATCHTHREAD        = 0x00000001;
    const DWORD ACT_DATA_IGNORETHREAD       = 0x00000002;
    
    const DWORD ACT_DATA_SHOW               = 0x00000001;
    const DWORD ACT_DATA_HIDE               = 0x00000002;
    
    HRESULT Reset();
    
    const DWORD ACT_STATE_NULL      = 0x00000000;
    const DWORD ACT_STATE_DIRTY     = 0x00000100;
    const DWORD ACT_STATE_LOADED    = 0x00000200;
    
    const DWORD ACT_STATE_SERVER    = 0x01000000;
    const DWORD ACT_STATE_LOCAL     = 0x02000000;
    const DWORD ACT_STATE_MASK      = 0xFF000000;
    
    HRESULT GetState(
        [out]   DWORD *         pdwState);
        
    HRESULT GetActions(
        [in]    DWORD           dwFlags,
        [out]   PACT_ITEM *     ppItem,
        [out]   ULONG *         pcItem);

    HRESULT SetActions(
        [in]    DWORD           dwFlags,
        [in]    ACT_ITEM *      pItem,
        [in]    ULONG           cItem);
        
    HRESULT Validate(
        [in]     DWORD          dwFlags);
        
    HRESULT AppendActions(
        [in]    DWORD           dwFlags,
        [in]    ACT_ITEM *      pItem,
        [in]    ULONG           cItem,
        [out]   ULONG *         pcItemAppended);
        
    HRESULT LoadReg(
        [in]        LPCSTR      szRegPath);

    HRESULT SaveReg(
        [in]        LPCSTR      szRegPath,
        [in]        BOOL        fClearDirty);

    HRESULT Clone(
        [out]   IOEActions **   ppIActions);
};

//---------------------------------------------------------------------------
// OE Rules Type Library
//---------------------------------------------------------------------------
[
    uuid(626bafec-e5d6-11d1-b1dd-006097d503d9),
    version(1.0),
    helpstring("Microsoft Outlook Express Rules Type Library")
]
library OERules
{
    importlib("stdole2.tlb");

    [
        uuid(626bafe1-e5d6-11d1-b1dd-006097d503d9),
    ]
    coclass OERulesManager
    {
        [default]   interface IOERulesManager;
    };      

    [
        uuid(626bafe3-e5d6-11d1-b1dd-006097d503d9),
    ]
    coclass OEEnumRules
    {
        [default]   interface IOEEnumRules;
    };      

    [
        uuid(626bafe5-e5d6-11d1-b1dd-006097d503d9),
    ]
    coclass OEExecRules
    {
        [default]   interface IOEExecRules;
    };      

    [
        uuid(626bafe7-e5d6-11d1-b1dd-006097d503d9),
    ]
    coclass OERule
    {
        [default]   interface IOERule;
                    interface IPersistStream;
    };      

    [
        uuid(626bafe9-e5d6-11d1-b1dd-006097d503d9),
    ]
    coclass OECriteria
    {
        [default]   interface IOECriteria;
                    interface IPersistStream;
    };      

    [
        uuid(626bafeb-e5d6-11d1-b1dd-006097d503d9),
    ]
    coclass OEActions
    {
        [default]   interface IOEActions;
                    interface IPersistStream;
    };      

};

