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);
40 * Cross-reference newsgroup names to Citadel room names
42 int rnewsxref(char *room, char *ngroup) {
48 fp=fopen("network/rnews.xref","r");
49 GNA: strcpy(aaa,""); strcpy(bbb,"");
53 if (a>0) { b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
58 if (a>0) { b=strlen(bbb); bbb[b]=a; bbb[b+1]=0; }
64 if (strcasecmp(ngroup,aaa)) goto GNA;
71 void main(int argc, char **argv)
73 char aaa[128],bbb[128],ccc[128];
74 char author[128],recipient[128],room[128],node[128],path[512];
80 char flnm[128],tname[128];
81 FILE *minput,*mout,*mtemp;
82 char binary_input = 0;
83 char compressed_input = 0;
87 sprintf(flnm,"./network/spoolin/rnews.%d",getpid());
88 sprintf(tname,"/tmp/rnews.%d",getpid());
90 for (a=1; a<argc; ++a) {
91 if (!strcmp(argv[a],"-c")) binary_input = 1;
92 if (!strcmp(argv[a],"-z")) compressed_input = 1;
93 if (!strcmp(argv[a],"-s")) spool_only = 1;
97 if (compressed_input) minput=popen(UNCOMPRESS,"r");
98 if (minput==NULL) fprintf(stderr,"rnews: can't open input!!!!\n");
100 mout=fopen(flnm,"w");
102 /* process Citadel/UX binary format input */
104 while ((a=getc(minput))>=0) putc(a,mout);
108 /* process UseNet news input */
109 A: if (fgets(aaa,128,minput)==NULL) goto END;
110 aaa[strlen(aaa)-1]=0;
111 if (strncmp(aaa,"#! rnews ",9)) goto A;
112 bcount=atol(&aaa[9]);
113 mtemp=fopen(tname,"w");
114 for (aa=0L; aa<bcount; ++aa) {
117 if (a>=0) putc(a,mtemp);
121 fprintf(stderr,"rnews: EOF unexpected\n");
125 mtemp=fopen(tname,"r");
127 strcpy(recipient,"");
134 B: if (fgets(aaa,128,mtemp)==NULL) goto ABORT;
135 aaa[strlen(aaa)-1]=0;
136 if (strlen(aaa)==0) goto C;
139 if (!strncmp(aaa,"From: ",6)) {
140 strcpy(author,&aaa[6]);
141 while((author[0]==' ')&&(strlen(author)>0))
142 strcpy(author,&author[1]);
143 for (a=0; a<strlen(author); ++a) {
144 if (author[a]=='<') author[a-1]=0;
145 if (author[a]==')') author[a]=0;
146 if (author[a]=='(') {
147 strcpy(author,&author[a+1]);
151 if (!strcmp(author,")")) {
152 strcpy(author,&aaa[6]);
153 for (a=0; a<strlen(author); ++a)
154 if (author[a]=='@') author[a]=0;
156 strcpy(node,&aaa[6]);
157 for (a=0; a<strlen(node); ++a) {
158 if ((node[a]=='<')||(node[a]=='@')) {
159 strcpy(node,&node[a+1]);
162 if (node[a]=='>') node[a]=0;
163 if (node[a]=='(') node[a-1]=0;
165 for (a=0; a<strlen(author); ++a)
166 if (author[a]=='@') author[a]=0;
169 if (!strncmp(aaa,"Path: ",6)) strcpy(path,&aaa[6]);
170 if (!strncmp(aaa,"To: ",4)) strcpy(recipient,&aaa[4]);
171 if (!strncmp(aaa,"Subject: ",9)) strcpy(subject,&aaa[9]);
172 if (!strncmp(aaa,"Organization: ",14)) strcpy(orgname,&aaa[14]);
174 if (!strncmp(aaa,"Newsgroups: ",11)) {
175 strcpy(room,&aaa[12]);
176 for (a=0; a<strlen(aaa); ++a) if (aaa[a]==',') aaa[a]=0;
180 if (!strncmp(aaa,"Message-ID: ",11)) {
181 strcpy(bbb,&aaa[13]);
182 for (a=0; a<strlen(bbb); ++a) if (bbb[a]=='@') bbb[a]=0;
184 while((aaa[0]!='@')&&(aaa[0]!=0)) {
185 strcpy(&aaa[0],&aaa[1]);
187 strcpy(&aaa[0],&aaa[1]);
188 for (a=0; a<strlen(aaa); ++a) if (aaa[a]=='>') aaa[a]=0;
194 C: if ((author[0]==0)||(room[0]==0)||(node[0]==0)) goto ABORT;
195 putc(255,mout); /* start of message */
196 putc(MES_NORMAL,mout); /* not anonymous */
197 putc(1,mout); /* not formatted */
200 fprintf(mout,"I%ld",mid); putc(0,mout);
201 fprintf(mout,"P%s",path); putc(0,mout);
202 fprintf(mout,"T%ld",now); putc(0,mout);
203 fprintf(mout,"A%s",author); putc(0,mout);
206 fprintf(mout,"O%s",room); putc(0,mout);
207 fprintf(mout,"N%s",node); putc(0,mout);
209 fprintf(mout,"H%s",orgname); putc(0,mout);
211 if (recipient[0]!=0) {
212 fprintf(mout,"R%s",recipient); putc(0,mout);
215 fprintf(mout,"U%s",subject); putc(0,mout);
223 if (a>0) putc(a,mout);
226 ABORT: fclose(mtemp);
233 if (compressed_input) pclose(minput);
234 if (!spool_only) execlp("./netproc","netproc",NULL);