/*
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "MPL"); you may not use this file
 * except in compliance with the MPL. You may obtain a copy of
 * the MPL at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the MPL is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the MPL for the specific language governing
 * rights and limitations under the MPL.
 * 
 * The Original Code is Enigmail.
 * 
 * The Initial Developer of the Original Code is Ramalingam Saravanan.
 * Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
 * Copyright (C) 2001 Ramalingam Saravanan. All Rights Reserved.
 * 
 * Contributor(s):
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License (the "GPL"), in which case
 * the provisions of the GPL are applicable instead of
 * those above. If you wish to allow use of your version of this
 * file only under the terms of the GPL and not to allow
 * others to use your version of this file under the MPL, indicate
 * your decision by deleting the provisions above and replace them
 * with the notice and other provisions required by the GPL.
 * If you do not delete the provisions above, a recipient
 * may use your version of this file under either the MPL or the
 * GPL.
 */

#include "nsISupports.idl"
#include "nsIIPCBuffer.idl"

interface nsIDOMWindow;
interface nsIPrompt;
interface nsIPrefBranch;
interface nsIStreamListener;
interface nsIPipeConsole;
interface nsIPipeTransport;
interface nsIIPCRequest;
interface nsIRequestObserver;
interface nsIFileOutputStream;
interface nsIIPCBuffer;

/**
 * The nsIEnigmail provides an openPGP-based encryption/decryption service
 */
[scriptable, uuid(847b3a00-7ab1-11d4-8f02-006008948af5)]
interface nsIEnigmail : nsISupports
{
  readonly attribute string agentType;        /* "gpg" or "pgp" */

  readonly attribute string agentPath;        /* executable path */

  readonly attribute nsIPipeConsole console;  /* Enigmail console */

  readonly attribute boolean isWin32;         /* Platform type */

  readonly attribute nsIIPCRequest keygenRequest;

  readonly attribute long maxIdleMinutes;

  readonly attribute boolean initialized;
  readonly attribute boolean initializationAttempted;
  readonly attribute  string initializationError;

  readonly attribute boolean composeSecure;
  readonly attribute nsIFileOutputStream logFileStream;

  void initialize(in nsIDOMWindow domWindow, in string version,
                  in nsIPrefBranch enigmailPrefs);
  void finalize();
  boolean mimeInitialized();

  void stillActive();
  void clearCachedPassphrase();

  string getLogDirectoryPrefix();

  nsIPipeTransport encryptMessageStart(in nsIDOMWindow parent,
                                       in nsIPrompt prompter,
                                       in unsigned long uiFlags,
                                       in string  fromMailAddr,
                                       in string  toMailAddr,
                                       in string  hashAlgorithm,
                                       in unsigned long sendFlags,
                                       in nsIStreamListener listener,
                                       in boolean noProxy,
                                       out wstring errorMsg);

  long encryptMessageEnd(in nsIDOMWindow parent,
                         in nsIPrompt prompter,
                         in unsigned long uiFlags,
                         in unsigned long sendFlags,
                         in unsigned long outputLen,
                         in nsIPipeTransport pipeTransport,
                         out unsigned long statusFlags,
                         out wstring errorMsg);

  nsIPipeTransport decryptMessageStart(in nsIDOMWindow parent,
                                       in nsIPrompt prompter,
                                       in boolean verifyOnly,
                                       in boolean noOutput,
                                       in nsIStreamListener listener,
                                       in boolean noProxy,
                                       out wstring errorMsg);

  long decryptMessageEnd(in unsigned long uiFlags,
                         in unsigned long outputLen,
                         in nsIPipeTransport pipeTransport,
                         in boolean verifyOnly,
                         in boolean noOutput,
                         out unsigned long statusFlags,
                         out wstring keyId,
                         out wstring userId,
                         out wstring errorMsg);

  string locateArmoredBlock(in string text,
                            in long offset,
                            in string indentStr,
                            out long beginIndex,
                            out long endIndex);

  /* Cleartext signature parts */
  const long SIGNATURE_TEXT    = 1;
  const long SIGNATURE_HEADERS = 2;
  const long SIGNATURE_ARMOR   = 3;

  string extractSignaturePart(in string signatureBlock,
                              in long part);

  /* User interaction flags */
  const long UI_INTERACTIVE       = 0x01;
  const long UI_ALLOW_KEY_IMPORT  = 0x02;
  const long UI_UNVERIFIED_ENC_OK = 0x04;
  const long UI_PGP_MIME          = 0x08;
  const long UI_TEST              = 0x10;

