1 #define UNCOMPRESS "/usr/bin/gunzip"
6 * This program functions the same as the standard rnews program for
7 * UseNet. It accepts standard input, and looks for rooms to post messages
8 * (translated from UseNet format to the Citadel/UX binary message format)
9 * in that match the names of the newsgroups. network/rnews.xref is checked
10 * in case the sysop wants to cross-reference room names to newsgroup names.
11 * If standard input is already in binary, the -c flag should be used.
12 * The netproc program is then called to do the processing.
14 * If you have a separate newsreader and don't want to use Citadel for news,
15 * just call this program something else (rcit, for example) -- but make sure
16 * to tell your Citadel network neighbors the new name of the program to call.
19 * rnews [-c] [-z] [-s]
21 * -c Input is already in Citadel binary format
22 * (default is UseNet news format)
23 * -z Input is compressed, run uncompress on it before processing
24 * -s Don't run netproc now, just accept the input into spoolin
36 void get_config(void);
39 char roomlist[MAXROOMS][20];
41 void load_roomlist(void) {
43 struct quickroom QRtemp;
46 for (a=0; a<MAXROOMS; ++a) strcpy(roomlist[a],TWITROOM);
47 fp=fopen("quickroom","r");
49 for (a=0; a<MAXROOMS; ++a) {
50 fread((char *)&QRtemp,sizeof(struct quickroom),1,fp);
51 if (QRtemp.QRflags & QR_INUSE)
52 strcpy(roomlist[a],QRtemp.QRname);
59 int rnewsxref(char *room, char *ngroup) /* xref table */
67 fp=fopen("network/rnews.xref","r");
68 GNA: strcpy(aaa,""); strcpy(bbb,"");
72 if (a>0) { b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
77 if (a>0) { b=strlen(bbb); bbb[b]=a; bbb[b+1]=0; }
83 if (strcasecmp(ngroup,aaa)) goto GNA;
90 void getroom(char *room, char *ngroup)
95 struct quickroom qbuf;
99 for (a=0; a<strlen(ngbuf); ++a) {
100 if ((ngbuf[a]==',')||(ngbuf[a]==0)) {
103 if (!rnewsxref(room,tryme)) return;
104 room[sizeof(qbuf.QRname)-1]=0;
105 for (b=0; b<MAXROOMS; ++b) {
106 if (!strcasecmp(roomlist[b],room)) return;
108 strcpy(ngbuf,&ngbuf[a+1]);
114 void main(int argc, char **argv)
116 char aaa[128],bbb[128],ccc[128];
117 char author[128],recipient[128],room[128],node[128],path[512];
123 char flnm[128],tname[128];
124 FILE *minput,*mout,*mtemp;
125 char binary_input = 0;
126 char compressed_input = 0;
130 sprintf(flnm,"./network/spoolin/rnews.%d",getpid());
131 sprintf(tname,"/tmp/rnews.%d",getpid());
133 for (a=1; a<argc; ++a) {
134 if (!strcmp(argv[a],"-c")) binary_input = 1;
135 if (!strcmp(argv[a],"-z")) compressed_input = 1;
136 if (!strcmp(argv[a],"-s")) spool_only = 1;
140 if (compressed_input) minput=popen(UNCOMPRESS,"r");
141 if (minput==NULL) fprintf(stderr,"rnews: can't open input!!!!\n");
143 mout=fopen(flnm,"w");
145 /* process Citadel/UX binary format input */
147 while ((a=getc(minput))>=0) putc(a,mout);
151 /* process UseNet news input */
153 A: if (fgets(aaa,128,minput)==NULL) goto END;
154 aaa[strlen(aaa)-1]=0;
155 if (strncmp(aaa,"#! rnews ",9)) goto A;
156 bcount=atol(&aaa[9]);
157 mtemp=fopen(tname,"w");
158 for (aa=0L; aa<bcount; ++aa) {
161 if (a>=0) putc(a,mtemp);
165 fprintf(stderr,"rnews: EOF unexpected\n");
169 mtemp=fopen(tname,"r");
171 strcpy(recipient,"");
178 B: if (fgets(aaa,128,mtemp)==NULL) goto ABORT;
179 aaa[strlen(aaa)-1]=0;
180 if (strlen(aaa)==0) goto C;
183 if (!strncmp(aaa,"From: ",6)) {
184 strcpy(author,&aaa[6]);
185 while((author[0]==' ')&&(strlen(author)>0))
186 strcpy(author,&author[1]);
187 for (a=0; a<strlen(author); ++a) {
188 if (author[a]=='<') author[a-1]=0;
189 if (author[a]==')') author[a]=0;
190 if (author[a]=='(') {
191 strcpy(author,&author[a+1]);
195 if (!strcmp(author,")")) {
196 strcpy(author,&aaa[6]);
197 for (a=0; a<strlen(author); ++a)
198 if (author[a]=='@') author[a]=0;
200 strcpy(node,&aaa[6]);
201 for (a=0; a<strlen(node); ++a) {
202 if ((node[a]=='<')||(node[a]=='@')) {
203 strcpy(node,&node[a+1]);
206 if (node[a]=='>') node[a]=0;
207 if (node[a]=='(') node[a-1]=0;
209 for (a=0; a<strlen(author); ++a)
210 if (author[a]=='@') author[a]=0;
213 if (!strncmp(aaa,"Path: ",6)) strcpy(path,&aaa[6]);
214 if (!strncmp(aaa,"To: ",4)) strcpy(recipient,&aaa[4]);
215 if (!strncmp(aaa,"Subject: ",9)) strcpy(subject,&aaa[9]);
216 if (!strncmp(aaa,"Organization: ",14)) strcpy(orgname,&aaa[14]);
218 if (!strncmp(aaa,"Newsgroups: ",11)) {
219 strcpy(room,&aaa[12]);
220 for (a=0; a<strlen(aaa); ++a) if (aaa[a]==',') aaa[a]=0;
224 if (!strncmp(aaa,"Message-ID: ",11)) {
225 strcpy(bbb,&aaa[13]);
226 for (a=0; a<strlen(bbb); ++a) if (bbb[a]=='@') bbb[a]=0;
228 while((aaa[0]!='@')&&(aaa[0]!=0)) {
229 strcpy(&aaa[0],&aaa[1]);
231 strcpy(&aaa[0],&aaa[1]);
232 for (a=0; a<strlen(aaa); ++a) if (aaa[a]=='>') aaa[a]=0;
238 C: if ((author[0]==0)||(room[0]==0)||(node[0]==0)) goto ABORT;
239 putc(255,mout); /* start of message */
240 putc(MES_NORMAL,mout); /* not anonymous */
241 putc(1,mout); /* not formatted */
244 fprintf(mout,"I%ld",mid); putc(0,mout);
245 fprintf(mout,"P%s",path); putc(0,mout);
246 fprintf(mout,"T%ld",now); putc(0,mout);
247 fprintf(mout,"A%s",author); putc(0,mout);
250 fprintf(mout,"O%s",room); putc(0,mout);
251 fprintf(mout,"N%s",node); putc(0,mout);
253 fprintf(mout,"H%s",orgname); putc(0,mout);
255 if (recipient[0]!=0) {
256 fprintf(mout,"R%s",recipient); putc(0,mout);
259 fprintf(mout,"U%s",subject); putc(0,mout);
267 if (a>0) putc(a,mout);
270 ABORT: fclose(mtemp);
277 if (compressed_input) pclose(minput);
278 if (!spool_only) execlp("./netproc","netproc",NULL);