/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "nsISupports.idl"
#include "nsMsgFilterCore.idl"
#include "nsIMsgSearchScopeTerm.idl"
#include "nsIMsgSearchValue.idl"
#include "nsIMsgSearchTerm.idl"
#include "nsISupportsArray.idl"

interface nsOutputStream;
interface nsIMsgFilterCustomAction;

[scriptable, uuid(190A2A18-D245-473a-A402-9F0814598C7F)]
interface nsIMsgRuleAction : nsISupports {

  attribute nsMsgRuleActionType type;

  // target priority.. throws an exception if the action is not priority
  attribute nsMsgPriorityValue priority;

  // target folder.. throws an exception if the action is not move to folder
  attribute ACString targetFolderUri;

  // target label. throws an exception if the action is not label
  attribute nsMsgLabelValue label;

  attribute long junkScore; 

  attribute AUTF8String strValue;

  // action id if type is Custom
  attribute ACString customId;

  // custom action associated with customId
  // (which must be set prior to reading this attribute)
  readonly attribute nsIMsgFilterCustomAction customAction;
  
};

[scriptable, uuid(346C8CC6-35EA-4F44-B348-94E84D7C03E0)]
interface nsIMsgFilter : nsISupports {
    attribute nsMsgFilterTypeType filterType;
    /**
     * some filters are "temporary".  For example, the filters we create when the user
     * filters return receipts to the Sent folder.
     * we don't show temporary filters in the UI
     * and we don't write them to disk.
     */
    attribute boolean temporary;
    attribute boolean enabled;
    attribute AString filterName;
    attribute ACString filterDesc;
    attribute ACString unparsedBuffer; //holds the entire filter if we don't know how to handle it
    attribute boolean unparseable;  //whether we could parse the filter or not

    readonly attribute nsIMsgFilterList filterList; // owning filter list
    
    void AddTerm(in nsMsgSearchAttribValue attrib,
                 in nsMsgSearchOpValue op,
                 in nsIMsgSearchValue value,
                 in boolean BooleanAND,
                 in ACString arbitraryHeader);

    void GetTerm(in long termIndex,
                 out nsMsgSearchAttribValue attrib,
                 out nsMsgSearchOpValue op,
                 out nsIMsgSearchValue value, // bad! using shared structure
                 out boolean BooleanAND,
                 out ACString arbitraryHeader);

    void appendTerm(in nsIMsgSearchTerm term);

    nsIMsgSearchTerm createTerm();

    attribute nsISupportsArray searchTerms;

    attribute nsIMsgSearchScopeTerm scope;

    // marking noscript because "headers" is actually a null-separated
    // list of headers, which is not scriptable
    [noscript] void MatchHdr(in nsIMsgDBHdr msgHdr, in nsIMsgFolder folder,
                  in nsIMsgDatabase db,
                  in string headers,
                  //                  [array, size_is(headerSize)] in string headers,
                  in unsigned long headerSize, out boolean result);

    void logRuleHit(in nsIMsgRuleAction aFilterAction, in nsIMsgDBHdr aHeader);
    nsIMsgRuleAction createAction();

    nsIMsgRuleAction getActionAt(in long aIndex);

    void appendAction(in nsIMsgRuleAction action);

    void clearActionList();
    void getSortedActionList(in nsISupportsArray actionList);  //will return an action list with moveAction (if present) as last one.
    readonly attribute nsISupportsArray actionList;
};

