//---------------------------------------------------------------------------
// =====================
// Cancel Message Hunter
// =====================
//
// by JTHZ
// using Borland C++Builder 5 PRO
// April 10, 2000
//---------------------------------------------------------------------------

#ifndef CancelHuntUnitH
#define CancelHuntUnitH

//---------------------------------------------------------------------------

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <NMNNTP.hpp>
#include <Psock.hpp>

//---------------------------------------------------------------------------

// current state of the program
typedef enum {
  E_HUNT_Invalid,
  E_HUNT_Unarmed,
  E_HUNT_HuntingForMessage,
  E_HUNT_HuntingForCancelMessage,
  E_HUNT_Finished
} THuntMode;

// all article-indices of the group we are
// hunting in are stored in a TArticleIndices container
typedef std::vector <int>         TArticleIndices;
typedef TArticleIndices::iterator TArticleIndicesIterator;

// function pointer to point out what to do with new messages
typedef bool __fastcall (__closure *THuntAction)(const String, const String);

//---------------------------------------------------------------------------

class THuntForm : public TForm
{
__published:
  TPanel *ConfigPanel;
  TPanel *OutputPanel;
  TLabel *Label1;
  TLabel *Label2;
  TLabel *Label3;
  TLabel *Label4;
  TLabel *Label5;
  TLabel *Label6;
  TLabel *Label7;
  TLabel *Label8;
  TEdit *NewsserverEdit;
  TEdit *UserEdit;
  TEdit *PasswordEdit;
  TEdit *NewsgroupEdit;
  TEdit *CancelgroupEdit;
  TEdit *HuntEdit;
  TEdit *StorageDirectoryEdit;
  TEdit *TimerIntervalEdit;
  TSpeedButton *DirectoryButton;
  TUpDown *TimerIntervalUpDown;
  TBitBtn *ArmButton;
  TBitBtn *KillButton;
  TLabel *ModeLabel;
  TNMNNTP *Nntp;
  TTimer *Timer1;
  TProgressBar *ProgressBar1;
  TAnimate *Animate1;
  TLabel *NewsgroupLabel;
  TLabel *IndexLabel;
  TLabel *MessageIdLabel;
  TLabel *ActionLabel;
  TCheckBox *TopmostCheckBox;
  void __fastcall FormCreate(TObject *Sender);
  void __fastcall FormDestroy(TObject *Sender);
  void __fastcall EditsChange(TObject *Sender);
  void __fastcall DirectoryButtonClick(TObject *Sender);
  void __fastcall Timer1Timer(TObject *Sender);
  void __fastcall ArmButtonClick(TObject *Sender);
  void __fastcall KillButtonClick(TObject *Sender);
  void __fastcall NntpInvalidArticle(TObject *Sender);
  void __fastcall NntpHeaderList(TObject *Sender);
  void __fastcall TopmostCheckBoxClick(TObject *Sender);

private:

  // registry i/o, overloaded for Strings and ints
  String __fastcall RegGet(const String Name, const String DefaultValue = "");
  int    __fastcall RegGet(const String Name, const int DefaultValue = 0);
  void   __fastcall RegPut(const String Name, const String Value);
  void   __fastcall RegPut(const String Name, const int Value);

  void   __fastcall StorageChange();
  String __fastcall ExtractMessageId(TStringList* Header);
  void __fastcall UpdateStatus();
  void __fastcall EnableControls(bool Status = true);
  bool __fastcall ScanBodyForString(  const String Token, const String MessageId);
  bool __fastcall ScanHeaderForString(const String Token, const String MessageId);
  bool __fastcall ScanNewsgroup(const String Newsgroup, THuntAction HuntAction,
                                const String Token);
  void __fastcall SaveCurrentMessage(const String ShortName);

  String          StorageDirectory;

  THuntMode       HuntMode;

  int             TimerElapsed;

  TArticleIndices ArticleIndices;

  bool            IsValidArticle;

  // Message-ID to look for in cancel group
  String          CancelMessageId;

public:

  __fastcall THuntForm(TComponent* Owner);

};

//---------------------------------------------------------------------------

extern PACKAGE THuntForm *HuntForm;

//---------------------------------------------------------------------------

#endif

//---------------------------------------------------------------------------

