summaryrefslogtreecommitdiff
path: root/unit1.pas
blob: 3f1e3342b54384d5f0da6fee4cb627f7fb3a8dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, popunit, gitUpdateUnit;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    emailsDaIcon: TImage;
    nichtsDaIcon: TImage;
    Memo1: TMemo;
    TrayIcon1: TTrayIcon;
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TrayIcon1Click(Sender: TObject);
    procedure TrayIcon1DblClick(Sender: TObject);
    procedure TrayIcon1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { private declarations }
    lb: tMouseButton;
  public
    { public declarations }
    pc: tPopClient;
    procedure neueNachrichten(sender: tObject);
  end;

var
  Form1: TForm1;

implementation

uses myStringListUnit, lowLevelUnit, process;

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
  sl: tMyStringList;
  s:  string;
begin
  if fileexists(extractfilepath(application.exename)+'optionen.konf') then begin
    sl:=tMyStringList.create;
    sl.loadFromFile(extractfilepath(application.exename)+'optionen.konf');

    s:=sl.grepFirst('^aufploppen\s*=');
    erstesArgument(s,'=');
    if uppercase(s)='JA' then
      checkBox1.checked:=true
    else if uppercase(s)='NEIN' then
      checkBox1.checked:=false
    else if s<>'' then
      raise exception.create(''''+s+''' ist kein gültiger Wert für ''aufploppen'' (ja|nein)!');

    s:=sl.grepFirst('^Ton\s+geben\s*=');
    erstesArgument(s,'=');
    if uppercase(s)='JA' then
      checkBox2.checked:=true
    else if uppercase(s)='NEIN' then
      checkBox2.checked:=false
    else if s<>'' then
      raise exception.create(''''+s+''' ist kein gültiger Wert für ''Ton geben'' (ja|nein)!');

    sl.free;
  end;

  pc:=tPopClient.create;
  pc.timeout:=10;
  pc.neueNachrichten:=@neueNachrichten;
  pc.sshUser:='erich';
  pc.host:='eckner.net';
  pc.user:='notify@eckner.net';
  pc.pass:='C7sd7k8*';
  pc.gueltigerAdressat:='('+
     '.*@eckner\.net'                                                                    +'|'+
     '(ee|intern|vorstand)@wurzel\.org'                                                  +'|'+
     'erich\.eckner@uni-jena\.de'                                                        +'|'+
     'erich\.eckner@gmx\.de'                                                             +'|'+
     '(ioq_(nlo|staff)|alle_mitarbeiter|fsr-physik-newsletter)@listserv\.uni-jena\.de'   +'|'+
     '(sox-users|logwatch-devel)@lists\.sourceforge\.net'                                +'|'+
     'gmp-discuss@gmplib\.org'                                                           +'|'+
     'hashcash@freelists\.org'                                                           +'|'+
     'crux(-commits)?@lists.crux.nu'+
     ')';
  pc.port:=995;
end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  pc.threadAnhalten;
  pc.aufThreadWarten;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
var
  sl: tMyStringList;
begin
  sl:=tMyStringList.create;

  if checkBox1.checked then
    sl.add('aufploppen = JA')
  else
    sl.add('aufploppen = NEIN');

  if checkBox2.checked then
    sl.add('Ton geben =  JA')
  else
    sl.add('Ton geben =  NEIN');

  sl.saveToFile(extractfilepath(application.exename)+'optionen.konf');
  sl.free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  pc.loeschen;
  form1.visible:=false;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  button1.top:=form1.clientHeight-button1.height;
  checkBox1.top:=button1.top + (button1.height-checkBox1.height) div 2;
  checkBox2.top:=button1.top + (button1.height-checkBox2.height) div 2;
  button1.left:=(form1.clientWidth - button1.width - checkBox1.width - checkBox2.width) div 6;
  checkBox1.left:=button1.left+button1.width + (form1.clientWidth - button1.width - checkBox1.width - checkBox2.width) div 3;
  checkBox2.left:=checkBox1.left+checkBox1.width + (form1.clientWidth - button1.width - checkBox1.width - checkBox2.width) div 3;
  memo1.width:=form1.clientWidth-memo1.left;
  memo1.height:=button1.top-memo1.top;
end;

const __erstesMal: boolean = true;

procedure TForm1.FormShow(Sender: TObject);
begin
  if __erstesMal then begin
    __erstesMal:=false;
    form1.visible:=false;
  end;
  if form1.visible then begin
    form1.top:=screen.monitors[screen.monitorCount-1].top  +  (screen.monitors[screen.monitorCount-1].height-form1.height-24) div 2;
    form1.left:=screen.monitors[screen.monitorCount-1].left + (screen.monitors[screen.monitorCount-1].width-form1.width) div 2;
  end;
end;

procedure TForm1.TrayIcon1Click(Sender: TObject);
begin
  form1.visible:=not form1.visible;
end;

procedure TForm1.TrayIcon1DblClick(Sender: TObject);
begin
  if (lb=mbRight) or
     ((lb=mbLeft) and
      (messageDlg('Email-Tool beenden?',mtConfirmation,[mbYes,mbNo],0)=mrYes)) then
    form1.close;
end;

procedure TForm1.TrayIcon1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  lb:=button;
end;

procedure tForm1.neueNachrichten(sender: tObject);
var
  i,ung,mitMarkeDa: longint;
  argumente:        array of string;
  ausgabe:          string;
begin
  mitMarkeDa:=0;
  memo1.lines.clear;
  ung:=0;
  for i:=pc.nAnz-1 downto 0 do
    case pc.marke(i) of
      mvGueltig: begin
        inc(mitMarkeDa);
        memo1.lines.add('! '+pc.zeit(i)+' '+pc.von(i)+': '+pc.betreff(i));
      end;
      mvUngueltig: begin
        memo1.lines.add('( '+pc.zeit(i)+' '+pc.von(i)+': '+pc.betreff(i)+' )');
        inc(ung);
      end;
      mvKeine:
        memo1.lines.add('  '+pc.zeit(i)+' '+pc.von(i)+': '+pc.betreff(i));
    end{of case};
  if pc.nAnz<=ung then begin
    trayIcon1.icon:=nichtsDaIcon.picture.icon;
    trayIcon1.hint:='keine Post';
  end
  else begin
    trayIcon1.icon:=emailsDaIcon.picture.icon;
    trayIcon1.hint:=inttostr(pc.nAnz-ung)+' neue Nachrichten';
    if mitMarkeDa>0 then begin
      trayIcon1.hint:=trayIcon1.hint+', davon '+inttostr(mitMarkeDa)+' mit Marke';
      if checkBox1.checked then
        form1.visible:=true;
      if checkBox2.checked then begin
        setlength(argumente,1);
        argumente[0]:=extractFilePath(application.exename)+'gotmail.wav';
        ausgabe:='';
        runCommand('play',argumente,ausgabe);
        setlength(argumente,0);
      end;
    end;
  end;
  if ung>0 then
    trayIcon1.hint:=trayIcon1.hint+' (und noch '+inttostr(ung)+' mit ungültiger Marke)';
  trayIcon1.visible:=true;
  form1.icon:=trayIcon1.icon;
  form1.caption:=trayIcon1.hint;
end;

end.