|
|
1.1 ! root 1: #line 1 "EMAIL.C" ! 2: ! 3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */ ! 4: ! 5: #include "sbbs.h" ! 6: #include "cmdshell.h" ! 7: ! 8: /****************************************************************************/ ! 9: /* Mails a message to usernumber. 'top' is a buffer to place at beginning */ ! 10: /* of message. */ ! 11: /* Called from functions main_sec, newuser, readmail and scanposts */ ! 12: /****************************************************************************/ ! 13: void email(int usernumber, char *top, char *subj, char mode) ! 14: { ! 15: char str[256],str2[256],msgpath[256],title[LEN_TITLE+1],ch ! 16: ,buf[SDT_BLOCK_LEN]; ! 17: ushort xlat=XLAT_NONE,msgattr=0; ! 18: int i,j,x,file; ! 19: long l; ! 20: ulong length,offset,crc=0xffffffffUL; ! 21: FILE *instream; ! 22: node_t node; ! 23: smbmsg_t msg; ! 24: ! 25: sprintf(title,"%.*s",LEN_TITLE,subj); ! 26: ! 27: if(useron.etoday>=level_emailperday[useron.level] && !SYSOP) { ! 28: bputs(text[TooManyEmailsToday]); ! 29: return; } ! 30: ! 31: if(usernumber==1 && useron.rest&FLAG('S') ! 32: && (node_valuser!=1 || useron.fbacks || useron.emails)) { /* ! val fback */ ! 33: bprintf(text[R_Feedback],sys_op); ! 34: return; } ! 35: if(usernumber!=1 && useron.rest&FLAG('E') ! 36: && (node_valuser!=usernumber || useron.fbacks || useron.emails)) { ! 37: bputs(text[R_Email]); ! 38: return; } ! 39: if(!usernumber) { ! 40: bputs(text[UnknownUser]); ! 41: return; } ! 42: getuserrec(usernumber,U_MISC,8,str); ! 43: l=ahtoul(str); ! 44: if(l&(DELETED|INACTIVE)) { /* Deleted or Inactive User */ ! 45: bputs(text[UnknownUser]); ! 46: return; } ! 47: if(l&NETMAIL && sys_misc&SM_FWDTONET ! 48: && yesno(text[ForwardMailQ])) { /* Forward to netmail address */ ! 49: getuserrec(usernumber,U_NETMAIL,LEN_NETMAIL,str); ! 50: netmail(str,subj,mode); ! 51: return; } ! 52: bprintf(text[Emailing],username(usernumber,tmp),usernumber); ! 53: action=NODE_SMAL; ! 54: nodesync(); ! 55: ! 56: sprintf(str,"%sFEEDBACK.BIN",exec_dir); ! 57: if(usernumber==1 && useron.fbacks && fexist(str)) { ! 58: exec_bin("FEEDBACK",&main_csi); ! 59: if(main_csi.logic!=LOGIC_TRUE) ! 60: return; } ! 61: ! 62: if(sys_misc&SM_ANON_EM && (SYSOP || useron.exempt&FLAG('A')) ! 63: && !noyes(text[AnonymousQ])) ! 64: msgattr|=MSG_ANONYMOUS; ! 65: ! 66: if(sys_misc&SM_DELREADM) ! 67: msgattr|=MSG_KILLREAD; ! 68: ! 69: sprintf(msgpath,"%sINPUT.MSG",node_dir); ! 70: sprintf(str2,"%s #%u",username(usernumber,tmp),usernumber); ! 71: if(!writemsg(msgpath,top,title,mode,0,str2)) { ! 72: bputs(text[Aborted]); ! 73: return; } ! 74: ! 75: if(mode&WM_FILE) { ! 76: sprintf(str2,"%sFILE\\%04u.IN",data_dir,usernumber); ! 77: mkdir(str2); ! 78: sprintf(str2,"%sFILE\\%04u.IN\\%s",data_dir,usernumber,title); ! 79: if(fexist(str2)) { ! 80: bputs(text[FileAlreadyThere]); ! 81: remove(msgpath); ! 82: return; } ! 83: if(online==ON_LOCAL) { /* Local upload */ ! 84: bputs(text[EnterPath]); ! 85: if(!getstr(str,60,K_LINE|K_UPPER)) { ! 86: bputs(text[Aborted]); ! 87: remove(msgpath); ! 88: return; } ! 89: backslash(str); ! 90: strcat(str,title); ! 91: mv(str,str2,1); } ! 92: else { /* Remote */ ! 93: menu("ULPROT"); ! 94: mnemonics(text[ProtocolOrQuit]); ! 95: strcpy(str,"Q"); ! 96: for(x=0;x<total_prots;x++) ! 97: if(prot[x]->ulcmd[0] && chk_ar(prot[x]->ar,useron)) { ! 98: sprintf(tmp,"%c",prot[x]->mnemonic); ! 99: strcat(str,tmp); } ! 100: ch=getkeys(str,0); ! 101: if(ch=='Q' || sys_status&SS_ABORT) { ! 102: bputs(text[Aborted]); ! 103: remove(msgpath); ! 104: return; } ! 105: for(x=0;x<total_prots;x++) ! 106: if(prot[x]->ulcmd[0] && prot[x]->mnemonic==ch ! 107: && chk_ar(prot[x]->ar,useron)) ! 108: break; ! 109: if(x<total_prots) /* This should be always */ ! 110: protocol(cmdstr(prot[x]->ulcmd,str2,nulstr,NULL),0); } ! 111: l=flength(str2); ! 112: if(l>0) ! 113: bprintf(text[FileNBytesReceived],title,ultoac(l,tmp)); ! 114: else { ! 115: bprintf(text[FileNotReceived],title); ! 116: remove(msgpath); ! 117: return; } } ! 118: ! 119: bputs(text[WritingIndx]); ! 120: ! 121: if((i=smb_stack(&smb,SMB_STACK_PUSH))!=0) { ! 122: errormsg(WHERE,ERR_OPEN,"MAIL",i); ! 123: return; } ! 124: sprintf(smb.file,"%sMAIL",data_dir); ! 125: smb.retry_time=smb_retry_time; ! 126: if((i=smb_open(&smb))!=0) { ! 127: smb_stack(&smb,SMB_STACK_POP); ! 128: errormsg(WHERE,ERR_OPEN,smb.file,i); ! 129: return; } ! 130: ! 131: if(filelength(fileno(smb.shd_fp))<1) { /* Create it if it doesn't exist */ ! 132: smb.status.max_crcs=mail_maxcrcs; ! 133: smb.status.max_age=mail_maxage; ! 134: smb.status.max_msgs=MAX_SYSMAIL; ! 135: smb.status.attr=SMB_EMAIL; ! 136: if((i=smb_create(&smb))!=0) { ! 137: smb_close(&smb); ! 138: smb_stack(&smb,SMB_STACK_POP); ! 139: errormsg(WHERE,ERR_CREATE,smb.file,i); ! 140: return; } } ! 141: ! 142: if((i=smb_locksmbhdr(&smb))!=0) { ! 143: smb_close(&smb); ! 144: smb_stack(&smb,SMB_STACK_POP); ! 145: errormsg(WHERE,ERR_LOCK,smb.file,i); ! 146: return; } ! 147: ! 148: length=flength(msgpath)+2; /* +2 for translation string */ ! 149: ! 150: if(length&0xfff00000UL) { ! 151: smb_unlocksmbhdr(&smb); ! 152: smb_close(&smb); ! 153: smb_stack(&smb,SMB_STACK_POP); ! 154: errormsg(WHERE,ERR_LEN,msgpath,length); ! 155: return; } ! 156: ! 157: if((i=smb_open_da(&smb))!=0) { ! 158: smb_unlocksmbhdr(&smb); ! 159: smb_close(&smb); ! 160: smb_stack(&smb,SMB_STACK_POP); ! 161: errormsg(WHERE,ERR_OPEN,smb.file,i); ! 162: return; } ! 163: if(sys_misc&SM_FASTMAIL) ! 164: offset=smb_fallocdat(&smb,length,1); ! 165: else ! 166: offset=smb_allocdat(&smb,length,1); ! 167: smb_close_da(&smb); ! 168: ! 169: if((file=open(msgpath,O_RDONLY|O_BINARY))==-1 ! 170: || (instream=fdopen(file,"rb"))==NULL) { ! 171: smb_freemsgdat(&smb,offset,length,1); ! 172: smb_unlocksmbhdr(&smb); ! 173: smb_close(&smb); ! 174: smb_stack(&smb,SMB_STACK_POP); ! 175: errormsg(WHERE,ERR_OPEN,msgpath,O_RDONLY|O_BINARY); ! 176: return; } ! 177: ! 178: setvbuf(instream,NULL,_IOFBF,2*1024); ! 179: fseek(smb.sdt_fp,offset,SEEK_SET); ! 180: xlat=XLAT_NONE; ! 181: fwrite(&xlat,2,1,smb.sdt_fp); ! 182: x=SDT_BLOCK_LEN-2; /* Don't read/write more than 255 */ ! 183: while(!feof(instream)) { ! 184: memset(buf,0,x); ! 185: j=fread(buf,1,x,instream); ! 186: if((j!=x || feof(instream)) && buf[j-1]==LF && buf[j-2]==CR) ! 187: buf[j-1]=buf[j-2]=0; ! 188: if(mail_maxcrcs) { ! 189: for(i=0;i<j;i++) ! 190: crc=ucrc32(buf[i],crc); } ! 191: fwrite(buf,j,1,smb.sdt_fp); ! 192: x=SDT_BLOCK_LEN; } ! 193: fflush(smb.sdt_fp); ! 194: fclose(instream); ! 195: crc=~crc; ! 196: ! 197: memset(&msg,0,sizeof(smbmsg_t)); ! 198: memcpy(msg.hdr.id,"SHD\x1a",4); ! 199: msg.hdr.version=SMB_VERSION; ! 200: msg.hdr.attr=msg.idx.attr=msgattr; ! 201: if(mode&WM_FILE) ! 202: msg.hdr.auxattr|=MSG_FILEATTACH; ! 203: msg.hdr.when_written.time=msg.hdr.when_imported.time=time(NULL); ! 204: msg.hdr.when_written.zone=msg.hdr.when_imported.zone=sys_timezone; ! 205: ! 206: if(mail_maxcrcs) { ! 207: i=smb_addcrc(&smb,crc); ! 208: if(i) { ! 209: smb_freemsgdat(&smb,offset,length,1); ! 210: smb_unlocksmbhdr(&smb); ! 211: smb_close(&smb); ! 212: smb_stack(&smb,SMB_STACK_POP); ! 213: bputs("\1r\1h\1iDuplicate message!\r\n"); ! 214: return; } } ! 215: ! 216: msg.hdr.offset=offset; ! 217: ! 218: username(usernumber,str); ! 219: smb_hfield(&msg,RECIPIENT,strlen(str),str); ! 220: ! 221: sprintf(str,"%u",usernumber); ! 222: smb_hfield(&msg,RECIPIENTEXT,strlen(str),str); ! 223: msg.idx.to=usernumber; ! 224: ! 225: strcpy(str,useron.alias); ! 226: smb_hfield(&msg,SENDER,strlen(str),str); ! 227: ! 228: sprintf(str,"%u",useron.number); ! 229: smb_hfield(&msg,SENDEREXT,strlen(str),str); ! 230: msg.idx.from=useron.number; ! 231: ! 232: smb_hfield(&msg,SUBJECT,strlen(title),title); ! 233: strlwr(title); ! 234: msg.idx.subj=crc16(title); ! 235: ! 236: smb_dfield(&msg,TEXT_BODY,length); ! 237: ! 238: smb_unlocksmbhdr(&smb); ! 239: i=smb_addmsghdr(&smb,&msg,SMB_SELFPACK); ! 240: smb_close(&smb); ! 241: smb_stack(&smb,SMB_STACK_POP); ! 242: ! 243: smb_freemsgmem(&msg); ! 244: if(i) { ! 245: smb_freemsgdat(&smb,offset,length,1); ! 246: errormsg(WHERE,ERR_WRITE,smb.file,i); ! 247: return; } ! 248: ! 249: if(usernumber==1) { ! 250: useron.fbacks++; ! 251: logon_fbacks++; ! 252: putuserrec(useron.number,U_FBACKS,5,itoa(useron.fbacks,tmp,10)); } ! 253: else { ! 254: useron.emails++; ! 255: logon_emails++; ! 256: putuserrec(useron.number,U_EMAILS,5,itoa(useron.emails,tmp,10)); } ! 257: useron.etoday++; ! 258: putuserrec(useron.number,U_ETODAY,5,itoa(useron.etoday,tmp,10)); ! 259: bprintf(text[Emailed],username(usernumber,tmp),usernumber); ! 260: sprintf(str,"E-mailed %s #%d",username(usernumber,tmp),usernumber); ! 261: logline("E+",str); ! 262: if(mode&WM_FILE && online==ON_REMOTE) ! 263: autohangup(); ! 264: if(msgattr&MSG_ANONYMOUS) /* Don't tell user if anonymous */ ! 265: return; ! 266: for(i=1;i<=sys_nodes;i++) { /* Tell user, if online */ ! 267: getnodedat(i,&node,0); ! 268: if(node.useron==usernumber && !(node.misc&NODE_POFF) ! 269: && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { ! 270: sprintf(str,text[EmailNodeMsg],node_num,useron.alias); ! 271: putnmsg(i,str); ! 272: break; } } ! 273: if(i>sys_nodes) { /* User wasn't online, so leave short msg */ ! 274: sprintf(str,text[UserSentYouMail],useron.alias); ! 275: putsmsg(usernumber,str); } ! 276: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.