void __fastcall TMainFrm::DisconnectExecute(TObject *Sender)
{


   if (POP->Connected())
      {
         try
           { POP->Reset();
           }

         catch (...)
         {
            ShowStatus("Your POP server doesn''t have Reset feature");
         }
         POP->Disconnect();
      }
    ToggleStatus(false,true);
    TListItem * li;
    int count=lvHeaders->Items->Count;
    while (count)
      {
      li=lvHeaders->Items->Item[count-1];
       if  (li->ImageIndex==3)
       li->ImageIndex=5;
      count--;
      }

}
void CJobControlDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int	JobIdx = GetCurSel();
	if (JobIdx >= 0 && !IsRunning(JobIdx)) {	// can't change status of running job
		if (GetStatus(JobIdx) == JOB_FAILED)
			ShowErrorMsg(JobIdx);
		ToggleStatus(JobIdx, JOB_WAITING, JOB_POSTPONED);
	}
	*pResult = 0;
}
void __fastcall TMainFrm::CheckMailExecute(TObject *Sender)
{
   ShowBusy(true);

   ShowStatus("Connecting....");

   if (POP->Connected())
      {
       POP->Disconnect();
      }

   
   POP->Host = Pop3ServerName;
   POP->Port = Pop3ServerPort;
   POP->UserId = Pop3ServerUser;
   POP->Password = Pop3ServerPassword;
   Application->ProcessMessages();
   Application->ProcessMessages();
   Application->ProcessMessages();
   POP->Connect();
   ToggleStatus(true,true);
   FMsgCount = POP->CheckMessages();
   FMailBoxSize = POP->RetrieveMailBoxSize()/1024;
   ShowFileStatus();
   if (FMsgCount > 0)
        {
         ShowFileStatus();
         RetrievePOPHeaders(FMsgCount);
        }
   else
      {
         ShowStatus("No messages on server");
      }

  if (POP->Connected())
      {
       POP->Disconnect();
      }
   ToggleStatus(false,true);
   ShowBusy(false);

}
void __fastcall TMainFrm::PurgeExecute(TObject *Sender)
{
   TListItem * li;
   int count=lvHeaders->Items->Count;
    while (count)
        {
        li=lvHeaders->Items->Item[count-1];
        if  (li->ImageIndex==3)
        {  if (!POP->Connected())
           POP->Connect();
           POP->Delete(count);
        }
        count--;
        }


   if (POP->Connected())
   POP->Disconnect();
   ToggleStatus(false,false);
   ::Sleep(500);//needed to delay reconnection..... raises an exception otherwise
   CheckMailExecute(Sender);

}
void CJobControlDlg::OnPostpone() 
{
	int	JobIdx = GetCurSel();
	if (JobIdx >= 0 && !IsRunning(JobIdx))	// can't change status of running job
		ToggleStatus(JobIdx, JOB_POSTPONED, JOB_WAITING);
}
void __fastcall TMainFrm::FormActivate(TObject *Sender)
{
   ResetHeadersGrid();
   ToggleStatus(false,false);
}