/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1999
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Seth Spitzer <sspitzer@netscape.com>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"
#include "nsMsgFilterCore.idl"
#include "nsIMsgFilter.idl"
#include "nsIMsgFilterHitNotify.idl"

interface nsIOFileStream;
interface nsIOutputStream;

///////////////////////////////////////////////////////////////////////////////
// The Msg Filter List is an interface designed to make accessing filter lists
// easier. Clients typically open a filter list and either enumerate the filters,
// or add new filters, or change the order around...
//
///////////////////////////////////////////////////////////////////////////////

typedef long nsMsgFilterFileAttribValue;

[scriptable, uuid(ab0105ad-86bf-4862-9adb-84f4e266577c)]
interface nsIMsgFilterList : nsISupports {

    const nsMsgFilterFileAttribValue attribNone = 0;
    const nsMsgFilterFileAttribValue attribVersion = 1;
    const nsMsgFilterFileAttribValue attribLogging = 2;
    const nsMsgFilterFileAttribValue attribName = 3;
    const nsMsgFilterFileAttribValue attribEnabled = 4; 
    const nsMsgFilterFileAttribValue attribDescription = 5; 
    const nsMsgFilterFileAttribValue attribType = 6;
    const nsMsgFilterFileAttribValue attribScriptFile = 7; 
    const nsMsgFilterFileAttribValue attribAction = 8; 
    const nsMsgFilterFileAttribValue attribActionValue = 9; 
    const nsMsgFilterFileAttribValue attribCondition = 10;

    attribute nsIMsgFolder folder;
    readonly attribute short version;
    readonly attribute string arbitraryHeaders;
    readonly attribute boolean shouldDownloadAllHeaders;
    readonly attribute unsigned long filterCount;
    nsIMsgFilter getFilterAt(in unsigned long filterIndex);
    nsIMsgFilter getFilterNamed(in wstring filterName);

    void setFilterAt(in unsigned long filterIndex, in nsIMsgFilter filter);
    void removeFilter(in nsIMsgFilter filter);
    void removeFilterAt(in unsigned long filterIndex);
    
    void moveFilterAt(in unsigned long filterIndex,
                      in nsMsgFilterMotionValue motion);
    void moveFilter(in nsIMsgFilter filter,
                    in nsMsgFilterMotionValue motion);
    
    void insertFilterAt(in unsigned long filterIndex, in nsIMsgFilter filter);

    attribute boolean loggingEnabled;

    nsIMsgFilter createFilter(in wstring name);

    void saveToFile(in nsIOFileStream stream);

    void parseCondition(in nsIMsgFilter aFilter, in string condition);
    // this is temporary so that we can save the filterlist to disk
    // without knowing where the filters were read from intially
    // (such as the filter list dialog)
    attribute nsIFileSpec defaultFile;
    void saveToDefaultFile();
    

    // marking noscript because headers is a null-separated list
    // of strings, which is not scriptable
    [noscript]
    void applyFiltersToHdr(in nsMsgFilterTypeType filterType,
                           in nsIMsgDBHdr msgHdr,
                           in nsIMsgFolder folder,
                           in nsIMsgDatabase db,
                           in string headers,
                           //[array, size_is(headerSize)] in string headers,
                           in unsigned long headerSize,
                           in nsIMsgFilterHitNotify listener,
                           in nsIMsgWindow msgWindow,
                           in nsILocalFile aMessageFile);

    // IO routines, used by filter object filing code.
    void writeIntAttr(in nsMsgFilterFileAttribValue attrib, in long value, in nsIOFileStream stream);
    void writeStrAttr(in nsMsgFilterFileAttribValue attrib, in string value, in nsIOFileStream stream);
    void writeWstrAttr(in nsMsgFilterFileAttribValue attrib, in wstring value, in nsIOFileStream stream);
    void writeBoolAttr(in nsMsgFilterFileAttribValue attrib, in boolean value, in nsIOFileStream stream);
    boolean matchOrChangeFilterTarget(in string oldUri, in string newUri, in boolean caseInsensitive);
 
    // for filter logging
    attribute nsIOutputStream logStream;
    readonly attribute string logURL;
    void clearLog();
    void ensureLogFile();
	void flushLogIfNecessary();
};


/* these longs are all actually of type nsMsgFilterMotionValue */
[scriptable, uuid(d067b528-304e-11d3-a0e1-00a0c900d445)]
interface nsMsgFilterMotion {
    const long up = 0;
    const long down = 1;
};
