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(void);
21 void get_config(void);
34 int haschar(char *st, int ch)
38 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
44 void fpgetfield(FILE *fp, char *string)
61 /* This is NOT the same msgform() found in the main program. It has been
62 * modified to format 80 columns into a temporary file, and extract the
63 * sender and recipient names for use within the main() loop.
65 void msgform(char *msgfile, FILE *mfout, char *sbuf, char *rbuf, char *nbuf, char *pbuf, time_t *mid_buf, char *rmname, char *subj)
69 /* recipient (in this case, an Internet address) */
76 int a,b,c,e,old,mtype,aflag;
78 char aaa[128],bbb[128];
81 int generate_subject = 1;
85 strcpy(nbuf, NODENAME);
89 fp=fopen(msgfile, "rb");
91 fprintf(stderr, "netmailer: can't open message file\n");
94 strcpy(aaa,""); old=255;
95 c=1; /* c is the current pos */
98 fprintf(stderr,"netmailer: This is not a Citadel message.\n");
101 mtype=getc(fp); aflag=getc(fp);
103 A: if (aflag==1) goto AFLAG;
104 old=real; a=getc(fp); real=a;
108 /* generate subject... */
109 if ( (generate_subject == 1) && (strlen(subj) < 60)) {
110 subj[strlen(subj)+1] = 0;
111 subj[strlen(subj)] = (((a>31)&&(a<127)) ? a : 32);
114 if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
115 if ( ((old==13)||(old==10)) && ((real==32)||(real==13)||(real==10))) {
116 fprintf(mfout,"\n"); c=1; }
119 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
120 { fprintf(mfout,"\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
121 b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
122 if (a==32) { if ((strlen(aaa)+c)>(width-5)) {
126 fprintf(mfout,"%s ",aaa); ++c; c=c+strlen(aaa);
127 strcpy(aaa,""); goto A; }
128 if ((a==13)||(a==10)) {
129 fprintf(mfout,"%s\n",aaa); c=1;
130 strcpy(aaa,""); goto A; }
146 BONFGM: b=getc(fp); if (b<0) goto END;
149 if (b=='A') strcpy(sbuf, bbb);
150 if (b=='R') strcpy(rbuf, bbb);
151 if (b=='N') strcpy(nbuf, bbb);
152 if (b=='P') strcpy(pbuf, bbb);
153 if (b=='I') *mid_buf = atol(bbb);
154 if (b=='O') strcpy(rmname, bbb);
157 generate_subject = 0; /* have a real subj so don't gen one */
162 int main(int argc, char **argv)
166 char sbuf[200],rbuf[200],cstr[100],fstr[128];
167 char nbuf[64],pbuf[128],rmname[128],buf[128];
173 fprintf(stderr, "netmailer: started... sending mail to %s\n", argv[1]);
174 openlog("netmailer", LOG_PID, LOG_USER);
176 LoadInternetConfig();
177 sprintf(temp, tmpnam(NULL)); /* temp file name */
179 if ( (argc < 2) || (argc > 3) ) {
180 fprintf(stderr, "netmailer: usage: netmailer recipient@node.dom [mlist]\n");
185 * If we are running in mailing list mode, the room is being two-way
186 * gatewayed to an Internet mailing list. Since many listprocs only
187 * accept postings from subscribed addresses, we must always use the
188 * room's address as the originating user.
190 if ( (argc == 3) && (!strcasecmp(argv[2], "mlist")) ) {
194 /* convert to ASCII & get info */
196 msgform(argv[1], fp, sbuf, rbuf, nbuf, pbuf, &mid_buf, rmname, subject);
200 strcpy(rmname, "room_");
202 for (a=0; a<strlen(rmname); ++a) {
203 if (rmname[a] == ' ') rmname[a] = '_';
204 rmname[a] = tolower(rmname[a]);
207 sprintf(cstr, SENDMAIL, rbuf);
208 rmail=(FILE *)popen(cstr,"w");
211 for (a=0; a<strlen(sbuf); ++a) if (sbuf[a]==32) sbuf[a]='_';
212 for (a=0; a<strlen(rbuf); ++a) if (rbuf[a]==32) rbuf[a]='_';
215 * This logic attempts to compose From and From: lines that are
216 * as RFC822-compliant as possible. The return addresses are correct
217 * if you're using Citadel's 'citmail' delivery agent to allow BBS
218 * users to receive Internet mail.
220 fprintf(rmail,"From ");
221 if (strcasecmp(nbuf,NODENAME)) fprintf(rmail,"%s!",nbuf);
223 if (!strcasecmp(nbuf,NODENAME)) strcpy(nbuf, FQDN);
226 fprintf(rmail,"%s\n", rmname);
227 fprintf(rmail,"From: %s@%s (%s)\n", rmname, FQDN, fstr);
231 if (!strcasecmp(nbuf, NODENAME)) { /* from this system */
232 fprintf(rmail,"%s\n",pbuf);
233 fprintf(rmail,"From: %s@%s (%s)\n",
236 else if (haschar(nbuf, '.')) { /* from an FQDN */
237 fprintf(rmail,"%s\n",sbuf);
238 fprintf(rmail,"From: %s@%s (%s)\n",
241 else { /* from another Cit */
242 fprintf(rmail,"%s\n",sbuf);
243 fprintf(rmail,"From: %s@%s.%s (%s)\n",
244 sbuf, nbuf, GW_DOMAIN, fstr);
250 * Everything else is pretty straightforward.
252 fprintf(rmail,"To: %s\n", rbuf);
254 fprintf(rmail,"Date: %s", asctime(localtime(&now)));
255 fprintf(rmail,"Message-Id: <%ld@%s>\n", (long)mid_buf, nbuf);
256 fprintf(rmail,"X-Mailer: %s\n", CITADEL);
257 fprintf(rmail,"Subject: %s\n", subject);
263 if (a>=0) putc(a,rmail);
270 unlink(temp); /* get rid of the ASCII file */
271 execlp("./netproc", "netproc", "-i", NULL);
272 exit(0); /* go back to the main program */