Annotation of sbbs/sbbs2/msgtoqwk.c, revision 1.1.1.2

1.1       root        1: #line 1 "MSGTOQWK.C"
                      2: 
                      3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
                      4: 
                      5: #include "sbbs.h"
                      6: #include "qwk.h"
                      7: #include "etext.h"
                      8: 
1.1.1.2 ! root        9: #define MAX_MSGNUM     0x7FFFFFUL      // only 7 (decimal) digits allowed for msg num 
        !            10: 
1.1       root       11: /****************************************************************************/
                     12: /* Converts message 'msg' to QWK format, writing to file 'qwk_fp'.          */
                     13: /* mode determines how to handle Ctrl-A codes                                                          */
                     14: /****************************************************************************/
                     15: ulong msgtoqwk(smbmsg_t msg, FILE *qwk_fp, int mode, int subnum
                     16:        , int conf)
                     17: {
                     18:        uchar   str[512],from[512],to[512],ch,tear=0,tearwatch=0,HUGE16 *buf,*p;
                     19:        ushort  xlat;
                     20:        long    l,size=0,offset;
                     21:        int     i;
                     22: 
                     23: offset=ftell(qwk_fp);
                     24: memset(str,SP,128);
                     25: fwrite(str,128,1,qwk_fp);              /* Init header to space */
                     26: 
                     27: if(msg.from_net.addr && (uint)subnum==INVALID_SUB) {
                     28:        if(mode&TO_QNET)
                     29:                sprintf(from,"%.128s",msg.from);
                     30:        else if(msg.from_net.type==NET_FIDO)
                     31:                sprintf(from,"%.128s@%.128s"
                     32:                        ,msg.from,faddrtoa(*(faddr_t *)msg.from_net.addr));
                     33:        else if(msg.from_net.type==NET_INTERNET)
                     34:                sprintf(from,"%.128s",msg.from_net.addr);
                     35:        else
                     36:                sprintf(from,"%.128s@%.128s",msg.from,msg.from_net.addr);
                     37:        if(strlen(from)>25) {
                     38:                sprintf(str,"From: %.128s\xe3\xe3",from);
                     39:                fwrite(str,strlen(str),1,qwk_fp);
                     40:                size+=strlen(str);
                     41:                sprintf(from,"%.128s",msg.from); } }
                     42: else {
                     43:        sprintf(from,"%.128s",msg.from);
                     44:        if(msg.hdr.attr&MSG_ANONYMOUS && !SYSOP)           /* from user */
                     45:                strcpy(from,text[Anonymous]); }
                     46: 
                     47: if(msg.to_net.addr && (uint)subnum==INVALID_SUB) {
                     48:        if(msg.to_net.type==NET_FIDO)
                     49:                sprintf(to,"%.128s@%s",msg.to,faddrtoa(*(faddr_t *)msg.to_net.addr));
                     50:        else if(msg.to_net.type==NET_INTERNET)
                     51:                sprintf(to,"%.128s",msg.to_net.addr);
                     52:        else if(msg.to_net.type==NET_QWK) {
                     53:                if(mode&TO_QNET) {
                     54:                        p=strchr(msg.to_net.addr,'/');
                     55:                        if(p) {         /* Another hop */
                     56:                                p++;
                     57:                                strcpy(to,"NETMAIL");
                     58:                                sprintf(str,"%.128s@%.128s\xe3",msg.to,p);
                     59:                                fwrite(str,strlen(str),1,qwk_fp);
                     60:                                size+=strlen(str); }
                     61:                        else
                     62:                                sprintf(to,"%.128s",msg.to); }
                     63:                else
                     64:                        sprintf(to,"%.128s@%.128s",msg.to,msg.to_net.addr); }
                     65:        else
                     66:                sprintf(to,"%.128s@%.128s",msg.to,msg.to_net.addr);
                     67:        if(strlen(to)>25) {
                     68:                sprintf(str,"To: %.128s\xe3\xe3",to);
                     69:                fwrite(str,strlen(str),1,qwk_fp);
                     70:                size+=strlen(str);
                     71:                if(msg.to_net.type==NET_QWK)
                     72:                        strcpy(to,"NETMAIL");
                     73:                else
                     74:                        sprintf(to,"%.128s",msg.to); } }
                     75: else
                     76:        sprintf(to,"%.128s",msg.to);
                     77: 
                     78: if(msg.from_net.type==NET_QWK && mode&VIA && !msg.forwarded) {
                     79:        sprintf(str,"@VIA:%.128s\xe3",msg.from_net.addr);
                     80:        fwrite(str,strlen(str),1,qwk_fp);
                     81:        size+=strlen(str); }
                     82: 
                     83: if(msg.hdr.when_written.zone && mode&TZ) {
                     84:        sprintf(str,"@TZ:%04x\xe3",msg.hdr.when_written.zone);
                     85:        fwrite(str,strlen(str),1,qwk_fp);
                     86:        size+=strlen(str); }
                     87: 
                     88: p=0;
                     89: for(i=0;i<msg.total_hfields;i++) {
                     90:        if(msg.hfield[i].type==SENDER)
                     91:                p=msg.hfield_dat[i];
                     92:        if(msg.hfield[i].type==FORWARDED && p) {
                     93:                sprintf(str,"Forwarded from %s on %s\xe3",p
                     94:                        ,timestr((time_t *)msg.hfield_dat[i]));
                     95:                fwrite(str,strlen(str),1,qwk_fp);
                     96:                size+=strlen(str); } }
                     97: 
                     98: buf=smb_getmsgtxt(&smb,&msg,1);
                     99: if(!buf)
                    100:        return(0);
                    101: 
                    102: for(l=0;buf[l];l++) {
                    103:        ch=buf[l];
                    104: 
                    105:        if(ch==LF) {
                    106:                if(tear)
                    107:                        tear++;                                 /* Count LFs after tearline */
                    108:                if(tear>3)                                      /* more than two LFs after the tear */
                    109:                        tear=0;
                    110:                if(tearwatch==4) {                      /* watch for LF---LF */
                    111:                        tear=1;
                    112:                        tearwatch=0; }
                    113:                else if(!tearwatch)
                    114:                        tearwatch=1;
                    115:                else
                    116:                        tearwatch=0;
                    117:                ch=0xe3;
                    118:                fputc(ch,qwk_fp);                 /* Replace LF with funky char */
                    119:                size++;
                    120:                continue; }
                    121: 
                    122:        if(ch==CR) {                                    /* Ignore CRs */
                    123:                if(tearwatch<4)                         /* LF---CRLF is okay */
                    124:                        tearwatch=0;                    /* LF-CR- is not okay */
                    125:                continue; }
                    126: 
                    127:        if(ch==SP && tearwatch==4) {    /* watch for "LF--- " */
                    128:                tear=1;
                    129:                tearwatch=0; }
                    130: 
                    131:        if(ch=='-') {                   /* watch for "LF---" */
                    132:                if(l==0 || (tearwatch && tearwatch<4))
                    133:                        tearwatch++;
                    134:                else
                    135:                        tearwatch=0; }
                    136:        else
                    137:                tearwatch=0;
                    138: 
                    139:        if((uint)subnum!=INVALID_SUB && sub[subnum]->misc&SUB_ASCII) {
                    140:                if(ch<SP && ch!=1)
                    141:                        ch='.';
                    142:                else if(ch>0x7f)
                    143:                        ch='*'; }
                    144: 
                    145:        if(ch==0xE3)                                    /* funky char */
                    146:                ch='*';
                    147: 
                    148:        if(ch==1) {  /* ctrl-a */
                    149:                ch=buf[++l];
                    150:                if(!ch)
                    151:                        break;
                    152:                if(mode&A_EXPAND) {
                    153:                        str[0]=0;
                    154:                        switch(toupper(ch)) {           /* non-color codes */
                    155:                                case 'L':
                    156:                                        strcpy(str,"\x1b[2J");
                    157:                                        break;
                    158:                                case 'W':
                    159:                                        strcpy(str,ansi(LIGHTGRAY));
                    160:                                        break;
                    161:                                case 'K':
                    162:                                        strcpy(str,ansi(BLACK));
                    163:                                        break;
                    164:                                case 'H':
                    165:                                        strcpy(str,ansi(HIGH));
                    166:                                        break;
                    167:                                case 'I':
                    168:                                        strcpy(str,ansi(BLINK));
                    169:                                        break;
                    170:                                case 'N':   /* Normal */
                    171:                                        strcpy(str,"\x1b[0m");
                    172:                                        break;
                    173:                                case '0':
                    174:                                        strcpy(str,"\x1b[40m");
                    175:                                        break;
                    176:                                case '7':
                    177:                                        strcpy(str,ansi(LIGHTGRAY<<4));
                    178:                                        break;
                    179:                                case 'R':                               /* Color codes */
                    180:                                        strcpy(str,ansi(RED));
                    181:                                        break;
                    182:                                case 'G':
                    183:                                        strcpy(str,ansi(GREEN));
                    184:                                        break;
                    185:                                case 'B':
                    186:                                        strcpy(str,ansi(BLUE));
                    187:                                        break;
                    188:                                case 'C':
                    189:                                        strcpy(str,ansi(CYAN));
                    190:                                        break;
                    191:                                case 'M':
                    192:                                        strcpy(str,ansi(MAGENTA));
                    193:                                        break;
                    194:                                case 'Y':   /* Yellow */
                    195:                                        strcpy(str,ansi(BROWN));
                    196:                                        break;
                    197:                                case '1':
                    198:                                        strcpy(str,ansi(RED<<4));
                    199:                                        break;
                    200:                                case '2':
                    201:                                        strcpy(str,ansi(GREEN<<4));
                    202:                                        break;
                    203:                                case '3':
                    204:                                        strcpy(str,ansi(BROWN<<4));
                    205:                                        break;
                    206:                                case '4':
                    207:                                        strcpy(str,ansi(BLUE<<4));
                    208:                                        break;
                    209:                                case '5':
                    210:                                        strcpy(str,ansi(MAGENTA<<4));
                    211:                                        break;
                    212:                                case '6':
                    213:                                        strcpy(str,ansi(CYAN<<4));
                    214:                                        break; }
                    215:                        if(str[0]) {
                    216:                                fwrite(str,strlen(str),1,qwk_fp);
                    217:                                size+=strlen(str); }
                    218:                        continue; }                                             /* End Expand */
                    219: 
                    220:                if(mode&A_LEAVE) {
                    221:                        fputc(1,qwk_fp);
                    222:                        fputc(ch,qwk_fp);
                    223:                        size+=2L; }
                    224:                else                                                                    /* Strip */
                    225:                        if(toupper(ch)=='L') {
                    226:                                fputc(FF,qwk_fp);
                    227:                                size++; }
                    228:                continue; }                                                     /* End of Ctrl-A shit */
                    229:        fputc(ch,qwk_fp);
                    230:        size++; }
                    231: 
                    232: LFREE(buf);
                    233: if(ch!=0xE3) {
                    234:        fputc(0xE3,qwk_fp);             /* make sure it ends in CRLF */
                    235:        size++; }
                    236: 
                    237: if(mode&TAGLINE && !(sub[subnum]->misc&SUB_NOTAG)) {
                    238:        if(!tear)                                                                               /* no tear line */
                    239:                strcpy(str,"\1n---\xe3");                   /* so add one */
                    240:     else
                    241:                strcpy(str,"\1n");
                    242:        if(sub[subnum]->misc&SUB_ASCII) ch='*';
                    243:        else ch='�';
                    244:        sprintf(tmp," %c \1g%s\1n %c %.127s\xe3"
                    245:                ,ch,decrypt(Synchronet,0),ch,sub[subnum]->tagline);
                    246:        strcat(str,tmp);
                    247:        if(!(mode&A_LEAVE))
                    248:                remove_ctrl_a(str);
                    249:        fwrite(str,strlen(str),1,qwk_fp);
                    250:        size+=strlen(str); }
                    251: 
                    252: while(size%128L) {                              /* Pad with spaces */
                    253:        size++;
                    254:        fputc(SP,qwk_fp); }
                    255: 
                    256: unixtodos(msg.hdr.when_written.time,&date,&curtime);
                    257: 
                    258: sprintf(tmp,"%02u-%02u-%02u%02u:%02u"
1.1.1.2 ! root      259:     ,date.da_mon,date.da_day,TM_YEAR(date.da_year-1900)
1.1       root      260:     ,curtime.ti_hour,curtime.ti_min);
                    261: 
                    262: if(msg.hdr.attr&MSG_PRIVATE) {
                    263:     if(msg.hdr.attr&MSG_READ)
                    264:         ch='*'; /* private, read */
                    265:     else
                    266:         ch='+'; /* private, unread */ }
                    267: else {
                    268:     if(msg.hdr.attr&MSG_READ)
                    269:         ch='-'; /* public, read */
                    270:     else
                    271:         ch=' '; /* public, unread */ }
                    272: 
                    273: 
                    274: sprintf(str,"%c%-7lu%-13.13s%-25.25s"
                    275:        "%-25.25s%-25.25s%12s%-8lu%-6lu\xe1%c%c%c%c%c"
                    276:     ,ch                     /* message status flag */
                    277:        ,mode&REP ? (ulong)conf /* conference or */
1.1.1.2 ! root      278:                : msg.hdr.number&MAX_MSGNUM     /* message number */
1.1       root      279:        ,tmp                                    /* date and time */
                    280:        ,to                                     /* To: */
                    281:        ,from                                   /* From: */
                    282:     ,msg.subj               /* Subject */
                    283:     ,nulstr                 /* Password */
1.1.1.2 ! root      284:     ,msg.hdr.thread_orig&MAX_MSGNUM    /* Message Re: Number */
1.1       root      285:        ,(size/128L)+1                  /* Number of 128byte blocks */
                    286:     ,(char)conf&0xff        /* Conference number lo byte */
                    287:        ,(ushort)conf>>8                /*                                       hi byte */
                    288:     ,SP                     /* not used */
                    289:     ,SP                     /* not used */
                    290:     ,useron.rest&FLAG('Q') ? '*' : SP     /* Net tag line */
                    291:     );
                    292: 
                    293: fseek(qwk_fp,offset,SEEK_SET);
                    294: fwrite(str,128,1,qwk_fp);
                    295: fseek(qwk_fp,size,SEEK_CUR);
                    296: 
                    297: return(size);
                    298: }

unix.superglobalmegacorp.com

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