int DLLCALL getmail(scfg_t* cfg, int usernumber, BOOL sent) { char str[128]; int i=0; long l; idxrec_t idx; smb_t smb; ZERO_VAR(smb); sprintf(smb.file,"%smail",cfg->data_dir); smb.retry_time=cfg->smb_retry_time; sprintf(str,"%s.sid",smb.file); l=flength(str); if(l<(long)sizeof(idxrec_t)) return(0); if(!usernumber) return(l/sizeof(idxrec_t)); /* Total system e-mail */ smb.subnum=INVALID_SUB; if(smb_open(&smb)!=0) return(0); while(!smb_feof(smb.sid_fp)) { if(smb_fread(&smb,&idx,sizeof(idx),smb.sid_fp) != sizeof(idx)) break; if(idx.number==0) /* invalid message number, ignore */ continue; if(idx.attr&MSG_DELETE) continue; if((!sent && idx.to==usernumber) || (sent && idx.from==usernumber)) i++; } smb_close(&smb); return(i); }
void dump_hashes(void) { char tmp[128]; int retval; hash_t hash; if((retval=smb_open_hash(&smb))!=SMB_SUCCESS) { fprintf(errfp,"\n%s!smb_open_hash returned %d: %s\n" ,beep, retval, smb.last_error); return; } while(!smb_feof(smb.hash_fp)) { if(smb_fread(&smb,&hash,sizeof(hash),smb.hash_fp)!=sizeof(hash)) break; printf("\n"); printf("%-10s: %"PRIu32"\n","Number", hash.number); printf("%-10s: %s\n", "Source", smb_hashsourcetype(hash.source)); printf("%-10s: %"PRIu32"\n","Length", hash.length); printf("%-10s: %s\n", "Time", my_timestr(hash.time)); printf("%-10s: %02x\n", "Flags", hash.flags); if(hash.flags&SMB_HASH_CRC16) printf("%-10s: %04x\n", "CRC-16", hash.crc16); if(hash.flags&SMB_HASH_CRC32) printf("%-10s: %08"PRIx32"\n","CRC-32", hash.crc32); if(hash.flags&SMB_HASH_MD5) printf("%-10s: %s\n", "MD5", MD5_hex((BYTE*)tmp,hash.md5)); } smb_close_hash(&smb); }
mail_t* DLLCALL loadmail(smb_t* smb, long* msgs, uint usernumber ,int which, long mode) { ulong l=0; idxrec_t idx; mail_t* mail=NULL; if(msgs==NULL) return(NULL); *msgs=0; if(smb==NULL) return(NULL); if(smb_locksmbhdr(smb)!=0) /* Be sure noone deletes or */ return(NULL); /* adds while we're reading */ smb_rewind(smb->sid_fp); while(!smb_feof(smb->sid_fp)) { if(smb_fread(smb,&idx,sizeof(idx),smb->sid_fp) != sizeof(idx)) break; if(idx.number==0) /* invalid message number, ignore */ continue; if((which==MAIL_SENT && idx.from!=usernumber) || (which==MAIL_YOUR && idx.to!=usernumber) || (which==MAIL_ANY && idx.from!=usernumber && idx.to!=usernumber)) continue; if(idx.attr&MSG_DELETE && !(mode&LM_INCDEL)) /* Don't included deleted msgs */ continue; if(mode&LM_UNREAD && idx.attr&MSG_READ) continue; if((mail=(mail_t *)realloc(mail,sizeof(mail_t)*(l+1))) ==NULL) { smb_unlocksmbhdr(smb); return(NULL); } mail[l]=idx; l++; } smb_unlocksmbhdr(smb); *msgs=l; return(mail); }