|
|
1.1 root 1: /* readmail.cpp */
2:
3: /* Synchronet private mail reading function */
4:
1.1.1.2 ! root 5: /* $Id: readmail.cpp,v 1.33 2004/11/22 20:19:47 deuce Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: /****************************************************************************/
41: /* Reads mail waiting for usernumber. */
42: /****************************************************************************/
43: void sbbs_t::readmail(uint usernumber, int which)
44: {
45: char str[256],str2[256],str3[256],done=0,domsg=1
46: ,*p,*tp,*sp,ch;
47: char tmp[512];
48: int i,j;
1.1.1.2 ! root 49: int error;
1.1 root 50: int mismatches=0,act;
51: ulong msgs,curmsg;
52: long length,l,lm_mode;
53: ulong last;
54: bool replied;
55: file_t fd;
56: mail_t *mail;
57: smbmsg_t msg;
58:
1.1.1.2 ! root 59: if(which==MAIL_SENT && useron.rest&FLAG('K')) {
! 60: bputs(text[R_ReadSentMail]);
! 61: return;
! 62: }
! 63:
1.1 root 64: msg.total_hfields=0; /* init to NULL, cause not allocated yet */
65:
66: fd.dir=cfg.total_dirs+1; /* temp dir for file attachments */
67:
68: if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) {
69: errormsg(WHERE,ERR_OPEN,"MAIL",i);
70: return; }
71: sprintf(smb.file,"%smail",cfg.data_dir);
72: smb.retry_time=cfg.smb_retry_time;
1.1.1.2 ! root 73: smb.subnum=INVALID_SUB;
1.1 root 74: if((i=smb_open(&smb))!=0) {
75: smb_stack(&smb,SMB_STACK_POP);
76: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
77: return; }
78:
79: if(cfg.sys_misc&SM_SYSVDELM && (SYSOP || cfg.sys_misc&SM_USRVDELM))
80: lm_mode=LM_INCDEL;
81: else
82: lm_mode=0;
83: mail=loadmail(&smb,&msgs,usernumber,which,lm_mode);
84: if(!msgs) {
85: if(which==MAIL_SENT)
86: bputs(text[NoMailSent]);
87: else if(which==MAIL_ALL)
88: bputs(text[NoMailOnSystem]);
89: else
90: bputs(text[NoMailWaiting]);
91: smb_close(&smb);
92: smb_stack(&smb,SMB_STACK_POP);
93: return; }
94:
95: last=smb.status.last_msg;
96:
97: if(which==MAIL_SENT)
98: act=NODE_RSML;
99: else if(which==MAIL_ALL)
100: act=NODE_SYSP;
101: else
102: act=NODE_RMAL;
103: action=act;
104: if(msgs>1 && which!=MAIL_ALL) {
105: if(which==MAIL_SENT)
106: bputs(text[MailSentLstHdr]);
107: else
108: bputs(text[MailWaitingLstHdr]);
109:
110: for(curmsg=0;curmsg<msgs && !msgabort();curmsg++) {
111: if(msg.total_hfields)
112: smb_freemsgmem(&msg);
113: msg.total_hfields=0;
114: msg.idx.offset=mail[curmsg].offset;
115: if(!loadmsg(&msg,mail[curmsg].number))
116: continue;
117: smb_unlockmsghdr(&smb,&msg);
118: bprintf(text[MailWaitingLstFmt],curmsg+1
119: ,which==MAIL_SENT ? msg.to
120: : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP ? text[Anonymous]
121: : msg.from
122: ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
123: : msg.hdr.attr&MSG_READ ? ' '
124: : msg.from_net.type || msg.to_net.type ? 'N':'*'
125: ,msg.subj);
126: smb_freemsgmem(&msg);
127: msg.total_hfields=0; }
128:
129: ASYNC;
130: if(!(sys_status&SS_ABORT)) {
131: bprintf(text[StartWithN],1L);
132: if((long)(curmsg=getnum(msgs))>0)
133: curmsg--;
1.1.1.2 ! root 134: else if((long)curmsg==-1) {
1.1 root 135: FREE(mail);
136: smb_close(&smb);
137: smb_stack(&smb,SMB_STACK_POP);
138: return; } }
139: sys_status&=~SS_ABORT; }
140: else {
141: curmsg=0;
142: if(which==MAIL_ALL)
143: domsg=0; }
1.1.1.2 ! root 144: if(which==MAIL_SENT) {
! 145: sprintf(str,"%s read sent mail",useron.alias);
! 146: logline("E",str);
! 147: } else if(which==MAIL_ALL) {
! 148: sprintf(str,"%s read all mail",useron.alias);
! 149: logline("S+",str);
! 150: } else {
! 151: sprintf(str,"%s read mail",useron.alias);
! 152: logline("E",str);
! 153: }
1.1 root 154: if(useron.misc&RIP) {
1.1.1.2 ! root 155: strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ?
! 156: "allmail" : "sentmail");
1.1 root 157: menu(str); }
158: while(online && !done) {
159: action=act;
160:
161: if(msg.total_hfields)
162: smb_freemsgmem(&msg);
163: msg.total_hfields=0;
164:
165: msg.idx.offset=mail[curmsg].offset;
166: msg.idx.number=mail[curmsg].number;
167: msg.idx.to=mail[curmsg].to;
168: msg.idx.from=mail[curmsg].from;
169: msg.idx.subj=mail[curmsg].subj;
170:
171: if((i=smb_locksmbhdr(&smb))!=0) {
172: errormsg(WHERE,ERR_LOCK,smb.file,i);
173: break; }
174:
175: if((i=smb_getstatus(&smb))!=0) {
176: smb_unlocksmbhdr(&smb);
177: errormsg(WHERE,ERR_READ,smb.file,i);
178: break; }
179: smb_unlocksmbhdr(&smb);
180:
181: if(smb.status.last_msg!=last) { /* New messages */
182: last=smb.status.last_msg;
183: FREE(mail);
184: mail=loadmail(&smb,&msgs,usernumber,which,lm_mode); /* So re-load */
185: if(!msgs)
186: break;
187: for(curmsg=0;curmsg<msgs;curmsg++)
188: if(mail[curmsg].number==msg.idx.number)
189: break;
190: if(curmsg>=msgs)
191: curmsg=(msgs-1);
192: continue; }
193:
194: if(!loadmsg(&msg,mail[curmsg].number)) { /* Message header gone */
195: if(mismatches>5) { /* We can't do this too many times in a row */
196: errormsg(WHERE,ERR_CHK,"message number",mail[curmsg].number);
197: break; }
198: FREE(mail);
199: mail=loadmail(&smb,&msgs,usernumber,which,lm_mode);
200: if(!msgs)
201: break;
202: if(curmsg>(msgs-1))
203: curmsg=(msgs-1);
204: mismatches++;
205: continue; }
206: smb_unlockmsghdr(&smb,&msg);
207: msg.idx.attr=msg.hdr.attr;
208:
209: mismatches=0;
210:
211: if(domsg && !(sys_status&SS_ABORT)) {
212:
213: show_msg(&msg
214: ,msg.from_ext && msg.idx.from==1 && !msg.from_net.type
215: ? 0:P_NOATCODES);
216:
217: if(msg.hdr.auxattr&MSG_FILEATTACH) { /* Attached file */
218: smb_getmsgidx(&smb,&msg);
219: strcpy(str,msg.subj); /* filenames in title */
1.1.1.2 ! root 220: // strupr(str);
1.1 root 221: tp=str;
222: while(online) {
1.1.1.2 ! root 223: p=strchr(tp,' ');
1.1 root 224: if(p) *p=0;
225: sp=strrchr(tp,'/'); /* sp is slash pointer */
226: if(!sp) sp=strrchr(tp,'\\');
227: if(sp) tp=sp+1;
228: padfname(tp,fd.name);
229: sprintf(str2,"%sfile/%04u.in/%s" /* str2 is path/fname */
230: ,cfg.data_dir,msg.idx.to,tp);
231: length=flength(str2);
232: if(length<1)
233: bputs(text[FileNotFound]);
234: else if(!(useron.exempt&FLAG('T')) && cur_cps && !SYSOP
235: && length/(long)cur_cps>(time_t)timeleft)
236: bputs(text[NotEnoughTimeToDl]);
237: else {
238: sprintf(str3,text[DownloadAttachedFileQ]
239: ,tp,ultoac(length,tmp));
240: if(length>0L && yesno(str3)) {
241: if(online==ON_LOCAL) {
242: bputs(text[EnterPath]);
243: if(getstr(str3,60,K_LINE|K_UPPER)) {
244: backslashcolon(str3);
245: sprintf(tmp,"%s%s",str3,tp);
246: if(!mv(str2,tmp,which!=MAIL_YOUR)) {
247: logon_dlb+=length;
248: logon_dls++;
249: useron.dls=(ushort)adjustuserrec(&cfg,useron.number
250: ,U_DLS,5,1);
251: useron.dlb=adjustuserrec(&cfg,useron.number
252: ,U_DLB,10,length);
253: bprintf(text[FileNBytesSent]
254: ,fd.name,ultoac(length,tmp)); } } }
255:
256: else { /* Remote User */
1.1.1.2 ! root 257: xfer_prot_menu(XFER_DOWNLOAD);
1.1 root 258: mnemonics(text[ProtocolOrQuit]);
259: strcpy(str3,"Q");
260: for(i=0;i<cfg.total_prots;i++)
261: if(cfg.prot[i]->dlcmd[0]
262: && chk_ar(cfg.prot[i]->ar,&useron)) {
263: sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
264: strcat(str3,tmp); }
265: ch=(char)getkeys(str3,0);
266: for(i=0;i<cfg.total_prots;i++)
267: if(cfg.prot[i]->dlcmd[0] && ch==cfg.prot[i]->mnemonic
268: && chk_ar(cfg.prot[i]->ar,&useron))
269: break;
270: if(i<cfg.total_prots) {
1.1.1.2 ! root 271: error=protocol(cfg.prot[i],XFER_DOWNLOAD,str2,nulstr,false);
! 272: if(checkprotresult(cfg.prot[i],error,&fd)) {
! 273: if(which==MAIL_YOUR)
! 274: remove(str2);
! 275: logon_dlb+=length; /* Update stats */
! 276: logon_dls++;
! 277: useron.dls=(ushort)adjustuserrec(&cfg,useron.number
! 278: ,U_DLS,5,1);
! 279: useron.dlb=adjustuserrec(&cfg,useron.number
! 280: ,U_DLB,10,length);
! 281: bprintf(text[FileNBytesSent]
! 282: ,fd.name,ultoac(length,tmp));
! 283: sprintf(str3
! 284: ,"%s downloaded attached file: %s"
! 285: ,useron.alias
! 286: ,fd.name);
! 287: logline("D-",str3);
! 288: }
! 289: autohangup();
! 290: }
! 291: }
! 292: }
! 293: }
! 294: if(!p)
! 295: break;
! 296: tp=p+1;
! 297: while(*tp==' ') tp++;
! 298: }
1.1 root 299: sprintf(str,"%sfile/%04u.in",cfg.data_dir,usernumber);
300: rmdir(str); }
301: if(which==MAIL_YOUR && !(msg.hdr.attr&MSG_READ)) {
302: mail[curmsg].attr|=MSG_READ;
303: if(thisnode.status==NODE_INUSE)
304: telluser(&msg);
305: if(msg.total_hfields)
306: smb_freemsgmem(&msg);
307: msg.total_hfields=0;
308: msg.idx.offset=0; /* Search by number */
309: if(!smb_locksmbhdr(&smb)) { /* Lock the entire base */
310: if(loadmsg(&msg,msg.idx.number)) {
311: msg.hdr.attr|=MSG_READ;
312: msg.idx.attr=msg.hdr.attr;
313: if((i=smb_putmsg(&smb,&msg))!=0)
314: errormsg(WHERE,ERR_WRITE,smb.file,i);
315: smb_unlockmsghdr(&smb,&msg); }
316: smb_unlocksmbhdr(&smb); }
317: if(!msg.total_hfields) { /* unsuccessful reload */
318: domsg=0;
319: continue; } }
320: }
321: else domsg=1;
322:
323: if(useron.misc&WIP) {
1.1.1.2 ! root 324: strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL ?
! 325: "allmail" : "sentmail");
1.1 root 326: menu(str); }
327:
328: ASYNC;
329: if(which==MAIL_SENT)
330: bprintf(text[ReadingSentMail],curmsg+1,msgs);
331: else if(which==MAIL_ALL)
332: bprintf(text[ReadingAllMail],curmsg+1,msgs);
333: else
334: bprintf(text[ReadingMail],curmsg+1,msgs);
335: sprintf(str,"ADFLNQRT?<>[]{}-+");
336: if(SYSOP)
1.1.1.2 ! root 337: strcat(str,"CUSPH");
1.1 root 338: if(which!=MAIL_YOUR)
339: strcat(str,"E");
340: l=getkeys(str,msgs);
341: if(l&0x80000000L) {
342: if(l==-1) /* ctrl-c */
343: break;
344: curmsg=(l&~0x80000000L)-1;
345: continue; }
346: switch(l) {
347: case 'A': /* Auto-reply to last piece */
348: case 'R':
349: if(l==(cfg.sys_misc&SM_RA_EMU ? 'A' : 'R')) /* re-read last message */
350: break;
351:
352: if(which==MAIL_SENT)
353: break;
354: if((msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP) {
355: bputs(text[CantReplyToAnonMsg]);
356: break; }
357:
358: quotemsg(&msg,1);
359:
1.1.1.2 ! root 360: if(msg.from_net.addr==NULL)
! 361: strcpy(str,msg.from);
! 362: else if(msg.from_net.type==NET_FIDO) /* FidoNet type */
! 363: sprintf(str,"%s@%s",msg.from
! 364: ,smb_faddrtoa((faddr_t *)msg.from_net.addr,tmp));
1.1 root 365: else if(msg.from_net.type==NET_INTERNET)
366: strcpy(str,(char *)msg.from_net.addr);
1.1.1.2 ! root 367: else
! 368: sprintf(str,"%s@%s",msg.from,(char*)msg.from_net.addr);
1.1 root 369:
370: strcpy(str2,str);
371:
372: bputs(text[Email]);
373: if(!getstr(str,64,K_EDIT|K_AUTODEL))
374: break;
375: msg.hdr.number=msg.idx.number;
376: smb_getmsgidx(&smb,&msg);
377:
378: if(!stricmp(str2,str)) /* Reply to sender */
379: sprintf(str2,text[Regarding],msg.subj);
380: else /* Reply to other */
381: sprintf(str2,text[RegardingByOn],msg.subj,msg.from
382: ,timestr((time_t *)&msg.hdr.when_written.time));
383:
384: p=strrchr(str,'@');
385: if(p) { /* name @addr */
386: replied=netmail(str,msg.subj,WM_QUOTE);
387: sprintf(str2,text[DeleteMailQ],msg.from); }
388: else {
389: if(!msg.from_net.type && !stricmp(str,msg.from))
390: replied=email(msg.idx.from,str2,msg.subj,WM_EMAIL|WM_QUOTE);
391: else if(!stricmp(str,"SYSOP"))
392: replied=email(1,str2,msg.subj,WM_EMAIL|WM_QUOTE);
393: else if((i=finduser(str))!=0)
394: replied=email(i,str2,msg.subj,WM_EMAIL|WM_QUOTE);
1.1.1.2 ! root 395: else
! 396: replied=false;
1.1 root 397: sprintf(str2,text[DeleteMailQ],msg.from); }
398:
399: if(replied==true && !(msg.hdr.attr&MSG_REPLIED)) {
400: if(msg.total_hfields)
401: smb_freemsgmem(&msg);
402: msg.total_hfields=0;
403: msg.idx.offset=0;
404: if(loadmsg(&msg,msg.idx.number)) {
405: msg.hdr.attr|=MSG_REPLIED;
406: msg.idx.attr=msg.hdr.attr;
407: if((i=smb_putmsg(&smb,&msg))!=0)
408: errormsg(WHERE,ERR_WRITE,smb.file,i);
409: smb_unlockmsghdr(&smb,&msg); }
410: }
411:
1.1.1.2 ! root 412: if(msg.hdr.attr&MSG_DELETE || !yesno(str2)) {
1.1 root 413: if(curmsg<msgs-1) curmsg++;
414: else done=1;
415: break; }
416: /* Case 'D': must follow! */
417: case 'D': /* Delete last piece (toggle) */
418: if(msg.hdr.attr&MSG_PERMANENT) {
419: bputs("\r\nPermanent message.\r\n");
420: domsg=0;
421: break; }
422: if(msg.total_hfields)
423: smb_freemsgmem(&msg);
424: msg.total_hfields=0;
425: msg.idx.offset=0;
426: if(loadmsg(&msg,msg.idx.number)) {
427: msg.hdr.attr^=MSG_DELETE;
428: msg.idx.attr=msg.hdr.attr;
429: // mail[curmsg].attr=msg.hdr.attr;
430: if((i=smb_putmsg(&smb,&msg))!=0)
431: errormsg(WHERE,ERR_WRITE,smb.file,i);
432: smb_unlockmsghdr(&smb,&msg); }
433: if(curmsg<msgs-1) curmsg++;
434: else done=1;
435: break;
436: case 'F': /* Forward last piece */
437: domsg=0;
438: bputs(text[ForwardMailTo]);
1.1.1.2 ! root 439: if(!getstr(str,LEN_ALIAS,cfg.uq&UQ_NOUPRLWR ? K_NONE:K_UPRLWR))
1.1 root 440: break;
441: i=finduser(str);
442: if(!i)
443: break;
444: domsg=1;
445: if(curmsg<msgs-1) curmsg++;
446: else done=1;
447: smb_getmsgidx(&smb,&msg);
448: forwardmail(&msg,i);
449: if(msg.hdr.attr&MSG_PERMANENT)
450: break;
451: sprintf(str2,text[DeleteMailQ],msg.from);
452: if(!yesno(str2))
453: break;
454: if(msg.total_hfields)
455: smb_freemsgmem(&msg);
456: msg.total_hfields=0;
457: msg.idx.offset=0;
458: if(loadmsg(&msg,msg.idx.number)) {
459: msg.hdr.attr|=MSG_DELETE;
460: msg.idx.attr=msg.hdr.attr;
461: // mail[curmsg].attr=msg.hdr.attr;
462: if((i=smb_putmsg(&smb,&msg))!=0)
463: errormsg(WHERE,ERR_WRITE,smb.file,i);
464: smb_unlockmsghdr(&smb,&msg); }
465:
466: break;
1.1.1.2 ! root 467: case 'H':
! 468: domsg=0;
! 469: msghdr(&msg);
! 470: break;
1.1 root 471: case 'L': /* List mail */
472: domsg=0;
473: bprintf(text[StartWithN],(long)curmsg+1);
474: if((i=getnum(msgs))>0)
475: i--;
476: else if(i==-1)
477: break;
478: else
479: i=curmsg;
480: if(which==MAIL_SENT)
481: bputs(text[MailSentLstHdr]);
482: else if(which==MAIL_ALL)
483: bputs(text[MailOnSystemLstHdr]);
484: else
485: bputs(text[MailWaitingLstHdr]);
486: for(;(ulong)i<msgs && !msgabort();i++) {
487: if(msg.total_hfields)
488: smb_freemsgmem(&msg);
489: msg.total_hfields=0;
490: msg.idx.offset=mail[i].offset;
491: if(!loadmsg(&msg,mail[i].number))
492: continue;
493: smb_unlockmsghdr(&smb,&msg);
494: if(which==MAIL_ALL)
495: bprintf(text[MailOnSystemLstFmt]
496: ,i+1,msg.from,msg.to
497: ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
1.1.1.2 ! root 498: : msg.hdr.attr&MSG_READ ? ' '
1.1 root 499: : msg.from_net.type || msg.to_net.type ? 'N':'*'
500: ,msg.subj);
501: else
502: bprintf(text[MailWaitingLstFmt],i+1
503: ,which==MAIL_SENT ? msg.to
504: : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP
505: ? text[Anonymous] : msg.from
506: ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
1.1.1.2 ! root 507: : msg.hdr.attr&MSG_READ ? ' '
1.1 root 508: : msg.from_net.type || msg.to_net.type ? 'N':'*'
509: ,msg.subj);
510: smb_freemsgmem(&msg);
511: msg.total_hfields=0; }
512: break;
513: case 'Q':
514: done=1;
515: break;
516: case 'C': /* Change attributes of last piece */
517: i=chmsgattr(msg.hdr.attr);
518: if(msg.hdr.attr==i)
519: break;
520: if(msg.total_hfields)
521: smb_freemsgmem(&msg);
522: msg.total_hfields=0;
523: msg.idx.offset=0;
524: if(loadmsg(&msg,msg.idx.number)) {
525: msg.hdr.attr=msg.idx.attr=(ushort)i;
526: if((i=smb_putmsg(&smb,&msg))!=0)
527: errormsg(WHERE,ERR_WRITE,smb.file,i);
528: smb_unlockmsghdr(&smb,&msg); }
529: break;
530: case '>':
531: for(i=curmsg+1;(ulong)i<msgs;i++)
532: if(mail[i].subj==msg.idx.subj)
533: break;
534: if((ulong)i<msgs)
535: curmsg=i;
536: else
537: domsg=0;
538: break;
539: case '<': /* Search Title backward */
540: for(i=curmsg-1;i>-1;i--)
541: if(mail[i].subj==msg.idx.subj)
542: break;
543: if(i>-1)
544: curmsg=i;
545: else
546: domsg=0;
547: break;
548: case '}': /* Search Author forward */
549: strcpy(str,msg.from);
550: for(i=curmsg+1;(ulong)i<msgs;i++)
551: if(mail[i].from==msg.idx.from)
552: break;
553: if((ulong)i<msgs)
554: curmsg=i;
555: else
556: domsg=0;
557: break;
558: case 'N': /* Got to next un-read message */
559: for(i=curmsg+1;(ulong)i<msgs;i++)
560: if(!(mail[i].attr&MSG_READ))
561: break;
562: if((ulong)i<msgs)
563: curmsg=i;
564: else
565: domsg=0;
566: break;
567: case '{': /* Search Author backward */
568: strcpy(str,msg.from);
569: for(i=curmsg-1;i>-1;i--)
570: if(mail[i].from==msg.idx.from)
571: break;
572: if(i>-1)
573: curmsg=i;
574: else
575: domsg=0;
576: break;
577: case ']': /* Search To User forward */
578: strcpy(str,msg.to);
579: for(i=curmsg+1;(ulong)i<msgs;i++)
580: if(mail[i].to==msg.idx.to)
581: break;
582: if((ulong)i<msgs)
583: curmsg=i;
584: else
585: domsg=0;
586: break;
587: case '[': /* Search To User backward */
588: strcpy(str,msg.to);
1.1.1.2 ! root 589: for(i=curmsg-1;i>-1;i--)
1.1 root 590: if(mail[i].to==msg.idx.to)
591: break;
1.1.1.2 ! root 592: if(i>-1)
1.1 root 593: curmsg=i;
594: else
595: domsg=0;
596: break;
597: case 0:
598: case '+':
599: if(curmsg<msgs-1) curmsg++;
600: else done=1;
601: break;
602: case '-':
603: if(curmsg>0) curmsg--;
604: break;
605: case 'S':
606: domsg=0;
607: /*
608: if(!yesno(text[SaveMsgToFile]))
609: break;
610: */
611: bputs(text[FileToWriteTo]);
612: if(getstr(str,40,K_LINE|K_UPPER))
613: msgtotxt(&msg,str,1,1);
614: break;
615: case 'E':
616: editmsg(&msg,INVALID_SUB);
617: break;
618: case 'T':
619: domsg=0;
620: i=curmsg;
621: if(i) i++;
622: j=i+10;
623: if((ulong)j>msgs)
624: j=msgs;
625:
626: if(which==MAIL_SENT)
627: bputs(text[MailSentLstHdr]);
628: else if(which==MAIL_ALL)
629: bputs(text[MailOnSystemLstHdr]);
630: else
631: bputs(text[MailWaitingLstHdr]);
632: for(;i<j;i++) {
633: if(msg.total_hfields)
634: smb_freemsgmem(&msg);
635: msg.total_hfields=0;
636: msg.idx.offset=mail[i].offset;
637: if(!loadmsg(&msg,mail[i].number))
638: continue;
639: smb_unlockmsghdr(&smb,&msg);
640: if(which==MAIL_ALL)
641: bprintf(text[MailOnSystemLstFmt]
642: ,i+1,msg.from,msg.to
643: ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
1.1.1.2 ! root 644: : msg.hdr.attr&MSG_READ ? ' '
1.1 root 645: : msg.from_net.type || msg.to_net.type ? 'N':'*'
646: ,msg.subj);
647: else
648: bprintf(text[MailWaitingLstFmt],i+1
649: ,which==MAIL_SENT ? msg.to
650: : (msg.hdr.attr&MSG_ANONYMOUS) && !SYSOP
651: ? text[Anonymous] : msg.from
652: ,msg.hdr.attr&MSG_DELETE ? '-' : msg.hdr.attr&MSG_REPLIED ? 'R'
1.1.1.2 ! root 653: : msg.hdr.attr&MSG_READ ? ' '
1.1 root 654: : msg.from_net.type || msg.to_net.type ? 'N':'*'
655: ,msg.subj);
656: smb_freemsgmem(&msg);
657: msg.total_hfields=0; }
658: curmsg=(i-1);
659: break;
660: case 'U': /* user edit */
661: msg.hdr.number=msg.idx.number;
662: smb_getmsgidx(&smb,&msg);
1.1.1.2 ! root 663: useredit(which==MAIL_SENT ? msg.idx.to : msg.idx.from);
1.1 root 664: break;
665: case 'P': /* Purge author and all mail to/from */
666: if(noyes(text[AreYouSureQ]))
667: break;
668: msg.hdr.number=msg.idx.number;
669: smb_getmsgidx(&smb,&msg);
670: purgeuser(msg.idx.from);
671: if(curmsg<msgs-1) curmsg++;
672: break;
673: case '?':
1.1.1.2 ! root 674: strcpy(str,which==MAIL_YOUR ? "mailread" : which==MAIL_ALL
! 675: ? "allmail" : "sentmail");
1.1 root 676: menu(str);
677: if(SYSOP && which==MAIL_SENT)
678: menu("syssmail");
679: else if(SYSOP && which==MAIL_YOUR)
680: menu("sysmailr"); /* Sysop Mail Read */
681: domsg=0;
682: break;
683: } }
684:
685: if(msg.total_hfields)
686: smb_freemsgmem(&msg);
687:
688: if(msgs)
689: FREE(mail);
690:
691: /***************************************/
692: /* Delete messages marked for deletion */
693: /***************************************/
694:
695: if(cfg.sys_misc&SM_DELEMAIL) {
696: if((i=smb_locksmbhdr(&smb))!=0) /* Lock the base, so nobody */
697: errormsg(WHERE,ERR_LOCK,smb.file,i); /* messes with the index */
698: else
699: delmail(usernumber,which); }
700:
701: smb_close(&smb);
702: smb_stack(&smb,SMB_STACK_POP);
703: }
704:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.