|
|
1.1.1.2 ! root 1: /* getmail.c */ 1.1 root 2: 3: /* Synchronet DLL-exported mail-related routines */ 4: 1.1.1.2 ! root 5: /* $Id: getmail.c,v 1.11 2011/09/10 08:57:55 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 2011 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: /* 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); 1.1.1.2 ! root 57: l=(long)flength(str); 1.1 root 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; 1.1.1.2 ! root 113: tp=p+1; ! 114: ! 115: } 1.1 root 116: sprintf(str,"%sfile/%04u.in",cfg->data_dir,msg->idx.to); 117: rmdir(str); /* remove the dir if it's empty */ 118: } 119: 120: /****************************************************************************/ 121: /* Loads mail waiting for user number 'usernumber' into the mail array of */ 122: /* of pointers to mail_t (message numbers and attributes) */ 123: /* smb_open(&smb) must be called prior */ 124: /****************************************************************************/ 1.1.1.2 ! root 125: mail_t* DLLCALL loadmail(smb_t* smb, int32_t* msgs, uint usernumber 1.1 root 126: ,int which, long mode) 127: { 128: ulong l=0; 129: idxrec_t idx; 130: mail_t* mail=NULL; 131: 132: if(msgs==NULL) 133: return(NULL); 134: 135: *msgs=0; 136: 137: if(smb==NULL) 138: return(NULL); 139: 140: if(smb_locksmbhdr(smb)!=0) /* Be sure noone deletes or */ 141: return(NULL); /* adds while we're reading */ 142: 143: smb_rewind(smb->sid_fp); 144: while(!smb_feof(smb->sid_fp)) { 145: if(smb_fread(smb,&idx,sizeof(idx),smb->sid_fp) != sizeof(idx)) 146: break; 147: if(idx.number==0) /* invalid message number, ignore */ 148: continue; 149: if((which==MAIL_SENT && idx.from!=usernumber) 150: || (which==MAIL_YOUR && idx.to!=usernumber) 151: || (which==MAIL_ANY && idx.from!=usernumber && idx.to!=usernumber)) 152: continue; 153: if(idx.attr&MSG_DELETE && !(mode&LM_INCDEL)) /* Don't included deleted msgs */ 154: continue; 155: if(mode&LM_UNREAD && idx.attr&MSG_READ) 156: continue; 157: if((mail=(mail_t *)realloc(mail,sizeof(mail_t)*(l+1))) 158: ==NULL) { 159: smb_unlocksmbhdr(smb); 160: return(NULL); 161: } 162: mail[l]=idx; 163: l++; 164: } 165: smb_unlocksmbhdr(smb); 166: *msgs=l; 167: return(mail); 168: } 169: 170: void DLLCALL freemail(mail_t* mail) 171: { 172: if(mail!=NULL) 173: free(mail); 174: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.