4 * 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)
45 void fpgetfield(FILE * fp, char *string)
62 /* This is NOT the same msgform() found in the main program. It has been
63 * modified to format 80 columns into a temporary file, and extract the
64 * sender and recipient names for use within the main() loop.
66 void msgform(char *msgfile, FILE * mfout, char *sbuf, char *rbuf, char *nbuf,
67 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");
96 c = 1; /* c is the current pos */
99 fprintf(stderr, "netmailer: This is not a Citadel message.\n");
116 /* generate subject... */
117 if ((generate_subject == 1) && (strlen(subj) < 60)) {
118 subj[strlen(subj) + 1] = 0;
119 subj[strlen(subj)] = (((a > 31) && (a < 127)) ? a : 32);
121 if (((a == 13) || (a == 10)) && (old != 13) && (old != 10))
123 if (((old == 13) || (old == 10)) && ((real == 32) || (real == 13) || (real == 10))) {
124 fprintf(mfout, "\n");
128 if (((strlen(aaa) + c) > (width - 5)) && (strlen(aaa) > (width - 5))) {
129 fprintf(mfout, "\n%s", aaa);
138 if ((strlen(aaa) + c) > (width - 5)) {
139 fprintf(mfout, "\n");
142 fprintf(mfout, "%s ", aaa);
148 if ((a == 13) || (a == 10)) {
149 fprintf(mfout, "%s\n", aaa);
169 BONFGM: b = getc(fp);
184 *mid_buf = atol(bbb);
189 generate_subject = 0; /* have a real subj so don't gen one */
194 int main(int argc, char **argv)
198 char sbuf[200], rbuf[200], cstr[100], fstr[128];
199 char nbuf[64], pbuf[128], rmname[128], buf[128];
206 openlog("netmailer", LOG_PID, LOG_USER);
208 LoadInternetConfig();
209 strcpy(temp, tmpnam(NULL)); /* temp file name */
211 if ((argc < 2) || (argc > 3)) {
212 fprintf(stderr, "netmailer: usage: "
213 "netmailer <filename> [mlist]\n");
217 * If we are running in mailing list mode, the room is being two-way
218 * gatewayed to an Internet mailing list. Since many listprocs only
219 * accept postings from subscribed addresses, we must always use the
220 * room's address as the originating user.
222 if ((argc == 3) && (!strcasecmp(argv[2], "mlist"))) {
225 /* convert to ASCII & get info */
226 fp = fopen(temp, "w");
227 msgform(argv[1], fp, sbuf, rbuf, nbuf, pbuf, &mid_buf, rmname, subject);
231 strcpy(rmname, "room_");
233 for (a = 0; a < strlen(rmname); ++a) {
234 if (rmname[a] == ' ')
236 rmname[a] = tolower(rmname[a]);
239 sprintf(cstr, SENDMAIL, rbuf);
240 rmail = (FILE *) popen(cstr, "w");
243 for (a = 0; a < strlen(sbuf); ++a)
246 for (a = 0; a < strlen(rbuf); ++a)
251 * This logic attempts to compose From and From: lines that are
252 * as RFC822-compliant as possible. The return addresses are correct
253 * if you're using Citadel's 'citmail' delivery agent to allow BBS
254 * users to receive Internet mail.
256 fprintf(rmail, "From ");
257 if (strcasecmp(nbuf, NODENAME))
258 fprintf(rmail, "%s!", nbuf);
260 if (!strcasecmp(nbuf, NODENAME))
264 fprintf(rmail, "%s\n", rmname);
265 fprintf(rmail, "From: %s@%s (%s)\n", rmname, FQDN, fstr);
268 if (!strcasecmp(nbuf, NODENAME)) { /* from this system */
269 fprintf(rmail, "%s\n", pbuf);
270 fprintf(rmail, "From: %s@%s (%s)\n",
272 } else if (haschar(nbuf, '.')) { /* from an FQDN */
273 fprintf(rmail, "%s\n", sbuf);
274 fprintf(rmail, "From: %s@%s (%s)\n",
276 } else { /* from another Cit */
277 fprintf(rmail, "%s\n", sbuf);
278 fprintf(rmail, "From: %s@%s.%s (%s)\n",
279 sbuf, nbuf, GW_DOMAIN, fstr);
285 * Everything else is pretty straightforward.
287 fprintf(rmail, "To: %s\n", rbuf);
289 datestring(datestamp, now, DATESTRING_RFC822);
290 fprintf(rmail, "Date: %s\n", datestamp);
291 fprintf(rmail, "Message-Id: <%ld@%s>\n", (long) mid_buf, nbuf);
292 fprintf(rmail, "X-Mailer: %s\n", CITADEL);
293 fprintf(rmail, "Subject: %s\n", subject);
294 fprintf(rmail, "\n");
295 fp = fopen(temp, "r");
304 fprintf(rmail, "\n");
307 unlink(temp); /* get rid of the ASCII file */
308 execlp("./netproc", "netproc", "-i", NULL);
309 exit(0); /* go back to the main program */