home *** CD-ROM | disk | FTP | other *** search
/ Freelog 11 / Freelog011.iso / BestOf / PhoenixMail / Source / phoenix / FMMailOptions.pas < prev    next >
Pascal/Delphi Source File  |  1999-02-10  |  12KB  |  417 lines

  1. {*****************************************************************************
  2.  *
  3.  *  FMMailOptions.pas - Properties form for EMails  (25-July-1998)
  4.  *
  5.  *  Copyright (c) 1998-99 Michael Haller
  6.  *
  7.  *  Author:     Michael Haller
  8.  *  E-mail:     michael@discountdrive.com
  9.  *  Homepage:   http://www.discountdrive.com/sunrise
  10.  *
  11.  *  This program is free software; you can redistribute it and/or
  12.  *  modify it under the terms of the GNU General Public License
  13.  *  as published by the Free Software Foundation;
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  23.  *
  24.  *----------------------------------------------------------------------------
  25.  *
  26.  *  Revision history:
  27.  *
  28.  *     DATE     REV                 DESCRIPTION
  29.  *  ----------- --- ----------------------------------------------------------
  30.  *
  31.  *****************************************************************************}
  32.  
  33. unit FMMailOptions;
  34.  
  35. interface
  36.  
  37. uses
  38.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  39.   Buttons, ExtCtrls, StdCtrls, Grids, ComCtrls, FlyOverControl, Menus,
  40.   MailParser, ComboBoxEx, PXStuff, FMAddress, ParserSup, LangSup;
  41.  
  42. type
  43.   TMailOptionsForm = class(TForm)
  44.     Button1: TButton;
  45.     Button2: TButton;
  46.     Label4: TLabel;
  47.     Bevel2: TBevel;
  48.     Notebook1: TNotebook;
  49.     Notebook2: TNotebook;
  50.     SpeedButton6: TSpeedButton;
  51.     Label6: TLabel;
  52.     Label13: TLabel;
  53.     SpeedButton8: TSpeedButton;
  54.     Label19: TLabel;
  55.     Label17: TLabel;
  56.     Label16: TLabel;
  57.     Edit5: TEdit;
  58.     Edit6: TEdit;
  59.     StringGrid1: TStringGrid;
  60.     Bevel1: TBevel;
  61.     Label7: TLabel;
  62.     Label8: TLabel;
  63.     Bevel3: TBevel;
  64.     Label9: TLabel;
  65.     Bevel4: TBevel;
  66.     Label10: TLabel;
  67.     Bevel5: TBevel;
  68.     Panel3: TPanel;
  69.     Image2: TImage;
  70.     Label11: TLabel;
  71.     Label15: TLabel;
  72.     Bevel6: TBevel;
  73.     Notebook3: TNotebook;
  74.     Memo1: TMemo;
  75.     SpeedButton5: TSpeedButton;
  76.     Memo2: TMemo;
  77.     SpeedButton7: TSpeedButton;
  78.     Memo3: TMemo;
  79.     SpeedButton9: TSpeedButton;
  80.     FlyOverControl1: TFlyOverControl;
  81.     ComboBox1: TComboBoxEx;
  82.     SpeedButton10: TSpeedButton;
  83.     SpeedButton11: TSpeedButton;
  84.     DateTimePicker1: TDateTimePicker;
  85.     DateTimePicker2: TDateTimePicker;
  86.     Label14: TLabel;
  87.     SpeedButton1: TSpeedButton;
  88.     SpeedButton13: TSpeedButton;
  89.     SpeedButton14: TSpeedButton;
  90.     SpeedButton3: TSpeedButton;
  91.     SpeedButton2: TSpeedButton;
  92.     SpeedButton4: TSpeedButton;
  93.     Label2: TLabel;
  94.     Bevel7: TBevel;
  95.     Label3: TLabel;
  96.     Bevel8: TBevel;
  97.     ComboBox2: TComboBox;
  98.     procedure FormCreate(Sender: TObject);
  99.     procedure SpeedButton2Click(Sender: TObject);
  100.     procedure SpeedButton3Click(Sender: TObject);
  101.     procedure SpeedButton4Click(Sender: TObject);
  102.     procedure SpeedButton6Click(Sender: TObject);
  103.     procedure FlyOverControl1ControlChange(Sender: TObject;
  104.       Control: TControl);
  105.     procedure FormShow(Sender: TObject);
  106.     procedure SpeedButton10Click(Sender: TObject);
  107.     procedure SpeedButton11Click(Sender: TObject);
  108.     procedure Button1Click(Sender: TObject);
  109.     procedure Memo3Change(Sender: TObject);
  110.     procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
  111.       const Value: String);
  112.     procedure SpeedButton5Click(Sender: TObject);
  113.     procedure SpeedButton7Click(Sender: TObject);
  114.     procedure SpeedButton9Click(Sender: TObject);
  115.     procedure SpeedButton8Click(Sender: TObject);
  116.     procedure SpeedButton1Click(Sender: TObject);
  117.     procedure SpeedButton13Click(Sender: TObject);
  118.     procedure SpeedButton14Click(Sender: TObject);
  119.     procedure Label11Click(Sender: TObject);
  120.   private
  121.     { Private declarations }
  122.     ReceiverIndex: Integer;
  123.   public
  124.     { Public declarations }
  125.     procedure SetFields(Index: Integer);
  126.     procedure LoadMailHeader;
  127.     procedure SaveMailHeader;
  128.   end;
  129.  
  130. var
  131.   MailOptionsForm: TMailOptionsForm;
  132.  
  133. implementation
  134.  
  135. {$R *.DFM}
  136.  
  137. uses
  138.   Main;
  139.  
  140. var
  141.   ReceiverButtonLabels: array [0..2] of String;
  142.  
  143. procedure TMailOptionsForm.LoadMailHeader;
  144. var
  145.   I: Integer;
  146.   B: Boolean;
  147.   S: String;
  148. begin
  149.   ComboBox2.Items.Clear;
  150.   for I := 0 to MainForm.TreeView1.Items.Count-1 do
  151.     if MainForm.TreeView1.Items[I].StateIndex = 1 then
  152.       if Assigned(Mainform.TreeView1.Items[I].Data) then begin
  153.         S := PAccountData(Mainform.TreeView1.Items[I].Data)^.FromDesc+' <'+PAccountData(Mainform.TreeView1.Items[I].Data)^.FromMail+'>';
  154.         if ExtractEMailAddress(S) <> '' then
  155.           if Combobox2.Items.IndexOf(S) = -1 then
  156.             ComboBox2.Items.Add(S);
  157.         S := PAccountData(Mainform.TreeView1.Items[I].Data)^.ReplyDesc+' <'+PAccountData(Mainform.TreeView1.Items[I].Data)^.ReplyMail+'>';
  158.         if ExtractEMailAddress(S) <> '' then
  159.           if Combobox2.Items.IndexOf(S) = -1 then
  160.             ComboBox2.Items.Add(S);
  161.       end;
  162.   B := SaveMessage;
  163.   with CurrentEMail do begin
  164.     Memo1.Lines.Assign(ToReceiver);
  165.     Memo2.Lines.Assign(CC);
  166.     Memo3.Lines.Assign(BCC);
  167.     StringGrid1.RowCount := Fields.Count+1;
  168.     for I := 1 to Fields.Count do begin
  169.       StringGrid1.Cells[0, I] := Fields[I-1];
  170.       StringGrid1.Cells[1, I] := FieldValues[I-1];
  171.     end;
  172.     Edit5.Text := Subject;
  173.     Edit6.Text := Keywords;
  174.     ComboBox2.Text := From;
  175.     ComboBox1.Value := LowerCase(Priority);
  176.     DateTimePicker1.Date := ADate;
  177.     DateTimePicker2.Time := ATime;
  178.   end;
  179.   SaveMessage := B;
  180. end;
  181.  
  182. procedure TMailOptionsForm.SaveMailHeader;
  183. begin
  184.   with CurrentEMail do begin
  185.     ToReceiver.Assign(Memo1.Lines);
  186.     CC.Assign(Memo2.Lines);
  187.     BCC.Assign(Memo3.Lines);
  188.     Fields.Assign(StringGrid1.Cols[0]);
  189.     Fields.Delete(0);
  190.     FieldValues.Assign(StringGrid1.Cols[1]);
  191.     FieldValues.Delete(0);
  192.     Subject := Edit5.Text;
  193.     Keywords := Edit6.Text;
  194.     From := ComboBox2.Text;
  195.     Priority := ComboBox1.Values[ComboBox1.ItemIndex];
  196.     Priority[1] := UpCase(Priority[1]);
  197.     ADate := DateTimePicker1.Date;
  198.     ATime := DateTimePicker2.Time;
  199.   end;
  200. end;
  201.  
  202. procedure TMailOptionsForm.SetFields(Index: Integer);
  203. begin
  204.   case Index of
  205.     0: begin
  206.       NoteBook2.PageIndex := 0;
  207.       NoteBook1.PageIndex := 0;
  208.       ReceiverIndex := 0;
  209.       NoteBook3.PageIndex := 0;
  210.       SpeedButton6.Caption := ReceiverButtonLabels[ReceiverIndex];
  211.       SpeedButton3.Down := True;
  212.     end;
  213.     1: begin
  214.       NoteBook2.PageIndex := 1;
  215.       NoteBook1.PageIndex := 0;
  216.       SpeedButton2.Down := True;
  217.     end;
  218.     2: begin
  219.       NoteBook1.PageIndex := 1;
  220.       SpeedButton4.Down := True;
  221.     end;
  222.   end;
  223. end;
  224.  
  225. procedure TMailOptionsForm.FormCreate(Sender: TObject);
  226. begin
  227.   AttachLanguageToForm(Self);
  228.   if bOfficeFonts then Font.Name := sOfficeFontName;
  229.   if bFlatButtons = False then begin
  230.     Set3DButtons(False, Self);
  231.     Bevel8.Visible := False;
  232.   end;
  233.   ReceiverButtonLabels[0] := MainForm.ListBox1.Items[52];
  234.   ReceiverButtonLabels[1] := MainForm.ListBox1.Items[53];
  235.   ReceiverButtonLabels[2] := MainForm.ListBox1.Items[54];
  236.   SpeedButton6.Caption := ReceiverButtonLabels[0];
  237.   Image2.Hint := Label11.Hint;
  238.   Panel3.Hint := Label11.Hint;
  239.   Label10.Caption := Label10.Caption+' ';
  240.   Label8.Caption := Label8.Caption+' ';
  241.   Label7.Caption := Label7.Caption+' ';
  242.   Label9.Caption := Label9.Caption+' ';
  243.   Label15.Caption := Label15.Caption+' ';
  244.   Label3.Caption := Label3.Caption+' ';
  245.   SetFields(0);
  246.   StringGrid1.Cells[0, 0] := MainForm.ListBox1.Items[55];
  247.   StringGrid1.Cells[1, 0] := MainForm.ListBox1.Items[56];
  248.   Combobox1.Images := MainForm.ImageList1;
  249. end;
  250.  
  251. procedure TMailOptionsForm.SpeedButton2Click(Sender: TObject);
  252. begin
  253.   SetFields(1);
  254. end;
  255.  
  256. procedure TMailOptionsForm.SpeedButton3Click(Sender: TObject);
  257. begin
  258.   SetFields(0);
  259. end;
  260.  
  261. procedure TMailOptionsForm.SpeedButton4Click(Sender: TObject);
  262. begin
  263.   SetFields(2);
  264. end;
  265.  
  266. procedure TMailOptionsForm.SpeedButton6Click(Sender: TObject);
  267. begin
  268.   Inc(ReceiverIndex);
  269.   if ReceiverIndex = 3 then ReceiverIndex := 0;
  270.   NoteBook3.PageIndex := ReceiverIndex;
  271.   SpeedButton6.Caption := ReceiverButtonLabels[ReceiverIndex];
  272. end;
  273.  
  274. procedure TMailOptionsForm.FlyOverControl1ControlChange(Sender: TObject;
  275.   Control: TControl);
  276. begin
  277.   if Assigned(Control) then
  278.     Label11.Caption := Control.Hint
  279.   else
  280.     Label11.Caption := '';
  281. end;
  282.  
  283. procedure TMailOptionsForm.FormShow(Sender: TObject);
  284. begin
  285.   LoadMailHeader;
  286.   if bFlatButtons then begin
  287.     Set3DButtons(True, Self);
  288.     Bevel8.Visible := True;
  289.     SpeedButton10.Flat := False;
  290.     SpeedButton11.Flat := False;
  291.     SpeedButton6.Flat := False;
  292.   end else begin
  293.     Set3DButtons(False, Self);
  294.     Bevel8.Visible := False;
  295.   end;
  296. end;
  297.  
  298. procedure TMailOptionsForm.SpeedButton10Click(Sender: TObject);
  299. begin
  300.   StringGrid1.RowCount := StringGrid1.RowCount+1;
  301.   StringGrid1.Invalidate;
  302.   SaveMessage := True;
  303. end;
  304.  
  305. procedure TMailOptionsForm.SpeedButton11Click(Sender: TObject);
  306. var
  307.   I: Integer;
  308. begin
  309.   if (StringGrid1.Row > 0) and (StringGrid1.Col > -1) then begin
  310.     for I := StringGrid1.Row to StringGrid1.RowCount-1 do begin
  311.       StringGrid1.Cells[0, I] := StringGrid1.Cells[0, I+1];
  312.       StringGrid1.Cells[1, I] := StringGrid1.Cells[1, I+1];
  313.     end;
  314.     StringGrid1.Cells[0, StringGrid1.RowCount-1] := '';
  315.     StringGrid1.Cells[1, StringGrid1.RowCount-1] := '';
  316.     if StringGrid1.RowCount > 2 then
  317.       StringGrid1.RowCount := StringGrid1.RowCount-1;
  318.     StringGrid1.Invalidate;
  319.     SaveMessage := True;
  320.   end;
  321. end;
  322.  
  323. procedure TMailOptionsForm.Button1Click(Sender: TObject);
  324. begin
  325.   if (Memo1.Lines.Count = 0) and (Memo2.Lines.Count = 0) and (Memo3.Lines.Count = 0) then begin
  326.     MessageDlg(MainForm.ListBox1.Items[57], mtWarning, [mbOK], 0);
  327.   end else begin
  328.     SaveMailHeader;
  329.     ModalResult := mrOK;
  330.   end;
  331. end;
  332.  
  333. procedure TMailOptionsForm.Memo3Change(Sender: TObject);
  334. begin
  335.   SaveMessage := True;
  336. end;
  337.  
  338. procedure TMailOptionsForm.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String);
  339. begin
  340.   Memo3Change(Self);
  341. end;
  342.  
  343. procedure TMailOptionsForm.SpeedButton5Click(Sender: TObject);
  344. var
  345.   SL: TStringList;
  346. begin
  347.   if AddressForm.ShowModal = mrOK then begin
  348.     SL := TStringList.Create;
  349.     CommataStringToStringList(AddressForm.GetSelAddresses, SL);
  350.     Memo1.Lines.Assign(SL);
  351.     SL.Free;
  352.   end;
  353. end;
  354.  
  355. procedure TMailOptionsForm.SpeedButton7Click(Sender: TObject);
  356. var
  357.   SL: TStringList;
  358. begin
  359.   if AddressForm.ShowModal = mrOK then begin
  360.     SL := TStringList.Create;
  361.     CommataStringToStringList(AddressForm.GetSelAddresses, SL);
  362.     Memo2.Lines.Assign(SL);
  363.     SL.Free;
  364.   end;
  365. end;
  366.  
  367. procedure TMailOptionsForm.SpeedButton9Click(Sender: TObject);
  368. var
  369.   SL: TStringList;
  370. begin
  371.   if AddressForm.ShowModal = mrOK then begin
  372.     SL := TStringList.Create;
  373.     CommataStringToStringList(AddressForm.GetSelAddresses, SL);
  374.     Memo3.Lines.Assign(SL);
  375.     SL.Free;
  376.   end;
  377. end;
  378.  
  379. procedure TMailOptionsForm.SpeedButton8Click(Sender: TObject);
  380. begin
  381.   AddressForm.SetAddress(ComboBox2.Text);
  382. end;
  383.  
  384. procedure TMailOptionsForm.SpeedButton1Click(Sender: TObject);
  385. var
  386.   I: Integer;
  387. begin
  388.   for I := 0 to Memo1.Lines.Count-1 do
  389.     if Memo1.Lines[I] <> '' then
  390.       if AddressForm.SetAddress(Memo1.Lines[I]) <> False then Exit;
  391. end;
  392.  
  393. procedure TMailOptionsForm.SpeedButton13Click(Sender: TObject);
  394. var
  395.   I: Integer;
  396. begin
  397.   for I := 0 to Memo2.Lines.Count-1 do
  398.     if Memo2.Lines[I] <> '' then
  399.       if AddressForm.SetAddress(Memo2.Lines[I]) <> False then Exit;
  400. end;
  401.  
  402. procedure TMailOptionsForm.SpeedButton14Click(Sender: TObject);
  403. var
  404.   I: Integer;
  405. begin
  406.   for I := 0 to Memo3.Lines.Count-1 do
  407.     if Memo3.Lines[I] <> '' then
  408.       if AddressForm.SetAddress(Memo3.Lines[I]) <> False then Exit;
  409. end;
  410.  
  411. procedure TMailOptionsForm.Label11Click(Sender: TObject);
  412. begin
  413.   Application.HelpContext(10);
  414. end;
  415.  
  416. end.
  417.