2 * netmailer for Citadel/UX
3 * see copyright.doc for copyright information
5 * netproc calls this to export Citadel mail to RFC822-compliant mailers.
21 void LoadInternetConfig(void);
22 void get_config(void);
35 int haschar(char *st, int ch)
39 for (a = 0; a < strlen(st); ++a)
47 void fpgetfield(FILE * fp, char *string)
64 /* This is NOT the same msgform() found in the main program. It has been
65 * modified to format 80 columns into a temporary file, and extract the
66 * sender and recipient names for use within the main() loop.
68 void msgform(char *msgfile, FILE * mfout, char *sbuf, char *rbuf, char *nbuf,
69 char *pbuf, time_t * mid_buf, char *rmname, char *subj)
71 /* recipient (in this case, an Internet address) */
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");
98 c = 1; /* c is the current pos */
101 fprintf(stderr, "netmailer: This is not a Citadel message.\n");
118 /* generate subject... */
119 if ((generate_subject == 1) && (strlen(subj) < 60)) {
120 subj[strlen(subj) + 1] = 0;
121 subj[strlen(subj)] = (((a > 31) && (a < 127)) ? a : 32);
123 if (((a == 13) || (a == 10)) && (old != 13) && (old != 10))
125 if (((old == 13) || (old == 10)) && ((real == 32) || (real == 13) || (real == 10))) {
126 fprintf(mfout, "\n");
130 if (((strlen(aaa) + c) > (width - 5)) && (strlen(aaa) > (width - 5))) {
131 fprintf(mfout, "\n%s", aaa);
140 if ((strlen(aaa) + c) > (width - 5)) {
141 fprintf(mfout, "\n");
144 fprintf(mfout, "%s ", aaa);
150 if ((a == 13) || (a == 10)) {
151 fprintf(mfout, "%s\n", aaa);
171 BONFGM: b = getc(fp);
186 *mid_buf = atol(bbb);
191 generate_subject = 0; /* have a real subj so don't gen one */
196 int main(int argc, char **argv)
200 char sbuf[200], rbuf[200], cstr[100], fstr[128];
201 char nbuf[64], pbuf[128], rmname[128], buf[128];
208 openlog("netmailer", LOG_PID, LOG_USER);
210 LoadInternetConfig();
211 sprintf(temp, tmpnam(NULL)); /* temp file name */
213 if ((argc < 2) || (argc > 3)) {
214 fprintf(stderr, "netmailer: usage: "
215 "netmailer <filename> [mlist]\n");
219 * If we are running in mailing list mode, the room is being two-way
220 * gatewayed to an Internet mailing list. Since many listprocs only
221 * accept postings from subscribed addresses, we must always use the
222 * room's address as the originating user.
224 if ((argc == 3) && (!strcasecmp(argv[2], "mlist"))) {
227 /* convert to ASCII & get info */
228 fp = fopen(temp, "w");
229 msgform(argv[1], fp, sbuf, rbuf, nbuf, pbuf, &mid_buf, rmname, subject);
233 strcpy(rmname, "room_");
235 for (a = 0; a < strlen(rmname); ++a) {
236 if (rmname[a] == ' ')
238 rmname[a] = tolower(rmname[a]);
241 sprintf(cstr, SENDMAIL, rbuf);
242 rmail = (FILE *) popen(cstr, "w");
245 for (a = 0; a < strlen(sbuf); ++a)
248 for (a = 0; a < strlen(rbuf); ++a)
253 * This logic attempts to compose From and From: lines that are
254 * as RFC822-compliant as possible. The return addresses are correct
255 * if you're using Citadel's 'citmail' delivery agent to allow BBS
256 * users to receive Internet mail.
258 fprintf(rmail, "From ");
259 if (strcasecmp(nbuf, NODENAME))
260 fprintf(rmail, "%s!", nbuf);
262 if (!strcasecmp(nbuf, NODENAME))
266 fprintf(rmail, "%s\n", rmname);
267 fprintf(rmail, "From: %s@%s (%s)\n", rmname, FQDN, fstr);
270 if (!strcasecmp(nbuf, NODENAME)) { /* from this system */
271 fprintf(rmail, "%s\n", pbuf);
272 fprintf(rmail, "From: %s@%s (%s)\n",
274 } else if (haschar(nbuf, '.')) { /* from an FQDN */
275 fprintf(rmail, "%s\n", sbuf);
276 fprintf(rmail, "From: %s@%s (%s)\n",
278 } else { /* from another Cit */
279 fprintf(rmail, "%s\n", sbuf);
280 fprintf(rmail, "From: %s@%s.%s (%s)\n",
281 sbuf, nbuf, GW_DOMAIN, fstr);
287 * Everything else is pretty straightforward.
289 fprintf(rmail, "To: %s\n", rbuf);
291 generate_rfc822_datestamp(datestamp, now);
292 fprintf(rmail, "Date: %s\n", datestamp);
293 fprintf(rmail, "Message-Id: <%ld@%s>\n", (long) mid_buf, nbuf);
294 fprintf(rmail, "X-Mailer: %s\n", CITADEL);
295 fprintf(rmail, "Subject: %s\n", subject);
296 fprintf(rmail, "\n");
297 fp = fopen(temp, "r");
306 fprintf(rmail, "\n");
309 unlink(temp); /* get rid of the ASCII file */
310 execlp("./netproc", "netproc", "-i", NULL);
311 exit(0); /* go back to the main program */