2 * netmailer for Citadel/UX
3 * see copyright.doc for copyright information
5 * netproc calls this to export Citadel mail to RFC822-compliant mailers.
19 void LoadInternetConfig();
38 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
44 void fpgetfield(fp,string)
63 /* This is NOT the same msgform() found in the main program. It has been
64 * modified to format 80 columns into a temporary file, and extract the
65 * sender and recipient names for use within the main() loop.
67 void msgform(msgfile,mfout,sbuf,rbuf,nbuf,pbuf,mid_buf,rmname,subj)
70 char *sbuf; /* sender */
71 char *rbuf; /* recipient (in this case, an Internet address) */
72 char *nbuf; /* source node */
73 char *pbuf; /* path */
74 long *mid_buf; /* message ID */
75 char *rmname; /* room name */
76 char *subj; /* subject */
78 int a,b,c,e,old,mtype,aflag;
80 char aaa[128],bbb[128];
83 int generate_subject = 1;
87 strcpy(nbuf, NODENAME);
91 fp=fopen(msgfile, "rb");
93 fprintf(stderr, "netmailer: can't open message file\n");
96 strcpy(aaa,""); old=255;
97 c=1; /* c is the current pos */
100 fprintf(stderr,"netmailer: This is not a Citadel message.\n");
103 mtype=getc(fp); aflag=getc(fp);
105 A: if (aflag==1) goto AFLAG;
106 old=real; a=getc(fp); real=a;
110 /* generate subject... */
111 if ( (generate_subject == 1) && (strlen(subj) < 60)) {
112 subj[strlen(subj)+1] = 0;
113 subj[strlen(subj)] = (((a>31)&&(a<127)) ? a : 32);
116 if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
117 if ( ((old==13)||(old==10)) && ((real==32)||(real==13)||(real==10))) {
118 fprintf(mfout,"\n"); c=1; }
121 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
122 { fprintf(mfout,"\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
123 b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
124 if (a==32) { if ((strlen(aaa)+c)>(width-5)) {
128 fprintf(mfout,"%s ",aaa); ++c; c=c+strlen(aaa);
129 strcpy(aaa,""); goto A; }
130 if ((a==13)||(a==10)) {
131 fprintf(mfout,"%s\n",aaa); c=1;
132 strcpy(aaa,""); goto A; }
148 BONFGM: b=getc(fp); if (b<0) goto END;
151 if (b=='A') strcpy(sbuf, bbb);
152 if (b=='R') strcpy(rbuf, bbb);
153 if (b=='N') strcpy(nbuf, bbb);
154 if (b=='P') strcpy(pbuf, bbb);
155 if (b=='I') *mid_buf = atol(bbb);
156 if (b=='O') strcpy(rmname, bbb);
159 generate_subject = 0; /* have a real subj so don't gen one */
169 char sbuf[200],rbuf[200],cstr[100],fstr[128];
170 char nbuf[64],pbuf[128],rmname[128],buf[128];
176 fprintf(stderr, "netmailer: started... sending mail to %s\n", argv[1]);
177 openlog("netmailer", LOG_PID, LOG_USER);
179 LoadInternetConfig();
180 sprintf(temp, "/tmp/netmailer.%d", getpid()); /* temp file name */
182 if ( (argc < 2) || (argc > 3) ) {
183 fprintf(stderr, "netmailer: usage: netmailer recipient@node.dom [mlist]\n");
188 * If we are running in mailing list mode, the room is being two-way
189 * gatewayed to an Internet mailing list. Since many listprocs only
190 * accept postings from subscribed addresses, we must always use the
191 * room's address as the originating user.
193 if ( (argc == 3) && (!strcasecmp(argv[2], "mlist")) ) {
197 /* convert to ASCII & get info */
199 msgform(argv[1], fp, sbuf, rbuf, nbuf, pbuf, &mid_buf, rmname, subject);
203 strcpy(rmname, "room_");
205 for (a=0; a<strlen(rmname); ++a) {
206 if (rmname[a] == ' ') rmname[a] = '_';
207 rmname[a] = tolower(rmname[a]);
210 sprintf(cstr, SENDMAIL, rbuf);
211 rmail=(FILE *)popen(cstr,"w");
214 for (a=0; a<strlen(sbuf); ++a) if (sbuf[a]==32) sbuf[a]='_';
215 for (a=0; a<strlen(rbuf); ++a) if (rbuf[a]==32) rbuf[a]='_';
218 * This logic attempts to compose From and From: lines that are
219 * as RFC822-compliant as possible. The return addresses are correct
220 * if you're using Citadel's 'citmail' delivery agent to allow BBS
221 * users to receive Internet mail.
223 fprintf(rmail,"From ");
224 if (strcasecmp(nbuf,NODENAME)) fprintf(rmail,"%s!",nbuf);
226 if (!strcasecmp(nbuf,NODENAME)) strcpy(nbuf, FQDN);
229 fprintf(rmail,"%s\n", rmname);
230 fprintf(rmail,"From: %s@%s (%s)\n", rmname, FQDN, fstr);
234 if (!strcasecmp(nbuf, NODENAME)) { /* from this system */
235 fprintf(rmail,"%s\n",pbuf);
236 fprintf(rmail,"From: %s@%s (%s)\n",
239 else if (haschar(nbuf, '.')) { /* from an FQDN */
240 fprintf(rmail,"%s\n",sbuf);
241 fprintf(rmail,"From: %s@%s (%s)\n",
244 else { /* from another Cit */
245 fprintf(rmail,"%s\n",sbuf);
246 fprintf(rmail,"From: %s@%s.%s (%s)\n",
247 sbuf, nbuf, GW_DOMAIN, fstr);
253 * Everything else is pretty straightforward.
255 fprintf(rmail,"To: %s\n", rbuf);
257 fprintf(rmail,"Date: %s", asctime(localtime(&now)));
258 fprintf(rmail,"Message-Id: <%ld@%s>\n", mid_buf, nbuf);
259 fprintf(rmail,"X-Mailer: %s\n", CITADEL);
260 fprintf(rmail,"Subject: %s\n", subject);
266 if (a>=0) putc(a,rmail);
273 unlink(temp); /* get rid of the ASCII file */
274 exit(0); /* go back to the main program */