|
|
1.1 root 1: /* qwktomsg.cpp */
2:
3: /* Synchronet QWK to SMB message conversion routine */
4:
1.1.1.2 ! root 5: /* $Id: qwktomsg.cpp,v 1.35 2004/12/29 10:17:45 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 2004 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: #include "qwk.h"
40:
41: /****************************************************************************/
42: /* Converts a QWK message packet into a message. */
43: /****************************************************************************/
44: bool sbbs_t::qwktomsg(FILE *qwk_fp, char *hdrblk, char fromhub, uint subnum
45: , uint touser)
46: {
1.1.1.2 ! root 47: char* body;
! 48: char* tail;
! 49: char* header;
! 50: char str[256],col=0,lastch=0,*p,qwkbuf[QWK_BLOCK_LEN+1];
! 51: uint i,j,k,lzh=0,skip=0;
! 52: long bodylen,taillen;
! 53: bool header_cont=false;
! 54: bool success=false;
! 55: ulong block,blocks;
1.1 root 56: smbmsg_t msg;
1.1.1.2 ! root 57: struct tm tm;
! 58: ushort xlat=XLAT_NONE;
! 59: int storage=SMB_SELFPACK;
! 60: long dupechk_hashes=SMB_HASH_SOURCE_ALL;
1.1 root 61:
62: memset(&msg,0,sizeof(smbmsg_t)); /* Initialize message header */
63: msg.hdr.version=smb_ver();
64:
65: blocks=atol(hdrblk+116);
66: if(blocks<2) {
67: errormsg(WHERE,ERR_CHK,"QWK packet header blocks",blocks);
68: return(false);
69: }
70:
71: if(subnum!=INVALID_SUB
72: && (hdrblk[0]=='*' || hdrblk[0]=='+' || cfg.sub[subnum]->misc&SUB_PONLY))
1.1.1.2 ! root 73: msg.hdr.attr|=MSG_PRIVATE;
1.1 root 74: if(subnum!=INVALID_SUB && cfg.sub[subnum]->misc&SUB_AONLY)
1.1.1.2 ! root 75: msg.hdr.attr|=MSG_ANONYMOUS;
1.1 root 76: if(subnum==INVALID_SUB && cfg.sys_misc&SM_DELREADM)
1.1.1.2 ! root 77: msg.hdr.attr|=MSG_KILLREAD;
1.1 root 78: if((fromhub || useron.rest&FLAG('Q')) &&
79: (hdrblk[0]=='*' || hdrblk[0]=='-' || hdrblk[0]=='`'))
1.1.1.2 ! root 80: msg.hdr.attr|=MSG_READ;
1.1 root 81:
82: if(subnum!=INVALID_SUB && !fromhub && cfg.sub[subnum]->mod_ar[0]
83: && chk_ar(cfg.sub[subnum]->mod_ar,&useron))
1.1.1.2 ! root 84: msg.hdr.attr|=MSG_MODERATED;
1.1 root 85: if(subnum!=INVALID_SUB && !fromhub && cfg.sub[subnum]->misc&SUB_SYSPERM
86: && sub_op(subnum))
1.1.1.2 ! root 87: msg.hdr.attr|=MSG_PERMANENT;
1.1 root 88:
89: memset(&tm,0,sizeof(tm));
90: tm.tm_mon = ((hdrblk[8]&0xf)*10)+(hdrblk[9]&0xf);
91: if(tm.tm_mon>0) tm.tm_mon--; /* zero based */
92: tm.tm_mday=((hdrblk[11]&0xf)*10)+(hdrblk[12]&0xf);
93: tm.tm_year=((hdrblk[14]&0xf)*10)+(hdrblk[15]&0xf);
94: if(tm.tm_year<Y2K_2DIGIT_WINDOW)
95: tm.tm_year+=100;
96: tm.tm_hour=((hdrblk[16]&0xf)*10)+(hdrblk[17]&0xf);
97: tm.tm_min=((hdrblk[19]&0xf)*10)+(hdrblk[20]&0xf);
98: tm.tm_sec=0;
99:
100: msg.hdr.when_written.time=mktime(&tm);
101: if(!(useron.rest&FLAG('Q')) && !fromhub)
1.1.1.2 ! root 102: msg.hdr.when_written.zone=sys_timezone(&cfg);
1.1 root 103: msg.hdr.when_imported.time=time(NULL);
1.1.1.2 ! root 104: msg.hdr.when_imported.zone=sys_timezone(&cfg);
1.1 root 105:
106: hdrblk[116]=0; // don't include number of blocks in "re: msg number"
1.1.1.2 ! root 107: if(!(useron.rest&FLAG('Q')) && !fromhub)
! 108: msg.hdr.thread_back=atol((char *)hdrblk+108);
! 109:
! 110: if(subnum==INVALID_SUB) { /* E-mail */
! 111: if(cfg.sys_misc&SM_FASTMAIL)
! 112: storage=SMB_FASTALLOC;
1.1 root 113:
1.1.1.2 ! root 114: /* duplicate message-IDs must be allowed in mail database */
! 115: dupechk_hashes&=~(1<<SMB_HASH_SOURCE_MSG_ID);
1.1 root 116:
117: username(&cfg,touser,str);
1.1.1.2 ! root 118: smb_hfield_str(&msg,RECIPIENT,str);
1.1 root 119: sprintf(str,"%u",touser);
1.1.1.2 ! root 120: smb_hfield_str(&msg,RECIPIENTEXT,str);
! 121: } else {
! 122: if(cfg.sub[subnum]->misc&SUB_HYPER)
! 123: storage = SMB_HYPERALLOC;
! 124: else if(cfg.sub[subnum]->misc&SUB_FAST)
! 125: storage = SMB_FASTALLOC;
1.1 root 126:
1.1.1.2 ! root 127: if(cfg.sub[subnum]->misc&SUB_LZH)
! 128: xlat=XLAT_LZH;
1.1 root 129:
1.1.1.2 ! root 130: sprintf(str,"%25.25s",(char *)hdrblk+21); /* To user */
1.1 root 131: truncsp(str);
1.1.1.2 ! root 132: smb_hfield_str(&msg,RECIPIENT,str);
! 133: if(cfg.sub[subnum]->misc&SUB_LZH)
! 134: xlat=XLAT_LZH;
! 135: }
1.1 root 136:
137: sprintf(str,"%25.25s",hdrblk+71); /* Subject */
138: truncsp(str);
1.1.1.2 ! root 139: smb_hfield_str(&msg,SUBJECT,str);
1.1 root 140:
141: /********************************/
142: /* Convert the QWK message text */
143: /********************************/
144:
1.1.1.2 ! root 145: if((header=(char *)calloc((blocks-1L)*QWK_BLOCK_LEN*2L,sizeof(char)))==NULL) {
! 146: smb_freemsgmem(&msg);
! 147: errormsg(WHERE,ERR_ALLOC,"QWK msg header",(blocks-1L)*QWK_BLOCK_LEN*2L);
! 148: return(false);
! 149: }
! 150:
1.1 root 151: bodylen=0;
1.1.1.2 ! root 152: if((body=(char *)LMALLOC((blocks-1L)*QWK_BLOCK_LEN*2L))==NULL) {
! 153: LFREE(header);
1.1 root 154: smb_freemsgmem(&msg);
1.1.1.2 ! root 155: errormsg(WHERE,ERR_ALLOC,"QWK msg body",(blocks-1L)*QWK_BLOCK_LEN*2L);
! 156: return(false);
! 157: }
1.1 root 158:
159: taillen=0;
1.1.1.2 ! root 160: if((tail=(char *)LMALLOC((blocks-1L)*QWK_BLOCK_LEN*2L))==NULL) {
! 161: LFREE(header);
1.1 root 162: LFREE(body);
163: smb_freemsgmem(&msg);
1.1.1.2 ! root 164: errormsg(WHERE,ERR_ALLOC,"QWK msg tail",(blocks-1L)*QWK_BLOCK_LEN*2L);
! 165: return(false);
! 166: }
! 167:
! 168: memset(qwkbuf,0,sizeof(qwkbuf));
1.1 root 169:
170: for(block=1;block<blocks;block++) {
1.1.1.2 ! root 171: if(!fread(qwkbuf,1,QWK_BLOCK_LEN,qwk_fp))
! 172: break;
! 173: for(k=0;k<QWK_BLOCK_LEN;k++) {
1.1 root 174: if(qwkbuf[k]==0)
175: continue;
1.1.1.2 ! root 176: if(bodylen==0 && (qwkbuf[k]=='@' || header_cont)) {
! 177: if((p=strchr(qwkbuf+k, QWK_NEWLINE))!=NULL)
! 178: *p=0;
! 179: strcat(header, qwkbuf+k);
! 180: strcat(header, "\n");
! 181: if(p==NULL) {
! 182: header_cont=true;
! 183: break;
! 184: }
! 185: k+=strlen(qwkbuf+k);
! 186: header_cont=false;
! 187: continue;
! 188: }
! 189: if(!taillen && qwkbuf[k]==' ' && col==3 && bodylen>=3
1.1 root 190: && body[bodylen-3]=='-' && body[bodylen-2]=='-'
191: && body[bodylen-1]=='-') {
192: bodylen-=3;
193: strcpy(tail,"--- ");
194: taillen=4;
195: col++;
1.1.1.2 ! root 196: continue;
! 197: }
! 198: if(qwkbuf[k]==QWK_NEWLINE) { /* expand QWK_NEWLINE to crlf */
1.1 root 199: if(!taillen && col==3 && bodylen>=3 && body[bodylen-3]=='-'
200: && body[bodylen-2]=='-' && body[bodylen-1]=='-') {
201: bodylen-=3;
202: strcpy(tail,"---");
1.1.1.2 ! root 203: taillen=3;
! 204: }
1.1 root 205: col=0;
206: if(taillen) {
207: tail[taillen++]=CR;
1.1.1.2 ! root 208: tail[taillen++]=LF;
! 209: }
1.1 root 210: else {
211: body[bodylen++]=CR;
1.1.1.2 ! root 212: body[bodylen++]=LF;
! 213: }
! 214: continue;
! 215: }
1.1 root 216: /* beep restrict */
217: if(!fromhub && qwkbuf[k]==BEL && useron.rest&FLAG('B'))
218: continue;
219: /* ANSI restriction */
220: if(!fromhub && (qwkbuf[k]==1 || qwkbuf[k]==ESC)
221: && useron.rest&FLAG('A'))
222: continue;
223: if(qwkbuf[k]!=1 && lastch!=1)
224: col++;
1.1.1.2 ! root 225: if(lastch==CTRL_A && !validattr(qwkbuf[k])) {
1.1 root 226: if(taillen) taillen--;
227: else bodylen--;
228: lastch=0;
1.1.1.2 ! root 229: continue;
! 230: }
1.1 root 231: lastch=qwkbuf[k];
232: if(taillen)
233: tail[taillen++]=qwkbuf[k];
234: else
1.1.1.2 ! root 235: body[bodylen++]=qwkbuf[k];
! 236: }
! 237: }
1.1 root 238:
1.1.1.2 ! root 239: while(bodylen && body[bodylen-1]==' ') bodylen--; /* remove trailing spaces */
1.1 root 240: if(bodylen>=2 && body[bodylen-2]==CR && body[bodylen-1]==LF)
241: bodylen-=2;
242:
1.1.1.2 ! root 243: while(taillen && tail[taillen-1]<=' ') taillen--; /* remove trailing garbage */
1.1 root 244:
1.1.1.2 ! root 245: skip=0;
! 246: if(useron.rest&FLAG('Q') || fromhub) { /* QWK Net */
! 247: if(!strnicmp(header,"@VIA:",5)) {
! 248: if(!fromhub)
! 249: set_qwk_flag(QWK_VIA);
! 250: p=strchr(header, '\n');
! 251: if(p) {
! 252: *p=0;
! 253: skip=strlen(header)+1;
! 254: }
! 255: truncsp(header);
! 256: p=header+5; /* Skip "@VIA:" */
! 257: while(*p && *p<=' ') p++; /* Skip any spaces */
! 258: if(route_circ(p,cfg.sys_id)) {
! 259: free(header);
! 260: free(body);
! 261: free(tail);
! 262: smb_freemsgmem(&msg);
! 263: bprintf("\r\nCircular message path: %s\r\n",p);
! 264: sprintf(str,"Circular message path: %s from %s"
! 265: ,p,fromhub ? cfg.qhub[fromhub-1]->id:useron.alias);
! 266: errorlog(str);
! 267: return(false);
! 268: }
! 269: sprintf(str,"%s/%s"
! 270: ,fromhub ? cfg.qhub[fromhub-1]->id : useron.alias,p);
! 271: strupr(str);
! 272: update_qwkroute(str);
! 273: }
1.1 root 274: else {
1.1.1.2 ! root 275: if(fromhub)
! 276: strcpy(str,cfg.qhub[fromhub-1]->id);
! 277: else
! 278: strcpy(str,useron.alias);
! 279: }
! 280: strupr(str);
! 281: j=NET_QWK;
! 282: smb_hfield(&msg,SENDERNETTYPE,2,&j);
! 283: smb_hfield_str(&msg,SENDERNETADDR,str);
! 284: sprintf(str,"%25.25s",hdrblk+46); /* From user */
! 285: truncsp(str);
! 286: } else {
! 287: sprintf(str,"%u",useron.number);
! 288: smb_hfield_str(&msg,SENDEREXT,str);
! 289: if((uint)subnum!=INVALID_SUB && cfg.sub[subnum]->misc&SUB_NAME)
! 290: strcpy(str,useron.name);
! 291: else
! 292: strcpy(str,useron.alias);
! 293: }
! 294: smb_hfield_str(&msg,SENDER,str);
! 295:
! 296: if(!strnicmp(header+skip,"@MSGID:",7)) {
! 297: if(!fromhub)
! 298: set_qwk_flag(QWK_MSGID);
! 299: p=strchr(header+skip, '\n');
! 300: i=skip;
! 301: if(p) {
! 302: *p=0;
! 303: skip+=strlen(header+i)+1;
! 304: }
! 305: p=header+i+7; /* Skip "@MSGID:" */
! 306: while(*p && *p<=' ') p++; /* Skip any spaces */
! 307: truncstr(p," "); /* Truncate at first space char */
! 308: smb_hfield_str(&msg,RFC822MSGID,p);
! 309: }
! 310: if(!strnicmp(header+skip,"@REPLY:",7)) {
! 311: if(!fromhub)
! 312: set_qwk_flag(QWK_MSGID);
! 313: p=strchr(header+skip, '\n');
! 314: i=skip;
! 315: if(p) {
! 316: *p=0;
! 317: skip+=strlen(header+i)+1;
! 318: }
! 319: p=header+i+7; /* Skip "@REPLY:" */
! 320: while(*p && *p<=' ') p++; /* Skip any spaces */
! 321: truncstr(p," "); /* Truncate at first space char */
! 322: smb_hfield_str(&msg,RFC822REPLYID,p);
! 323: }
! 324: if(!strnicmp(header+skip,"@TZ:",4)) {
! 325: if(!fromhub)
! 326: set_qwk_flag(QWK_TZ);
! 327: p=strchr(header+skip, '\n');
! 328: i=skip;
! 329: if(p) {
! 330: *p=0;
! 331: skip+=strlen(header+i)+1;
! 332: }
! 333: p=header+i+4; /* Skip "@TZ:" */
! 334: while(*p && *p<=' ') p++; /* Skip any spaces */
! 335: msg.hdr.when_written.zone=(short)ahtoul(p);
! 336: }
! 337: if(!strnicmp(header+skip,"@REPLYTO:",9)) {
! 338: p=strchr(header+skip, '\n');
! 339: i=skip;
! 340: if(p) {
! 341: *p=0;
! 342: skip+=strlen(header+i)+1;
! 343: }
! 344: p=header+i+9; /* Skip "@REPLYTO:" */
! 345: while(*p && *p<=' ') p++; /* Skip any spaces */
! 346: smb_hfield_str(&msg,REPLYTO,p);
! 347: }
! 348: free(header);
1.1 root 349:
1.1.1.2 ! root 350: /* smb_addmsg required ASCIIZ strings */
! 351: body[bodylen]=0;
! 352: tail[taillen]=0;
! 353:
! 354: if(online==ON_REMOTE)
! 355: bputs(text[WritingIndx]);
! 356:
! 357: if(smb.status.max_crcs==0) /* no CRC checking means no body text dupe checking */
! 358: dupechk_hashes&=~(1<<SMB_HASH_SOURCE_BODY);
! 359:
! 360: if((i=smb_addmsg(&smb,&msg,storage,dupechk_hashes,xlat,(uchar*)body,(uchar*)tail))==SMB_SUCCESS)
! 361: success=true;
! 362: else if(i==SMB_DUPE_MSG) {
! 363: bprintf("\r\n!%s\r\n",smb.last_error);
! 364: if(!fromhub) {
! 365: if(subnum==INVALID_SUB) {
! 366: sprintf(str,"%s duplicate e-mail attempt (%s)",useron.alias,smb.last_error);
! 367: logline("E!",str);
! 368: } else {
! 369: sprintf(str,"%s duplicate message attempt in %s %s (%s)"
! 370: ,useron.alias
! 371: ,cfg.grp[cfg.sub[subnum]->grp]->sname
! 372: ,cfg.sub[subnum]->lname
! 373: ,smb.last_error);
! 374: logline("P!",str);
! 375: }
! 376: }
! 377: }
! 378: else
! 379: errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
1.1 root 380:
381: smb_freemsgmem(&msg);
382:
383: LFREE(body);
384: LFREE(tail);
385:
1.1.1.2 ! root 386: return(success);
1.1 root 387: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.