2 * netmailer for Citadel/UX
3 * see copyright.doc for copyright information
5 * netproc calls this to export Citadel mail to RFC822-compliant mailers.
20 void LoadInternetConfig();
39 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
44 int struncmp(lstr,rstr,len)
50 lc=tolower(lstr[pos]);
51 rc=tolower(rstr[pos]);
52 if ((lc==0)&&(rc==0)) return(0);
53 if (lc<rc) return(-1);
61 void fpgetfield(fp,string)
80 /* This is NOT the same msgform() found in the main program. It has been
81 * modified to format 80 columns into a temporary file, and extract the
82 * sender and recipient names for use within the main() loop.
84 void msgform(msgfile,mfout,sbuf,rbuf,nbuf,pbuf,mid_buf,rmname,subj)
87 char *sbuf; /* sender */
88 char *rbuf; /* recipient (in this case, an Internet address) */
89 char *nbuf; /* source node */
90 char *pbuf; /* path */
91 long *mid_buf; /* message ID */
92 char *rmname; /* room name */
93 char *subj; /* subject */
95 int a,b,c,e,old,mtype,aflag;
97 char aaa[128],bbb[128];
100 int generate_subject = 1;
104 strcpy(nbuf, NODENAME);
108 fp=fopen(msgfile, "rb");
110 fprintf(stderr, "netmailer: can't open message file\n");
113 strcpy(aaa,""); old=255;
114 c=1; /* c is the current pos */
117 fprintf(stderr,"netmailer: This is not a Citadel message.\n");
120 mtype=getc(fp); aflag=getc(fp);
122 A: if (aflag==1) goto AFLAG;
123 old=real; a=getc(fp); real=a;
127 /* generate subject... */
128 if ( (generate_subject == 1) && (strlen(subj) < 60)) {
129 subj[strlen(subj)+1] = 0;
130 subj[strlen(subj)] = (((a>31)&&(a<127)) ? a : 32);
133 if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
134 if ( ((old==13)||(old==10)) && ((real==32)||(real==13)||(real==10))) {
135 fprintf(mfout,"\n"); c=1; }
138 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
139 { fprintf(mfout,"\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
140 b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
141 if (a==32) { if ((strlen(aaa)+c)>(width-5)) {
145 fprintf(mfout,"%s ",aaa); ++c; c=c+strlen(aaa);
146 strcpy(aaa,""); goto A; }
147 if ((a==13)||(a==10)) {
148 fprintf(mfout,"%s\n",aaa); c=1;
149 strcpy(aaa,""); goto A; }
165 BONFGM: b=getc(fp); if (b<0) goto END;
168 if (b=='A') strcpy(sbuf, bbb);
169 if (b=='R') strcpy(rbuf, bbb);
170 if (b=='N') strcpy(nbuf, bbb);
171 if (b=='P') strcpy(pbuf, bbb);
172 if (b=='I') *mid_buf = atol(bbb);
173 if (b=='O') strcpy(rmname, bbb);
176 generate_subject = 0; /* have a real subj so don't gen one */
186 char sbuf[200],rbuf[200],cstr[100],fstr[128];
187 char nbuf[64],pbuf[128],rmname[128],buf[128];
193 fprintf(stderr, "netmailer: started... sending mail to %s\n", argv[1]);
194 openlog("netmailer", LOG_PID, LOG_USER);
196 LoadInternetConfig();
197 sprintf(temp, "/tmp/netmailer.%d", getpid()); /* temp file name */
199 if ( (argc < 2) || (argc > 3) ) {
200 fprintf(stderr, "netmailer: usage: netmailer recipient@node.dom [mlist]\n");
205 * If we are running in mailing list mode, the room is being two-way
206 * gatewayed to an Internet mailing list. Since many listprocs only
207 * accept postings from subscribed addresses, we must always use the
208 * room's address as the originating user.
210 if ( (argc == 3) && (!strucmp(argv[2], "mlist")) ) {
214 /* convert to ASCII & get info */
216 msgform(argv[1], fp, sbuf, rbuf, nbuf, pbuf, &mid_buf, rmname, subject);
220 strcpy(rmname, "room_");
222 for (a=0; a<strlen(rmname); ++a) {
223 if (rmname[a] == ' ') rmname[a] = '_';
224 rmname[a] = tolower(rmname[a]);
227 sprintf(cstr, SENDMAIL, rbuf);
228 rmail=(FILE *)popen(cstr,"w");
231 for (a=0; a<strlen(sbuf); ++a) if (sbuf[a]==32) sbuf[a]='_';
232 for (a=0; a<strlen(rbuf); ++a) if (rbuf[a]==32) rbuf[a]='_';
235 * This logic attempts to compose From and From: lines that are
236 * as RFC822-compliant as possible. The return addresses are correct
237 * if you're using Citadel's 'citmail' delivery agent to allow BBS
238 * users to receive Internet mail.
240 fprintf(rmail,"From ");
241 if (strucmp(nbuf,NODENAME)) fprintf(rmail,"%s!",nbuf);
243 if (!strucmp(nbuf,NODENAME)) strcpy(nbuf, FQDN);
246 fprintf(rmail,"%s\n", rmname);
247 fprintf(rmail,"From: %s@%s (%s)\n", rmname, FQDN, fstr);
251 if (!strucmp(nbuf, NODENAME)) { /* from this system */
252 fprintf(rmail,"%s\n",pbuf);
253 fprintf(rmail,"From: %s@%s (%s)\n",
256 else if (haschar(nbuf, '.')) { /* from an FQDN */
257 fprintf(rmail,"%s\n",sbuf);
258 fprintf(rmail,"From: %s@%s (%s)\n",
261 else { /* from another Cit */
262 fprintf(rmail,"%s\n",sbuf);
263 fprintf(rmail,"From: %s@%s.%s (%s)\n",
264 sbuf, nbuf, GW_DOMAIN, fstr);
270 * Everything else is pretty straightforward.
272 fprintf(rmail,"To: %s\n", rbuf);
274 fprintf(rmail,"Date: %s", asctime(localtime(&now)));
275 fprintf(rmail,"Message-Id: <%ld@%s>\n", mid_buf, nbuf);
276 fprintf(rmail,"X-Mailer: %s\n", CITADEL);
277 fprintf(rmail,"Subject: %s\n", subject);
283 if (a>=0) putc(a,rmail);
290 unlink(temp); /* get rid of the ASCII file */
291 exit(0); /* go back to the main program */