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)
46 void fpgetfield(FILE * fp, char *string)
63 /* This is NOT the same msgform() found in the main program. It has been
64 * modified to format 80 columns into a temporary file, and extract the
65 * sender and recipient names for use within the main() loop.
67 void msgform(char *msgfile, FILE * mfout, char *sbuf, char *rbuf, char *nbuf,
68 char *pbuf, time_t * mid_buf, char *rmname, char *subj)
70 /* recipient (in this case, an Internet address) */
77 int a, b, c, e, old, mtype, aflag;
79 char aaa[128], bbb[128];
82 int generate_subject = 1;
86 strcpy(nbuf, NODENAME);
90 fp = fopen(msgfile, "rb");
92 fprintf(stderr, "netmailer: can't open message file\n");
97 c = 1; /* c is the current pos */
100 fprintf(stderr, "netmailer: This is not a Citadel message.\n");
117 /* generate subject... */
118 if ((generate_subject == 1) && (strlen(subj) < 60)) {
119 subj[strlen(subj) + 1] = 0;
120 subj[strlen(subj)] = (((a > 31) && (a < 127)) ? a : 32);
122 if (((a == 13) || (a == 10)) && (old != 13) && (old != 10))
124 if (((old == 13) || (old == 10)) && ((real == 32) || (real == 13) || (real == 10))) {
125 fprintf(mfout, "\n");
129 if (((strlen(aaa) + c) > (width - 5)) && (strlen(aaa) > (width - 5))) {
130 fprintf(mfout, "\n%s", aaa);
139 if ((strlen(aaa) + c) > (width - 5)) {
140 fprintf(mfout, "\n");
143 fprintf(mfout, "%s ", aaa);
149 if ((a == 13) || (a == 10)) {
150 fprintf(mfout, "%s\n", aaa);
170 BONFGM: b = getc(fp);
185 *mid_buf = atol(bbb);
190 generate_subject = 0; /* have a real subj so don't gen one */
195 int main(int argc, char **argv)
199 char sbuf[200], rbuf[200], cstr[100], fstr[128];
200 char nbuf[64], pbuf[128], rmname[128], buf[128];
206 openlog("netmailer", LOG_PID, LOG_USER);
208 LoadInternetConfig();
209 sprintf(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 fprintf(rmail, "Date: %s", asctime(localtime(&now)));
290 fprintf(rmail, "Message-Id: <%ld@%s>\n", (long) mid_buf, nbuf);
291 fprintf(rmail, "X-Mailer: %s\n", CITADEL);
292 fprintf(rmail, "Subject: %s\n", subject);
293 fprintf(rmail, "\n");
294 fp = fopen(temp, "r");
303 fprintf(rmail, "\n");
306 unlink(temp); /* get rid of the ASCII file */
307 execlp("./netproc", "netproc", "-i", NULL);
308 exit(0); /* go back to the main program */