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(void);
20 void get_config(void);
33 int haschar(char *st, int ch)
37 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
43 void fpgetfield(FILE *fp, char *string)
60 /* This is NOT the same msgform() found in the main program. It has been
61 * modified to format 80 columns into a temporary file, and extract the
62 * sender and recipient names for use within the main() loop.
64 void msgform(char *msgfile, FILE *mfout, char *sbuf, char *rbuf, char *nbuf, char *pbuf, time_t *mid_buf, char *rmname, char *subj)
68 /* recipient (in this case, an Internet address) */
75 int a,b,c,e,old,mtype,aflag;
77 char aaa[128],bbb[128];
80 int generate_subject = 1;
84 strcpy(nbuf, NODENAME);
88 fp=fopen(msgfile, "rb");
90 fprintf(stderr, "netmailer: can't open message file\n");
93 strcpy(aaa,""); old=255;
94 c=1; /* c is the current pos */
97 fprintf(stderr,"netmailer: This is not a Citadel message.\n");
100 mtype=getc(fp); aflag=getc(fp);
102 A: if (aflag==1) goto AFLAG;
103 old=real; a=getc(fp); real=a;
107 /* generate subject... */
108 if ( (generate_subject == 1) && (strlen(subj) < 60)) {
109 subj[strlen(subj)+1] = 0;
110 subj[strlen(subj)] = (((a>31)&&(a<127)) ? a : 32);
113 if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32;
114 if ( ((old==13)||(old==10)) && ((real==32)||(real==13)||(real==10))) {
115 fprintf(mfout,"\n"); c=1; }
118 if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) )
119 { fprintf(mfout,"\n%s",aaa); c=strlen(aaa); aaa[0]=0; }
120 b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; }
121 if (a==32) { if ((strlen(aaa)+c)>(width-5)) {
125 fprintf(mfout,"%s ",aaa); ++c; c=c+strlen(aaa);
126 strcpy(aaa,""); goto A; }
127 if ((a==13)||(a==10)) {
128 fprintf(mfout,"%s\n",aaa); c=1;
129 strcpy(aaa,""); goto A; }
145 BONFGM: b=getc(fp); if (b<0) goto END;
148 if (b=='A') strcpy(sbuf, bbb);
149 if (b=='R') strcpy(rbuf, bbb);
150 if (b=='N') strcpy(nbuf, bbb);
151 if (b=='P') strcpy(pbuf, bbb);
152 if (b=='I') *mid_buf = atol(bbb);
153 if (b=='O') strcpy(rmname, bbb);
156 generate_subject = 0; /* have a real subj so don't gen one */
161 int main(int argc, char **argv)
165 char sbuf[200],rbuf[200],cstr[100],fstr[128];
166 char nbuf[64],pbuf[128],rmname[128],buf[128];
172 fprintf(stderr, "netmailer: started... sending mail to %s\n", argv[1]);
173 openlog("netmailer", LOG_PID, LOG_USER);
175 LoadInternetConfig();
176 sprintf(temp, "/tmp/netmailer.%d", getpid()); /* temp file name */
178 if ( (argc < 2) || (argc > 3) ) {
179 fprintf(stderr, "netmailer: usage: netmailer recipient@node.dom [mlist]\n");
184 * If we are running in mailing list mode, the room is being two-way
185 * gatewayed to an Internet mailing list. Since many listprocs only
186 * accept postings from subscribed addresses, we must always use the
187 * room's address as the originating user.
189 if ( (argc == 3) && (!strcasecmp(argv[2], "mlist")) ) {
193 /* convert to ASCII & get info */
195 msgform(argv[1], fp, sbuf, rbuf, nbuf, pbuf, &mid_buf, rmname, subject);
199 strcpy(rmname, "room_");
201 for (a=0; a<strlen(rmname); ++a) {
202 if (rmname[a] == ' ') rmname[a] = '_';
203 rmname[a] = tolower(rmname[a]);
206 sprintf(cstr, SENDMAIL, rbuf);
207 rmail=(FILE *)popen(cstr,"w");
210 for (a=0; a<strlen(sbuf); ++a) if (sbuf[a]==32) sbuf[a]='_';
211 for (a=0; a<strlen(rbuf); ++a) if (rbuf[a]==32) rbuf[a]='_';
214 * This logic attempts to compose From and From: lines that are
215 * as RFC822-compliant as possible. The return addresses are correct
216 * if you're using Citadel's 'citmail' delivery agent to allow BBS
217 * users to receive Internet mail.
219 fprintf(rmail,"From ");
220 if (strcasecmp(nbuf,NODENAME)) fprintf(rmail,"%s!",nbuf);
222 if (!strcasecmp(nbuf,NODENAME)) strcpy(nbuf, FQDN);
225 fprintf(rmail,"%s\n", rmname);
226 fprintf(rmail,"From: %s@%s (%s)\n", rmname, FQDN, fstr);
230 if (!strcasecmp(nbuf, NODENAME)) { /* from this system */
231 fprintf(rmail,"%s\n",pbuf);
232 fprintf(rmail,"From: %s@%s (%s)\n",
235 else if (haschar(nbuf, '.')) { /* from an FQDN */
236 fprintf(rmail,"%s\n",sbuf);
237 fprintf(rmail,"From: %s@%s (%s)\n",
240 else { /* from another Cit */
241 fprintf(rmail,"%s\n",sbuf);
242 fprintf(rmail,"From: %s@%s.%s (%s)\n",
243 sbuf, nbuf, GW_DOMAIN, fstr);
249 * Everything else is pretty straightforward.
251 fprintf(rmail,"To: %s\n", rbuf);
253 fprintf(rmail,"Date: %s", asctime(localtime(&now)));
254 fprintf(rmail,"Message-Id: <%ld@%s>\n", mid_buf, nbuf);
255 fprintf(rmail,"X-Mailer: %s\n", CITADEL);
256 fprintf(rmail,"Subject: %s\n", subject);
262 if (a>=0) putc(a,rmail);
269 unlink(temp); /* get rid of the ASCII file */
270 exit(0); /* go back to the main program */