[go: up one dir, main page]

Menu

[65d1b3]: / xpmakeheader.pas  Maximize  Restore  History

Download this file

574 lines (511 with data), 19.3 kB

  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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
{ $Id$
Copyright (C) 1991-2001 Peter Mandrella
Copyright (C) 2000-2002 OpenXP team (www.openxp.de)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
{ beliebig grossen Netcall- oder ZConnect-Header auswerten }
{ wird in XP3, MAGGI und XPCHECK included }
{$I xpdefine.inc }
unit xpmakeheader;
interface
uses
xpglobal, classes, xpheader;
procedure makeheader(ZConnect:boolean; var f:file; NrOfFirstRecipient: integer;
var size:longint; var hd:Theader; var ok:boolean;
PM2AMconv:boolean; ConvBrettEmpf: Boolean);
implementation
uses
xpdatum, xpnt, Xp0, SysUtils, Typeform, mime, xpmime, debug;
{ Achtung! hd.empfaenger entaelt u.U. eine /TO:-Kennung }
const
bufsize = 65535;
var line : string;
procedure makeheader(ZConnect:boolean; var f:file; NrOfFirstRecipient:integer;
var size:longint; var hd:Theader; var ok:boolean;
PM2AMconv:boolean; ConvBrettEmpf: Boolean);
var i,res : integer;
o: Integer; { Offset im Lesepuffer }
s : string;
dummy : string;
id : string;
id0 : string;
p : integer;
buf : PCharArray;
bufsize : Integer;
bufanz : Integer; { gelesene Bytes im Puffer }
tc : char; { 1. Trennzeichen hinter ':' }
idummy : Integer;
procedure ReadBuf;
begin
blockread(f,buf^,bufsize,bufanz);
o:=0;
end;
procedure getline(var s:string);
var
l: Integer;
procedure IncO;
begin
inc(o);
if o=bufanz then
if eof(f) then
ok:=false
else begin
inc(size,bufsize);
ReadBuf;
end;
end;
begin
l := o;
while l < BufAnz do
begin
if Buf^[l] = #13 then break;
inc(l);
end;
if l = BufAnz then // das letze Byte war noch kein #13, dann neue Daten holen
begin
s := '';
while (o<bufanz) and (buf^[o]<>#13) do
begin
s := s + buf^[o];
incO;
end;
IncO;
end else
begin
SetLength(s, l-o);
if l-o > 0 then
Move(Buf^[o], s[1], l-o);
o := l-1;
IncO;
IncO;
end;
if ok and (buf^[o]=#10) then IncO;
end;
procedure LRead(var s:string);
begin
s:=line;
end;
procedure GetName(var name,realname:string);
var p :integer;
begin
p:=pos(' (',line);
if (p=0) or (p<cpos('@',line)) then begin
realname:='';
name:=line;
end else begin
realname:=trim(copy(line,p+2,length(line)-p-2));
name:=LeftStr(line,p-1);
end;
end;
procedure GetEmpf;
var
p: Integer;
s: String;
begin
s := line;
if (cpos('@',s)>0) or (FirstChar(s)<>'/') then
begin
p:=pos(' (',s);
if p>0 then SetLength(s, p-1);
end;
if (hd.empfaenger.count+1=NrOfFirstRecipient) or
((NrOfFirstRecipient=0) and (hd.empfaenger.count=0)) then
hd.Empfaenger.Insert(0,s)
else
hd.Empfaenger.Add(s);
end;
procedure GetTyp(var typ,charset:string);
begin
if line<>'' then begin
if (UpperCase(line)='MIME') then typ:='M' else
if (UpperCase(line)<>'TRANSPARENT') then typ:='B';
if (typ<>'T') and (typ<>'') then charset:='';
end;
end;
procedure GetStat;
var p : integer;
begin
if line='' then exit;
UpString(line);
line:=trim(line)+' ';
repeat
p:=cpos(' ',line);
if LeftStr(line,p-1)='EB' then hd.attrib:=hd.attrib or attrIsEB else
if LeftStr(line,p-1)='PM-REPLY' then hd.pm_reply:=true else
if LeftStr(line,p-1)='NOKOP' then hd.nokop:=true else
if LeftStr(line,p-1)='CTL' then hd.attrib:=hd.attrib or attrControl;
line:=trimleft(mid(line,p+1));
until line='';
end;
procedure CheckBetreff;
var p : integer;
begin
repeat
p:=cpos(#7,hd.betreff);
if p>0 then hd.betreff[p]:=' ';
until p=0;
repeat
p:=cpos(#8,hd.betreff);
if p>0 then hd.betreff[p]:=' ';
until p=0;
end;
procedure GetStichwort;
var s : string;
begin
s := line;
if hd.keywords<>'' then hd.keywords:=hd.keywords+',';
hd.keywords:=hd.keywords+s;
end;
procedure GetCrypt;
var s : string;
begin
s := Uppercase(line);
if s='QPC' then
inc(hd.attrib,attrQPC)
else if(s='PMCRYPT2')or(s='PM-CRYPT') then
inc(hd.attrib,attrPMCrypt)
else if s='PGP' then
inc(hd.pgpflags,fPGP_encoded);
hd.crypt.method:=s;
end;
procedure GetSigned;
var
s : string;
begin
s := UpperCase(line);
if s='PGP' then
inc(hd.pgpflags,fPGP_signed)
else
if s='PGPCLEAR' then
inc(hd.pgpflags,fPGP_clearsig);
end;
procedure GetPGP;
var
s : string;
begin
s := UpperCase(line);
if s='PLEASE' then inc(hd.attrib,fPGP_please) else
if s='REQUEST' then inc(hd.pgpflags,fPGP_request);
end;
procedure GetPGPid;
var s : string;
p : integer;
begin
s := line;
p:=cpos('<',s);
if (p>0) and (lastchar(s)='>') then begin
delete(s,1,p);
DeleteLastChar(s);
if cpos('@',s)>0 then hd.pgp_uid:=s;
end;
end;
procedure GetXPpgp;
var s : string;
begin
s := LowerCase(Line);
if s='sigok' then hd.pgpflags := hd.pgpflags or fPGP_sigok else
if s='sigerror' then hd.pgpflags := hd.pgpflags or fPGP_sigerr;
end;
procedure GetQStr;
begin
with hd do begin
QuoteString := Line;
if FirstChar(quotestring)='"' then DeleteFirstChar(quotestring);
if LastChar(quotestring)='"' then DeleteLastChar(quotestring);
end;
end;
procedure GetCharset(var charset:string);
begin
if charset='' then
Charset := LowerCase(Line)
end;
procedure ParseContentType(var hd:Theader);
var pa: TMimeContentType;
begin
pa := TMimeContentType.Create(line);
if (pa.boundary <>'') then hd.boundary := pa.boundary;
if (pa.ParamValues['name']<>'') and (hd.datei ='') then hd.datei := pa.ParamValues['name'];
if (pa.Charset <>'') and (hd.x_charset='') then hd.x_charset:= pa.Charset;
// pa.Boundary:='';
// pa.Charset :='';
hd.Mime.CType := pa.AsString;
if pa.iscomposed then hd.typ := 'M';
pa.free;
end;
procedure ParseDisposition(var hd:Theader);
var pa: TMimeDisposition;
begin
pa := TMimeDisposition.Create(line);
if (pa.ParamValues['filename']<>'') and (hd.datei='') then hd.datei := pa.ParamValues['filename'];
if (pa.ParamValues['modification-date']<>'') and (hd.ddatum='') then hd.ddatum := RFC2Zdate(pa.ParamValues['modification-date']);
hd.Mime.Disposition := pa.AsString;
pa.free;
end;
procedure ParseEncoding(var hd:THeader);
var ll: string;
begin
ll:=LowerCase(line);
if ll='8bit' then hd.mime.encoding:=MimeEncoding8bit else
if ll='7bit' then hd.mime.encoding:=MimeEncoding7bit else
if ll='quoted-printable' then hd.mime.encoding:=MimeEncodingQuotedPrintable else
if ll='base64' then hd.mime.encoding:=MimeEncodingBase64 else
if ll='binary' then hd.mime.encoding:=MimeEncodingBinary else
hd.mime.encoding:=MimeEncodingUnknown;
end;
procedure CheckEmpfs; { /Brett@Box.domain -> /Brett }
function check(const s:string): String;
begin
if (cpos('@',s)>0) and (FirstChar(s)='/') then
Result := LeftStr(s, cpos('@',s)-1)
else
Result := s;
end;
var
i: Integer;
begin
with hd do
if (netztyp=nt_ZConnect) and not archive and PM2AMconv then
for i := 0 to Empfaenger.Count - 1 do
Empfaenger[i] := Check(Empfaenger[i]);
end;
begin
ok:=true;
hd.Clear;
bufsize := 2048;
getmem(buf,bufsize);
size:=0; Readbuf;
with hd do
if ZConnect then
begin
netztyp:=nt_ZConnect;
archive:=false;
typ:='T';
repeat
getline(line);
if length(line)>2 then
begin
if line[1]<' ' then DeleteFirstChar(line); { gegen LF's o.ae. }
p:=cpos(':',line);
if p<2 then ok:=false // Die ID muss mindestens ein Zeichen sein
else begin
id:=LeftStr(line,p-1);
id0:=id;
if length(line)>p then
tc:=line[p+1] { Fix: Exception bei leeren Headern }
else
tc := '_';
for i:=1 to length(id) do { UpperCase }
if (id[i]>='a') and (id[i]<='z') then
dec(byte(id[i]),32);
i:=p; { ltrim }
while (i<length(line)) and ((line[i+1]=' ') or (line[i+1]=#9)) do
inc(i);
delete(line,1,i);
line:= TrimRight(line);
if LeftStr(id,2)='U-' then { RFC }
begin
if id = 'U-KEYWORDS' then Keywords := Line else
if id = 'U-SUMMARY' then Summary := line else
if id = 'U-DISTRIBUTION' then Distribution:= line else
if id = 'U-X-NEWSREADER' then Programm:= line else
if id = 'U-X-MAILER' then Programm := line else
if id = 'U-ENCRYPTED' then GetCrypt else
if id = 'U-X-HOMEPAGE' then homepage := Line else
if id = 'U-CONTENT-TYPE' then ParseContentType(hd) else
if id = 'U-CONTENT-TRANSFER-ENCODING' then ParseEncoding(hd) else
if id = 'U-CONTENT-DISPOSITION' then ParseDisposition(hd) else
if id = 'U-CONTENT-ID' then Mime.CID := line else
{ X-No-Archive Konvertierung }
if id = 'U-X-NO-ARCHIVE' then begin
if LowerCase(line)='yes' then xnoarchive:=true;
end else
if id = 'U-X-PRIORITY' then begin
i:=ival(line);
if i<>0 then priority:=minmax(i,1,5)
end else
{ suboptimal, eigentlich sollten alle Mail-Copies-To-
Zeilen eingelesen werden, damit es auch hinter
Gateways, die MCT nicht umwandeln, funktioniert }
if (id='U-MAIL-COPIES-TO') and ((lowercase(line)='nobody')
or (lowercase(line)='never')) then
mailcopies.add(line)
else
{ Mime-Version wegschmeissen - wird neu erzeugt}
if id = 'U-MIME-VERSION' then
mime.mversion:=line
else
ULine.Add(mid(id0,3)+': '+line);
end // 'U-'
else
if id = 'MIME-TYPE' then ParseContentType(hd) else
if id = 'MIME-ENCODING' then ParseEncoding(hd) else
if id = 'MIME-VERSION' then mime.mversion := line else
if id = 'MIME-ID' then mime.Cid := line else
if id = 'EMP' then GetEmpf else { ZConnect 3.0 }
if id = 'ABS' then GetName(absender,realname) else
if id = 'BET' then betreff := Line else
if id = 'ROT' then pfad:=line else
if id = 'O-ROT' then if pfad='' then pfad:=line
else pfad:=pfad+'!'+line else
if id = 'MID' then MsgID := line else
if id = 'EDA' then begin
zdatum := line;
ZCtoZdatum(zdatum,datum);
{ if tc=' ' then xpmail:=true; }
end else
if id = 'LEN' then val(line,groesse,res) else
if id = 'KOM' then val(line,komlen,res) else
if id = 'KOP' then hd.Kopien.Add(line) else
if id = 'BEZ' then begin
if (Line<>'') then
begin
idummy := References.IndexOf(Line);
if idummy <> -1 then
begin
Debug.DebugLog('xpmakeheader.pas','makeheader,'
+'deleting first of dublicate BEZ:<'
+References[idummy]+'>'
+', first index: '+IntToStr(idummy)
, DLDebug);
References.Delete(idummy);
end;
References.Add(Line);
end
end else
if id = 'MAILER' then programm := line else
if id = 'ORG' then organisation := line else
if id = 'OEM' then hd.Oem.Add(Line) else
if id = 'OAB' then GetName(oab,oar) else
if id = 'WAB' then GetName(wab,war) else
if id = 'FILE' then datei := line else
if id = 'DDA' then ddatum := line else
if id = 'TYP' then GetTyp(hd.typ,hd.charset) else
if id = 'PRIO' then prio:=byte(minmax(ival(line),0,20)) else
if id = 'EB' then begin
GetName(empfbestto,dummy);
attrib:=attrib or attrReqEB;
end else
if id = 'STAT' then GetStat else
if id = 'CHARSET'then GetCharset(hd.charset) else
if id = 'ERR' then error := line else
if id = 'ANTWORT-AN' then GetName(ReplyTo,dummy) else
{ if id = 'DISKUSSION-IN' then GetFollowup else }
if id = 'DISKUSSION-IN' then begin
if cpos('@',line) = 0 then
followup.add(line)
else
mailcopies.add(line)
end else
if id = 'STICHWORT' then GetStichwort else
if id = 'ZUSAMMENFASSUNG' then Summary := Line else
if id = 'QUOTE-STRING' then GetQStr else
if id = 'POST' then postanschrift := Line else
if id = 'TELEFON' then telefon := Line else
if id = 'HOMEPAGE' then homepage := Line else
{ if id = 'X_C' then xpmail:=true else }
if id = 'VER' then GetName(vertreter,dummy) else
if id = 'CONTROL' then control := Line else
if id = 'ERSETZT' then ersetzt := Line else
if id = 'LDA' then expiredate := line else
if id = 'F-TO' then fido_to := line else
if leftstr(id,2) = 'F-' then
fline.add(rightstr(id,length(id)-2)+': '+line) else
if FirstChar(id)='X' then begin { XP }
if id = 'X-CHARSET' then LRead(x_charset) else
if id = 'X-XP-CHARSET' then LRead(x_charset) else
if id = 'X-XP-NTP' then netztyp:=minmax(ival(line),0,99) else {XP}
if id = 'X-XP-BOX' then LRead(real_box) else
if id = 'X-XP-PNT' then LRead(hd_point) else
if id = 'X-XP-BST' then LRead(pm_bstat) else
if id = 'X-XP-ATT' then attrib:=hexval(LeftStr(line,4)) else
if id = 'X-XP-FTO' then LRead(fido_to) else
if id = 'X-XP-MRP' then LRead(ReplyPath) else
if id = 'X-XP-RGR' then LRead(ReplyGroup) else
if id = 'X-XP-ORGMID' then LRead(org_msgid) else
if id = 'X-XP-ORGREF' then LRead(org_xref) else
if id = 'X-XP-BOUNDARY' then LRead(boundary) else
if id = 'X-XP-CTL' then XpointCtl:=ival(line) else
if id = 'X-XP-ARC' then archive:=true else
if id = 'X-XP-MODE' then LRead(XPMode) else
if tc=' ' then
if id = 'X-XP_F' then filterattr:=minmax(ival(line),0,65535);
end else
if pos('CRYPT',id)>0 then begin
if id = 'CRYPT' then GetCrypt else
if id = 'CRYPT-CONTENT-TYP' then GetTyp(crypt.typ,crypt.charset) else
if id = 'CRYPT-CONTENT-CHARSET' then GetCharset(crypt.charset) else
if id = 'CRYPT-CONTENT-KOM' then val(line,crypt.komlen,res);
end else
if id = 'SIGNED' then GetSigned else
if id = 'U-X-SIGNED' then GetSigned else
if pos('PGP',id)>0 then begin
if id = 'PGP' then GetPGP else
if id = 'U-X-PGP' then GetPGP else
if id = 'PGP-ID' then GetPGPid else
if id = 'PGP-KEY-AVAIL' then inc(pgpflags,fPGP_avail) else
if id = 'U-X-PGP-KEY-AVAIL' then inc(pgpflags,fPGP_avail) else
if id = 'PGP-PUBLIC-KEY' then inc(pgpflags,fPGP_haskey) else
if id = 'U-X-PGP-PUBLIC-KEY' then inc(pgpflags,fPGP_haskey) else
if id = 'PGP-KEY-COMPROMISE' then inc(pgpflags,fPGP_comprom) else
if id = 'X-XP-PGP' then GetXPpgp;
end
else
if id = 'ABR' then LRead(realname) else { ZConnect 1.9 }
if id = 'BIN' then typ:='B' else
if id = 'MAL' then LRead(programm)
else
// unbearbeitete X-Lines fuer UUZ merken
if Copy(id, 1, 2) = 'X-' then
XLine.Add(mid(id0,3)+': '+line) else
zline.add(id+': '+line);
{ Customizable Headerlines }
if id = UpperCase(mheadercustom[1]) then Cust1 := line
else
if id = UpperCase(mheadercustom[2]) then Cust2 := line;
line:='*';
end;
end
else { line='' }
if not ok and eof(f) then
ok:=(groesse=0); { letzte Msg hat Laenge 0 }
until (line='') or not ok;
{ "DISKUSSION-IN: foo@bar.example.org" <-> "Followup-To: poster" }
if (mailcopies.count>0) and (followup.count=0) and
(lowercase(mailcopies[0])<>'nobody') and
(lowercase(mailcopies[0])<>'never') then
pm_reply:=true;
if ok and (attrib and attrQPC<>0) and (UpperCase(LeftStr(betreff,4))<>'QPC:') then
betreff:='QPC:'+betreff;
end
else begin
Debug.DebugLog('xpmakeheader','buffer type not zconnect?!',dlWarning);
GetLine(s);
Empfaenger.Add(TrimRight(s));
getline(betreff);
Betreff := TrimLeft(Betreff);
getline(absender);
getline(datum);
getline(pfad);
getline(msgid);
getline(typ);
getline(s);
val(trim(s),groesse,res);
end;
freemem(buf,bufsize);
CheckBetreff;
if ConvBrettEmpf then
CheckEmpfs; { /Brett@Box.domain -> /Brett }
inc(size,o);
if res<>0 then ok:=false;
end;
end.