/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  Copyright (C) 2008 OMC Denmark ApS.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef F2T_IMAPISESSION_DEF
#define F2T_IMAPISESSION_DEF

#pragma prefix "omc.brutus"

#include "types.idl"
#include "defines.idl"
#include "BrutusCheck.idl"
#include "ITnef.idl"
#include "IStream.idl"
#include "IMessage.idl"
#include "IMsgStore.idl"
#include "IAddrBook.idl"
#include "IProfSect.idl"
#include "IPropData.idl"
#include "IProfAdmin.idl"
#include "IMAPITable.idl"
#include "IMAPIFolder.idl"
#include "IMAPIAdviseSink.idl"
#include "IMsgServiceAdmin.idl"


module BRUTUS {

        interface IMAPISession : IUnknown {
                BRESULT GetLastError(in BRESULT ReturnCode,
                                     in BDEFINE ulFlags,
                                     out MAPIERROR lppMAPIError);

                BRESULT GetMsgStoresTable(in BDEFINE ulFlags,
                                          out IMAPITable lppTable);

                BRESULT OpenMsgStore(in ENTRYID lpEntryID, 
                                     in GUID lpInterface,
                                     in BDEFINE ulFlags,
                                     out IMsgStore lppMDB);

                BRESULT OpenAddressBook(in GUID lpInterface, 
                                        in BDEFINE ulFlags,
                                        out IAddrBook lppAdrBook);

                BRESULT OpenProfileSection(in MAPIUID lpUID,
                                           in GUID lpInterface,
                                           in BDEFINE ulFlags,
                                           out IProfSect lppProfSect);

                BRESULT GetStatusTable(in BDEFINE ulFlags,
                                       out IMAPITable lppTable);

                BRESULT OpenEntry(in ENTRYID lpEntryID,
                                  in GUID lpInterface,
                                  in BDEFINE ulFlags,
                                  out BDEFINE lpulObjType, 
                                  out IUnknown lppUnk); 

                BRESULT CompareEntryIDs(in ENTRYID lpEntryID1,
                                        in ENTRYID lpEntryID2,
                                        in BDEFINE ulFlags,
                                        out boolean lpulResult);

                BRESULT Advise(in ENTRYID lpEntryID,                  
                               in BDEFINE ulEventMask,                
                               in IMAPIAdviseSink lpAdviseSink,               
                               out unsigned long lpulConnection);      

                BRESULT Unadvise(in unsigned long ulConnection);        

                BRESULT QueryDefaultMessageOpt(in string lpszAdrType,
                                               in BDEFINE ulFlags,
                                               out seq_SPropValue lppOptions);

                BRESULT EnumAdrTypes(in BDEFINE ulFlags,
                                     out seq_string lpppszAdrTypes);

                BRESULT QueryIdentity(out ENTRYID lppEntryID);

                BRESULT SetDefaultStore(in BDEFINE ulFlags,                    
                                        in ENTRYID lpEntryID);           

                BRESULT AdminServices(in BDEFINE ulFlags, // Unknown direction
                                      out IMsgServiceAdmin lppServiceAdmin);

///////////////////////////////////////////////////////////
//                                                       //
// The following functions are generic helper functions  //
// typically found in the Exchange SDK. They are *not*   //
// a part of IMAPISession proper.                        //
//                                                       //
///////////////////////////////////////////////////////////

		// Call this method to add another life line. You must always have
		// at least one active life line on the session. The returned value
		// must be used as input to IMAPISession::Destroy(). You must use
		// 0 (zero) when invoking IMAPISession::Destroy() if you haven't 
		// added any lifelines.
		unsigned long addLifeline(in BRUTUS::BrutusCheck LifeLine);

		// This method is just an easy way for the client to 
		// determine whether the session is alive or not.
		void ping();

		// Returns a reference to an IPropData servant
                BRESULT CreateIProp(out IPropData lppPropData);
		
		// The lpvSupport parameter is rather undefined in MSDN. Is
		// this object in reality a pointer to an object implementing
		// IMAPISupport or is it something different? I have removed
		// that parameter for the time being due to this very 
		// uncertainty. IMAPISupport can always be implemented later 
		// should the lpvSupport parameter be proven needed.
		BRESULT OpenTnefStreamEx(in IStream lpStreamName,   
					 in string lpszStreamName,   
					 in BDEFINE ulFlags,
					 in IMessage lpMessage,   
					 in short wKeyVal,          
					 in IAddrBook lpAdressBook,   
					 out ITnef lppTNEF);

		// Retrieves the IProfAdmin object for the logged 
		// on MAPI session.
		BRESULT MAPIAdminProfiles(in BDEFINE ulFlags,
					  out IProfAdmin ProfAdmin);

		// Returns the default message store for the logged 
		// on MAPI session.
		BRESULT GetDefaultMsgStore(in BDEFINE ulFlags, // Flags given to IMAPISession::OpenMsgStore()
					   out IMsgStore lpMDB);

