3 * see copyright.doc for copyright information
5 * This program is a filter which converts Citadel/UX binary message format
6 * to standard UseNet news format. Useful for Citadel<->News gateways.
17 void get_config(); struct config config;
19 int struncmp(lstr,rstr,len)
25 lc=tolower(lstr[pos]);
26 rc=tolower(rstr[pos]);
27 if ((lc==0)&&(rc==0)) return(0);
28 if (lc<rc) return(-1);
39 int a,b,e,mtype,aflag;
40 char bbb[100],ngn[100];
50 /* experimental cuunbatch header generation */
51 for (a=0; a<argc; ++a) {
52 if (!strcmp(argv[a],"-c")) cuunbatch = 1;
57 sprintf(tflnm,"/tmp/c2a%d",getpid());
65 mtype=getc(fp); aflag=getc(fp);
69 strcpy(tuid,"postmaster");
75 fprintf(tfp,"Message-ID: <%ld@%s>\n",tmid,tsid);
77 if (aflag!=1) fmout(80,fp,tfp);
78 else while(a=getc(fp), a>0) {
79 putc(a,tfp); if (a==13) putc(10,tfp);
82 if ((b!='M')&&(b>0)) fpgetfield(fp,bbb);
83 if (b=='I') tmid=atol(bbb);
86 if (!strcmp(tsid,NODENAME)) strcpy(tsid,FQDN);
87 for (a=0; a<strlen(tuid); ++a) if (tuid[a]==' ') tuid[a]='_';
88 fprintf(tfp,"From: %s@%s ",tuid,tsid);
89 for (a=0; a<strlen(tuid); ++a) if (tuid[a]=='_') tuid[a]=' ';
90 fprintf(tfp,"(%s)\n",tuid);
92 if (b=='P') fprintf(tfp,"Path: %s\n",bbb);
93 if (b=='A') strcpy(tuid,bbb);
96 fprintf(tfp,"Newsgroups: %s\n",ngn);
98 if (b=='R') fprintf(tfp,"To: %s\n",bbb);
99 if (b=='U') fprintf(tfp,"Subject: %s\n",bbb);
102 tm=(struct tm *)localtime(&now);
103 fprintf(tfp,"Date: %s",asctime(tm));
105 } while ((b!='M')&&(b>0));
110 printf("#! cuunbatch %ld\n",msglen);
113 printf("#! rnews %ld\n",msglen);
116 tfp=fopen(tflnm,"r");
117 while(msglen--) putc(getc(tfp),stdout);
124 fpgetfield(fp,string) /* level-2 break out next null-terminated string */
133 if (b<1) { string[a]=0; return(0); }
147 strcpy(aaa,""); old=255;
148 c=1; /* c is the current pos */
149 FMTA: old=real; a=getc(fp); real=a;
150 if (a<=0) goto FMTEND;
152 if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
153 if ( ((old==13)||(old==10)) && (isspace(real)) ) {
154 fprintf(mout,"\n"); c=1; }
155 if (a>126) goto FMTA;
158 if ( ((strlen(aaa)+c)>(width-1)) && (strlen(aaa)>(width-1)) )
159 { fprintf(mout,"\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
160 b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
161 if (a==32) { if ((strlen(aaa)+c)>(width-1)) {
165 fprintf(mout,"%s ",aaa); ++c; c=c+strlen(aaa);
166 strcpy(aaa,""); goto FMTA; }
167 if ((a==13)||(a==10)) {
168 fprintf(mout,"%s\n",aaa); c=1;
169 strcpy(aaa,""); goto FMTA; }
172 FMTEND: fprintf(mout,"\n");
176 xref(roomname,newsgroup)
177 char *roomname,*newsgroup; {
182 strcpy(newsgroup,roomname);
183 fp=fopen("./network/rnews.xref","r");
184 if (fp==NULL) return(1);
185 while (fgets(tbuf,128,fp)!=NULL) {
186 tbuf[strlen(tbuf)-1]=0; /* strip off the newline */
188 while (a--) if (tbuf[a]==',') commapos=a;
190 if (!strucmp(&tbuf[commapos+1],roomname))
191 strcpy(newsgroup,tbuf);