home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / delphi / TPOP3 / POP3MAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-26  |  5.9 KB  |  244 lines

  1. unit Pop3main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, POP3, Buttons, Grids, ExtCtrls,
  8.   Pop3Su, IniFiles, MsgDcd, mailbase, ComCtrls;
  9.  
  10. type
  11.   TPOP3Form = class(TForm)
  12.     ToolBar: TPanel;
  13.     GetButton: TSpeedButton;
  14.     CancelButton: TSpeedButton;
  15.     SetupButton: TSpeedButton;
  16.     ExitButton: TSpeedButton;
  17.     InBox: TStringGrid;
  18.     POP3: TPOP3;
  19.     Panel1: TPanel;
  20.     StatusBar: TStatusBar;
  21.     ProgressBar: TProgressBar;
  22.     procedure FormCreate(Sender: TObject);
  23.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  24.     procedure GetButtonClick(Sender: TObject);
  25.     procedure CancelButtonClick(Sender: TObject);
  26.     procedure ExitButtonClick(Sender: TObject);
  27.     procedure SetupButtonClick(Sender: TObject);
  28.     procedure FormResize(Sender: TObject);
  29.     procedure InBoxDblClick(Sender: TObject);
  30.     procedure POP3StatusChange(Sender: TObject);
  31.     procedure POP3Progress(Sender: TObject);
  32.     procedure InBoxKeyPress(Sender: TObject; var Key: Char);
  33.   private
  34.     { Private declarations }
  35.     IniName : string;
  36.     AttDir : string;
  37.   public
  38.     { Public declarations }
  39.     procedure ProcessInBox;
  40.     procedure EnableControls;
  41.     procedure DisableControls;
  42.   end;
  43.  
  44. var
  45.   POP3Form: TPOP3Form;
  46.  
  47. implementation
  48.  
  49. {$R *.DFM}
  50.  
  51. procedure TPOP3Form.FormCreate(Sender: TObject);
  52. begin
  53.   IniName:=ChangeFileExt(Application.ExeName,'.ini');
  54.   with TIniFile.Create(IniName) do
  55.   try
  56.     POP3.Server:=ReadString('Setup','Server','');
  57.     POP3.UserName:=ReadString('Setup','User Name','');
  58. {****** Warning!!! No Encription for Password!!! *****}
  59.     POP3.Password:=ReadString('Setup','Password','');
  60.     POP3.LogFileName:=ReadString('Setup','Log File','');
  61.     AttDir:=ReadString('Setup','Attachments','');
  62.   finally
  63.     free;
  64.   end;
  65.   InBox.Cells[0,0]:='From';
  66.   InBox.Cells[1,0]:='Subject';
  67.   InBox.Cells[2,0]:='Size';
  68. end;
  69.  
  70. procedure TPOP3Form.FormClose(Sender: TObject; var Action: TCloseAction);
  71. begin
  72.   with TIniFile.Create(IniName) do
  73.   try
  74.     WriteString('Setup','Server',POP3.Server);
  75.     WriteString('Setup','User Name',POP3.UserName);
  76. {****** Warning!!! No Encription for Password!!! *****}
  77.     WriteString('Setup','Password',POP3.Password);
  78.     WriteString('Setup','Log File',POP3.LogFileName);
  79.     WriteString('Setup','Attachments',AttDir);
  80.   finally
  81.     free;
  82.   end;
  83. end;
  84.  
  85. procedure TPOP3Form.DisableControls;
  86. var
  87.   i : Integer;
  88.   SB : TSpeedButton;
  89. begin
  90.   for i:=0 to ToolBar.ControlCount-1 do
  91.   begin
  92.     SB:=ToolBar.Controls[i] as TSpeedButton;
  93.     SB.Enabled:=SB.Tag=1;
  94.   end;
  95.   Cursor:=crHourGlass;
  96. end;
  97.  
  98. procedure TPOP3Form.EnableControls;
  99. var
  100.   i : Integer;
  101.   SB : TSpeedButton;
  102. begin
  103.   for i:=0 to ToolBar.ControlCount-1 do
  104.   begin
  105.     SB:=ToolBar.Controls[i] as TSpeedButton;
  106.     SB.Enabled:=SB.Tag<>1;
  107.   end;
  108.   Cursor:=crDefault;
  109. end;
  110.  
  111. procedure TPOP3Form.GetButtonClick(Sender: TObject);
  112. begin
  113.   if (POP3.Server='') or (POP3.UserName='') or
  114.      (POP3.Password='') then
  115.    MessageDlg('You might want to enter the information'^M^J+
  116.               'in the Setup dialog box...',mtError,[mbOk],0)
  117.   else
  118.   with POP3 do
  119.   begin
  120.     try
  121.       DisableControls;
  122.       Open;
  123.       LogIn;
  124.       GetStatistics;
  125.       if TotalMessages>0 then
  126.         GetMessages;
  127.       LogOut;
  128.     finally
  129.       Close;
  130.       EnableControls;
  131.     end;
  132.   end;
  133.   ProcessInBox;
  134. end;
  135.  
  136. procedure TPOP3Form.ProcessInBox;
  137. var
  138.   i : Integer;
  139. begin
  140.   if POP3.MailMessages.Count>0 then
  141.   begin
  142.     InBox.Enabled:=true;
  143.     InBox.RowCount:=POP3.MailMessages.Count+1;
  144.     for i:=1 to Pop3.MailMessages.Count do
  145.     with TMailMessage(POP3.MailMessages.Objects[i-1]) do
  146.     begin
  147.       InBox.Cells[0,i]:=From;
  148.       InBox.Cells[1,i]:=Subject;
  149.       InBox.Cells[2,i]:=IntToStr(Size);
  150.     end;
  151.     InBox.Repaint;
  152.     StatusBar.Panels[0].Text:='Doubleclick or press Enter to process a message';
  153.   end
  154.   else
  155.     StatusBar.Panels[0].Text:='No New Messages';
  156. end;
  157.  
  158. procedure TPOP3Form.CancelButtonClick(Sender: TObject);
  159. begin
  160.   Pop3.Cancel;
  161. end;
  162.  
  163. procedure TPOP3Form.ExitButtonClick(Sender: TObject);
  164. begin
  165.   Close;
  166. end;
  167.  
  168. procedure TPOP3Form.SetupButtonClick(Sender: TObject);
  169. begin
  170.   with TSetupDlg.Create(Self) do
  171.   try
  172.     ServerEdit.Text:=POP3.Server;
  173.     UserNameEdit.Text:=POP3.UserName;
  174.     PasswordEdit.Text:=POP3.Password;
  175.     LogFileNameEdit.Text:=POP3.LogFileName;
  176.     AttDirEdit.Text:=AttDir;
  177.     if ShowModal=mrOk then
  178.     begin
  179.       POP3.Server:=ServerEdit.Text;
  180.       POP3.UserName:=UserNameEdit.Text;
  181.       POP3.Password:=PasswordEdit.Text;
  182.       POP3.LogFileName:=LogFileNameEdit.Text;
  183.       AttDir:=AttDirEdit.Text;
  184.     end;
  185.   finally
  186.     free;
  187.   end;
  188. end;
  189.  
  190. procedure TPOP3Form.FormResize(Sender: TObject);
  191. begin
  192.   with InBox do
  193.   begin
  194.     ColWidths[0]:=Trunc(0.25*Width);
  195.     ColWidths[1]:=Trunc(0.5*Width);
  196.     ColWidths[2]:=Trunc(0.25*Width);
  197.   end;
  198. end;
  199.  
  200. procedure TPOP3Form.InBoxDblClick(Sender: TObject);
  201. var
  202.   MailMessage : TMailMessage;
  203. begin
  204.   MsgDcd.AttachmentsDir:=AttDir;
  205.   MailMessage:=TMailMessage(POP3.MailMessages.Objects[InBox.Row-1]);
  206.   MailMessage.Body.Position:=0;
  207.   with TMsgProcessor.Create(Self,MailMessage.Body) do
  208.   try
  209.     ShowModal;
  210.   finally
  211.     free;
  212.   end;
  213. end;
  214.  
  215. procedure TPOP3Form.POP3StatusChange(Sender: TObject);
  216. var
  217.   s : string;
  218. begin
  219.   case POP3.Status of
  220.    psIdle : s:='';
  221.    psConnecting : s:='Connecting to server';
  222.    psLogIn : s:='Logging In';
  223.    psLogOut : s:='Logging Out';
  224.    psRetrieving : s:='Retrieving Message(s)';
  225.    psDeleting : s:='Deleting Message(s)';
  226.    psCancel : s:='Canceled';
  227.    psTimeOut : s:='Timed Out';
  228.   end;
  229.   StatusBar.Panels[0].Text:=s;
  230. end;
  231.  
  232. procedure TPOP3Form.POP3Progress(Sender: TObject);
  233. begin
  234.   ProgressBar.Position:=POP3.Progress;
  235. end;
  236.  
  237. procedure TPOP3Form.InBoxKeyPress(Sender: TObject; var Key: Char);
  238. begin
  239.   if Key=#13 then
  240.     InBoxDblClick(Sender);
  241. end;
  242.  
  243. end.
  244.