/* -*- 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"
// Disable deprecation warnings generated by nsISupportsArray and associated
// classes.
%{C++
#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning (disable : 4996)
#endif
%}
interface nsISupportsArray;

interface nsIArray;
interface nsIOutputStream;
interface nsIMsgFilterCustomAction;
interface nsIMsgFilterList;
interface nsIMsgSearchScopeTerm;
interface nsIMsgSearchValue;
interface nsIMsgSearchTerm;

[scriptable, uuid(36d2748e-9246-44f3-bb74-46cbb0b8c23a)]
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(d304fcfc-b588-11e4-981c-770e1e5d46b0)]
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

    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);


    /*
     * Report that Rule was matched and executed when filter logging is enabled.
     *
     * @param aFilterAction  The filter rule that was invoked.
     * @param aHeader        The header information of the message acted on by
     *                       the filter.
     */
    void logRuleHit(in nsIMsgRuleAction aFilterAction,
                    in nsIMsgDBHdr aHeader);

    /* Report that filtering failed for some reason when filter logging is enabled.
     *
     * @param aFilterAction Filter rule that was invoked.
     * @param aHeader Header of the message acted on by the filter.
     * @param aRcode  Error code returned by low-level routine that
     *                led to the filter failure.
     * @param aErrmsg Error message
     */
    void logRuleHitFail(in nsIMsgRuleAction aFilterAction,
                        in nsIMsgDBHdr aHeader,
                        in nsresult aRcode,
                        in string aErrmsg );

    nsIMsgRuleAction createAction();

    nsIMsgRuleAction getActionAt(in unsigned long aIndex);

    long getActionIndex(in nsIMsgRuleAction aAction);

    void appendAction(in nsIMsgRuleAction action);

    readonly attribute unsigned long actionCount;

    void clearActionList();

    // Returns the action list in the order it will be really executed in.
    readonly attribute nsIArray sortedActionList;

    void SaveToTextFile(in nsIOutputStream aStream);
};
