|
|
1.1 root 1: /* getmail.cpp */
2:
3: /* Synchronet DLL-exported mail-related routines */
4:
5: /* $Id: getmail.c,v 1.7 2006/03/16 22:35:54 rswindell Exp $ */
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 2006 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: /* Returns the number of pieces of mail waiting for usernumber */
42: /* If sent is non-zero, it returns the number of mail sent by usernumber */
43: /* If usernumber is 0, it returns all mail on the system */
44: /****************************************************************************/
45: int DLLCALL getmail(scfg_t* cfg, int usernumber, BOOL sent)
46: {
47: char str[128];
48: int i=0;
49: long l;
50: idxrec_t idx;
51: smb_t smb;
52:
53: ZERO_VAR(smb);
54: sprintf(smb.file,"%smail",cfg->data_dir);
55: smb.retry_time=cfg->smb_retry_time;
56: sprintf(str,"%s.sid",smb.file);
57: l=flength(str);
58: if(l<(long)sizeof(idxrec_t))
59: return(0);
60: if(!usernumber)
61: return(l/sizeof(idxrec_t)); /* Total system e-mail */
62: smb.subnum=INVALID_SUB;
63: if(smb_open(&smb)!=0)
64: return(0);
65: while(!smb_feof(smb.sid_fp)) {
66: if(smb_fread(&smb,&idx,sizeof(idx),smb.sid_fp) != sizeof(idx))
67: break;
68: if(idx.number==0) /* invalid message number, ignore */
69: continue;
70: if(idx.attr&MSG_DELETE)
71: continue;
72: if((!sent && idx.to==usernumber)
73: || (sent && idx.from==usernumber))
74: i++;
75: }
76: smb_close(&smb);
77: return(i);
78: }
79:
80:
81: /***************************/
82: /* Delete file attachments */
83: /***************************/
84: void DLLCALL delfattach(scfg_t* cfg, smbmsg_t* msg)
85: {
86: char str[MAX_PATH+1];
87: char str2[MAX_PATH+1];
88: char *tp,*sp,*p;
89:
90: if(msg->idx.to==0) { /* netmail */
91: sprintf(str,"%sfile/%04u.out/%s"
92: ,cfg->data_dir,msg->idx.from,getfname(msg->subj));
93: remove(str);
94: sprintf(str,"%sfile/%04u.out"
95: ,cfg->data_dir,msg->idx.from);
96: rmdir(str);
97: return;
98: }
99:
100: strcpy(str,msg->subj);
101: tp=str;
102: while(1) {
103: p=strchr(tp,' ');
104: if(p) *p=0;
105: sp=strrchr(tp,'/'); /* sp is slash pointer */
106: if(!sp) sp=strrchr(tp,'\\');
107: if(sp) tp=sp+1;
108: sprintf(str2,"%sfile/%04u.in/%s" /* str2 is path/fname */
109: ,cfg->data_dir,msg->idx.to,tp);
110: remove(str2);
111: if(!p)
112: break;
113: tp=p+1; }
114: sprintf(str,"%sfile/%04u.in",cfg->data_dir,msg->idx.to);
115: rmdir(str); /* remove the dir if it's empty */
116: }
117:
118: /****************************************************************************/
119: /* Loads mail waiting for user number 'usernumber' into the mail array of */
120: /* of pointers to mail_t (message numbers and attributes) */
121: /* smb_open(&smb) must be called prior */
122: /****************************************************************************/
123: mail_t* DLLCALL loadmail(smb_t* smb, long* msgs, uint usernumber
124: ,int which, long mode)
125: {
126: ulong l=0;
127: idxrec_t idx;
128: mail_t* mail=NULL;
129:
130: if(msgs==NULL)
131: return(NULL);
132:
133: *msgs=0;
134:
135: if(smb==NULL)
136: return(NULL);
137:
138: if(smb_locksmbhdr(smb)!=0) /* Be sure noone deletes or */
139: return(NULL); /* adds while we're reading */
140:
141: smb_rewind(smb->sid_fp);
142: while(!smb_feof(smb->sid_fp)) {
143: if(smb_fread(smb,&idx,sizeof(idx),smb->sid_fp) != sizeof(idx))
144: break;
145: if(idx.number==0) /* invalid message number, ignore */
146: continue;
147: if((which==MAIL_SENT && idx.from!=usernumber)
148: || (which==MAIL_YOUR && idx.to!=usernumber)
149: || (which==MAIL_ANY && idx.from!=usernumber && idx.to!=usernumber))
150: continue;
151: if(idx.attr&MSG_DELETE && !(mode&LM_INCDEL)) /* Don't included deleted msgs */
152: continue;
153: if(mode&LM_UNREAD && idx.attr&MSG_READ)
154: continue;
155: if((mail=(mail_t *)realloc(mail,sizeof(mail_t)*(l+1)))
156: ==NULL) {
157: smb_unlocksmbhdr(smb);
158: return(NULL);
159: }
160: mail[l]=idx;
161: l++;
162: }
163: smb_unlocksmbhdr(smb);
164: *msgs=l;
165: return(mail);
166: }
167:
168: void DLLCALL freemail(mail_t* mail)
169: {
170: if(mail!=NULL)
171: free(mail);
172: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.