Skip to content

Latest commit

 

History

History
403 lines (360 loc) · 9.27 KB

mail0.pas

File metadata and controls

403 lines (360 loc) · 9.27 KB
 
Nov 18, 2000
Nov 18, 2000
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
{$A+,B+,D-,E+,F+,I+,L+,N-,O+,R-,S+,V-}
unit mail0;
interface
uses
crt, dos,
{rcg11172000 no overlay under Linux.}
{overlay,}
common, timejunk;
const
_brd_opened:boolean=FALSE; { has brdf been opened yet? }
oldnummsgs:integer=0; { old number of messages }
gotlastmheader:boolean=FALSE;
type
pinforec=record
xbrdfnopen:string[160];
xbread,xmintabloaded:longint;
xopen:boolean;
end;
var
brdfnopen:string; { what *.BRD filename is open }
lastmheader:mheaderrec;
wasyourmsg:boolean;
procedure blockwritestr2(var f:file; s:string);
procedure blockreadstr2(var f:file; var s:string);
function getmixnum(x:word):word;
function getmintab(x:word):word;
procedure loadmintab(x:word);
procedure ensureloaded(x:word);
procedure loadmhead1(var brdf:file; x:word; var mhead:mheaderrec);
procedure savemhead1(var brdf:file; mhead:mheaderrec);
procedure loadmhead(x:word; var mhead:mheaderrec);
procedure savemhead(mhead:mheaderrec);
procedure savemix(mixr:msgindexrec; x:word);
procedure newmix(mixr:msgindexrec);
procedure outmessagetext(fn:string; var mhead:mheaderrec; eraseit:boolean);
procedure findhimsg;
procedure initbrd(x:integer);
procedure closebrd;
function forwardm(n:integer):integer;
function moremail(u:userrec; un,what:word):boolean;
procedure savepinfo(var x:pinforec);
procedure loadpinfo(x:pinforec);
procedure delmail(x:integer);
function rmail(x:integer):string; { bread must = -1 }
implementation
procedure blockwritestr2(var f:file; s:string);
var bb:byte;
begin
bb:=$FF;
blockwrite(f,bb,1);
blockwrite(f,s[0],1);
blockwrite(f,s[1],ord(s[0]));
end;
procedure blockreadstr2(var f:file; var s:string);
begin
blockread(f,s[0],1); { filler-chr }
if (ord(s[0])<>$FF) then exit;
blockread(f,s[0],1);
blockread(f,s[1],ord(s[0]));
end;
function getmixnum(x:word):word;
begin
getmixnum:=x mod 100;
end;
function getmintab(x:word):word;
begin
getmintab:=x div 100;
end;
procedure loadmintab(x:word);
var lng:longint;
numread:word;
i,j:integer;
begin
lng:=x*100; (* stupid *#@$(@($#*($ TP typecasting... *)
while ((lng>=filesize(mixf)) and (x>0)) do begin
dec(x);
lng:=x*100;
end;
mintaboffset:=x*100;
seek(mixf,mintaboffset);
blockread(mixf,mintab,100,numread);
if (numread<>100) then begin
for i:=numread to 99 do begin
mintab[i].messagenum:=0;
mintab[i].hdrptr:=-1;
mintab[i].msgid:=memboard.lastmsgid;
mintab[i].isreplytoid:=0;
for j:=1 to 6 do mintab[i].msgdate[i]:=0;
mintab[i].msgdowk:=0;
mintab[i].msgindexstat:=[];
mintab[i].isreplyto:=65535;
mintab[i].numreplys:=0;
end;
seek(mixf,mintaboffset);
blockwrite(mixf,mintab,100); { fill remainder with garbage .. }
end;
mintabloaded:=x;
end;
procedure ensureloaded(x:word);
var i:word;
begin
i:=getmintab(x);
if (i<>mintabloaded) then loadmintab(i);
end;
procedure loadmhead1(var brdf:file; x:word; var mhead:mheaderrec);
begin
blockread(brdf,mhead,sizeof(mheaderrec));
end;
{ caller must postition to correct place in brdf .... }
procedure savemhead1(var brdf:file; mhead:mheaderrec);
begin
blockwrite(brdf,mhead,sizeof(mheaderrec));
end;
procedure loadmhead(x:word; var mhead:mheaderrec);
begin
ensureloaded(x);
seek(brdf,mintab[getmixnum(x)].hdrptr);
loadmhead1(brdf,x,mhead);
end;
procedure savemhead(mhead:mheaderrec);
begin
savemhead1(brdf,mhead);
end;
procedure savemix(mixr:msgindexrec; x:word);
begin
loadmintab(getmintab(x));
seek(mixf,mintaboffset+getmixnum(x));
blockwrite(mixf,mixr,1);
loadmintab(getmintab(x));
end;
procedure newmix(mixr:msgindexrec);
var lng:longint;
i,j:integer;
begin
if ((getmixnum(himsg+1)=0) and (himsg>-1)) then begin
for i:=0 to 99 do begin
mintab[i].messagenum:=0;
mintab[i].hdrptr:=-1;
mintab[i].msgid:=memboard.lastmsgid;
mintab[i].isreplytoid:=0;
for j:=1 to 6 do mintab[i].msgdate[i]:=0;
mintab[i].msgdowk:=0;
mintab[i].msgindexstat:=[];
mintab[i].isreplyto:=65535;
mintab[i].numreplys:=0;
end;
inc(himintab);
seek(mixf,himintab*100); blockwrite(mixf,mintab[0],100);
end;
inc(himsg); savemix(mixr,himsg);
end;
procedure outmessagetext(fn:string; var mhead:mheaderrec; eraseit:boolean);
var t:text;
f:file;
s:string;
lng:longint;
begin
assign(t,fn);
{$I-} reset(t); {$I+}
if (ioresult<>0) then exit;
lng:=filesize(brdf);
seek(brdf,lng);
mhead.msgptr:=lng+sizeof(mheaderrec);
savemhead(mhead);
while (not eof(t)) do begin
readln(t,s);
blockwritestr2(brdf,s);
end;
close(t);
if (eraseit) then erase(t);
end;
procedure findhimsg;
var mixr:msgindexrec;
lng:longint;
numread:word;
begin
himintab:=(filesize(mixf)-1) div 100;
himsg:=himintab*100-1;
seek(mixf,himsg+1);
repeat
lng:=himsg;
blockread(mixf,mixr,1,numread);
if ((numread=1) and (mixr.hdrptr<>-1)) then inc(himsg);
until (lng=himsg);
end;
procedure initbrd(x:integer); { x=-1 = e-mail }
var mixr:msgindexrec;
fn:string;
lng:longint;
numread:word;
i,j:integer;
begin
closebrd;
bread:=x;
if (x=-1) then fn:='EMAIL' else begin
loadboard(x);
fn:=memboard.filename;
end;
fn:=allcaps(fn);
brdfnopen:=fn;
assign(mixf,systat.msgpath+fn+'.MIX');
{$I-} reset(mixf,sizeof(mixr)); {$I+}
if (ioresult<>0) then begin
rewrite(mixf,sizeof(mixr));
for i:=0 to 99 do begin
mintab[i].messagenum:=0;
mintab[i].hdrptr:=-1;
mintab[i].msgid:=memboard.lastmsgid;
mintab[i].isreplytoid:=0;
for j:=1 to 6 do mintab[i].msgdate[i]:=0;
mintab[i].msgdowk:=0;
mintab[i].msgindexstat:=[];
mintab[i].isreplyto:=65535;
mintab[i].numreplys:=0;
end;
blockwrite(mixf,mintab[0],100);
end;
assign(brdf,systat.msgpath+fn+'.BRD');
{$I-} reset(brdf,1); {$I+}
if (ioresult<>0) then rewrite(brdf,1);
findhimsg;
loadmintab(himintab);
_brd_opened:=TRUE;
gotlastmheader:=FALSE;
end;
procedure closebrd;
begin
if (_brd_opened) then begin
if (filerec(brdf).mode<>fmclosed) then close(brdf);
if (filerec(mixf).mode<>fmclosed) then close(mixf);
end;
filerec(brdf).mode:=fmclosed;
filerec(mixf).mode:=fmclosed;
end;
{ this routine will find the user that user n is forwarding their mail to.
it will also check to get around "circular forwarding", such as:
5 -> 10 -> 15 -> 5 ... }
function forwardm(n:integer):integer;
var chk:array[1..1250] of byte; { 1250 * 8 = 10000 users max }
cur:integer;
u:userrec;
done:boolean;
function chkval(i:integer):boolean;
begin
dec(i);
chkval:=((chk[i div 8] and (1 shl (i mod 8)))<>0);
end;
procedure chkset(i:integer);
var bb,bc:byte;
begin
dec(i);
bb:=chk[i div 8]; bc:=(1 shl(i mod 8));
if ((bb and bc)=0) then chk[i div 8]:=chk[i div 8]+bc;
end;
begin
for cur:=1 to 1250 do
chk[cur]:=0;
cur:=n;
done:=FALSE;
while not done do
if (chkval(cur)) then begin
done:=TRUE;
cur:=0;
end else
if (cur<filesize(uf)) and (cur>0) then begin
seek(uf,cur); read(uf,u);
if (u.deleted) then begin
done:=TRUE;
cur:=0;
end else begin
if (u.forusr=0) then begin
done:=TRUE;
end else begin
chkset(cur);
cur:=u.forusr;
end;
end;
end else begin
done:=TRUE;
cur:=0;
end;
forwardm:=cur;
end;
{
1: user has too much mail waiting already
2: user mailbox is closed
3: user is deleted
4: can't send mail to yourself! <idiot!>
}
function moremail(u:userrec; un,what:word):boolean;
begin
moremail:=TRUE;
case what of
1:moremail:=(not (((aacs1(u,un,systat.csop)) and
(u.waiting>=systat.csmaxwaiting)) or
((not aacs1(u,un,systat.csop)) and (u.waiting>=systat.maxwaiting))));
2:moremail:=(not (nomail in u.ac));
3:moremail:=(not (u.deleted));
4:moremail:=(not ((un=usernum) and (not cso)));
end;
end;
procedure savepinfo(var x:pinforec);
begin
with x do begin
xbread:=bread;
xbrdfnopen:=brdfnopen;
xopen:=FALSE;
if (not _brd_opened) then xopen:=FALSE
else if (filerec(mixf).mode<>fmclosed) then xopen:=TRUE;
end;
end;
procedure loadpinfo(x:pinforec);
begin
closebrd;
with x do begin
brdfnopen:=xbrdfnopen;
if (xopen) then begin
initbrd(xbread);
loadmintab(0);
end;
end;
end;
{ toggles "existance" flag. If normal, deletes it -- otherwise, undeletes }
procedure delmail(x:integer);
var mixr:msgindexrec;
begin
ensureloaded(x);
mixr:=mintab[getmixnum(x)];
if (miexist in mixr.msgindexstat) then
mixr.msgindexstat:=mixr.msgindexstat-[miexist]
else
mixr.msgindexstat:=mixr.msgindexstat+[miexist];
savemix(mixr,x);
ensureloaded(x);
end;
function rmail(x:integer):string; { bread must = -1 }
var u:userrec;
mheader:mheaderrec;
i:integer;
ufo:boolean;
begin
loadmhead(x,mheader);
with mheader do begin
rmail:=caps(fromi.alias)+' #'+cstr(fromi.usernum);
ufo:=(filerec(uf).mode<>fmclosed);
if (not ufo) then reset(uf);
if ((toi.usernum>=1) and (toi.usernum<=filesize(uf)-1)) then begin
if (toi.usernum=usernum) then dec(thisuser.waiting);
seek(uf,toi.usernum);
read(uf,u);
dec(u.waiting);
seek(uf,toi.usernum);
write(uf,u);
end;
if (not ufo) then close(uf);
end;
delmail(x);
mailread:=TRUE;
end;
end.