4 * netproc calls this to export Citadel mail to RFC822-compliant mailers.
12 #if TIME_WITH_SYS_TIME
13 # include <sys/time.h>
17 # include <sys/time.h>
30 void LoadInternetConfig(void);
31 void get_config(void);
44 int haschar(char *st, int ch)
48 for (a = 0; a < strlen(st); ++a)
56 void fpgetfield(FILE * fp, char *string)
73 /* This is NOT the same msgform() found in the main program. It has been
74 * modified to format 80 columns into a temporary file, and extract the
75 * sender and recipient names for use within the main() loop.
77 void msgform(char *msgfile, FILE * mfout, char *sbuf, char *rbuf, char *nbuf,
78 char *pbuf, time_t * mid_buf, char *rmname, char *subj)
80 /* recipient (in this case, an Internet address) */
87 int a, b, c, e, old, mtype, aflag;
89 char aaa[128], bbb[128];
92 int generate_subject = 1;
96 strcpy(nbuf, NODENAME);
100 fp = fopen(msgfile, "rb");
102 fprintf(stderr, "netmailer: can't open message file\n");
107 c = 1; /* c is the current pos */
110 fprintf(stderr, "netmailer: This is not a Citadel message.\n");
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);
132 if (((a == 13) || (a == 10)) && (old != 13) && (old != 10))
134 if (((old == 13) || (old == 10)) && ((real == 32) || (real == 13) || (real == 10))) {
135 fprintf(mfout, "\n");
139 if (((strlen(aaa) + c) > (width - 5)) && (strlen(aaa) > (width - 5))) {
140 fprintf(mfout, "\n%s", aaa);
149 if ((strlen(aaa) + c) > (width - 5)) {
150 fprintf(mfout, "\n");
153 fprintf(mfout, "%s ", aaa);
159 if ((a == 13) || (a == 10)) {
160 fprintf(mfout, "%s\n", aaa);
180 BONFGM: b = getc(fp);
195 *mid_buf = atol(bbb);
200 generate_subject = 0; /* have a real subj so don't gen one */
205 int main(int argc, char **argv)
209 char sbuf[200], rbuf[200], cstr[100], fstr[128];
210 char nbuf[64], pbuf[128], rmname[128], buf[128];
217 openlog("netmailer", LOG_PID, LOG_USER);
219 LoadInternetConfig();
220 strcpy(temp, tmpnam(NULL)); /* temp file name */
222 if ((argc < 2) || (argc > 3)) {
223 fprintf(stderr, "netmailer: usage: "
224 "netmailer <filename> [mlist]\n");
228 * If we are running in mailing list mode, the room is being two-way
229 * gatewayed to an Internet mailing list. Since many listprocs only
230 * accept postings from subscribed addresses, we must always use the
231 * room's address as the originating user.
233 if ((argc == 3) && (!strcasecmp(argv[2], "mlist"))) {
236 /* convert to ASCII & get info */
237 fp = fopen(temp, "w");
238 msgform(argv[1], fp, sbuf, rbuf, nbuf, pbuf, &mid_buf, rmname, subject);
242 strcpy(rmname, "room_");
244 for (a = 0; a < strlen(rmname); ++a) {
245 if (rmname[a] == ' ')
247 rmname[a] = tolower(rmname[a]);
250 sprintf(cstr, SENDMAIL, rbuf);
251 rmail = (FILE *) popen(cstr, "w");
254 for (a = 0; a < strlen(sbuf); ++a)
257 for (a = 0; a < strlen(rbuf); ++a)
262 * This logic attempts to compose From and From: lines that are
263 * as RFC822-compliant as possible. The return addresses are correct
264 * if you're using Citadel's 'citmail' delivery agent to allow BBS
265 * users to receive Internet mail.
267 fprintf(rmail, "From ");
268 if (strcasecmp(nbuf, NODENAME))
269 fprintf(rmail, "%s!", nbuf);
271 if (!strcasecmp(nbuf, NODENAME))
275 fprintf(rmail, "%s\n", rmname);
276 fprintf(rmail, "From: %s@%s (%s)\n", rmname, FQDN, fstr);
279 if (!strcasecmp(nbuf, NODENAME)) { /* from this system */
280 fprintf(rmail, "%s\n", pbuf);
281 fprintf(rmail, "From: %s@%s (%s)\n",
283 } else if (haschar(nbuf, '.')) { /* from an FQDN */
284 fprintf(rmail, "%s\n", sbuf);
285 fprintf(rmail, "From: %s@%s (%s)\n",
287 } else { /* from another Cit */
288 fprintf(rmail, "%s\n", sbuf);
289 fprintf(rmail, "From: %s@%s.%s (%s)\n",
290 sbuf, nbuf, GW_DOMAIN, fstr);
296 * Everything else is pretty straightforward.
298 fprintf(rmail, "To: %s\n", rbuf);
300 datestring(datestamp, now, DATESTRING_RFC822);
301 fprintf(rmail, "Date: %s\n", datestamp);
302 fprintf(rmail, "Message-Id: <%ld@%s>\n", (long) mid_buf, nbuf);
303 fprintf(rmail, "X-Mailer: %s\n", CITADEL);
304 fprintf(rmail, "Subject: %s\n", subject);
305 fprintf(rmail, "\n");
306 fp = fopen(temp, "r");
315 fprintf(rmail, "\n");
318 unlink(temp); /* get rid of the ASCII file */
319 execlp("./netproc", "netproc", "-i", NULL);
320 exit(0); /* go back to the main program */