#ifndef __GOLEM_H
#define __GOLEM_H

#ifndef __DATE_H
#include <date.h>
#endif

#ifndef __STRINGS_H
#include <strings.h>
#endif

bool goto_url(const char* url);
bool edit_url(const char* url);
bool print_url(const char* url);

class TMAPI_session;

class TMail_message : public TString_array
{                  
  TString_array _recipients, _copy_recipients, _attachments;
  TString _subject;
  TString _sender;
  TString _id;
  TDate _date;
  long _hms;
  
protected:
  bool add_recipient_ex(const char* recipient, int type);

public: // Semiprotected: You don't have access to TMAPI_session
  bool send(TMAPI_session& lhSession, bool hide_ui = FALSE);
  bool remove(TMAPI_session& lhSession);
  
public:                                                       
  bool add_recipient(const char* address) { return add_recipient_ex(address, 0); }
  void set_subject(const char* subject) { _subject = subject; _subject.trim(); }
  bool add_copy_recipient(const char* address) { return add_recipient_ex(address, 1); }
  bool attach(const char* filename) { return add_recipient_ex(filename, 2); }
  void set_sender(const char* address) { _sender = address; _sender.trim(); }
  void set_id(const char* id) { _id = id; }
  int add_line(const char * s);   
  
  TMail_message& operator = (const char* msg) { destroy(); add(msg); return *this; }
  TMail_message& operator = (const TString& msg) { destroy(); add(msg); return *this; }
  
  bool send(bool hide_ui = FALSE);
  bool remove();

  const TString& sender() const { return _sender; }
  const TString& subject() const { return _subject; }
  const TString& id() const { return _id; }

  void set_date_time(const char* date_time);
  const TDate& date() const { return _date; }
  long time() const { return _hms; }

  int recipients() const { return _recipients.items(); }
  const TString& recipient(int n = 0) const;
  
  TMail_message(const char* recipient = NULL, const char* subject = NULL, 
                const char* text = NULL, const char* sender = NULL);
  virtual ~TMail_message() { }
};

class TMail_messages : public TArray
{
public:
  int get(const char* sender = NULL, const char* subject = NULL, 
          const char* body = NULL, bool attachments = FALSE, bool mark_as_read = FALSE);

  bool send(bool hide_ui = TRUE);
  bool remove();

  TMail_message& msg(int i) 
  { return (TMail_message&)(*this)[i]; }
  
  const TMail_message& msg(int i) const 
  { return (const TMail_message&)(*this)[i]; }
  
  TMail_messages();
  virtual ~TMail_messages() { }
};

// @doc EXTERNAL

// @class TDDE | Classe per la gestione del DDE
//
// @base public | TObject
class TDDE : public TObject

// @comm Attualmente utilizzato all'avvio di PRASSI per comunicare al Program Manager il nome
//     dell'utente in modo da comunicarlo a tutti i programmi PRASSI avviati in seguito.

// @author:(INTERNAL) Guido

// @access:(INTERNAL) Private Member
{ 
  // @cmember:(INTERNAL) Handle della finestra Windows
  word _hwnd;
  // @cmember:(INTERNAL) Handle della finestra del server DDE
  word _server;
  // @cmember:(INTERNAL) Puntatore alla funzione di gestione dei messaggi
  long _old_hook;
  
// @access Public Member
public:                                                
  virtual bool do_initiate(word id, const TString& topic) { return FALSE; }
  virtual bool do_execute(word id, const TString& cmd) { return FALSE; }
  virtual bool do_ack(word id) { _server = id; return TRUE; }
  virtual bool do_terminate(word id) { return FALSE; }
  virtual bool do_custom_message(word msg, word wparam, long lparam) { return FALSE; }
  virtual const char* get_app_name() const { return NULL; }
  virtual const char* get_topics() const { return NULL; }

  // @cmember Stabilisce il collegamento dell'<p app> per i <p topic> indicati
  bool initiate(const char* app, const char* topic);
  // @cmember Esegue il comando <p cmd>
  bool execute(const char* cmd) const;
  // @cmember Lancia il server ed esegue un comando
  bool execute(const char* app, const char* topic, const char* cmd, const char* filename = NULL);
  // @cmember Chiude la connessione
  void terminate();
  
  
  // @cmember Inizia a fornire i servizi di DDE server
  bool start_server();
  
  word hwnd() const { return _hwnd; }

  // @cmember Costruttore
  TDDE();
  // @cmember Distruttore
  virtual ~TDDE();
};

#endif