		// Returns the public message store for the logged 
		// on MAPI session.
		BRESULT GetPublicMsgStore(in BDEFINE ulFlags, // Flags given to IMAPISession::OpenMsgStore()
					  out IMsgStore lpMDB);

                BRESULT OpenStoreFromGuid(in GUID lpGUID,
					  in BDEFINE ulFlags, // Flags given to IMAPISession::OpenMsgStore()
                                          out IMsgStore lpMDB);      

		// Will return the default message store for 
		// another user. You can only succeed with this
		// method if your are authenticated with sufficient
		// rights, e.g. Administrator rights.
		BRESULT MailboxLogon(in IMsgStore lpMDB,       // A message store          
				     in string lpszMsgStoreDN, // Information store distinguished name
				     in string lpszMailboxDN,  // Mailbox distinguished name
				     in BDEFINE ulCreateFlags, // Flags given to IExchangeManageStore::CreateStoreEntryID()
				     in BDEFINE ulOpenFlags,   // Flags given to IMAPISession::OpenMsgStore()
				     out IMsgStore lppMailboxMDB); 

		// Will retrieve the ENTRYID of specified Outlook 
		// folder. The return value will be !S_OK if not
		// successful. The specified message store is used 
		// to get the ENTRYID of the specified folder 
		// unless the message store is NIL in which case 
		// the logged on MAPI session's default message 
		// store is used. 
		// Will return MAPI_E_INVALID_PARAMETER if Which
		// is OUTLOOK_NONE or OUTLOOK_DEVNULL.
		BRESULT GetOutlookFolderENTRYID(in OUTLOOK_FOLDER Which,
						in IMsgStore lpMDB, // Some default/private message store
						out ENTRYID lppEntryID);

		// Will retrieve the specified Outlook folder or
		// NIL if not successful. The folder returned is
		// for the specified message store unless it is
		// NIL in which case the returned folder is for
		// the logged on MAPI session's default message 
		// store.
		// Will return MAPI_E_INVALID_PARAMETER if Which
		// is OUTLOOK_NONE or OUTLOOK_DEVNULL.
		BRESULT GetOutlookFolder(in OUTLOOK_FOLDER Which,
					 in IMsgStore lpMDB, // Some default/private message store
					 out IMAPIFolder Folder);

		// Invokes HrDispatchNotification(Flags)
                BRESULT DispatchNotifications(in unsigned long Flags);

		// Will briefly open the object signified by Eid and retrieve, 
		// using IMAPIProp::GetProps(), a sequence of SPropValue 
		// corresponding to the tags specified in PropTagArray. The flags 
		// given to GetProps() is 0 (zero). 
		BRESULT QueryProps(in ENTRYID Eid,
				   in SPropTagArray PropTagArray, 
				   out seq_SPropValue PropValueArray); 

		// Will briefly open the IMessage object signified by Eid and  
		// retrieve, using IMAPIProp::GetProps(), a sequence of SPropValue 
		// corresponding to the tags specified in ObjPropTagArray. The flags 
		// given to GetProps() is 0 (zero). An SRowSet is retrieved from the 
		// recipient table corresponding to the tags specified in RecpPropTagArray.
		BRESULT QueryMessage(in ENTRYID Eid,
				     in SPropTagArray ObjPropTagArray,               // Properties to get from message
				     in SPropTagArray AdditionalObjPropTagArray,     // Additional properties to get from message (NOTE: No additional properties is retrieved if this is empty)
				     in SPropTagArray RecpPropTagArray,              // Properties to get from recipient table
				     out seq_SPropValue ObjPropValueArray,           // SPropValues from message
				     out seq_SPropValue AdditionalObjPropValueArray, // Additional SPropValues from message
				     out SRowSet RecpRows);                          // SRowSet from recipient table
		
		// Will return true if successful and false otherwise.
		// "server" is the DNS resolvable name of remote Windows server to query.
		// The name of the server must begin with \\ if the server is running Windows NT.
		// Try prepending \\ to the server name if this method fails.
		//
		// CAUTION: This method might hang due to network conditions on the server side.
		//
		boolean GetServerTime(in string server, 
				      out TIME_OF_DAY_INFO tod);

		// MSDN: 
		// The LookupAccountName function accepts the name of a system and an 
		// account as input. It retrieves a security identifier (SID) for the 
		// account and the name of the domain on which the account was found.
		boolean LookupAccountName(in string lpSystemName,
					  in string lpAccountName,
					  out seq_octet Sid,
					  out string ReferencedDomainName,
					  out SID_NAME_USE peUse);

		// Creates the standard mailbox folders which are assumed present
		// by Outlook and some of the Brutus helper funstions.
		BRESULT InitMailbox();

		// Returns true on success, false otherwise
		boolean GetServerVersion(out SERVER_VERSION Version);

		// Will determine which codepage is used to write non-unicode strings.
		// No adjustment will be made if this method isn't called.
		void SetCodePage(in unsigned long codepage);
        };

}; // End of module BRUTUS


#endif
