Annotation of sbbs/sbbs3/getmail.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.