/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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
 * The Mozilla Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   David Bienvenu <bienvenu@mozilla.com>
 *   Karsten Düsterloh <mnyromyr@tprac.de>
 *
 * 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"

/*
 * Keys are the internal representation of tags, and use a limited range of
 * characters, basically the characters allowed in imap keywords, which are
 * alphanumeric characters, but don't include spaces. Keys are stored on
 * the imap server, in local mail messages, and in summary files.
 *
 * Tags are the user visible representation of keys, and are full unicode
 * strings. Tags should allow any unicode character.
 *
 * This service will do the mapping between keys and tags. When a tag
 * is added, we'll need to "compute" the corresponding key to use. This
 * will probably entail replacing illegal ascii characters (' ', '/', etc)
 * with '_' and then converting to imap mod utf7. We'll then need to make
 * sure that no other keyword has the same value since that algorithm
 * doesn't guarantee a unique mapping.
 *
 * Tags are sorted internally by 'importance' by their ordinal strings (which by
 * default are equal to a tag's key and thus only stored if different). 
 * The alphanumerically 'smallest' string is called the 'most important' one and
 * comes first in any sorted array. The remainder follows in ascending order.
 */

[scriptable, uuid(84d593a3-5d8a-45e6-96e2-9189acd422e1)]
interface nsIMsgTag : nsISupports {
  readonly attribute ACString key;     // distinct tag identifier
  readonly attribute AString  tag;     // human readable tag name
  readonly attribute ACString color;   // tag color
  readonly attribute ACString ordinal; // custom sort string (usually empty)
};

[scriptable, uuid(b897da55-8256-4cf5-892b-32e77bc7c50b)]
interface nsIMsgTagService : nsISupports {
  // create new tag by deriving the key from the tag
  void addTag(in AString tag, in ACString color, in ACString ordinal);
  // create/update tag with known key
  void addTagForKey(in ACString key, in AString tag, in ACString color, in ACString ordinal);
  // get the key representation of a given tag
  ACString getKeyForTag(in AString tag);
  // get the first key by ordinal order
  ACString getTopKey(in string keyList);
  // support functions for single tag aspects
  AString getTagForKey(in ACString key); // look up the tag for a key.
  void setTagForKey(in ACString key, in AString tag); // this can be used to "rename" a tag
  ACString getColorForKey(in ACString key);
  void setColorForKey(in ACString key, in ACString color);
  ACString getOrdinalForKey(in ACString key);
  void setOrdinalForKey(in ACString key, in ACString ordinal);
  // delete a tag from the list of known tags (but not from any messages)
  void deleteKey(in ACString key);
  // get all known tags
  void getAllTags(out unsigned long count,
                  [retval, array, size_is(count)] out nsIMsgTag tagArray);
};
