1 #define UNCOMPRESS "/usr/bin/gunzip"
3 /* Citadel/UX rcit $Id$
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 int 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];
81 char flnm[128],tname[128];
82 FILE *minput,*mout,*mtemp;
83 char binary_input = 0;
84 char compressed_input = 0;
88 sprintf(flnm,"./network/spoolin/rnews.%d", getpid());
89 sprintf(tname, tmpnam(NULL));
91 for (a=1; a<argc; ++a) {
92 if (!strcmp(argv[a],"-c")) binary_input = 1;
93 if (!strcmp(argv[a],"-z")) compressed_input = 1;
94 if (!strcmp(argv[a],"-s")) spool_only = 1;
98 if (compressed_input) minput=popen(UNCOMPRESS,"r");
99 if (minput==NULL) fprintf(stderr,"rnews: can't open input!!!!\n");
101 mout=fopen(flnm,"w");
103 /* process Citadel/UX binary format input */
105 while ((a=getc(minput))>=0) putc(a,mout);
109 /* process UseNet news input */
110 A: if (fgets(aaa,128,minput)==NULL) goto END;
111 aaa[strlen(aaa)-1]=0;
112 if (strncmp(aaa,"#! rnews ",9)) goto A;
113 bcount=atol(&aaa[9]);
114 mtemp=fopen(tname,"w");
115 for (aa=0L; aa<bcount; ++aa) {
118 if (a>=0) putc(a,mtemp);
122 fprintf(stderr,"rnews: EOF unexpected\n");
126 mtemp=fopen(tname,"r");
128 strcpy(recipient,"");
135 B: if (fgets(aaa,128,mtemp)==NULL) goto ABORT;
136 aaa[strlen(aaa)-1]=0;
137 if (strlen(aaa)==0) goto C;
140 if (!strncmp(aaa,"From: ",6)) {
141 strcpy(author,&aaa[6]);
142 while((author[0]==' ')&&(strlen(author)>0))
143 strcpy(author,&author[1]);
144 for (a=0; a<strlen(author); ++a) {
145 if (author[a]=='<') author[a-1]=0;
146 if (author[a]==')') author[a]=0;
147 if (author[a]=='(') {
148 strcpy(author,&author[a+1]);
152 if (!strcmp(author,")")) {
153 strcpy(author,&aaa[6]);
154 for (a=0; a<strlen(author); ++a)
155 if (author[a]=='@') author[a]=0;
157 strcpy(node,&aaa[6]);
158 for (a=0; a<strlen(node); ++a) {
159 if ((node[a]=='<')||(node[a]=='@')) {
160 strcpy(node,&node[a+1]);
163 if (node[a]=='>') node[a]=0;
164 if (node[a]=='(') node[a-1]=0;
166 for (a=0; a<strlen(author); ++a)
167 if (author[a]=='@') author[a]=0;
170 if (!strncmp(aaa,"Path: ",6)) strcpy(path,&aaa[6]);
171 if (!strncmp(aaa,"To: ",4)) strcpy(recipient,&aaa[4]);
172 if (!strncmp(aaa,"Subject: ",9)) strcpy(subject,&aaa[9]);
173 if (!strncmp(aaa,"Organization: ",14)) strcpy(orgname,&aaa[14]);
175 if (!strncmp(aaa,"Newsgroups: ",11)) {
176 strcpy(room,&aaa[12]);
177 for (a=0; a<strlen(aaa); ++a) if (aaa[a]==',') aaa[a]=0;
181 if (!strncmp(aaa,"Message-ID: ",11)) {
182 strcpy(bbb,&aaa[13]);
183 for (a=0; a<strlen(bbb); ++a) if (bbb[a]=='@') bbb[a]=0;
185 while((aaa[0]!='@')&&(aaa[0]!=0)) {
186 strcpy(&aaa[0],&aaa[1]);
188 strcpy(&aaa[0],&aaa[1]);
189 for (a=0; a<strlen(aaa); ++a) if (aaa[a]=='>') aaa[a]=0;
195 C: if ((author[0]==0)||(room[0]==0)||(node[0]==0)) goto ABORT;
196 putc(255,mout); /* start of message */
197 putc(MES_NORMAL,mout); /* not anonymous */
198 putc(1,mout); /* not formatted */
201 fprintf(mout,"I%ld",mid); putc(0,mout);
202 fprintf(mout,"P%s",path); putc(0,mout);
203 fprintf(mout,"T%ld",(long)now); putc(0,mout);
204 fprintf(mout,"A%s",author); putc(0,mout);
207 fprintf(mout,"O%s",room); putc(0,mout);
208 fprintf(mout,"N%s",node); putc(0,mout);
210 fprintf(mout,"H%s",orgname); putc(0,mout);
212 if (recipient[0]!=0) {
213 fprintf(mout,"R%s",recipient); putc(0,mout);
216 fprintf(mout,"U%s",subject); putc(0,mout);
224 if (a>0) putc(a,mout);
227 ABORT: fclose(mtemp);
234 if (compressed_input) pclose(minput);
235 if (!spool_only) execlp("./netproc", "netproc", "-i", NULL);