|
|
1.1 root 1: /* mail.cpp */
2:
3: /* Synchronet mail-related routines */
4:
1.1.1.2 ! root 5: /* $Id: mail.cpp,v 1.17 2003/12/17 09:48:12 rswindell 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: * *
1.1.1.2 ! root 11: * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 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: /* Deletes all mail messages for usernumber that have been marked 'deleted' */
42: /* smb_locksmbhdr() should be called prior to this function */
43: /****************************************************************************/
44: int sbbs_t::delmail(uint usernumber, int which)
45: {
46: ulong i,l,now;
47: idxrec_t HUGE16 *idxbuf;
48: smbmsg_t msg;
49:
50: now=time(NULL);
51: if((i=smb_getstatus(&smb))!=0) {
52: errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
53: return(2); }
54: if(!smb.status.total_msgs)
55: return(0);
56: if((idxbuf=(idxrec_t *)LMALLOC(smb.status.total_msgs*sizeof(idxrec_t)))==NULL) {
57: errormsg(WHERE,ERR_ALLOC,smb.file,smb.status.total_msgs*sizeof(idxrec_t));
58: return(-1); }
59: if((i=smb_open_da(&smb))!=0) {
60: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
61: LFREE(idxbuf);
62: return(i); }
63: if((i=smb_open_ha(&smb))!=0) {
64: smb_close_da(&smb);
65: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
66: LFREE(idxbuf);
67: return(i); }
68: smb_rewind(smb.sid_fp);
69: for(l=0;l<smb.status.total_msgs;) {
1.1.1.2 ! root 70: if(smb_fread(&smb,&msg.idx,sizeof(idxrec_t),smb.sid_fp)!=sizeof(idxrec_t))
1.1 root 71: break;
72: if(which==MAIL_ALL && !(msg.idx.attr&MSG_PERMANENT)
73: && smb.status.max_age && now>msg.idx.time
74: && (now-msg.idx.time)/(24L*60L*60L)>smb.status.max_age)
75: msg.idx.attr|=MSG_DELETE;
76: if(msg.idx.attr&MSG_DELETE && !(msg.idx.attr&MSG_PERMANENT)
77: && ((which==MAIL_SENT && usernumber==msg.idx.from)
78: || (which==MAIL_YOUR && usernumber==msg.idx.to)
79: || (which==MAIL_ANY
80: && (usernumber==msg.idx.to || usernumber==msg.idx.from))
81: || which==MAIL_ALL)) {
82: /* Don't need to lock message because base is locked */
83: // if(which==MAIL_ALL && !online)
84: // lprintf(" #%lu",msg.idx.number);
85: if((i=smb_getmsghdr(&smb,&msg))!=0)
86: errormsg(WHERE,ERR_READ,smb.file,i,smb.last_error);
87: else {
88: if(msg.hdr.attr!=msg.idx.attr) {
89: msg.hdr.attr=msg.idx.attr;
90: if((i=smb_putmsghdr(&smb,&msg))!=0)
91: errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error); }
92: if((i=smb_freemsg(&smb,&msg))!=0)
93: errormsg(WHERE,ERR_REMOVE,smb.file,i,smb.last_error);
94: if(msg.hdr.auxattr&MSG_FILEATTACH)
1.1.1.2 ! root 95: delfattach(&cfg,&msg);
1.1 root 96: smb_freemsgmem(&msg); }
97: continue; }
98: idxbuf[l]=msg.idx;
99: l++; }
100: smb_rewind(smb.sid_fp);
101: smb_fsetlength(smb.sid_fp,0);
102: for(i=0;i<l;i++)
1.1.1.2 ! root 103: smb_fwrite(&smb,&idxbuf[i],sizeof(idxrec_t),smb.sid_fp);
1.1 root 104: LFREE(idxbuf);
105: smb.status.total_msgs=l;
106: smb_putstatus(&smb);
107: smb_fflush(smb.sid_fp);
108: smb_close_ha(&smb);
109: smb_close_da(&smb);
110: return(0);
111: }
112:
113:
114: /***********************************************/
115: /* Tell the user that so-and-so read your mail */
116: /***********************************************/
117: void sbbs_t::telluser(smbmsg_t* msg)
118: {
119: char str[256];
120: uint usernumber,n;
121: node_t node;
122:
123: if(msg->from_net.type)
124: return;
125: if(msg->from_ext)
126: usernumber=atoi(msg->from_ext);
127: else {
1.1.1.2 ! root 128: usernumber=matchuser(&cfg,msg->from,TRUE /*sysop_alias*/);
1.1 root 129: if(!usernumber)
130: return; }
131: for(n=1;n<=cfg.sys_nodes;n++) { /* Tell user */
132: getnodedat(n,&node,0);
133: if(node.useron==usernumber
134: && (node.status==NODE_INUSE
135: || node.status==NODE_QUIET)) {
136: sprintf(str
137: ,text[UserReadYourMailNodeMsg]
138: ,cfg.node_num,useron.alias);
1.1.1.2 ! root 139: putnmsg(&cfg,n,str);
1.1 root 140: break; } }
141: if(n>cfg.sys_nodes) {
142: now=time(NULL);
143: sprintf(str,text[UserReadYourMail]
144: ,useron.alias,timestr(&now));
145: putsmsg(&cfg,usernumber,str); }
146: }
147:
148: /************************************************************************/
149: /* Deletes all mail waiting for user number 'usernumber' */
150: /************************************************************************/
151: void sbbs_t::delallmail(uint usernumber)
152: {
153: int i;
154: ulong l,msgs,deleted=0;
155: mail_t *mail;
156: smbmsg_t msg;
157:
158: if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) {
159: errormsg(WHERE,ERR_OPEN,"MAIL",i);
160: return; }
161: sprintf(smb.file,"%smail",cfg.data_dir);
162: smb.retry_time=cfg.smb_retry_time;
1.1.1.2 ! root 163: smb.subnum=INVALID_SUB;
1.1 root 164: if((i=smb_open(&smb))!=0) {
165: errormsg(WHERE,ERR_OPEN,smb.file,i,smb.last_error);
166: smb_stack(&smb,SMB_STACK_POP);
167: return; }
168:
169: mail=loadmail(&smb,&msgs,usernumber,MAIL_ANY,0);
170: if(!msgs) {
171: smb_close(&smb);
172: smb_stack(&smb,SMB_STACK_POP);
173: return; }
174: if((i=smb_locksmbhdr(&smb))!=0) { /* Lock the base, so nobody */
175: smb_close(&smb);
176: smb_stack(&smb,SMB_STACK_POP);
177: FREE(mail);
178: errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error); /* messes with the index */
179: return; }
180: for(l=0;l<msgs;l++) {
181: msg.idx.offset=0; /* search by number */
182: if(loadmsg(&msg,mail[l].number)) { /* message still there */
183: msg.hdr.attr|=MSG_DELETE;
184: msg.hdr.attr&=~MSG_PERMANENT;
185: msg.idx.attr=msg.hdr.attr;
186: if((i=smb_putmsg(&smb,&msg))!=0)
187: errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
188: else
189: deleted++;
190: smb_freemsgmem(&msg);
191: smb_unlockmsghdr(&smb,&msg); } }
192:
193: if(msgs)
194: FREE(mail);
195: if(deleted && cfg.sys_misc&SM_DELEMAIL)
196: delmail(usernumber,MAIL_ANY);
197: smb_unlocksmbhdr(&smb);
198: smb_close(&smb);
199: smb_stack(&smb,SMB_STACK_POP);
200: }
201:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.