  /* Send message flags */
  const long SEND_SIGNED          = 0x001;
  const long SEND_ENCRYPTED       = 0x002;
  const long SEND_DEFAULT         = 0x004;
  const long SEND_LATER           = 0x008;
  const long SEND_WITH_CHECK      = 0x010;
  const long SEND_ALWAYS_TRUST    = 0x020;
  const long SEND_ENCRYPT_TO_SELF = 0x040;
  const long SEND_PGP_MIME        = 0x080;
  const long SEND_TEST            = 0x100;

  string encryptMessage(in nsIDOMWindow parent,
                        in unsigned long uiFlags,
                        in string  plainText,
                        in string  fromMailAddr,
                        in string  toMailAddr,
                        in unsigned long sendFlags,
                        out long exitCode,
                        out unsigned long statusFlags,
                        out wstring errorMsg);                       
  
  /* Status flags */
  const long GOOD_SIGNATURE       = 0x000001;
  const long BAD_SIGNATURE        = 0x000002;
  const long UNVERIFIED_SIGNATURE = 0x000004;
  const long EXPIRED_SIGNATURE    = 0x000008;
  const long EXPIRED_KEY_SIGNATURE= 0x000010;
  const long EXPIRED_KEY          = 0x000020;
  const long REVOKED_KEY          = 0x000040;
  const long NO_PUBKEY            = 0x000080;
  const long NO_SECKEY            = 0x000100;
  const long IMPORTED_KEY         = 0x000200;
  const long INVALID_RECIPIENT    = 0x000400;
  const long MISSING_PASSPHRASE   = 0x000800;
  const long BAD_PASSPHRASE       = 0x001000;
  const long BAD_ARMOR            = 0x002000;
  const long NODATA               = 0x004000;
  const long DECRYPTION_INCOMPLETE= 0x008000;
  const long DECRYPTION_FAILED    = 0x010000;
  const long DECRYPTION_OKAY      = 0x020000;
  const long UNTRUSTED_IDENTITY   = 0x040000;
  const long TRUSTED_IDENTITY     = 0x080000;
  const long PGP_MIME_SIGNED      = 0x100000;
  const long PGP_MIME_ENCRYPTED   = 0x200000;
  const long DISPLAY_MESSAGE      = 0x400000;
  const long INLINE_KEY           = 0x800000;

  string decryptMessage(in nsIDOMWindow parent,
                        in unsigned long uiFlags,
                        in string  cipherText,
                        inout string signature,
                        out long exitCode,
                        out unsigned long statusFlags,
                        out wstring keyId,
                        out wstring userId,
                        out wstring errorMsg);

  string extractKey(in nsIDOMWindow parent,
                    in unsigned long uiFlags,
                    in string userId,
                    out long   exitCode,
                    out wstring errorMsg);

  long importKey(in nsIDOMWindow parent,
                 in unsigned long uiFlags,
                 in string msgText,
                 in string keyId,
                 out wstring errorMsg);

  long receiveKey(in nsIDOMWindow parent,
                  in unsigned long uiFlags,
                  in string keyId,
                  out wstring errorMsg);

  nsIIPCRequest generateKey(in nsIDOMWindow parent,
                            in string name,
                            in string comment,
                            in string email,
                            in long   expiryDate,
                            in string passphrase,
                            in nsIRequestObserver requestObserver);

  string createMessageURI(in string originalUrl,
                          in string contentType,
                          in string contentCharset,
                          in string contentData,
                          in boolean persist);

  boolean deleteMessageURI(in string uri);

  boolean selectPanel(in string url);
  
  string getUserIdList (in nsIDOMWindow parent,
                      in unsigned long sendFlags,
                      out long exitCode,
                      out unsigned long statusFlags,
                      out wstring errorMsg);

  string encryptAttachment (in nsIDOMWindow parent,
                      in string fromMailAddr,
                      in string toMailAddr,
                      in unsigned long sendFlags,
                      in wstring inFile,
                      in wstring outFile,
                      out long exitCode,
                      out unsigned long statusFlags,
                      out wstring errorMsg);

  boolean decryptAttachment (in nsIDOMWindow parent,
                      in string outFileName,
                      in nsIIPCBuffer ipcBuffer,
                      out long exitCode,
                      out unsigned long statusFlags,
                      out wstring errorMsg);

};

%{C++

#define NS_ENIGMAIL_CLASSNAME  "Enigmail"
#define NS_ENIGMAIL_CONTRACTID "@mozdev.org/enigmail/enigmail;1"
     
#define NS_ENIGMAIL_CID                          \
{ /* 847b3a01-7ab1-11d4-8f02-006008948af5 */     \
   0x847b3a01, 0x7ab1, 0x11d4,                   \
{0x8f, 0x02, 0x00, 0x60, 0x08, 0x94, 0x8a, 0xf5} }

%}

//////////////////////////////////////////////////////////////////////////////
