|
|
1.1 ! root 1: /* SBBSFIDO.C */ ! 2: ! 3: /* Synchronet FidoNet EchoMail Scanning/Tossing and NetMail Tossing Utility */ ! 4: ! 5: #define VER "2.24" ! 6: ! 7: #include "sbbs.h" ! 8: #include "crc32.h" ! 9: #include "lzh.h" ! 10: #include "post.h" ! 11: #include "scfglib.h" ! 12: ! 13: #define IMPORT_NETMAIL (1L<<0) ! 14: #define IMPORT_ECHOMAIL (1L<<1) ! 15: #define EXPORT_ECHOMAIL (1L<<2) ! 16: #define DELETE_NETMAIL (1L<<3) ! 17: #define DELETE_ECHOMAIL (1L<<4) ! 18: #define IGNORE_POINT (1L<<5) ! 19: #define IGNORE_ZONE (1L<<6) ! 20: #define IGNORE_MSGPTRS (1L<<7) ! 21: #define UPDATE_MSGPTRS (1L<<8) ! 22: #define LEAVE_MSGPTRS (1L<<9) ! 23: #define KILL_ECHOMAIL (1L<<10) ! 24: #define ASCII_ONLY (1L<<11) ! 25: #define LOGFILE (1L<<12) ! 26: #define REPORT (1L<<13) ! 27: #define EXPORT_ALL (1L<<14) ! 28: #define PURGE_ECHOMAIL (1L<<15) ! 29: #define UNKNOWN_NETMAIL (1L<<16) ! 30: #define IGNORE_ADDRESS (1L<<17) ! 31: #define IMPORT_LOCAL (1L<<18) ! 32: #define IMPORT_NEW_ONLY (1L<<19) ! 33: #define DONT_SET_RECV (1L<<20) ! 34: #define IGNORE_RECV (1L<<21) ! 35: #define CONVERT_TEAR (1L<<22) ! 36: #define IMPORT_PRIVATE (1L<<23) ! 37: #define LOCAL_NETMAIL (1L<<24) ! 38: #define NOTIFY_RECEIPT (1L<<25) ! 39: ! 40: char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; ! 41: char *mon[]={"Jan","Feb","Mar","Apr","May","Jun" ! 42: ,"Jul","Aug","Sep","Oct","Nov","Dec"}; ! 43: ! 44: long misc=(IMPORT_NETMAIL|IMPORT_ECHOMAIL|EXPORT_ECHOMAIL ! 45: |DELETE_NETMAIL|DELETE_ECHOMAIL|KILL_ECHOMAIL); ! 46: char tmp[256]; ! 47: ! 48: FILE *fidologfile=NULL; ! 49: #ifdef __TURBOC__ ! 50: unsigned _stklen=20000; ! 51: #endif ! 52: int startmsg=1; ! 53: int nodefile; ! 54: ! 55: #ifdef __WATCOMC__ ! 56: #define O_DENYNONE SH_DENYNO ! 57: #endif ! 58: ! 59: long lputs(char FAR16 *str) ! 60: { ! 61: char tmp[256]; ! 62: int i,j,k; ! 63: ! 64: if(misc&LOGFILE && fidologfile!=NULL) ! 65: fputs(str,fidologfile); ! 66: j=strlen(str); ! 67: for(i=k=0;i<j;i++) /* remove CRs */ ! 68: if(str[i]==CR && str[i+1]==LF) ! 69: continue; ! 70: else ! 71: tmp[k++]=str[i]; ! 72: tmp[k]=0; ! 73: return(fputs(tmp,stdout)); ! 74: } ! 75: ! 76: /******************************************/ ! 77: /* CRC-16 routines required for SMB index */ ! 78: /******************************************/ ! 79: ! 80: /****************************************************************************/ ! 81: /* Updates 16-bit "rcrc" with character 'ch' */ ! 82: /****************************************************************************/ ! 83: void ucrc16(uchar ch, ushort *rcrc) { ! 84: ushort i, cy; ! 85: uchar nch=ch; ! 86: ! 87: for (i=0; i<8; i++) { ! 88: cy=*rcrc & 0x8000; ! 89: *rcrc<<=1; ! 90: if (nch & 0x80) *rcrc |= 1; ! 91: nch<<=1; ! 92: if (cy) *rcrc ^= 0x1021; } ! 93: } ! 94: ! 95: /****************************************************************************/ ! 96: /* Returns 16-crc of string (not counting terminating NULL) */ ! 97: /****************************************************************************/ ! 98: ushort crc16(char *str) ! 99: { ! 100: int i=0; ! 101: ushort crc=0; ! 102: ! 103: ucrc16(0,&crc); ! 104: while(str[i]) ! 105: ucrc16(str[i++],&crc); ! 106: ucrc16(0,&crc); ! 107: ucrc16(0,&crc); ! 108: return(crc); ! 109: } ! 110: ! 111: /****************************************************************************/ ! 112: /* Returns 32-crc of string (not counting terminating NULL) */ ! 113: /****************************************************************************/ ! 114: ulong crc32(char *str) ! 115: { ! 116: int i=0; ! 117: ulong crc=0xffffffffUL; ! 118: ! 119: while(str[i]) ! 120: crc=ucrc32(str[i++],crc); ! 121: crc=~crc; ! 122: return(crc); ! 123: } ! 124: ! 125: ! 126: ! 127: /****************************************************************************/ ! 128: /* Performs printf() through local assembly routines */ ! 129: /* Called from everywhere */ ! 130: /****************************************************************************/ ! 131: int lprintf(char *fmat, ...) ! 132: { ! 133: va_list argptr; ! 134: char sbuf[256]; ! 135: int chcount; ! 136: ! 137: va_start(argptr,fmat); ! 138: chcount=vsprintf(sbuf,fmat,argptr); ! 139: va_end(argptr); ! 140: lputs(sbuf); ! 141: return(chcount); ! 142: } ! 143: ! 144: /****************************************************************************/ ! 145: /* Reads the data for node number 'number' into the structure 'node' */ ! 146: /* from NODE.DAB */ ! 147: /* if lockit is non-zero, locks this node's record. putnodedat() unlocks it */ ! 148: /****************************************************************************/ ! 149: void getnodedat(uint number, node_t *node, char lockit) ! 150: { ! 151: char str[256]; ! 152: int count=0; ! 153: ! 154: number--; /* make zero based */ ! 155: while(count<LOOP_NODEDAB) { ! 156: lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET); ! 157: if(lockit ! 158: && lock(nodefile,(long)number*sizeof(node_t),sizeof(node_t))==-1) { ! 159: count++; ! 160: continue; } ! 161: if(read(nodefile,node,sizeof(node_t))==sizeof(node_t)) ! 162: break; ! 163: count++; } ! 164: if(count==LOOP_NODEDAB) ! 165: lprintf("\7Error unlocking and reading NODE.DAB\r\n"); ! 166: } ! 167: ! 168: /****************************************************************************/ ! 169: /* Write the data from the structure 'node' into NODE.DAB */ ! 170: /* getnodedat(num,&node,1); must have been called before calling this func */ ! 171: /* NOTE: ------^ the indicates the node record has been locked */ ! 172: /****************************************************************************/ ! 173: void putnodedat(uint number, node_t node) ! 174: { ! 175: char str[256]; ! 176: int count; ! 177: ! 178: number--; /* make zero based */ ! 179: lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET); ! 180: if(write(nodefile,&node,sizeof(node_t))!=sizeof(node_t)) { ! 181: unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t)); ! 182: lprintf("\7Error writing NODE.DAB for node %u\r\n",number+1); ! 183: return; } ! 184: unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t)); ! 185: } ! 186: ! 187: ! 188: /****************************************************************************/ ! 189: /* Creates a short message for 'usernumber' than contains 'strin' */ ! 190: /****************************************************************************/ ! 191: void putsmsg(int usernumber, char *strin) ! 192: { ! 193: char str[256]; ! 194: int file,i; ! 195: node_t node; ! 196: ! 197: sprintf(str,"%sMSGS\\%4.4u.MSG",data_dir,usernumber); ! 198: if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) { ! 199: lprintf("\7Error opening/creating %s for creat/append access\r\n",str); ! 200: return; } ! 201: i=strlen(strin); ! 202: if(write(file,strin,i)!=i) { ! 203: close(file); ! 204: lprintf("\7Error writing %u bytes to %s\r\n",i,str); ! 205: return; } ! 206: close(file); ! 207: for(i=1;i<=sys_nodes;i++) { /* flag node if user on that msg waiting */ ! 208: getnodedat(i,&node,0); ! 209: if(node.useron==usernumber ! 210: && (node.status==NODE_INUSE || node.status==NODE_QUIET) ! 211: && !(node.misc&NODE_MSGW)) { ! 212: getnodedat(i,&node,1); ! 213: node.misc|=NODE_MSGW; ! 214: putnodedat(i,node); } } ! 215: } ! 216: ! 217: ! 218: /****************************************************************************/ ! 219: /* Converts an ASCII Hex string into an ulong */ ! 220: /****************************************************************************/ ! 221: ulong ahtoul(char *str) ! 222: { ! 223: ulong l,val=0; ! 224: ! 225: while((l=(*str++)|0x20)!=0x20) ! 226: val=(l&0xf)+(l>>6&1)*9+val*16; ! 227: return(val); ! 228: } ! 229: ! 230: /****************************************************************************/ ! 231: /* Truncates white-space chars off end of 'str' and terminates at first tab */ ! 232: /****************************************************************************/ ! 233: void truncsp(char *str) ! 234: { ! 235: char c; ! 236: ! 237: str[strcspn(str,"\t")]=0; ! 238: c=strlen(str); ! 239: while(c && str[c-1]<=SP) c--; ! 240: str[c]=0; ! 241: } ! 242: ! 243: /****************************************************************************/ ! 244: /* Puts a backslash on path strings */ ! 245: /****************************************************************************/ ! 246: void backslash(char *str) ! 247: { ! 248: int i; ! 249: ! 250: i=strlen(str); ! 251: if(i && str[i-1]!='\\') { ! 252: str[i]='\\'; str[i+1]=0; } ! 253: } ! 254: ! 255: void remove_re(char *str) ! 256: { ! 257: while(!strnicmp(str,"RE:",3)) { ! 258: strcpy(str,str+3); ! 259: while(str[0]==SP) ! 260: strcpy(str,str+1); } ! 261: } ! 262: ! 263: /****************************************************************************/ ! 264: /* Network open function. Opens all files DENYALL and retries LOOP_NOPEN */ ! 265: /* number of times if the attempted file is already open or denying access */ ! 266: /* for some other reason. All files are opened in BINARY mode. */ ! 267: /****************************************************************************/ ! 268: int nopen(char *str, int access) ! 269: { ! 270: char logstr[256]; ! 271: int file,share,count=0; ! 272: ! 273: if(access&O_DENYNONE) { ! 274: share=SH_DENYNO; ! 275: access&=~O_DENYNONE; } ! 276: else if(access==O_RDONLY) share=SH_DENYWR; ! 277: else share=SH_DENYRW; ! 278: while(((file=sopen(str,O_BINARY|access,share,S_IWRITE))==-1) ! 279: && errno==EACCES && count++<LOOP_NOPEN); ! 280: if(file==-1 && errno==EACCES) ! 281: lputs("\7\r\nNOPEN: ACCESS DENIED\r\n\7"); ! 282: return(file); ! 283: } ! 284: ! 285: /****************************************************************************/ ! 286: /* This function performs an nopen, but returns a file stream with a buffer */ ! 287: /* allocated. */ ! 288: /****************************************************************************/ ! 289: FILE *fnopen(int *file, char *str, int access) ! 290: { ! 291: char mode[128]; ! 292: FILE *stream; ! 293: ! 294: if(((*file)=nopen(str,access))==-1) ! 295: return(NULL); ! 296: ! 297: if(access&O_APPEND) { ! 298: if(access&O_RDONLY) ! 299: strcpy(mode,"a+"); ! 300: else ! 301: strcpy(mode,"a"); } ! 302: else { ! 303: if(access&O_WRONLY) ! 304: strcpy(mode,"r+"); ! 305: else ! 306: strcpy(mode,"r"); } ! 307: stream=fdopen((*file),mode); ! 308: if(stream==NULL) { ! 309: close(*file); ! 310: return(NULL); } ! 311: setvbuf(stream,NULL,_IOFBF,16*1024); ! 312: return(stream); ! 313: } ! 314: ! 315: ! 316: /****************************************************************************/ ! 317: /* Moves or copies a file from one dir to another */ ! 318: /* both 'src' and 'dest' must contain full path and filename */ ! 319: /* returns 0 if successful, -1 if error */ ! 320: /****************************************************************************/ ! 321: int mv(char *src, char *dest, char copy) ! 322: { ! 323: char buf[4096],str[256]; ! 324: int ind,outd; ! 325: long length,chunk=4096,l; ! 326: ushort ftime,fdate; ! 327: FILE *inp,*outp; ! 328: ! 329: if(!strcmp(src,dest)) /* source and destination are the same! */ ! 330: return(0); ! 331: if(!fexist(src)) { ! 332: lprintf("\r\nMV ERROR: Source doesn't exist\r\n'%s'\r\n" ! 333: ,src); ! 334: return(-1); } ! 335: if(!copy && fexist(dest)) { ! 336: lprintf("\r\nMV ERROR: Destination already exists\r\n'%s'\r\n" ! 337: ,dest); ! 338: return(-1); } ! 339: if(!copy && ((src[1]!=':' && dest[1]!=':') ! 340: || (src[1]==':' && dest[1]==':' && toupper(src[0])==toupper(dest[0])))) { ! 341: if(rename(src,dest)) { /* same drive, so move */ ! 342: lprintf("\r\nMV ERROR: Error renaming '%s'" ! 343: "\r\n to '%s'\r\n",src,dest); ! 344: return(-1); } ! 345: return(0); } ! 346: if((ind=nopen(src,O_RDONLY))==-1) { ! 347: lprintf("\r\nMV ERROR: ERR_OPEN %s\r\n",src); ! 348: return(-1); } ! 349: if((inp=fdopen(ind,"rb"))==NULL) { ! 350: close(ind); ! 351: lprintf("\r\nMV ERROR: ERR_FDOPEN %s\r\n",str); ! 352: return(-1); } ! 353: setvbuf(inp,NULL,_IOFBF,8*1024); ! 354: if((outd=nopen(dest,O_WRONLY|O_CREAT|O_TRUNC))==-1) { ! 355: fclose(inp); ! 356: lprintf("\r\nMV ERROR: ERR_OPEN %s\r\n",dest); ! 357: return(-1); } ! 358: if((outp=fdopen(outd,"wb"))==NULL) { ! 359: close(outd); ! 360: fclose(inp); ! 361: lprintf("\r\nMV ERROR: ERR_FDOPEN %s\r\n",str); ! 362: return(-1); } ! 363: setvbuf(outp,NULL,_IOFBF,8*1024); ! 364: length=filelength(ind); ! 365: l=0L; ! 366: while(l<length) { ! 367: if(l+chunk>length) ! 368: chunk=length-l; ! 369: fread(buf,chunk,1,inp); ! 370: fwrite(buf,chunk,1,outp); ! 371: l+=chunk; } ! 372: _dos_getftime(ind,&fdate,&ftime); ! 373: _dos_setftime(outd,fdate,ftime); ! 374: fclose(inp); ! 375: fclose(outp); ! 376: if(!copy && remove(src)) { ! 377: lprintf("MV ERROR: ERR_REMOVE %s\r\n",src); ! 378: return(-1); } ! 379: return(0); ! 380: } ! 381: ! 382: /****************************************************************************/ ! 383: /* Returns the total number of msgs in the sub-board and sets 'ptr' to the */ ! 384: /* date of the last message in the sub (0) if no messages. */ ! 385: /****************************************************************************/ ! 386: ulong getlastmsg(uint subnum, ulong *ptr, time_t *t) ! 387: { ! 388: char str[256]; ! 389: int i; ! 390: smbstatus_t status; ! 391: ! 392: sprintf(smb_file,"%s%s",sub[subnum]->data_dir,sub[subnum]->code); ! 393: if((i=smb_open(10))!=0) { ! 394: lprintf("ERR_OPEN %s %d\r\n",smb_file,i); ! 395: return(0); } ! 396: ! 397: if(!filelength(fileno(shd_fp))) { /* Empty base */ ! 398: if(ptr) (*ptr)=0; ! 399: smb_close(); ! 400: return(0); } ! 401: if((i=smb_locksmbhdr(10))!=0) { ! 402: smb_close(); ! 403: lprintf("ERR_LOCK %s %d\r\n",smb_file,i); ! 404: return(0); } ! 405: if((i=smb_getstatus(&status))!=0) { ! 406: smb_unlocksmbhdr(); ! 407: smb_close(); ! 408: lprintf("ERR_READ %s %d\r\n",smb_file,i); ! 409: return(0); } ! 410: smb_unlocksmbhdr(); ! 411: smb_close(); ! 412: if(ptr) (*ptr)=status.last_msg; ! 413: return(status.total_msgs); ! 414: } ! 415: ! 416: ! 417: ulong loadmsgs(post_t HUGE16 **post, ulong ptr) ! 418: { ! 419: int i; ! 420: long l=0; ! 421: idxrec_t idx; ! 422: ! 423: ! 424: if((i=smb_locksmbhdr(10))!=0) { /* Be sure noone deletes or */ ! 425: lprintf("ERR_LOCK %s %d\r\n",smb_file,i); /* adds while we're reading */ ! 426: return(0L); } ! 427: ! 428: fseek(sid_fp,0L,SEEK_SET); ! 429: while(!feof(sid_fp)) { ! 430: if(!fread(&idx,sizeof(idxrec_t),1,sid_fp)) ! 431: break; ! 432: ! 433: if(idx.number<=ptr || idx.attr&MSG_DELETE) ! 434: continue; ! 435: ! 436: if(idx.attr&MSG_MODERATED && !(idx.attr&MSG_VALIDATED)) ! 437: break; ! 438: ! 439: if(((*post)=(post_t HUGE16 *)REALLOC((*post),sizeof(post_t)*(l+1))) ! 440: ==NULL) { ! 441: smb_unlocksmbhdr(); ! 442: lprintf("ERR_ALLOC %s %lu\r\n",smb_file,sizeof(post_t *)*(l+1)); ! 443: return(l); } ! 444: (*post)[l].offset=idx.offset; ! 445: (*post)[l].number=idx.number; ! 446: l++; } ! 447: smb_unlocksmbhdr(); ! 448: return(l); ! 449: } ! 450: ! 451: ! 452: void allocfail(uint size) ! 453: { ! 454: lprintf("\7Error allocating %u bytes of memory.\r\n",size); ! 455: bail(1); ! 456: } ! 457: ! 458: void bail(int code) ! 459: { ! 460: exit(code); ! 461: } ! 462: ! 463: /****************************************************************************/ ! 464: /* Returns the length of the file in 'filespec' */ ! 465: /****************************************************************************/ ! 466: long flength(char *filespec) ! 467: { ! 468: struct find_t f; ! 469: ! 470: if(!findfirst(filespec,&f,0)) ! 471: return(f.size); ! 472: return(-1L); ! 473: } ! 474: ! 475: /****************************************************************************/ ! 476: /* Checks the disk drive for the existence of a file. Returns 1 if it */ ! 477: /* exists, 0 if it doesn't. */ ! 478: /* Called from upload */ ! 479: /****************************************************************************/ ! 480: char fexist(char *filespec) ! 481: { ! 482: struct find_t f; ! 483: ! 484: if(!findfirst(filespec,&f,0)) ! 485: return(1); ! 486: return(0); ! 487: } ! 488: ! 489: typedef struct { ! 490: ulong alias, ! 491: real; ! 492: } username_t; ! 493: ! 494: /****************************************************************************/ ! 495: /* Note: Wrote another version of this function that read all userdata into */ ! 496: /****************************************************************************/ ! 497: /* Looks for a perfect match amoung all usernames (not deleted users) */ ! 498: /* Returns the number of the perfect matched username or 0 if no match */ ! 499: /* Called from functions waitforcall and newuser */ ! 500: /* memory then scanned it from memory... took longer - always. */ ! 501: /****************************************************************************/ ! 502: ulong matchname(char *inname) ! 503: { ! 504: static ulong total_users; ! 505: static username_t *username; ! 506: int userdat,file,i; ! 507: char str[256],c; ! 508: ulong l,crc; ! 509: FILE *namedat; ! 510: ! 511: if(!total_users) { /* Load CRCs */ ! 512: fprintf(stderr,"%-25s","Loading user names..."); ! 513: sprintf(str,"%sUSER\\NAME.DAT",data_dir); ! 514: if((namedat=fnopen(&file,str,O_RDONLY))==NULL) ! 515: return(0); ! 516: sprintf(str,"%sUSER\\USER.DAT",data_dir); ! 517: if((userdat=nopen(str,O_RDONLY|O_DENYNONE))==-1) { ! 518: fclose(namedat); ! 519: return(0); } ! 520: while(!feof(namedat) && !eof(userdat)) { ! 521: if(!fread(str,LEN_ALIAS+2,1,namedat)) ! 522: break; ! 523: if((username=(username_t *)REALLOC(username ! 524: ,(total_users+1)*sizeof(username_t)))==NULL) ! 525: break; ! 526: ! 527: for(c=0;c<LEN_ALIAS;c++) ! 528: if(str[c]==ETX) break; ! 529: str[c]=0; ! 530: strlwr(str); ! 531: username[total_users].alias=crc32(str); ! 532: i=0; ! 533: while(i<LOOP_NODEDAB ! 534: && lock(userdat,(long)((long)(total_users)*U_LEN)+U_NAME ! 535: ,LEN_NAME)==-1) { ! 536: i++; } ! 537: if(i>=LOOP_NODEDAB) /* Couldn't lock USER.DAT record */ ! 538: continue; ! 539: lseek(userdat,(long)((long)(total_users)*U_LEN)+U_NAME,SEEK_SET); ! 540: read(userdat,str,LEN_NAME); ! 541: unlock(userdat,(long)((long)(total_users)*U_LEN)+U_NAME,LEN_NAME); ! 542: for(c=0;c<LEN_NAME;c++) ! 543: if(str[c]==ETX || str[c]==CR) break; ! 544: str[c]=0; ! 545: strlwr(str); ! 546: username[total_users].real=crc32(str); ! 547: total_users++; } ! 548: fclose(namedat); ! 549: close(userdat); ! 550: fprintf(stderr, ! 551: "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" ! 552: "%25s" ! 553: "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" ! 554: ,""); } ! 555: ! 556: strcpy(str,inname); ! 557: strlwr(str); ! 558: crc=crc32(str); ! 559: for(l=0;l<total_users;l++) ! 560: if(crc==username[l].alias || crc==username[l].real) ! 561: return(l+1); ! 562: return(0); ! 563: } ! 564: ! 565: /****************************************************************************/ ! 566: /* Converts goofy FidoNet time format into Unix format */ ! 567: /****************************************************************************/ ! 568: time_t fmsgtime(char *str) ! 569: { ! 570: char month[4]; ! 571: struct tm tm; ! 572: ! 573: memset(&tm,0,sizeof(tm)); ! 574: if(isdigit(str[1])) { /* Regular format: "01 Jan 86 02:34:56" */ ! 575: tm.tm_mday=atoi(str); ! 576: sprintf(month,"%3.3s",str+3); ! 577: if(!stricmp(month,"jan")) ! 578: tm.tm_mon=0; ! 579: else if(!stricmp(month,"feb")) ! 580: tm.tm_mon=1; ! 581: else if(!stricmp(month,"mar")) ! 582: tm.tm_mon=2; ! 583: else if(!stricmp(month,"apr")) ! 584: tm.tm_mon=3; ! 585: else if(!stricmp(month,"may")) ! 586: tm.tm_mon=4; ! 587: else if(!stricmp(month,"jun")) ! 588: tm.tm_mon=5; ! 589: else if(!stricmp(month,"jul")) ! 590: tm.tm_mon=6; ! 591: else if(!stricmp(month,"aug")) ! 592: tm.tm_mon=7; ! 593: else if(!stricmp(month,"sep")) ! 594: tm.tm_mon=8; ! 595: else if(!stricmp(month,"oct")) ! 596: tm.tm_mon=9; ! 597: else if(!stricmp(month,"nov")) ! 598: tm.tm_mon=10; ! 599: else ! 600: tm.tm_mon=11; ! 601: tm.tm_year=atoi(str+7); ! 602: tm.tm_hour=atoi(str+11); ! 603: tm.tm_min=atoi(str+14); ! 604: tm.tm_sec=atoi(str+17); } ! 605: ! 606: else { /* SEAdog format: "Mon 1 Jan 86 02:34" */ ! 607: tm.tm_mday=atoi(str+4); ! 608: sprintf(month,"%3.3s",str+7); ! 609: if(!stricmp(month,"jan")) ! 610: tm.tm_mon=0; ! 611: else if(!stricmp(month,"feb")) ! 612: tm.tm_mon=1; ! 613: else if(!stricmp(month,"mar")) ! 614: tm.tm_mon=2; ! 615: else if(!stricmp(month,"apr")) ! 616: tm.tm_mon=3; ! 617: else if(!stricmp(month,"may")) ! 618: tm.tm_mon=4; ! 619: else if(!stricmp(month,"jun")) ! 620: tm.tm_mon=5; ! 621: else if(!stricmp(month,"jul")) ! 622: tm.tm_mon=6; ! 623: else if(!stricmp(month,"aug")) ! 624: tm.tm_mon=7; ! 625: else if(!stricmp(month,"sep")) ! 626: tm.tm_mon=8; ! 627: else if(!stricmp(month,"oct")) ! 628: tm.tm_mon=9; ! 629: else if(!stricmp(month,"nov")) ! 630: tm.tm_mon=10; ! 631: else ! 632: tm.tm_mon=11; ! 633: tm.tm_year=atoi(str+11); ! 634: tm.tm_hour=atoi(str+14); ! 635: tm.tm_min=atoi(str+17); ! 636: tm.tm_sec=0; } ! 637: ! 638: if(tm.tm_year<70) ! 639: tm.tm_year+=100; ! 640: ! 641: return(mktime(&tm)); ! 642: } ! 643: ! 644: /****************************************************************************/ ! 645: /* Returns the FidoNet address kept in str as ASCII. */ ! 646: /****************************************************************************/ ! 647: faddr_t atofaddr(char *str) ! 648: { ! 649: char *p; ! 650: faddr_t addr; ! 651: ! 652: addr.zone=addr.net=addr.node=addr.point=0; ! 653: if((p=strchr(str,':'))!=NULL) { ! 654: addr.zone=atoi(str); ! 655: addr.net=atoi(p+1); } ! 656: else { ! 657: if(total_faddrs) ! 658: addr.zone=faddr[0].zone; ! 659: else ! 660: addr.zone=1; ! 661: addr.net=atoi(str); } ! 662: if(!addr.zone) /* no such thing as zone 0 */ ! 663: addr.zone=1; ! 664: if((p=strchr(str,'/'))!=NULL) ! 665: addr.node=atoi(p+1); ! 666: else { ! 667: if(total_faddrs) ! 668: addr.net=faddr[0].net; ! 669: else ! 670: addr.net=1; ! 671: addr.node=atoi(str); } ! 672: if((p=strchr(str,'.'))!=NULL) ! 673: addr.point=atoi(p+1); ! 674: return(addr); ! 675: } ! 676: ! 677: /****************************************************************************/ ! 678: /* Returns an ASCII string for FidoNet address 'addr' */ ! 679: /****************************************************************************/ ! 680: char *faddrtoa(faddr_t addr) ! 681: { ! 682: static char str[25]; ! 683: char point[25]; ! 684: ! 685: sprintf(str,"%u:%u/%u",addr.zone,addr.net,addr.node); ! 686: if(addr.point) { ! 687: sprintf(point,".%u",addr.point); ! 688: strcat(str,point); } ! 689: return(str); ! 690: } ! 691: ! 692: #ifndef __OS2__ ! 693: /****************************************************************************/ ! 694: /* This function reads files that are potentially larger than 32k. */ ! 695: /* Up to one megabyte of data can be read with each call. */ ! 696: /****************************************************************************/ ! 697: long lread(int file, char HUGE16 *buf,long bytes) ! 698: { ! 699: long count; ! 700: ! 701: for(count=bytes;count>32767;count-=32767,buf+=32767) ! 702: if(read(file,(char *)buf,32767)!=32767) ! 703: return(-1L); ! 704: if(read(file,(char *)buf,(int)count)!=count) ! 705: return(-1L); ! 706: return(bytes); ! 707: } ! 708: #endif ! 709: ! 710: /****************************************************************************/ ! 711: /* Coverts a FidoNet message into a Synchronet message */ ! 712: /****************************************************************************/ ! 713: void fmsgtosmsg(int file, fmsghdr_t fmsghdr, smbstatus_t status, uint user ! 714: ,uint subnum) ! 715: { ! 716: uchar ch,HUGE16 *fbuf,HUGE16 *sbody,HUGE16 *stail,HUGE16 *outbuf ! 717: ,done,col,esc,cr,*p,str[128]; ! 718: int i,chunk,lzh=0,storage; ! 719: ushort xlat,net; ! 720: ulong l,m,length,lzhlen,bodylen,taillen,crc; ! 721: faddr_t faddr,origaddr,destaddr; ! 722: smbmsg_t msg; ! 723: ! 724: memset(&msg,0,sizeof(smbmsg_t)); ! 725: memcpy(msg.hdr.id,"SHD\x1a",4); ! 726: msg.hdr.version=SMB_VERSION; ! 727: if(fmsghdr.attr&FIDO_PRIVATE) ! 728: msg.idx.attr|=MSG_PRIVATE; ! 729: msg.hdr.attr=msg.idx.attr; ! 730: ! 731: if(fmsghdr.attr&FIDO_FILE) ! 732: msg.hdr.auxattr|=MSG_FILEATTACH; ! 733: ! 734: msg.hdr.when_imported.time=time(NULL); ! 735: msg.hdr.when_imported.zone=sys_timezone; ! 736: msg.hdr.when_written.time=fmsgtime(fmsghdr.time); ! 737: ! 738: origaddr.zone=fmsghdr.origzone; /* only valid if NetMail */ ! 739: origaddr.net=fmsghdr.orignet; ! 740: origaddr.node=fmsghdr.orignode; ! 741: origaddr.point=fmsghdr.origpoint; ! 742: ! 743: destaddr.zone=fmsghdr.destzone; /* only valid if NetMail */ ! 744: destaddr.net=fmsghdr.destnet; ! 745: destaddr.node=fmsghdr.destnode; ! 746: destaddr.point=fmsghdr.destpoint; ! 747: ! 748: smb_hfield(&msg,SENDER,strlen(fmsghdr.from),fmsghdr.from); ! 749: strlwr(fmsghdr.from); ! 750: msg.idx.from=crc16(fmsghdr.from); ! 751: ! 752: smb_hfield(&msg,RECIPIENT,strlen(fmsghdr.to),fmsghdr.to); ! 753: strlwr(fmsghdr.to); ! 754: msg.idx.to=crc16(fmsghdr.to); ! 755: ! 756: if(user) { ! 757: sprintf(str,"%u",user); ! 758: smb_hfield(&msg,RECIPIENTEXT,strlen(str),str); ! 759: msg.idx.to=user; ! 760: msg.idx.from=0; } ! 761: ! 762: smb_hfield(&msg,SUBJECT,strlen(fmsghdr.subj),fmsghdr.subj); ! 763: remove_re(fmsghdr.subj); ! 764: strlwr(fmsghdr.subj); ! 765: msg.idx.subj=crc16(fmsghdr.subj); ! 766: ! 767: length=filelength(file)-sizeof(fmsghdr_t); ! 768: if((fbuf=(char *)LMALLOC(length+1))==NULL) { ! 769: printf("alloc error\r\n"); ! 770: smb_freemsgmem(msg); ! 771: return; } ! 772: if((sbody=(char *)LMALLOC((length+1)*2L))==NULL) { ! 773: printf("alloc error\n"); ! 774: LFREE((char *)fbuf); ! 775: smb_freemsgmem(msg); ! 776: return; } ! 777: if((stail=(char *)LMALLOC((length+1)*2L))==NULL) { ! 778: printf("alloc error\n"); ! 779: LFREE((char *)fbuf); ! 780: LFREE((char *)sbody); ! 781: smb_freemsgmem(msg); ! 782: return; } ! 783: lread(file,fbuf,length); ! 784: ! 785: for(col=l=esc=done=bodylen=taillen=0,cr=1;l<length;l++) { ! 786: ch=fbuf[l]; ! 787: if(ch==1 && cr) { /* kludge line */ ! 788: ! 789: if(!strncmp((char *)fbuf+l+1,"TOPT ",5)) ! 790: destaddr.point=atoi((char *)fbuf+l+6); ! 791: ! 792: else if(!strncmp((char *)fbuf+l+1,"FMPT ",5)) ! 793: origaddr.point=atoi((char *)fbuf+l+6); ! 794: ! 795: else if(!strncmp((char *)fbuf+l+1,"INTL ",5)) { ! 796: faddr=atofaddr((char *)fbuf+l+6); ! 797: destaddr.zone=faddr.zone; ! 798: destaddr.net=faddr.net; ! 799: destaddr.node=faddr.node; ! 800: l+=6; ! 801: while(l<length && fbuf[l]!=SP) l++; ! 802: faddr=atofaddr((char *)fbuf+l+1); ! 803: origaddr.zone=faddr.zone; ! 804: origaddr.net=faddr.net; ! 805: origaddr.node=faddr.node; } ! 806: ! 807: else if(!strncmp((char *)fbuf+l+1,"MSGID:",6)) { ! 808: l+=7; ! 809: while(l<length && fbuf[l]<=SP) l++; ! 810: m=l; ! 811: while(m<length && fbuf[m]!=CR) m++; ! 812: while(m && fbuf[m-1]<=SP) m--; ! 813: if(m>l) ! 814: smb_hfield(&msg,FIDOMSGID,m-l,fbuf+l); } ! 815: ! 816: else if(!strncmp((char *)fbuf+l+1,"REPLY:",6)) { ! 817: l+=7; ! 818: while(l<length && fbuf[l]<=SP) l++; ! 819: m=l; ! 820: while(m<length && fbuf[m]!=CR) m++; ! 821: while(m && fbuf[m-1]<=SP) m--; ! 822: if(m>l) ! 823: smb_hfield(&msg,FIDOREPLYID,m-l,fbuf+l); } ! 824: ! 825: else if(!strncmp((char *)fbuf+l+1,"FLAGS:",6)) { ! 826: l+=7; ! 827: while(l<length && fbuf[l]<=SP) l++; ! 828: m=l; ! 829: while(m<length && fbuf[m]!=CR) m++; ! 830: while(m && fbuf[m-1]<=SP) m--; ! 831: if(m>l) ! 832: smb_hfield(&msg,FIDOFLAGS,m-l,fbuf+l); } ! 833: ! 834: else if(!strncmp((char *)fbuf+l+1,"PATH:",5)) { ! 835: l+=6; ! 836: while(l<length && fbuf[l]<=SP) l++; ! 837: m=l; ! 838: while(m<length && fbuf[m]!=CR) m++; ! 839: while(m && fbuf[m-1]<=SP) m--; ! 840: if(m>l) ! 841: smb_hfield(&msg,FIDOPATH,m-l,fbuf+l); } ! 842: ! 843: else if(!strncmp((char *)fbuf+l+1,"PID:",4)) { ! 844: l+=5; ! 845: while(l<length && fbuf[l]<=SP) l++; ! 846: m=l; ! 847: while(m<length && fbuf[m]!=CR) m++; ! 848: while(m && fbuf[m-1]<=SP) m--; ! 849: if(m>l) ! 850: smb_hfield(&msg,FIDOPID,m-l,fbuf+l); } ! 851: ! 852: else { /* Unknown kludge line */ ! 853: while(l<length && fbuf[l]<=SP) l++; ! 854: m=l; ! 855: while(m<length && fbuf[m]!=CR) m++; ! 856: while(m && fbuf[m-1]<=SP) m--; ! 857: if(m>l) ! 858: smb_hfield(&msg,FIDOCTRL,m-l,fbuf+l); } ! 859: ! 860: while(l<length && fbuf[l]!=CR) l++; ! 861: continue; } ! 862: ! 863: if(ch!=LF && ch!=0x8d) { /* ignore LF and soft CRs */ ! 864: if(cr && (!strncmp((char *)fbuf+l,"--- ",4) ! 865: || !strncmp((char *)fbuf+l,"---\r",4))) ! 866: done=1; /* tear line and down go into tail */ ! 867: if(done && cr && !strncmp((char *)fbuf+l,"SEEN-BY:",8)) { ! 868: l+=8; ! 869: while(l<length && fbuf[l]<=SP) l++; ! 870: m=l; ! 871: while(m<length && fbuf[m]!=CR) m++; ! 872: while(m && fbuf[m-1]<=SP) m--; ! 873: if(m>l) ! 874: smb_hfield(&msg,FIDOSEENBY,m-l,fbuf+l); ! 875: while(l<length && fbuf[l]!=CR) l++; ! 876: continue; } ! 877: if(done) ! 878: stail[taillen++]=ch; ! 879: else ! 880: sbody[bodylen++]=ch; ! 881: col++; ! 882: if(ch==CR) { ! 883: cr=1; ! 884: col=0; ! 885: if(done) ! 886: stail[taillen++]=LF; ! 887: else ! 888: sbody[bodylen++]=LF; } ! 889: else { ! 890: cr=0; ! 891: if(col==1 && !strncmp((char *)fbuf+l," * Origin: ",11)) { ! 892: p=strchr((char *)fbuf+l+11,CR); /* find carriage return */ ! 893: while(p && *p!='(') p--; /* rewind to '(' */ ! 894: if(p) ! 895: origaddr=atofaddr(p+1); /* get orig address */ ! 896: done=1; } ! 897: if(done) ! 898: continue; ! 899: ! 900: if(ch==ESC) esc=1; /* ANSI codes */ ! 901: if(ch==SP && col>40 && !esc) { /* word wrap */ ! 902: for(m=l+1;m<length;m++) /* find next space */ ! 903: if(fbuf[m]<=SP) ! 904: break; ! 905: if(m<length && m-l>80-col) { /* if it's beyond the eol */ ! 906: sbody[bodylen++]=CR; ! 907: sbody[bodylen++]=LF; ! 908: col=0; } } ! 909: } } } ! 910: ! 911: LFREE(fbuf); ! 912: ! 913: if(bodylen>=2 && sbody[bodylen-2]==CR && sbody[bodylen-1]==LF) ! 914: bodylen-=2; /* remove last CRLF if present */ ! 915: ! 916: if(status.max_crcs) { ! 917: for(l=0,crc=0xffffffff;l<bodylen;l++) ! 918: crc=ucrc32(sbody[l],crc); ! 919: crc=~crc; ! 920: ! 921: i=smb_addcrc(status.max_crcs,crc,10); ! 922: if(i) { ! 923: if(i==1) ! 924: lprintf("Duplicate message\r\n"); ! 925: else ! 926: lprintf("smb_addcrc returned %d\r\n",i); ! 927: smb_freemsgmem(msg); ! 928: LFREE(sbody); ! 929: LFREE(stail); ! 930: return; } } ! 931: ! 932: while(taillen && stail[taillen-1]<=SP) /* trim all garbage off the tail */ ! 933: taillen--; ! 934: ! 935: net=NET_FIDO; /* Record origin address */ ! 936: smb_hfield(&msg,SENDERNETTYPE,sizeof(ushort),&net); ! 937: smb_hfield(&msg,SENDERNETADDR,sizeof(fidoaddr_t),&origaddr); ! 938: ! 939: if(subnum==INVALID_SUB) { /* No origin line means NetMail, so add dest addr */ ! 940: smb_hfield(&msg,RECIPIENTNETTYPE,sizeof(ushort),&net); ! 941: smb_hfield(&msg,RECIPIENTNETADDR,sizeof(fidoaddr_t),&destaddr); } ! 942: ! 943: if(subnum!=INVALID_SUB && sub[subnum]->misc&SUB_LZH ! 944: && bodylen+2+taillen+2>=SDT_BLOCK_LEN && bodylen) { ! 945: if((outbuf=(char *)LMALLOC(bodylen*2))==NULL) { ! 946: printf("alloc error for lzh: %lu\n",bodylen*2); ! 947: smb_freemsgmem(msg); ! 948: LFREE(sbody); ! 949: LFREE(stail); ! 950: return; } ! 951: lzhlen=lzh_encode((uchar *)sbody,bodylen,(uchar *)outbuf); ! 952: if(lzhlen>1 && ! 953: smb_datblocks(lzhlen+4+taillen+2)<smb_datblocks(bodylen+2+taillen+2)) { ! 954: bodylen=lzhlen; /* Compressable */ ! 955: l=bodylen+4; ! 956: LFREE(sbody); ! 957: lzh=1; ! 958: sbody=outbuf; } ! 959: else { /* Uncompressable */ ! 960: l=bodylen+2; ! 961: LFREE(outbuf); } } ! 962: else ! 963: l=bodylen+2; ! 964: ! 965: if(taillen) ! 966: l+=(taillen+2); ! 967: ! 968: ! 969: if(status.attr&SMB_HYPERALLOC) { ! 970: if((i=smb_locksmbhdr(10))!=0) { ! 971: printf("smb_locksmbhdr returned %d\n",i); ! 972: smb_freemsgmem(msg); ! 973: LFREE(sbody); ! 974: LFREE(stail); ! 975: return; } ! 976: msg.hdr.offset=smb_hallocdat(); ! 977: storage=SMB_HYPERALLOC; } ! 978: else { ! 979: if(smb_open_da(10)) { ! 980: smb_freemsgmem(msg); ! 981: printf("error opening %s.SDA\r\n",smb_file); ! 982: LFREE(sbody); ! 983: LFREE(stail); ! 984: return; } ! 985: if(subnum!=INVALID_SUB && sub[subnum]->misc&SUB_FAST) { ! 986: msg.hdr.offset=smb_fallocdat(l,1); ! 987: storage=SMB_FASTALLOC; } ! 988: else { ! 989: msg.hdr.offset=smb_allocdat(l,1); ! 990: storage=SMB_SELFPACK; } ! 991: fclose(sda_fp); } ! 992: ! 993: if(msg.hdr.offset && msg.hdr.offset<1L) { ! 994: smb_unlocksmbhdr(); ! 995: smb_freemsgmem(msg); ! 996: LFREE(sbody); ! 997: LFREE(stail); ! 998: printf("error %ld allocating records\r\n",msg.hdr.offset); ! 999: return; } ! 1000: fseek(sdt_fp,msg.hdr.offset,SEEK_SET); ! 1001: if(lzh) { ! 1002: xlat=XLAT_LZH; ! 1003: fwrite(&xlat,2,1,sdt_fp); } ! 1004: xlat=XLAT_NONE; ! 1005: fwrite(&xlat,2,1,sdt_fp); ! 1006: chunk=30000; ! 1007: for(l=0;l<bodylen;l+=chunk) { ! 1008: if(l+chunk>bodylen) ! 1009: chunk=bodylen-l; ! 1010: fwrite(sbody+l,1,chunk,sdt_fp); } ! 1011: if(taillen) { ! 1012: fwrite(&xlat,2,1,sdt_fp); ! 1013: fwrite(stail,1,taillen,sdt_fp); } ! 1014: fflush(sdt_fp); ! 1015: LFREE(sbody); ! 1016: LFREE(stail); ! 1017: ! 1018: if(status.attr&SMB_HYPERALLOC) ! 1019: smb_unlocksmbhdr(); ! 1020: ! 1021: if(lzh) ! 1022: bodylen+=2; ! 1023: bodylen+=2; ! 1024: smb_dfield(&msg,TEXT_BODY,bodylen); ! 1025: if(taillen) ! 1026: smb_dfield(&msg,TEXT_TAIL,taillen+2); ! 1027: ! 1028: smb_addmsghdr(&msg,&status,storage,10); ! 1029: smb_freemsgmem(msg); ! 1030: } ! 1031: ! 1032: /****************************************************************/ ! 1033: /* Get zone and point from kludge lines in 'file' if they exist */ ! 1034: /****************************************************************/ ! 1035: void getzpt(int file, fmsghdr_t *hdr) ! 1036: { ! 1037: char buf[0x1000]; ! 1038: int i,len,cr=0; ! 1039: faddr_t faddr; ! 1040: ! 1041: len=read(file,buf,0x1000); ! 1042: for(i=0;i<len;i++) { ! 1043: if((!i || cr) && buf[i]==1) { /* kludge */ ! 1044: if(!strncmp(buf+i+1,"TOPT ",5)) ! 1045: hdr->destpoint=atoi(buf+i+6); ! 1046: else if(!strncmp(buf+i+1,"FMPT ",5)) ! 1047: hdr->origpoint=atoi(buf+i+6); ! 1048: else if(!strncmp(buf+i+1,"INTL ",5)) { ! 1049: faddr=atofaddr(buf+i+6); ! 1050: hdr->destzone=faddr.zone; ! 1051: hdr->destnet=faddr.net; ! 1052: hdr->destnode=faddr.node; ! 1053: i+=6; ! 1054: while(buf[i] && buf[i]!=SP) i++; ! 1055: faddr=atofaddr(buf+i+1); ! 1056: hdr->origzone=faddr.zone; ! 1057: hdr->orignet=faddr.net; ! 1058: hdr->orignode=faddr.node; } ! 1059: while(i<len && buf[i]!=CR) i++; ! 1060: cr=1; ! 1061: continue; } ! 1062: if(buf[i]==CR) ! 1063: cr=1; ! 1064: else ! 1065: cr=0; } ! 1066: lseek(file,sizeof(fmsghdr_t),SEEK_SET); ! 1067: } ! 1068: ! 1069: /***********************************/ ! 1070: /* Synchronet/FidoNet Message util */ ! 1071: /***********************************/ ! 1072: int main(int argc, char **argv) ! 1073: { ! 1074: char ch,str[512],fname[256],touser[512],subj[512],path[512],sub_code[9] ! 1075: ,*p,*tp,*sp,*buf,*outbuf,cr,tear,lzh; ! 1076: ushort xlat; ! 1077: int i,j,k,n,x,last,file,fmsg,nextmsg,g; ! 1078: ulong files,msgfiles,echomail=0,netmail=0,exported=0,crc, ! 1079: l,m,length,lastmsg,posts,msgs,exp; ! 1080: time_t ptr,now,start,lastimport; ! 1081: read_cfg_text_t txt; ! 1082: struct find_t ff; ! 1083: struct tm tm,*tm_p; ! 1084: fmsghdr_t hdr; ! 1085: faddr_t addr,sys_faddr; ! 1086: post_t HUGE16 *post; ! 1087: FILE *stream,*fstream; ! 1088: smbstatus_t status; ! 1089: smbmsg_t msg; ! 1090: ! 1091: lprintf("\nSynchronet <=> FidoNet Utility Version %s " ! 1092: "Developed by Rob Swindell\n",VER); ! 1093: ! 1094: putenv("TZ=UCT0"); ! 1095: _fmode=O_BINARY; ! 1096: setvbuf(stdout,NULL,_IONBF,0); ! 1097: ! 1098: txt.openerr="\7\r\nError opening %s for read.\r\n"; ! 1099: txt.reading="\r\nReading %s..."; ! 1100: txt.readit="\rRead %s "; ! 1101: txt.allocerr="\7\r\nError allocating %u bytes of memory\r\n"; ! 1102: txt.error="\7\r\nERROR: Offset %lu in %s\r\n\r\n"; ! 1103: ! 1104: node_dir[0]=sub_code[0]=0; ! 1105: for(i=1;i<argc;i++) { ! 1106: if(argv[i][0]=='/') { ! 1107: j=1; ! 1108: while(argv[i][j]) { ! 1109: switch(toupper(argv[i][j])) { ! 1110: case 'A': ! 1111: misc|=ASCII_ONLY; ! 1112: break; ! 1113: case 'B': ! 1114: misc|=LOCAL_NETMAIL; ! 1115: break; ! 1116: case 'C': ! 1117: misc|=PURGE_ECHOMAIL; ! 1118: break; ! 1119: case 'D': ! 1120: misc&=~DELETE_NETMAIL; ! 1121: break; ! 1122: case 'E': ! 1123: misc&=~EXPORT_ECHOMAIL; ! 1124: break; ! 1125: case 'F': ! 1126: misc|=IMPORT_LOCAL; ! 1127: break; ! 1128: case 'G': ! 1129: misc|=IMPORT_NEW_ONLY; ! 1130: break; ! 1131: case 'H': ! 1132: misc|=EXPORT_ALL; ! 1133: break; ! 1134: case 'I': ! 1135: misc&=~IMPORT_ECHOMAIL; ! 1136: break; ! 1137: case 'J': ! 1138: misc|=IGNORE_RECV; ! 1139: break; ! 1140: case 'K': ! 1141: misc&=~KILL_ECHOMAIL; ! 1142: break; ! 1143: case 'L': ! 1144: misc|=LOGFILE; ! 1145: break; ! 1146: case 'M': ! 1147: misc|=IGNORE_MSGPTRS; ! 1148: break; ! 1149: case 'N': ! 1150: misc&=~IMPORT_NETMAIL; ! 1151: break; ! 1152: case 'O': ! 1153: misc|=IGNORE_ADDRESS; ! 1154: break; ! 1155: case 'P': ! 1156: misc|=IGNORE_POINT; ! 1157: break; ! 1158: case 'Q': ! 1159: misc|=DONT_SET_RECV; ! 1160: break; ! 1161: case 'R': ! 1162: misc|=REPORT; ! 1163: break; ! 1164: case 'S': ! 1165: misc|=IMPORT_PRIVATE; ! 1166: break; ! 1167: case 'T': ! 1168: misc|=LEAVE_MSGPTRS; ! 1169: break; ! 1170: case 'U': ! 1171: misc|=UPDATE_MSGPTRS; ! 1172: misc&=~EXPORT_ECHOMAIL; ! 1173: break; ! 1174: case 'X': ! 1175: misc&=~DELETE_ECHOMAIL; ! 1176: break; ! 1177: case 'Y': ! 1178: misc|=UNKNOWN_NETMAIL; ! 1179: break; ! 1180: case 'Z': ! 1181: misc|=IGNORE_ZONE; ! 1182: break; ! 1183: ! 1184: case '=': ! 1185: misc|=CONVERT_TEAR; ! 1186: break; ! 1187: case '!': ! 1188: misc|=NOTIFY_RECEIPT; ! 1189: break; ! 1190: case '2': ! 1191: startmsg=2; ! 1192: break; ! 1193: default: ! 1194: printf("\nusage: sbbsfido [sbbsnode] [/switches] " ! 1195: "[sub_code]"); ! 1196: printf("\nwhere: sbbsnode is the path for your " ! 1197: "NODE1 directory (example: c:\\sbbs\\node1)\n"); ! 1198: printf(" sub_code is the internal code for a " ! 1199: "sub-board (default is ALL subs)\n"); ! 1200: printf("\nvalid switches:\n\n"); ! 1201: printf("n:do not import netmail " ! 1202: "i:do not import echomail\n"); ! 1203: printf("p:ignore point in netmail address " ! 1204: "e:do not export echomail\n"); ! 1205: printf("z:ignore zone in netmail address " ! 1206: "h:export all echomail (hub rescan)\n"); ! 1207: printf("o:ignore entire netmail address " ! 1208: "m:ignore message pointers (export all)\n"); ! 1209: printf("y:import netmail for unknown users " ! 1210: "u:update message pointers (export none)\n"); ! 1211: printf("d:do not delete netmail after import " ! 1212: "x:do not delete echomail after import\n"); ! 1213: printf("l:output to SBBSFIDO.LOG (verbose) " ! 1214: "k:do not kill echomail after export\n"); ! 1215: printf("r:create report of import totals " ! 1216: "t:do not update message pointers\n"); ! 1217: printf("a:export ASCII characters only " ! 1218: "c:delete all messages (echomail purge)\n"); ! 1219: printf("j:ignore recieved bit on import " ! 1220: "s:import private override (strip pvt)\n"); ! 1221: printf("q:do not set received bit on import " ! 1222: "g:import new echomail only\n"); ! 1223: printf("b:import locally created netmail too " ! 1224: "f:import locally created echomail too\n"); ! 1225: printf("=:change existing tear lines to === " ! 1226: "2:export/import/delete starting at 2.MSG\n"); ! 1227: printf("!:notify users of received echomail\n"); ! 1228: exit(0); } ! 1229: j++; } } ! 1230: else { ! 1231: if(strchr(argv[i],'\\') || argv[i][1]==':') ! 1232: sprintf(node_dir,"%.40s",argv[i]); ! 1233: else ! 1234: sprintf(sub_code,"%.8s",argv[i]); } } ! 1235: ! 1236: if(!node_dir[0]) { ! 1237: p=getenv("SBBSNODE"); ! 1238: if(p==NULL) { ! 1239: printf("\7\nSBBSNODE environment variable not set.\n"); ! 1240: exit(1); } ! 1241: strcpy(node_dir,p); } ! 1242: ! 1243: strupr(node_dir); ! 1244: ! 1245: if(node_dir[strlen(node_dir)-1]!='\\') ! 1246: strcat(node_dir,"\\"); ! 1247: ! 1248: read_node_cfg(txt); ! 1249: if(ctrl_dir[0]=='.') { /* Relative path */ ! 1250: strcpy(str,ctrl_dir); ! 1251: sprintf(ctrl_dir,"%s%s",node_dir,str); ! 1252: if(_fullpath(str,ctrl_dir,40)) ! 1253: strcpy(ctrl_dir,str); } ! 1254: backslash(ctrl_dir); ! 1255: ! 1256: read_main_cfg(txt); ! 1257: if(data_dir[0]=='.') { /* Relative path */ ! 1258: strcpy(str,data_dir); ! 1259: sprintf(data_dir,"%s%s",node_dir,str); ! 1260: if(_fullpath(str,data_dir,40)) ! 1261: strcpy(data_dir,str); } ! 1262: backslash(data_dir); ! 1263: if(text_dir[0]=='.') { /* Relative path */ ! 1264: strcpy(str,text_dir); ! 1265: sprintf(text_dir,"%s%s",node_dir,str); ! 1266: if(_fullpath(str,text_dir,40)) ! 1267: strcpy(text_dir,str); } ! 1268: backslash(text_dir); ! 1269: read_msgs_cfg(txt); ! 1270: ! 1271: if(total_faddrs<1) { ! 1272: sys_faddr.zone=sys_faddr.net=sys_faddr.node=1; ! 1273: sys_faddr.point=0; } ! 1274: else ! 1275: sys_faddr=faddr[0]; ! 1276: ! 1277: ! 1278: if(misc&LOGFILE) ! 1279: if((fidologfile=fnopen(&i,"SBBSFIDO.LOG" ! 1280: ,O_WRONLY|O_APPEND|O_CREAT))==NULL) { ! 1281: lprintf("\7ERROR opening SBBSFIDO.LOG\r\n"); ! 1282: exit(1); } ! 1283: ! 1284: sprintf(str,"%s%s",ctrl_dir,"NODE.DAB"); ! 1285: if((nodefile=sopen(str,O_BINARY|O_RDWR,SH_DENYNO))==-1) { ! 1286: lprintf("\r\n\7Error opening %s\r\n",str); ! 1287: exit(1); } ! 1288: ! 1289: if(misc&IMPORT_NETMAIL) { ! 1290: ! 1291: lputs("\r\n\r\nScanning for Inbound NetMail...\r\n"); ! 1292: ! 1293: sprintf(smb_file,"%sMAIL",data_dir); ! 1294: if((i=smb_open(10))!=0) { ! 1295: lprintf("Error %d opening %s\r\n",i,smb_file); ! 1296: exit(1); } ! 1297: ! 1298: if(!filelength(fileno(shd_fp))) ! 1299: if((i=smb_create(mail_maxcrcs,MAX_SYSMAIL,mail_maxage,SMB_EMAIL,10))!=0) { ! 1300: lprintf("Error %d creating %s\r\n",i,smb_file); ! 1301: exit(1); } ! 1302: ! 1303: if((i=smb_locksmbhdr(10))!=0) { ! 1304: lprintf("Error %d locking %s\r\n",i,smb_file); ! 1305: exit(1); } ! 1306: if((i=smb_getstatus(&status))!=0) { ! 1307: lprintf("Error %d reading %s status header\r\n",i,smb_file); ! 1308: exit(1); } ! 1309: smb_unlocksmbhdr(); ! 1310: ! 1311: sprintf(str,"%s*.MSG",netmail_dir); ! 1312: ! 1313: for(last=findfirst(str,&ff,0);!last;last=findnext(&ff)) { ! 1314: sprintf(path,"%s%s",netmail_dir,ff.name); ! 1315: strupr(path); ! 1316: lprintf("\r%s ",path); ! 1317: if((fmsg=nopen(path,O_RDWR))==-1) { ! 1318: lprintf("\7ERROR opening"); ! 1319: continue; } ! 1320: if(filelength(fmsg)<sizeof(fmsghdr_t)) { ! 1321: lprintf("\7Invalid length of %u bytes\r\n",filelength(fmsg)); ! 1322: close(fmsg); ! 1323: continue; } ! 1324: if(read(fmsg,&hdr,sizeof(fmsghdr_t))!=sizeof(fmsghdr_t)) { ! 1325: close(fmsg); ! 1326: lprintf("\7ERROR reading %u bytes" ! 1327: ,sizeof(fmsghdr_t)); ! 1328: continue; } ! 1329: if(hdr.attr&FIDO_ORPHAN) { ! 1330: close(fmsg); ! 1331: lprintf("Orphan (%s).\r\n",hdr.to); ! 1332: continue; } ! 1333: if(misc&IGNORE_ZONE) /* default to system's zone */ ! 1334: hdr.destzone=hdr.origzone=sys_faddr.zone; ! 1335: if(misc&IGNORE_POINT) /* default to no point */ ! 1336: hdr.destpoint=hdr.origpoint=0; ! 1337: getzpt(fmsg,&hdr); /* use kludge if found */ ! 1338: for(i=0;i<total_faddrs;i++) ! 1339: if(hdr.destzone==faddr[i].zone ! 1340: && hdr.destnet==faddr[i].net ! 1341: && hdr.destnode==faddr[i].node ! 1342: && hdr.destpoint==faddr[i].point) ! 1343: break; ! 1344: lprintf("%u:%u/%u.%u " ! 1345: ,hdr.destzone,hdr.destnet,hdr.destnode,hdr.destpoint); ! 1346: if(misc&IGNORE_ADDRESS || i<total_faddrs) { ! 1347: if(!(misc&IGNORE_RECV) && hdr.attr&FIDO_RECV) { ! 1348: close(fmsg); ! 1349: lputs("Already received.\r\n"); ! 1350: continue; } ! 1351: if(hdr.attr&FIDO_LOCAL && !(misc&LOCAL_NETMAIL)) { ! 1352: close(fmsg); ! 1353: lputs("Created locally.\r\n"); ! 1354: continue; } ! 1355: i=atoi(hdr.to); ! 1356: if(!stricmp(hdr.to,"SYSOP")) /* NetMail to "sysop" goes to #1 */ ! 1357: i=1; ! 1358: if(!i) ! 1359: i=matchname(hdr.to); ! 1360: if(!i) { ! 1361: if(misc&UNKNOWN_NETMAIL) /* receive unknown user mail to 1 */ ! 1362: i=1; ! 1363: else { ! 1364: lprintf("\7ERROR unknown user '%s'\r\n",hdr.to); ! 1365: hdr.attr|=FIDO_ORPHAN; ! 1366: lseek(fmsg,0L,SEEK_SET); ! 1367: write(fmsg,&hdr,sizeof(fmsghdr_t)); ! 1368: close(fmsg); ! 1369: continue; } } ! 1370: lprintf("%s\r\n",hdr.to); ! 1371: ! 1372: /*********************/ ! 1373: /* Importing NetMail */ ! 1374: /*********************/ ! 1375: ! 1376: fmsgtosmsg(fmsg,hdr,status,i,INVALID_SUB); ! 1377: ! 1378: addr.zone=hdr.origzone; ! 1379: addr.net=hdr.orignet; ! 1380: addr.node=hdr.orignode; ! 1381: addr.point=hdr.origpoint; ! 1382: sprintf(str,"\7\1n\1hSBBSFIDO: \1m%.36s \1n\1msent you NetMail from " ! 1383: "\1h%s\1n\r\n" ! 1384: ,hdr.from,faddrtoa(addr)); ! 1385: putsmsg(i,str); ! 1386: ! 1387: if(hdr.attr&FIDO_FILE) { /* File attachment */ ! 1388: strcpy(subj,hdr.subj); ! 1389: tp=subj; ! 1390: while(1) { ! 1391: p=strchr(tp,SP); ! 1392: if(p) *p=0; ! 1393: sp=strrchr(tp,'/'); /* sp is slash pointer */ ! 1394: if(!sp) sp=strrchr(tp,'\\'); ! 1395: if(sp) tp=sp+1; ! 1396: sprintf(str,"%s%s",fidofile_dir,tp); ! 1397: sprintf(tmp,"%sFILE\\%04u.IN",data_dir,i); ! 1398: mkdir(tmp); ! 1399: strcat(tmp,"\\"); ! 1400: strcat(tmp,tp); ! 1401: mv(str,tmp,0); ! 1402: if(!p) ! 1403: break; ! 1404: tp=p+1; } } ! 1405: netmail++; ! 1406: ! 1407: /***************************/ ! 1408: /* Updating message header */ ! 1409: /***************************/ ! 1410: if(!(misc&DONT_SET_RECV)) { ! 1411: hdr.attr|=FIDO_RECV; ! 1412: lseek(fmsg,0L,SEEK_SET); ! 1413: write(fmsg,&hdr,sizeof(fmsghdr_t)); } ! 1414: ! 1415: /**************************************/ ! 1416: /* Delete source netmail if specified */ ! 1417: /**************************************/ ! 1418: close(fmsg); ! 1419: if(misc&DELETE_NETMAIL) ! 1420: remove(path); } ! 1421: else ! 1422: close(fmsg); } ! 1423: smb_close(); } ! 1424: ! 1425: ! 1426: if(misc&IMPORT_ECHOMAIL) { ! 1427: ! 1428: start=time(NULL); ! 1429: ! 1430: lputs("\r\n\r\nScanning for Inbound EchoMail...\r\n"); ! 1431: ! 1432: sprintf(path,"%sSBBSFIDO.DAB",data_dir); ! 1433: if((file=nopen(path,O_RDWR|O_CREAT))==-1) ! 1434: lastimport=0L; ! 1435: else { ! 1436: read(file,&lastimport,4); ! 1437: now=time(NULL); ! 1438: lseek(file,0L,SEEK_SET); ! 1439: write(file,&now,4); ! 1440: close(file); } ! 1441: ! 1442: for(g=files=0;g<total_grps;g++) ! 1443: for(i=0;i<total_subs;i++) ! 1444: if(sub[i]->misc&SUB_FIDO && sub[i]->grp==g) { ! 1445: if(sub_code[0] && stricmp(sub_code,sub[i]->code)) ! 1446: continue; ! 1447: if(!sub[i]->echopath[0]) ! 1448: sprintf(sub[i]->echopath,"%s%s\\",echomail_dir,sub[i]->code); ! 1449: if(files) { ! 1450: lputs("\r\n"); ! 1451: files=0; } ! 1452: lprintf("\r\n%-15.15s %s\r\n" ! 1453: ,grp[sub[i]->grp]->sname,sub[i]->lname); ! 1454: ! 1455: sprintf(path,"%s*.MSG",sub[i]->echopath); ! 1456: l=findfirst(path,&ff,0); ! 1457: if(startmsg==2 && !strcmp(ff.name,"1.MSG")) ! 1458: l=findnext(&ff); ! 1459: if(l) ! 1460: continue; ! 1461: lprintf("Counting %s",path); ! 1462: msgfiles=0; ! 1463: while(!l) { ! 1464: memset(&tm,0,sizeof(tm)); ! 1465: tm.tm_mday=ff.wr_date&31; ! 1466: tm.tm_mon=(ff.wr_date>>5)&15; ! 1467: tm.tm_year=80+((ff.wr_date>>9)&127); ! 1468: tm.tm_hour=(ff.wr_time>>11)&31; ! 1469: tm.tm_min=(ff.wr_time>>5)&63; ! 1470: tm.tm_sec=(ff.wr_time&0x1f)<<1; ! 1471: if(isdigit(ff.name[0]) ! 1472: && !(startmsg==2 && !strcmp(ff.name,"1.MSG")) ! 1473: && !(misc&IMPORT_NEW_ONLY && mktime(&tm)<=lastimport)) ! 1474: msgfiles++; /* msgfiles= messages to import */ ! 1475: l=findnext(&ff); } ! 1476: ! 1477: lprintf("\r\n%u messages.\r\n",msgfiles); ! 1478: if(!msgfiles) /* no messages, so continue. */ ! 1479: continue; ! 1480: ! 1481: sprintf(smb_file,"%s%s",sub[i]->data_dir,sub[i]->code); ! 1482: if((j=smb_open(10))!=0) { ! 1483: lprintf("Error %d opening %s\r\n",j,smb_file); ! 1484: continue; } ! 1485: if(!filelength(fileno(shd_fp))) ! 1486: if((j=smb_create(sub[i]->maxcrcs,sub[i]->maxmsgs ! 1487: ,sub[i]->maxage ! 1488: ,sub[i]->misc&SUB_HYPER ? SMB_HYPERALLOC:0 ! 1489: ,10))!=0) { ! 1490: lprintf("Error %d creating %s\r\n",j,smb_file); ! 1491: smb_close(); ! 1492: continue; } ! 1493: ! 1494: if((j=smb_locksmbhdr(10))!=0) { ! 1495: lprintf("Error %d locking SMB header\r\n",j); ! 1496: smb_close(); ! 1497: continue; } ! 1498: if((j=smb_getstatus(&status))!=0) { ! 1499: lprintf("Error %d reading SMB header\r\n",j); ! 1500: smb_close(); ! 1501: continue; } ! 1502: smb_unlocksmbhdr(); ! 1503: ! 1504: for(l=startmsg;l<0x8000 && msgfiles;l++) { ! 1505: sprintf(path,"%s%lu.MSG",sub[i]->echopath,l); ! 1506: if(findfirst(path,&ff,0)) /* doesn't exist */ ! 1507: continue; /* was break */ ! 1508: tm.tm_mday=ff.wr_date&31; ! 1509: tm.tm_mon=(ff.wr_date>>5)&15; ! 1510: tm.tm_year=80+((ff.wr_date>>9)&127); ! 1511: tm.tm_hour=(ff.wr_time>>11)&31; ! 1512: tm.tm_min=(ff.wr_time>>5)&63; ! 1513: tm.tm_sec=(ff.wr_time&0x1f)<<1; ! 1514: if(misc&IMPORT_NEW_ONLY && mktime(&tm)<=lastimport) ! 1515: continue; ! 1516: if(startmsg==2 && !strcmp(ff.name,"1.MSG")) ! 1517: continue; ! 1518: msgfiles--; /* so we only look for as many as are there */ ! 1519: strupr(path); ! 1520: lprintf("\r%s ",path); ! 1521: files++; ! 1522: if((fmsg=nopen(path,O_RDWR))==-1) { ! 1523: lprintf("\7ERROR opening\r\n"); ! 1524: continue; } ! 1525: if(filelength(fmsg)<sizeof(fmsghdr_t)) { ! 1526: lprintf("\7Invalid length of %u bytes\r\n",filelength(fmsg)); ! 1527: close(fmsg); ! 1528: continue; } ! 1529: if(read(fmsg,&hdr,sizeof(fmsghdr_t))!=sizeof(fmsghdr_t)) { ! 1530: close(fmsg); ! 1531: lprintf("\7ERROR reading %u bytes\r\n" ! 1532: ,sizeof(fmsghdr_t)); ! 1533: continue; } ! 1534: if(misc&IMPORT_LOCAL || !(hdr.attr&FIDO_LOCAL)) { ! 1535: ! 1536: if(!(misc&IGNORE_RECV) && hdr.attr&FIDO_RECV) { ! 1537: close(fmsg); ! 1538: lputs("Already received.\r\n"); ! 1539: continue; } ! 1540: ! 1541: if(hdr.attr&FIDO_SENT) { ! 1542: close(fmsg); ! 1543: lputs("Sent."); ! 1544: if(hdr.attr&FIDO_KILLSENT) ! 1545: if(!remove(path)) ! 1546: lputs(" Killed."); ! 1547: lputs("\r\n"); ! 1548: continue; } ! 1549: ! 1550: if(hdr.attr&FIDO_PRIVATE && !(sub[i]->misc&SUB_PRIV)) { ! 1551: if(misc&IMPORT_PRIVATE) ! 1552: hdr.attr&=~FIDO_PRIVATE; ! 1553: else { ! 1554: close(fmsg); ! 1555: lputs("Private posts disallowed.\r\n"); ! 1556: continue; } } ! 1557: ! 1558: if(!(hdr.attr&FIDO_PRIVATE) && sub[i]->misc&SUB_PONLY) ! 1559: hdr.attr|=MSG_PRIVATE; ! 1560: ! 1561: /**********************/ ! 1562: /* Importing EchoMail */ ! 1563: /**********************/ ! 1564: ! 1565: fmsgtosmsg(fmsg,hdr,status,0,i); ! 1566: ! 1567: echomail++; ! 1568: ! 1569: /* Updating message header */ ! 1570: if(!(misc&DONT_SET_RECV)) { ! 1571: hdr.attr|=FIDO_RECV; ! 1572: lseek(fmsg,0L,SEEK_SET); ! 1573: write(fmsg,&hdr,sizeof(fmsghdr_t)); } ! 1574: ! 1575: close(fmsg); ! 1576: if(misc&NOTIFY_RECEIPT && (m=matchname(hdr.to))!=0) { ! 1577: sprintf(str ! 1578: ,"\7\1n\1hSBBSFIDO: \1m%.36s \1n\1msent you EchoMail on " ! 1579: "\1h%s \1n\1m%s\1n\r\n" ! 1580: ,hdr.from,grp[sub[i]->grp]->sname,sub[i]->sname); ! 1581: putsmsg(m,str); } ! 1582: ! 1583: /* Delete source EchoMail if specified */ ! 1584: if(misc&DELETE_ECHOMAIL) ! 1585: remove(path); } ! 1586: else ! 1587: close(fmsg); } ! 1588: smb_close(); ! 1589: } ! 1590: ! 1591: now=time(NULL); ! 1592: if(now-start) ! 1593: lprintf("\r\nImported %lu EchoMail messages in %lu seconds " ! 1594: "(%lu messages/second).\r\n" ! 1595: ,echomail,now-start,echomail/(now-start)); ! 1596: } ! 1597: ! 1598: if(misc&EXPORT_ECHOMAIL) { ! 1599: ! 1600: start=time(NULL); ! 1601: ! 1602: lputs("\r\n\r\nScanning for Outbound EchoMail...\r\n"); ! 1603: ! 1604: for(g=files=0;g<total_grps;g++) ! 1605: for(i=0;i<total_subs;i++) ! 1606: if(sub[i]->misc&SUB_FIDO && sub[i]->grp==g) { ! 1607: if(sub_code[0] && stricmp(sub_code,sub[i]->code)) ! 1608: continue; ! 1609: if(!sub[i]->echopath[0]) ! 1610: sprintf(sub[i]->echopath,"%s%s\\",echomail_dir,sub[i]->code); ! 1611: if(files) { ! 1612: lputs("\r\n"); ! 1613: files=0; } ! 1614: lprintf("\r\n%-15.15s %s\r\n" ! 1615: ,grp[sub[i]->grp]->sname,sub[i]->lname); ! 1616: ptr=0; ! 1617: if(!(misc&IGNORE_MSGPTRS)) { ! 1618: sprintf(str,"%s%s.SFP",sub[i]->data_dir,sub[i]->code); ! 1619: if((file=nopen(str,O_RDONLY))!=-1) { ! 1620: read(file,&ptr,sizeof(time_t)); ! 1621: close(file); } } ! 1622: ! 1623: msgs=getlastmsg(i,&lastmsg,0); ! 1624: if(!msgs || (!(misc&IGNORE_MSGPTRS) && ptr>=lastmsg)) { ! 1625: if(ptr>lastmsg && !(misc&LEAVE_MSGPTRS)) { /* fix ptr */ ! 1626: sprintf(str,"%s%s.SFP",sub[i]->data_dir,sub[i]->code); ! 1627: if((file=nopen(str,O_WRONLY|O_CREAT))==-1) ! 1628: lprintf("\7ERROR opening/creating %s",str); ! 1629: else { ! 1630: write(file,&lastmsg,4); ! 1631: close(file); } } ! 1632: continue; } ! 1633: nextmsg=startmsg; ! 1634: ! 1635: sprintf(smb_file,"%s%s" ! 1636: ,sub[i]->data_dir,sub[i]->code); ! 1637: if((j=smb_open(10))!=0) { ! 1638: lprintf("Error %d opening %s\r\n",j,smb_file); ! 1639: continue; } ! 1640: ! 1641: post=NULL; ! 1642: posts=loadmsgs(&post,ptr); ! 1643: ! 1644: if(!posts) { /* no new messages */ ! 1645: smb_close(); ! 1646: if(post) ! 1647: FREE(post); ! 1648: continue; } ! 1649: ! 1650: for(m=exp=0;m<posts;m++) { ! 1651: printf("\rScanning: %lu of %lu " ! 1652: ,m+1,posts); ! 1653: ! 1654: msg.idx.offset=post[m].offset; ! 1655: if((k=smb_lockmsghdr(msg,10))!=0) { ! 1656: lprintf("ERR_LOCK %s %d\r\n",smb_file,k); ! 1657: continue; } ! 1658: k=smb_getmsghdr(&msg); ! 1659: if(k || msg.hdr.number!=post[m].number) { ! 1660: smb_unlockmsghdr(msg); ! 1661: smb_freemsgmem(msg); ! 1662: ! 1663: msg.hdr.number=post[m].number; ! 1664: if((k=smb_getmsgidx(&msg))!=0) { ! 1665: lprintf("ERR_READ %s %d\r\n",smb_file,k); ! 1666: continue; } ! 1667: if((k=smb_lockmsghdr(msg,10))!=0) { ! 1668: lprintf("ERR_LOCK %s %d\r\n",smb_file,k); ! 1669: continue; } ! 1670: if((k=smb_getmsghdr(&msg))!=0) { ! 1671: smb_unlockmsghdr(msg); ! 1672: lprintf("ERR_READ %s %d\r\n",smb_file,k); ! 1673: continue; } } ! 1674: ! 1675: if((!(misc&EXPORT_ALL) && msg.from_net.type==NET_FIDO) ! 1676: || !strnicmp(msg.subj,"NE:",3)) { /* no echo */ ! 1677: smb_unlockmsghdr(msg); ! 1678: smb_freemsgmem(msg); ! 1679: continue; } /* From a Fido node, ignore it */ ! 1680: ! 1681: if(msg.from_net.type && msg.from_net.type!=NET_FIDO ! 1682: && !(sub[i]->misc&SUB_GATE)) { ! 1683: smb_unlockmsghdr(msg); ! 1684: smb_freemsgmem(msg); ! 1685: continue; } ! 1686: ! 1687: for(j=nextmsg;j;j++) { ! 1688: sprintf(fname,"%s%u.MSG",sub[i]->echopath,j); ! 1689: if(!fexist(fname)) ! 1690: break; } ! 1691: if(!j) { ! 1692: lputs("\7EchoMail dir full!"); ! 1693: smb_unlockmsghdr(msg); ! 1694: smb_freemsgmem(msg); ! 1695: continue; } ! 1696: nextmsg=j+1; ! 1697: strupr(fname); ! 1698: if((fmsg=nopen(fname,O_WRONLY|O_CREAT))==-1) { ! 1699: smb_unlockmsghdr(msg); ! 1700: smb_freemsgmem(msg); ! 1701: lprintf("\7ERROR creating %s\r\n",fname); ! 1702: continue; } ! 1703: if((fstream=fdopen(fmsg,"wb"))==NULL) { ! 1704: close(fmsg); ! 1705: smb_unlockmsghdr(msg); ! 1706: smb_freemsgmem(msg); ! 1707: lprintf("\7ERROR fdopen %s\r\n",fname); ! 1708: continue; } ! 1709: setvbuf(fstream,NULL,_IOFBF,2048); ! 1710: ! 1711: files++; ! 1712: ! 1713: memset(&hdr,0,sizeof(fmsghdr_t)); /* Zero the header */ ! 1714: hdr.origzone=sub[i]->faddr.zone; ! 1715: hdr.orignet=sub[i]->faddr.net; ! 1716: hdr.orignode=sub[i]->faddr.node; ! 1717: hdr.origpoint=sub[i]->faddr.point; ! 1718: ! 1719: hdr.attr=FIDO_LOCAL; ! 1720: if(misc&KILL_ECHOMAIL) ! 1721: hdr.attr|=FIDO_KILLSENT; ! 1722: if(msg.hdr.attr&MSG_PRIVATE) ! 1723: hdr.attr|=FIDO_PRIVATE; ! 1724: ! 1725: sprintf(hdr.from,"%.35s",msg.from); ! 1726: ! 1727: tm_p=gmtime((time_t *)&msg.hdr.when_written.time); ! 1728: sprintf(hdr.time,"%02u %3.3s %02u %02u:%02u:%02u" ! 1729: ,tm_p->tm_mday,mon[tm_p->tm_mon],tm_p->tm_year%100 ! 1730: ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec); ! 1731: ! 1732: sprintf(hdr.to,"%.35s",msg.to); ! 1733: ! 1734: sprintf(hdr.subj,"%.71s",msg.subj); ! 1735: ! 1736: fwrite(&hdr,sizeof(fmsghdr_t),1,fstream); ! 1737: ! 1738: for(j=0;j<msg.hdr.total_dfields;j++) { ! 1739: ! 1740: if(msg.dfield[j].type!=TEXT_BODY ! 1741: && msg.dfield[j].type!=TEXT_TAIL) ! 1742: continue; /* skip non-text data fields */ ! 1743: ! 1744: if(msg.dfield[j].length<3) /* need at least 3 bytes */ ! 1745: continue; ! 1746: ! 1747: fseek(sdt_fp,msg.hdr.offset+msg.dfield[j].offset,SEEK_SET); ! 1748: ! 1749: lzh=0; ! 1750: fread(&xlat,2,1,sdt_fp); ! 1751: if(xlat==XLAT_LZH) { ! 1752: lzh=1; ! 1753: fread(&xlat,2,1,sdt_fp); } ! 1754: if(xlat!=XLAT_NONE) /* no other translations supported */ ! 1755: continue; ! 1756: ! 1757: length=msg.dfield[j].length-2; ! 1758: if(lzh) ! 1759: length-=2; ! 1760: ! 1761: if((buf=LMALLOC(length))==NULL) { ! 1762: lprintf("Error allocating %lu bytes\r\n",length); ! 1763: continue; } ! 1764: ! 1765: fread(buf,length,1,sdt_fp); ! 1766: ! 1767: if(lzh) { ! 1768: l=*(long *)buf; ! 1769: if((outbuf=LMALLOC(l))==NULL) { ! 1770: lprintf("Error allocationg %lu for lzh\r\n",l); ! 1771: LFREE(buf); ! 1772: continue; } ! 1773: length=lzh_decode(buf,length,outbuf); ! 1774: LFREE(buf); ! 1775: buf=outbuf; } ! 1776: ! 1777: tear=0; ! 1778: for(l=0,cr=1;l<length;l++) { ! 1779: if(buf[l]==1) { /* Ctrl-A, so skip it and the next char */ ! 1780: l++; ! 1781: continue; } ! 1782: if(buf[l]==LF || buf[l]==0) /* Ignore line feeds */ ! 1783: continue; ! 1784: if(cr) { ! 1785: if(l+3<length && buf[l]=='-' && buf[l+1]=='-' ! 1786: && buf[l+2]=='-' ! 1787: && (buf[l+3]==SP || buf[l+3]==CR)) { ! 1788: if(misc&CONVERT_TEAR) /* Convert to === */ ! 1789: buf[l]=buf[l+1]=buf[l+2]='='; ! 1790: else ! 1791: tear=1; } ! 1792: else if(l+10<length ! 1793: && !strncmp(buf+l," * Origin: ",11)) ! 1794: buf[l+1]='#'; } /* Convert * Origin into # Origin */ ! 1795: ! 1796: if(buf[l]==CR) ! 1797: cr=1; ! 1798: else ! 1799: cr=0; ! 1800: if(sub[i]->misc&SUB_ASCII || misc&ASCII_ONLY) { ! 1801: if(buf[l]<SP && buf[l]!=CR) /* Ctrl ascii */ ! 1802: buf[l]='.'; /* converted to '.' */ ! 1803: if((uchar)buf[l]>0x7f) /* extended ASCII */ ! 1804: buf[l]='*'; } /* converted to '*' */ ! 1805: fputc(buf[l],fstream); } ! 1806: fprintf(fstream,"\r\n"); ! 1807: LFREE(buf); } ! 1808: ! 1809: if(!(sub[i]->misc&SUB_NOTAG)) { ! 1810: if(!tear) /* No previous tear line */ ! 1811: fprintf(fstream,"--- Synchronet+SBBSfido v%s\r\n" ! 1812: ,VER); /* so add ours */ ! 1813: fprintf(fstream," * Origin: %s (%s)\r\n" ! 1814: ,sub[i]->origline[0] ? sub[i]->origline : origline ! 1815: ,faddrtoa(sub[i]->faddr)); } ! 1816: ! 1817: fputc(0,fstream); /* Null terminator */ ! 1818: fclose(fstream); ! 1819: exported++; ! 1820: exp++; ! 1821: printf("Exported: %lu of %lu",exp,exported); ! 1822: smb_unlockmsghdr(msg); ! 1823: smb_freemsgmem(msg); } ! 1824: ! 1825: smb_close(); ! 1826: FREE(post); ! 1827: ! 1828: /***********************/ ! 1829: /* Update FIDO_PTR.DAB */ ! 1830: /***********************/ ! 1831: if(!(misc&LEAVE_MSGPTRS) && lastmsg>ptr) { ! 1832: sprintf(str,"%s%s.SFP",sub[i]->data_dir,sub[i]->code); ! 1833: if((file=nopen(str,O_WRONLY|O_CREAT))==-1) ! 1834: lprintf("\7ERROR opening/creating %s",str); ! 1835: else { ! 1836: write(file,&lastmsg,4); ! 1837: close(file); } } } ! 1838: ! 1839: now=time(NULL); ! 1840: if(now-start) ! 1841: lprintf("\r\nExported %lu EchoMail messages in %lu seconds " ! 1842: "(%lu messages/second).\r\n" ! 1843: ,exported,now-start,exported/(now-start)); ! 1844: ! 1845: } ! 1846: ! 1847: if(misc&UPDATE_MSGPTRS) { ! 1848: ! 1849: lputs("\r\n\r\nUpdating Message Pointers to Last Posted Message...\r\n"); ! 1850: ! 1851: for(g=0;g<total_grps;g++) ! 1852: for(i=0;i<total_subs;i++) ! 1853: if(sub[i]->misc&SUB_FIDO && sub[i]->grp==g) { ! 1854: lprintf("\r\n%-15.15s %s\r\n" ! 1855: ,grp[sub[i]->grp]->sname,sub[i]->lname); ! 1856: getlastmsg(i,&l,0); ! 1857: sprintf(str,"%s%s.SFP",sub[i]->data_dir,sub[i]->code); ! 1858: if((file=nopen(str,O_WRONLY|O_CREAT))==-1) ! 1859: lprintf("\7ERROR opening/creating %s",str); ! 1860: else { ! 1861: write(file,&l,sizeof(time_t)); ! 1862: close(file); } } } ! 1863: ! 1864: if(misc&PURGE_ECHOMAIL) { ! 1865: ! 1866: lputs("\r\n\r\nPurging EchoMail...\r\n"); ! 1867: ! 1868: for(g=0;g<total_grps;g++) ! 1869: for(i=0;i<total_subs;i++) ! 1870: if(sub[i]->misc&SUB_FIDO && sub[i]->grp==g) { ! 1871: if(sub_code[0] && stricmp(sub_code,sub[i]->code)) ! 1872: continue; ! 1873: if(!sub[i]->echopath[0]) ! 1874: sprintf(sub[i]->echopath,"%s%s\\",echomail_dir,sub[i]->code); ! 1875: sprintf(str,"%s*.MSG",sub[i]->echopath); ! 1876: last=findfirst(str,&ff,0); ! 1877: while(!last) { ! 1878: sprintf(str,"%s%s",sub[i]->echopath,ff.name); ! 1879: if(startmsg!=2 || strcmp(ff.name,"1.MSG")) { ! 1880: lprintf("\r\nDeleting %s",str); ! 1881: remove(str); } ! 1882: last=findnext(&ff); } } } ! 1883: ! 1884: ! 1885: if(misc&(IMPORT_NETMAIL|IMPORT_ECHOMAIL) && misc&REPORT) { ! 1886: sprintf(str,"%sSBBSFIDO.MSG",text_dir); ! 1887: if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) { ! 1888: lprintf("Error opening %s\r\n",str); ! 1889: exit(1); } ! 1890: sprintf(fname,"\1c\1h " ! 1891: "���������������������������������������������������\r\n"); ! 1892: sprintf(path,"\1c\1h " ! 1893: "���������������������������������������������������\r\n"); ! 1894: write(file,fname,strlen(fname)); ! 1895: sprintf(str," \1n\1k\0016" ! 1896: " Last FidoNet Transfer on %.24s \1n\r\n",ctime(&start)); ! 1897: write(file,str,strlen(str)); ! 1898: write(file,path,strlen(path)); ! 1899: write(file,fname,strlen(fname)); ! 1900: sprintf(subj,"Imported %lu EchoMail and %lu NetMail Messages" ! 1901: ,echomail,netmail); ! 1902: sprintf(str," \1n\1k\0016 %-50.50s\1n\r\n",subj); ! 1903: write(file,str,strlen(str)); ! 1904: write(file,path,strlen(path)); ! 1905: close(file); } ! 1906: ! 1907: return(0); ! 1908: } ! 1909:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.