diff --git a/ChangeLog b/ChangeLog index 8ead4697..48387c11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,12 @@ v0.35.07 11-Dec-2002 The index command displays LFN names in the webpages again. The real download still sends the 8.3 name. + mbfido: + Better detection of zone information in netmails when netmail + was stored in a netmail packet of a different network and the + netmail misses a lot of kludges. Better logging of processed + netmails. + mbcico: Code cleanup in opentcp, better handling of given ports and better logging. diff --git a/mbfido/bounce.c b/mbfido/bounce.c index 92ae68e2..a98e0825 100644 --- a/mbfido/bounce.c +++ b/mbfido/bounce.c @@ -69,81 +69,81 @@ extern char *msgid; /* Original message id */ int Bounce(faddr *f, faddr *t, FILE *fp, char *reason) { - int rc = 0, count = 0; - char *Buf; - FILE *np; - time_t Now; - faddr *from; + int rc = 0, count = 0; + char *Buf; + FILE *np; + time_t Now; + faddr *from; - Now = time(NULL); - if (SearchFidonet(f->zone)) - f->domain = xstrcpy(fidonet.domain); + Now = time(NULL); + if (SearchFidonet(f->zone)) + f->domain = xstrcpy(fidonet.domain); - Syslog('+', "Bounce msg from %s", ascfnode(f, 0xff)); - Buf = calloc(2049, sizeof(char)); - rewind(fp); + Syslog('+', "Bounce msg from %s", ascfnode(f, 0xff)); + Buf = calloc(2049, sizeof(char)); + rewind(fp); - np = tmpfile(); - from = bestaka_s(f); - from->zone = t->zone; - from->net = t->net; - from->node = t->node; - from->point = t->point; - from->name = xstrcpy((char *)"Postmaster"); + np = tmpfile(); + from = bestaka_s(f); + from->zone = t->zone; + from->net = t->net; + from->node = t->node; + from->point = t->point; + from->name = xstrcpy((char *)"Postmaster"); - if (f->point) - fprintf(np, "\001TOPT %d\r", f->point); - if (from->point) - fprintf(np, "\001FMPT %d\r", from->point); - fprintf(np, "\001INTL %d:%d/%d %d:%d/%d\r", f->zone, f->net, f->node, from->zone, from->net, from->node); + if (f->point) + fprintf(np, "\001TOPT %d\r", f->point); + if (from->point) + fprintf(np, "\001FMPT %d\r", from->point); + fprintf(np, "\001INTL %d:%d/%d %d:%d/%d\r", f->zone, f->net, f->node, from->zone, from->net, from->node); - /* - * Add MSGID, REPLY and PID - */ - fprintf(np, "\001MSGID: %s %08lx\r", ascfnode(from, 0x1f), sequencer()); - while ((fgets(Buf, 2048, fp)) != NULL) { - Striplf(Buf); - if (strncmp(Buf, "\001MSGID:", 7) == 0) { - fprintf(np, "\001REPLY:%s\r", Buf+7); - } + /* + * Add MSGID, REPLY and PID + */ + fprintf(np, "\001MSGID: %s %08lx\r", ascfnode(from, 0x1f), sequencer()); + while ((fgets(Buf, 2048, fp)) != NULL) { + Striplf(Buf); + if (strncmp(Buf, "\001MSGID:", 7) == 0) { + fprintf(np, "\001REPLY:%s\r", Buf+7); } - fprintf(np, "\001PID: MBSE-FIDO %s\r", VERSION); - fprintf(np, "\001TZUTC: %s\r", gmtoffset(Now)); + } + fprintf(np, "\001PID: MBSE-FIDO %s\r", VERSION); + fprintf(np, "\001TZUTC: %s\r", gmtoffset(Now)); - fprintf(np, " Dear %s\r\r", MBSE_SS(f->name)); - fprintf(np, "Your message could not be delevered, reason: %s\r\r", reason); - fprintf(np, "Here are the first lines of the original message from you:\r\r"); - fprintf(np, "======================================================================\r"); + fprintf(np, " Dear %s\r\r", MBSE_SS(f->name)); + fprintf(np, "Your message could not be delevered, reason: %s\r\r", reason); + fprintf(np, "Here are the first lines of the original message from you:\r\r"); + fprintf(np, "======================================================================\r"); - rewind(fp); - while ((fgets(Buf, 2048, fp)) != NULL) { - Striplf(Buf); - if (Buf[0] == '\001') { - fprintf(np, "^a"); - fwrite(Buf + 1, strlen(Buf) -1, 1, np); - } else { - fwrite(Buf, strlen(Buf), 1, np); - } - fputc('\r', np); - count++; - if (count == 50) - break; - } - fprintf(np, "======================================================================\r"); - if (count == 50) { - fprintf(np, "\rOnly the first 50 lines are displayed\r"); + rewind(fp); + while ((fgets(Buf, 2048, fp)) != NULL) { + Striplf(Buf); + if (Buf[0] == '\001') { + fprintf(np, "^a"); + fwrite(Buf + 1, strlen(Buf) -1, 1, np); + } else { + fwrite(Buf, strlen(Buf), 1, np); } + fputc('\r', np); + count++; + if (count == 50) + break; + } + fprintf(np, "======================================================================\r"); + if (count == 50) { + fprintf(np, "\rOnly the first 50 lines are displayed\r"); + } - fprintf(np, "\rWith regards, %s\r\r", CFG.sysop_name); - fprintf(np, "%s\r", TearLine()); - Now = time(NULL) - (gmt_offset((time_t)0) * 60); - rc = postnetmail(np, from, f, NULL, (char *)"Bounced message", Now, 0x0000, FALSE); - tidy_faddr(from); + fprintf(np, "\rWith regards, %s\r\r", CFG.sysop_name); + fprintf(np, "%s\r", TearLine()); + Now = time(NULL) - (gmt_offset((time_t)0) * 60); + rc = postnetmail(np, from, f, NULL, (char *)"Bounced message", Now, 0x0000, FALSE, from->zone, f->zone); + tidy_faddr(from); - fclose(np); + fclose(np); - free(Buf); - return rc; + free(Buf); + return rc; } diff --git a/mbfido/ping.c b/mbfido/ping.c index 0c751151..983d704f 100644 --- a/mbfido/ping.c +++ b/mbfido/ping.c @@ -69,80 +69,80 @@ extern char *msgid; /* Original message id */ int Ping(faddr *f, faddr *t, FILE *fp, int intransit) { - int rc = 0; - char *Buf; - FILE *np; - time_t Now; - faddr *from; + int rc = 0; + char *Buf; + FILE *np; + time_t Now; + faddr *from; - Now = time(NULL); - if (SearchFidonet(f->zone)) - f->domain = xstrcpy(fidonet.domain); + Now = time(NULL); + if (SearchFidonet(f->zone)) + f->domain = xstrcpy(fidonet.domain); - Syslog('+', "%s ping msg from %s", intransit ? "Intransit":"Final", ascfnode(f, 0xff)); - Buf = calloc(2049, sizeof(char)); - rewind(fp); + Syslog('+', "%s ping msg from %s", intransit ? "Intransit":"Final", ascfnode(f, 0xff)); + Buf = calloc(2049, sizeof(char)); + rewind(fp); - np = tmpfile(); - from = bestaka_s(f); - if (intransit) { - from->name = xstrcpy((char *)"Ping TRACE service"); - } else { - from->zone = t->zone; - from->net = t->net; - from->node = t->node; - from->point = t->point; - from->name = xstrcpy((char *)"Ping service"); + np = tmpfile(); + from = bestaka_s(f); + if (intransit) { + from->name = xstrcpy((char *)"Ping TRACE service"); + } else { + from->zone = t->zone; + from->net = t->net; + from->node = t->node; + from->point = t->point; + from->name = xstrcpy((char *)"Ping service"); + } + + if (f->point) + fprintf(np, "\001TOPT %d\r", f->point); + if (from->point) + fprintf(np, "\001FMPT %d\r", from->point); + fprintf(np, "\001INTL %d:%d/%d %d:%d/%d\r", f->zone, f->net, f->node, from->zone, from->net, from->node); + + /* + * Add MSGID, REPLY and PID + */ + fprintf(np, "\001MSGID: %s %08lx\r", ascfnode(from, 0x1f), sequencer()); + while ((fgets(Buf, 2048, fp)) != NULL) { + Striplf(Buf); + if (strncmp(Buf, "\001MSGID:", 7) == 0) { + fprintf(np, "\001REPLY:%s\r", Buf+7); } + } + fprintf(np, "\001PID: MBSE-FIDO %s\r", VERSION); + fprintf(np, "\001TZUTC: %s\r", gmtoffset(Now)); - if (f->point) - fprintf(np, "\001TOPT %d\r", f->point); - if (from->point) - fprintf(np, "\001FMPT %d\r", from->point); - fprintf(np, "\001INTL %d:%d/%d %d:%d/%d\r", f->zone, f->net, f->node, from->zone, from->net, from->node); + fprintf(np, " Dear %s\r\r", MBSE_SS(f->name)); + if (intransit) { + fprintf(np, "You did send a PING to %s\r", ascfnode(t, 0x1f)); + fprintf(np, "This is a TRACE response from \"%s\" aka %s\r", CFG.bbs_name, ascfnode(from, 0x1f)); + fprintf(np, "The time of arrival is %s\r", rfcdate(Now)); + } else + fprintf(np, "Your Ping arrived here at %s\r", rfcdate(Now)); + fprintf(np, "Here are all the detected Via lines of the message from you:\r\r"); + fprintf(np, "======================================================================\r"); - /* - * Add MSGID, REPLY and PID - */ - fprintf(np, "\001MSGID: %s %08lx\r", ascfnode(from, 0x1f), sequencer()); - while ((fgets(Buf, 2048, fp)) != NULL) { - Striplf(Buf); - if (strncmp(Buf, "\001MSGID:", 7) == 0) { - fprintf(np, "\001REPLY:%s\r", Buf+7); - } + rewind(fp); + while ((fgets(Buf, 2048, fp)) != NULL) { + Striplf(Buf); + if (strncmp(Buf, "\1Via", 4) == 0) { + fprintf(np, "%s\r", Buf+1); } - fprintf(np, "\001PID: MBSE-FIDO %s\r", VERSION); - fprintf(np, "\001TZUTC: %s\r", gmtoffset(Now)); + } + fprintf(np, "======================================================================\r"); - fprintf(np, " Dear %s\r\r", MBSE_SS(f->name)); - if (intransit) { - fprintf(np, "You did send a PING to %s\r", ascfnode(t, 0x1f)); - fprintf(np, "This is a TRACE response from \"%s\" aka %s\r", CFG.bbs_name, ascfnode(from, 0x1f)); - fprintf(np, "The time of arrival is %s\r", rfcdate(Now)); - } else - fprintf(np, "Your Ping arrived here at %s\r", rfcdate(Now)); - fprintf(np, "Here are all the detected Via lines of the message from you:\r\r"); - fprintf(np, "======================================================================\r"); + fprintf(np, "\rWith regards, %s\r\r", CFG.sysop_name); + fprintf(np, "%s\r", TearLine()); + Now = time(NULL) - (gmt_offset((time_t)0) * 60); + rc = postnetmail(np, from, f, NULL, (char *)"Re: Ping", Now, 0x0000, FALSE, from->zone, f->zone); + tidy_faddr(from); - rewind(fp); - while ((fgets(Buf, 2048, fp)) != NULL) { - Striplf(Buf); - if (strncmp(Buf, "\1Via", 4) == 0) { - fprintf(np, "%s\r", Buf+1); - } - } - fprintf(np, "======================================================================\r"); + fclose(np); - fprintf(np, "\rWith regards, %s\r\r", CFG.sysop_name); - fprintf(np, "%s\r", TearLine()); - Now = time(NULL) - (gmt_offset((time_t)0) * 60); - rc = postnetmail(np, from, f, NULL, (char *)"Re: Ping", Now, 0x0000, FALSE); - tidy_faddr(from); - - fclose(np); - - free(Buf); - return rc; + free(Buf); + return rc; } diff --git a/mbfido/postnetmail.c b/mbfido/postnetmail.c index eb782de0..84022c1d 100644 --- a/mbfido/postnetmail.c +++ b/mbfido/postnetmail.c @@ -70,375 +70,386 @@ extern int net_bad; /* Bad netmails */ * 2 - Can't find netmail board. * */ -int postnetmail(FILE *fp, faddr *f, faddr *t, char *orig, char *subject, time_t mdate, int flags, int DoPing) +int postnetmail(FILE *fp, faddr *f, faddr *t, char *orig, char *subject, time_t mdate, + int flags, int DoPing, unsigned int fzone, unsigned int tzone) { - char *p, *msgid = NULL, *reply = NULL, *flagstr = NULL; - char name[36], *buf, *l, *r, *q; - char System[36], ext[4]; - int result = 1, email = FALSE, fmpt = 0, topt = 0; - faddr *ta, *ra; - fidoaddr na, routeto, Orig; - FILE *sfp, *net; - time_t now; - struct tm *tm; + char *p, *msgid = NULL, *reply = NULL, *flagstr = NULL; + char name[36], *buf, *l, *r, *q, System[36], ext[4]; + int result = 1, email = FALSE, fmpt = 0, topt = 0; + faddr *ta, *ra; + fidoaddr na, routeto, Orig; + FILE *sfp, *net; + time_t now; + struct tm *tm; - Syslog('M', "Post netmail from: %s", ascfnode(f, 0xff)); - Syslog('M', "Post netmail to : %s", ascfnode(t, 0xff)); - Syslog('M', "Post netmail subj: %s", MBSE_SS(subject)); - net_in++; + Syslog('M', "Post netmail from: %s", ascfnode(f, 0xff)); + Syslog('M', "Post netmail to : %s", ascfnode(t, 0xff)); + Syslog('M', "Post netmail subj: %s", MBSE_SS(subject)); + net_in++; - /* - * Extract MSGID and REPLY kludges from this netmail. - */ - buf = calloc(2048, sizeof(char)); - rewind(fp); - while ((fgets(buf, 2048, fp)) != NULL) { - Striplf(buf); - Syslogp('M', printable(buf, 0)); - if (!strncmp(buf, "\001MSGID: ", 8)) { - msgid = xstrcpy(buf + 8); - /* - * Extra test to see if the mail comes from a pointaddress. - */ - l = strtok(buf," \n"); - l = strtok(NULL," \n"); - if ((ta = parsefnode(l))) { - if (ta->zone == f->zone && ta->net == f->net && ta->node == f->node && !fmpt && ta->point) { - Syslog('m', "Setting pointinfo (%d) from MSGID", ta->point); - fmpt = f->point = ta->point; - } - tidy_faddr(ta); - } - } - if (!strncmp(buf, "\001FMPT", 5)) { - p = strtok(buf, " \n"); - p = strtok(NULL, " \n"); - fmpt = atoi(p); - } - if (!strncmp(buf, "\001TOPT", 5)) { - p = strtok(buf, " \n"); - p = strtok(NULL, " \n"); - topt = atoi(p); - } - if (!strncmp(buf, "\001REPLY: ", 8)) - reply = xstrcpy(buf + 8); - - /* - * Check DOMAIN and INTL kludges - */ - if (!strncmp(buf, "\001DOMAIN", 7)) { - l = strtok(buf," \n"); - l = strtok(NULL," \n"); - p = strtok(NULL," \n"); - r = strtok(NULL," \n"); - q = strtok(NULL," \n"); - if ((ta = parsefnode(p))) { - t->point = ta->point; - t->node = ta->node; - t->net = ta->net; - t->zone = ta->zone; - tidy_faddr(ta); - } - t->domain = xstrcpy(l); - if ((ta = parsefnode(q))) { - f->point = ta->point; - f->node = ta->node; - f->net = ta->net; - f->zone = ta->zone; - tidy_faddr(ta); - } - f->domain = xstrcpy(r); - } else { - if (!strncmp(buf, "\001INTL", 5)) { - l = strtok(buf," \n"); - l = strtok(NULL," \n"); - r = strtok(NULL," \n"); - if ((ta = parsefnode(l))) { - t->point = ta->point; - t->node = ta->node; - t->net = ta->net; - t->zone = ta->zone; - if (ta->domain) { - if (t->domain) - free(t->domain); - t->domain = ta->domain; - ta->domain = NULL; - } - tidy_faddr(ta); - } - if ((ta = parsefnode(r))) { - f->point = ta->point; - f->node = ta->node; - f->net = ta->net; - f->zone = ta->zone; - if (ta->domain) { - if (f->domain) - free(f->domain); - f->domain = ta->domain; - ta->domain = NULL; - } - tidy_faddr(ta); - } - } - } - - /* - * Check FLAGS kludge - */ - if (!strncmp(buf, "\001FLAGS ", 7)) { - flagstr = xstrcpy(buf + 7); - Syslog('m', "^aFLAGS %s", flagstr); - } - if (!strncmp(buf, "\001FLAGS: ", 8)) { - flagstr = xstrcpy(buf + 8); - Syslog('m', "^aFLAGS: %s", flagstr); - } - - /* - * Check for X-FTN- kludges, this could be gated email. - * This should be impossible. - */ - if (!strncmp(buf, "\001X-FTN-", 7)) { - email = TRUE; - Syslog('?', "Warning: detected ^aX-FTN- kludge in netmail"); + /* + * Extract MSGID and REPLY kludges from this netmail. + */ + buf = calloc(2049, sizeof(char)); + rewind(fp); + while ((fgets(buf, 2048, fp)) != NULL) { + Striplf(buf); + Syslogp('M', printable(buf, 0)); + if (!strncmp(buf, "\001MSGID: ", 8)) { + msgid = xstrcpy(buf + 8); + /* + * Extra test to see if the mail comes from a pointaddress. + */ + l = strtok(buf," \n"); + l = strtok(NULL," \n"); + if ((ta = parsefnode(l))) { + if (ta->net == f->net && ta->node == f->node && !fmpt && ta->point) { + Syslog('m', "Setting pointinfo (%d) from MSGID", ta->point); + fmpt = f->point = ta->point; } + tidy_faddr(ta); + } } - free(buf); + if (!strncmp(buf, "\001FMPT", 5)) { + p = strtok(buf, " \n"); + p = strtok(NULL, " \n"); + fmpt = atoi(p); + } + if (!strncmp(buf, "\001TOPT", 5)) { + p = strtok(buf, " \n"); + p = strtok(NULL, " \n"); + topt = atoi(p); + } + if (!strncmp(buf, "\001REPLY: ", 8)) + reply = xstrcpy(buf + 8); /* - * Only set point info if there was any info. - * GoldED doesn't set FMPT and TOPT kludges. + * Check DOMAIN and INTL kludges */ - if (fmpt) - f->point = fmpt; - if (topt) - t->point = topt; + if (!strncmp(buf, "\001DOMAIN", 7)) { + l = strtok(buf," \n"); + l = strtok(NULL," \n"); + p = strtok(NULL," \n"); + r = strtok(NULL," \n"); + q = strtok(NULL," \n"); + if ((ta = parsefnode(p))) { + t->point = ta->point; + t->node = ta->node; + t->net = ta->net; + t->zone = ta->zone; + tidy_faddr(ta); + } + t->domain = xstrcpy(l); + if ((ta = parsefnode(q))) { + f->point = ta->point; + f->node = ta->node; + f->net = ta->net; + f->zone = ta->zone; + tidy_faddr(ta); + } + f->domain = xstrcpy(r); + } else { + if (!strncmp(buf, "\001INTL", 5)) { + l = strtok(buf," \n"); + l = strtok(NULL," \n"); + r = strtok(NULL," \n"); + if ((ta = parsefnode(l))) { + t->point = ta->point; + t->node = ta->node; + t->net = ta->net; + t->zone = ta->zone; + if (ta->domain) { + if (t->domain) + free(t->domain); + t->domain = ta->domain; + ta->domain = NULL; + } + tidy_faddr(ta); + } + if ((ta = parsefnode(r))) { + f->point = ta->point; + f->node = ta->node; + f->net = ta->net; + f->zone = ta->zone; + if (ta->domain) { + if (f->domain) + free(f->domain); + f->domain = ta->domain; + ta->domain = NULL; + } + tidy_faddr(ta); + } + } + } - Syslog('m', "Final netmail from: %s", ascfnode(f, 0xff)); - Syslog('m', "Final netmail to : %s", ascfnode(t, 0xff)); + /* + * Check FLAGS kludge + */ + if (!strncmp(buf, "\001FLAGS ", 7)) { + flagstr = xstrcpy(buf + 7); + Syslog('m', "^aFLAGS %s", flagstr); + } + if (!strncmp(buf, "\001FLAGS: ", 8)) { + flagstr = xstrcpy(buf + 8); + Syslog('m', "^aFLAGS: %s", flagstr); + } - memset(&na, 0, sizeof(na)); - na.zone = t->zone; - na.net = t->net; - na.node = t->node; - na.point = t->point; - if (SearchFidonet(na.zone)) - sprintf(na.domain, "%s", fidonet.domain); + /* + * Check for X-FTN- kludges, this could be gated email. + * This should be impossible. + */ + if (!strncmp(buf, "\001X-FTN-", 7)) { + email = TRUE; + Syslog('?', "Warning: detected ^aX-FTN- kludge in netmail"); + } + } + free(buf); - switch(TrackMail(na, &routeto)) { + /* + * Only set point info if there was any info. + * GoldED doesn't set FMPT and TOPT kludges. + */ + if (fmpt) + f->point = fmpt; + if (topt) + t->point = topt; + + /* + * If zone info is still missing, set the defaults which came from the + * original mail packet addressing. + */ + if (fzone && (f->zone == 0)) + f->zone = fzone; + if (tzone && (t->zone == 0)) + t->zone = tzone; + + l = xstrcpy(ascfnode(f, 0xff)); + r = xstrcpy(ascfnode(t, 0xff)); + Syslog('+', "Netmail from \"%s\" to \"%s\"", l, r); + free(l); + free(r); + + memset(&na, 0, sizeof(na)); + na.zone = t->zone; + na.net = t->net; + na.node = t->node; + na.point = t->point; + if (SearchFidonet(na.zone)) + sprintf(na.domain, "%s", fidonet.domain); + + switch(TrackMail(na, &routeto)) { case R_LOCAL: - /* - * Check the To: field. - */ - if (strchr(t->name, '@') != NULL) { - sprintf(name, "%s", strtok(t->name, "@")); - sprintf(System, "%s", strtok(NULL, "\000")); - email = TRUE; - } else { - sprintf(name, "%s", t->name); - sprintf(System, "%s", CFG.sysdomain); - } - - if (email) { - /* - * Send this netmail via ftn2rfc -> postemail. - */ - result = ftn2rfc(f, t, subject, orig, mdate, flags, fp); - return result; - } + /* + * Check the To: field. + */ + if (strchr(t->name, '@') != NULL) { + sprintf(name, "%s", strtok(t->name, "@")); + sprintf(System, "%s", strtok(NULL, "\000")); + email = TRUE; + } else { + sprintf(name, "%s", t->name); + sprintf(System, "%s", CFG.sysdomain); + } + if (email) { /* - * If message to "sysop" or "postmaster" replace it - * with the sysops real name. + * Send this netmail via ftn2rfc -> postemail. */ - if ((strncasecmp(name, "sysop", 5) == 0) || (strcasecmp(name, "postmaster") == 0)) { - Syslog('+', " Readdress from %s to %s", name, CFG.sysop_name); - sprintf(name, "%s", CFG.sysop_name); - } + return result = ftn2rfc(f, t, subject, orig, mdate, flags, fp); + } - /* - * If the message is a service message, check the - * services database to see what action is needed. - * First make sure that the right noderecord is loaded. - */ - (void)noderecord(f); - p = calloc(PATH_MAX, sizeof(char)); - sprintf(p, "%s/etc/service.data", getenv("MBSE_ROOT")); - if ((sfp = fopen(p, "r")) == NULL) { - WriteError("$Can't open %s", p); - } else { - fread(&servhdr, sizeof(servhdr), 1, sfp); - while (fread(&servrec, servhdr.recsize, 1, sfp) == 1) { - if ((strncasecmp(servrec.Service, name, strlen(servrec.Service)) == 0) && servrec.Active) { - switch (servrec.Action) { - case AREAMGR: result = AreaMgr(f, t, msgid, subject, mdate, flags, fp); - break; - case FILEMGR: result = FileMgr(f, t, msgid, subject, mdate, flags, fp); - break; - case EMAIL: result = ftn2rfc(f, t, subject, orig, mdate, flags, fp); - if (result) { - if (result == 2) - Bounce(f, t, fp, (char *)"Could not post email"); - else - Bounce(f, t, fp, (char *)"Could not convert to email"); - } - break; - } - Syslog('m', "Handled service %s, rc=%d", servrec.Service, result); - fclose(sfp); - return result; - } - } - fclose(sfp); - } - free(p); - - /* - * Ping function - */ - if (!strcasecmp(name, (char *)"ping") && DoPing) { - return Ping(f, t, fp, FALSE); - } - - /* - * Check userlist real names, handles, unix names. - * Import if one fits. - */ - if (SearchUser(name)) { - return storenet(f, t, mdate, flags, subject, msgid, reply, fp, flagstr); - } - - Syslog('+', " \"%s\" is not a known BBS user", name); - /* - * Unknown, readdress it to the sysop. - */ - net_bad++; + /* + * If message to "sysop" or "postmaster" replace it + * with the sysops real name. + */ + if ((strncasecmp(name, "sysop", 5) == 0) || (strcasecmp(name, "postmaster") == 0)) { Syslog('+', " Readdress from %s to %s", name, CFG.sysop_name); sprintf(name, "%s", CFG.sysop_name); - if (SearchUser(name)) { - return storenet(f, t, mdate, flags, subject, msgid, reply, fp, flagstr); - } else { - WriteError("Readdress import failed, sysop doesn't exist. CHECK YOUR SETUP"); - return 0; + } + + /* + * If the message is a service message, check the + * services database to see what action is needed. + * First make sure that the right noderecord is loaded. + */ + (void)noderecord(f); + p = calloc(PATH_MAX, sizeof(char)); + sprintf(p, "%s/etc/service.data", getenv("MBSE_ROOT")); + if ((sfp = fopen(p, "r")) == NULL) { + WriteError("$Can't open %s", p); + } else { + fread(&servhdr, sizeof(servhdr), 1, sfp); + while (fread(&servrec, servhdr.recsize, 1, sfp) == 1) { + if ((strncasecmp(servrec.Service, name, strlen(servrec.Service)) == 0) && servrec.Active) { + switch (servrec.Action) { + case AREAMGR: result = AreaMgr(f, t, msgid, subject, mdate, flags, fp); + break; + case FILEMGR: result = FileMgr(f, t, msgid, subject, mdate, flags, fp); + break; + case EMAIL: result = ftn2rfc(f, t, subject, orig, mdate, flags, fp); + if (result) { + if (result == 2) + Bounce(f, t, fp, (char *)"Could not post email"); + else + Bounce(f, t, fp, (char *)"Could not convert to email"); + } + break; + } + Syslog('m', "Handled service %s, rc=%d", servrec.Service, result); + fclose(sfp); + return result; + } } - break; + fclose(sfp); + } + free(p); + + /* + * Ping function + */ + if (!strcasecmp(name, (char *)"ping") && DoPing) { + return Ping(f, t, fp, FALSE); + } + + /* + * Check userlist real names, handles, unix names. + * Import if one fits. + */ + if (SearchUser(name)) { + return storenet(f, t, mdate, flags, subject, msgid, reply, fp, flagstr); + } + + Syslog('+', " \"%s\" is not a known BBS user", name); + /* + * Unknown, readdress it to the sysop. + */ + net_bad++; + Syslog('+', " Readdress from %s to %s", name, CFG.sysop_name); + sprintf(name, "%s", CFG.sysop_name); + if (SearchUser(name)) { + return storenet(f, t, mdate, flags, subject, msgid, reply, fp, flagstr); + } else { + WriteError("Readdress import failed, sysop doesn't exist. CHECK YOUR SETUP"); + return 0; + } + break; case R_DIRECT: case R_ROUTE: - Syslog('+', "Route netmail via %s", aka2str(routeto)); - if (!strcasecmp(t->name, (char *)"ping") && DoPing) { - Syslog('+', "In transit \"Ping\" message detected"); - Ping(f, t, fp, TRUE); - (void)noderecord(f); - } + Syslog('+', "Route netmail via %s", aka2str(routeto)); + if (!strcasecmp(t->name, (char *)"ping") && DoPing) { + Syslog('+', "In transit \"Ping\" message detected"); + Ping(f, t, fp, TRUE); + (void)noderecord(f); + } - /* - * Forward this message. Will not work for unknown - * direct links. - */ - if (SearchNode(routeto)) { - memset(&Orig, 0, sizeof(Orig)); - ra = fido2faddr(routeto); - ta = bestaka_s(ra); - Orig.zone = ta->zone; - Orig.net = ta->net; - Orig.node = ta->node; - Orig.point = ta->point; - tidy_faddr(ra); - tidy_faddr(ta); - - memset(&ext, 0, sizeof(ext)); - if (nodes.PackNetmail) - sprintf(ext, (char *)"qqq"); - else if (nodes.Crash) - sprintf(ext, (char *)"ccc"); - else if (nodes.Hold) - sprintf(ext, (char *)"hhh"); - else - sprintf(ext, (char *)"nnn"); - - if ((net = OpenPkt(Orig , routeto, (char *)ext)) == NULL) { - net_bad++; - WriteError("Can't create netmail"); - return 0; - } - } else { - /* - * If it's not a direct link, create a outbound - * .pkt anyway, better then that this mail is - * lost. It gets the normal status, it might - * get delivered during ZMH this way. - */ - Syslog('!', "Warning: not a direct link, check setup"); - memset(&Orig, 0, sizeof(Orig)); - ra = fido2faddr(routeto); - ta = bestaka_s(ra); - Orig.zone = ta->zone; - Orig.net = ta->net; - Orig.node = ta->node; - Orig.point = ta->point; - tidy_faddr(ra); - tidy_faddr(ta); - - if ((net = OpenPkt(Orig , routeto, (char *)"nnn")) == NULL) { - net_bad++; - WriteError("Can't create netmail"); - return 0; - } - } - - /* - * Now start forward. - */ - Syslog('m', "Net from %s", ascfnode(f, 0xff)); - Syslog('m', "Net to %s", ascfnode(t, 0xff)); - Syslog('m', "Net flags %08x", flags); - Syslog('m', "Net subj %s", subject); - - if (AddMsgHdr(net, f, t, flags, 0, mdate, t->name, f->name, subject)) { - WriteError("Can't write message header"); - net_bad++; - return 0; - } - rewind(fp); - - /* - * Copy all text including kludges, when - * finished, insert our ^aVia line. - */ - buf = calloc(2048, sizeof(char)); - while ((fgets(buf, 2048, fp)) != NULL) - fprintf(net, "%s\r", buf); - - now = time(NULL); - tm = gmtime(&now); - ta = bestaka_s(t); - fprintf(net, "\001Via %s @%d%02d%02d.%02d%02d%02d.00.UTC mbfido %s\r", - ascfnode(ta, 0x1f), tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, VERSION); + /* + * Forward this message. Will not work for unknown + * direct links. + */ + if (SearchNode(routeto)) { + memset(&Orig, 0, sizeof(Orig)); + ra = fido2faddr(routeto); + ta = bestaka_s(ra); + Orig.zone = ta->zone; + Orig.net = ta->net; + Orig.node = ta->node; + Orig.point = ta->point; + tidy_faddr(ra); tidy_faddr(ta); - putc(0, net); - fclose(net); - free(buf); - net_out++; - Syslog('m', "Forward done."); + memset(&ext, 0, sizeof(ext)); + if (nodes.PackNetmail) + sprintf(ext, (char *)"qqq"); + else if (nodes.Crash) + sprintf(ext, (char *)"ccc"); + else if (nodes.Hold) + sprintf(ext, (char *)"hhh"); + else + sprintf(ext, (char *)"nnn"); + + if ((net = OpenPkt(Orig , routeto, (char *)ext)) == NULL) { + net_bad++; + WriteError("Can't create netmail"); + return 0; + } + } else { + /* + * If it's not a direct link, create a outbound + * .pkt anyway, better then that this mail is + * lost. It gets the normal status, it might + * get delivered during ZMH this way. + */ + Syslog('!', "Warning: not a direct link, check setup"); + memset(&Orig, 0, sizeof(Orig)); + ra = fido2faddr(routeto); + ta = bestaka_s(ra); + Orig.zone = ta->zone; + Orig.net = ta->net; + Orig.node = ta->node; + Orig.point = ta->point; + tidy_faddr(ra); + tidy_faddr(ta); + + if ((net = OpenPkt(Orig , routeto, (char *)"nnn")) == NULL) { + net_bad++; + WriteError("Can't create netmail"); + return 0; + } + } + + /* + * Now start forward. + */ + Syslog('m', "Net from %s", ascfnode(f, 0xff)); + Syslog('m', "Net to %s", ascfnode(t, 0xff)); + Syslog('m', "Net flags %08x", flags); + Syslog('m', "Net subj %s", subject); + + if (AddMsgHdr(net, f, t, flags, 0, mdate, t->name, f->name, subject)) { + WriteError("Can't write message header"); + net_bad++; return 0; + } + rewind(fp); + + /* + * Copy all text including kludges, when + * finished, insert our ^aVia line. + */ + buf = calloc(2048, sizeof(char)); + while ((fgets(buf, 2048, fp)) != NULL) + fprintf(net, "%s\r", buf); + + now = time(NULL); + tm = gmtime(&now); + ta = bestaka_s(t); + fprintf(net, "\001Via %s @%d%02d%02d.%02d%02d%02d.00.UTC mbfido %s\r", + ascfnode(ta, 0x1f), tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec, VERSION); + tidy_faddr(ta); + + putc(0, net); + fclose(net); + free(buf); + net_out++; + Syslog('m', "Forward done."); + return 0; default: - /* - * If we came this far, there's definitly something wrong - * with this netmail. - */ - WriteError("No ROUTE for this netmail"); - net_bad++; - flags |= M_ORPHAN; - return storenet(f, t, mdate, flags, subject, msgid, reply, fp, flagstr); - break; - } + /* + * If we came this far, there's definitly something wrong + * with this netmail. + */ + WriteError("No ROUTE for this netmail"); + net_bad++; + flags |= M_ORPHAN; + return storenet(f, t, mdate, flags, subject, msgid, reply, fp, flagstr); + break; + } - /* Never reached */ - return result; + /* Never reached */ + return result; } diff --git a/mbfido/postnetmail.h b/mbfido/postnetmail.h index 10b4b315..725d8059 100644 --- a/mbfido/postnetmail.h +++ b/mbfido/postnetmail.h @@ -1,8 +1,8 @@ #ifndef _POSTNETMAIL_H #define _POSTNETMAIL_H +/* $Id$ */ -int postnetmail(FILE *, faddr *, faddr *, char *, char *, time_t, int, int); +int postnetmail(FILE *, faddr *, faddr *, char *, char *, time_t, int, int, unsigned int, unsigned int); #endif - diff --git a/mbfido/rfc2ftn.c b/mbfido/rfc2ftn.c index 5d0da85f..73ba8765 100644 --- a/mbfido/rfc2ftn.c +++ b/mbfido/rfc2ftn.c @@ -134,721 +134,703 @@ int kludgewrite(char *s, FILE *fp) */ int rfc2ftn(FILE *fp, faddr *recipient) { - char sbe[16], *p, *q, *temp, *origin; - int i, rc, incode, outcode, pgpsigned, newsmode; - int seenlen, oldnet; - rfcmsg *msg = NULL, *tmsg, *tmp; - ftnmsg *fmsg = NULL; - FILE *ofp; - fa_list *sbl = NULL, *ptl = NULL, *tmpl; - faddr *ta, *fta; - unsigned long svmsgid, svreply; - int sot_kludge = FALSE, eot_kludge = FALSE, qp_or_base64 = FALSE, tinyorigin = FALSE; - int needsplit, hdrsize, datasize, splitpart, forbidsplit, rfcheaders; - char newsubj[4 * (MAXSUBJ+1)], *oldsubj, *acup_a = NULL; - unsigned long acup_n = 0; - int html_message = FALSE; - time_t Now; + char sbe[16], *p, *q, *temp, *origin, newsubj[4 * (MAXSUBJ+1)], *oldsubj, *acup_a = NULL; + int i, rc, incode, outcode, pgpsigned, newsmode, seenlen, oldnet; + rfcmsg *msg = NULL, *tmsg, *tmp; + ftnmsg *fmsg = NULL; + FILE *ofp; + fa_list *sbl = NULL, *ptl = NULL, *tmpl; + faddr *ta, *fta; + unsigned long svmsgid, svreply, acup_n = 0; + int sot_kludge = FALSE, eot_kludge = FALSE, qp_or_base64 = FALSE, tinyorigin = FALSE; + int needsplit, hdrsize, datasize, splitpart, forbidsplit, rfcheaders, html_message = FALSE; + time_t Now; - temp = calloc(4096, sizeof(char)); - Syslog('m', "Entering rfc2ftn"); - if (recipient) - Syslog('m', "Recipient: %s", ascfnode(recipient, 0xff)); - rewind(fp); -// Syslog('m', "========== RFC Start"); -// while ((fgets(temp, 4095, fp)) != NULL) { -// Syslogp('m', printable(temp, 0)); -// } -// Syslog('m', "========== RFC end"); -// rewind(fp); - msg = parsrfc(fp); - incode = outcode = CHRS_NOTSET; - pgpsigned = FALSE; + temp = calloc(4097, sizeof(char)); + Syslog('m', "Entering rfc2ftn"); + if (recipient) + Syslog('m', "Recipient: %s", ascfnode(recipient, 0xff)); + rewind(fp); +// Syslog('m', "========== RFC Start"); +// while ((fgets(temp, 4095, fp)) != NULL) { +// Syslogp('m', printable(temp, 0)); +// } +// Syslog('m', "========== RFC end"); +// rewind(fp); + msg = parsrfc(fp); + incode = outcode = CHRS_NOTSET; + pgpsigned = FALSE; - newsmode = hdr((char *)"Newsgroups", msg) ?TRUE:FALSE; - Syslog('m', "RFC message is %s", newsmode ? "news article":"e-mail message"); + newsmode = hdr((char *)"Newsgroups", msg) ?TRUE:FALSE; + Syslog('m', "RFC message is %s", newsmode ? "news article":"e-mail message"); - if (newsmode) - news_in++; - else - email_in++; + if (newsmode) + news_in++; + else + email_in++; - p = hdr((char *)"Content-Type",msg); - if (p) - incode = readcharset(p); - if (incode == CHRS_NOTSET) { - p = hdr((char *)"X-FTN-CHRS",msg); - if (p == NULL) - p = hdr((char *)"X-FTN-CHARSET", msg); - if (p == NULL) - p = hdr((char *)"X-FTN-CODEPAGE", msg); - if (p) - incode = readchrs(p); - } + p = hdr((char *)"Content-Type",msg); + if (p) + incode = readcharset(p); + if (incode == CHRS_NOTSET) { + p = hdr((char *)"X-FTN-CHRS",msg); + if (p == NULL) + p = hdr((char *)"X-FTN-CHARSET", msg); + if (p == NULL) + p = hdr((char *)"X-FTN-CODEPAGE", msg); + if (p) + incode = readchrs(p); + } - if ((p = hdr((char *)"Content-Type",msg)) && ((strcasestr(p,(char *)"multipart/signed")) || + if ((p = hdr((char *)"Content-Type",msg)) && ((strcasestr(p,(char *)"multipart/signed")) || (strcasestr(p,(char *)"application/pgp")))) { - pgpsigned = TRUE; - outcode = incode; - } else if ((p = hdr((char *)"X-FTN-ORIGCHRS", msg))) - outcode = readchrs(p); - else if (dirtyoutcode != CHRS_NOTSET) - outcode = dirtyoutcode; - else - outcode = getoutcode(incode); + pgpsigned = TRUE; + outcode = incode; + } else if ((p = hdr((char *)"X-FTN-ORIGCHRS", msg))) + outcode = readchrs(p); + else if (dirtyoutcode != CHRS_NOTSET) + outcode = dirtyoutcode; + else + outcode = getoutcode(incode); - if (!CFG.allowcontrol) { - if (hdr((char *)"Control",msg)) { - Syslog('+', "Control message skipped"); - tidyrfc(msg); - return 1; - } + if (!CFG.allowcontrol) { + if (hdr((char *)"Control",msg)) { + Syslog('+', "Control message skipped"); + tidyrfc(msg); + return 1; } + } - if ((fmsg = mkftnhdr(msg, incode, outcode, newsmode, recipient)) == NULL) { - WriteError("Unable to create FTN headers from RFC ones, aborting"); - tidyrfc(msg); - return 1; + if ((fmsg = mkftnhdr(msg, incode, outcode, newsmode, recipient)) == NULL) { + WriteError("Unable to create FTN headers from RFC ones, aborting"); + tidyrfc(msg); + return 1; + } + + if (newsmode) + fmsg->area = xstrcpy(msgs.Tag); + svmsgid = fmsg->msgid_n; + svreply = fmsg->reply_n; + if ((p = hdr((char *)"Message-ID",msg))) { + ftnmsgid(p, &fmsg->msgid_a, &fmsg->msgid_n, fmsg->area); + hash_update_s(&fmsg->msgid_n, fmsg->area); + } + + if ((p = hdr((char *)"References",msg))) { + p = strrchr(p,' '); + ftnmsgid(p,&fmsg->reply_a, &fmsg->reply_n,fmsg->area); + if (!chkftnmsgid(p)) { + hash_update_s(&fmsg->reply_n, fmsg->area); } + } else if ((p = hdr((char *)"In-Reply-To",msg))) { + ftnmsgid(p,&fmsg->reply_a, &fmsg->reply_n,fmsg->area); + if (!chkftnmsgid(p)) { + hash_update_s(&fmsg->reply_n, fmsg->area); + } + } + if (incode == CHRS_NOTSET && newsmode) + incode = msgs.Rfccode; + if (outcode == CHRS_NOTSET) { if (newsmode) - fmsg->area = xstrcpy(msgs.Tag); - svmsgid = fmsg->msgid_n; - svreply = fmsg->reply_n; - if ((p = hdr((char *)"Message-ID",msg))) { - ftnmsgid(p, &fmsg->msgid_a, &fmsg->msgid_n, fmsg->area); - hash_update_s(&fmsg->msgid_n, fmsg->area); - } + outcode = msgs.Ftncode; + else + outcode = CHRS_DEFAULT_FTN; + } + if ((incode == CHRS_NOTSET) && (hdr((char *)"Message-ID",msg))) { + if (chkftnmsgid(hdr((char *)"Message-ID",msg))) + incode = CHRS_DEFAULT_FTN; + else + incode = CHRS_DEFAULT_RFC; + } + removemime = FALSE; + removemsgid = FALSE; + removeref = FALSE; + removeinreply = FALSE; + removesupersedes = FALSE; + removeapproved = FALSE; + removereplyto = TRUE; + removereturnto = TRUE; + ftnorigin = fmsg->ftnorigin; + if ((hdr((char *)"X-PGP-Signed",msg))) + pgpsigned = TRUE; + if (pgpsigned) + Syslog('n', "pgpsigned = %s", pgpsigned ? "True":"False"); - if ((p = hdr((char *)"References",msg))) { - p = strrchr(p,' '); - ftnmsgid(p,&fmsg->reply_a, &fmsg->reply_n,fmsg->area); - if (!chkftnmsgid(p)) { - hash_update_s(&fmsg->reply_n, fmsg->area); - } - } else if ((p = hdr((char *)"In-Reply-To",msg))) { - ftnmsgid(p,&fmsg->reply_a, &fmsg->reply_n,fmsg->area); - if (!chkftnmsgid(p)) { - hash_update_s(&fmsg->reply_n, fmsg->area); - } - } + q = hdr((char *)"Content-Transfer-Encoding",msg); + if (q) + while (*q && isspace(*q)) + q++; + if (!(q)) + q = (char *)"8bit"; + if ((p = hdr((char *)"Content-Type",msg))) { + while (*p && isspace(*p)) + p++; - if (incode == CHRS_NOTSET && newsmode) - incode = msgs.Rfccode; - if (outcode == CHRS_NOTSET) { - if (newsmode) - outcode = msgs.Ftncode; - else - outcode = CHRS_DEFAULT_FTN; - } - if ((incode == CHRS_NOTSET) && (hdr((char *)"Message-ID",msg))) { - if (chkftnmsgid(hdr((char *)"Message-ID",msg))) - incode = CHRS_DEFAULT_FTN; - else - incode = CHRS_DEFAULT_RFC; - } - removemime = FALSE; - removemsgid = FALSE; - removeref = FALSE; - removeinreply = FALSE; - removesupersedes = FALSE; - removeapproved = FALSE; - removereplyto = TRUE; - removereturnto = TRUE; - ftnorigin = fmsg->ftnorigin; - if ((hdr((char *)"X-PGP-Signed",msg))) - pgpsigned = TRUE; - if (pgpsigned) - Syslog('n', "pgpsigned = %s", pgpsigned ? "True":"False"); + /* + * turn the quoted-printable decode mode on; remember FTN is virtually 8-bit clean + */ + if ((strncasecmp(p, "text/plain", 10) == 0) && (strncasecmp(q, "quoted-printable", 16) == 0)) + qp_or_base64 = 1; + /* + * turn the base64 decode mode on + */ + else if ((strncasecmp(p, "text/plain", 10) == 0) && (strncasecmp(q, "base64", 6) == 0)) + qp_or_base64 = 2; - q = hdr((char *)"Content-Transfer-Encoding",msg); - if (q) - while (*q && isspace(*q)) - q++; - if (!(q)) - q = (char *)"8bit"; - if ((p = hdr((char *)"Content-Type",msg))) { - while (*p && isspace(*p)) - p++; - - /* - * turn the quoted-printable decode mode on; remember FTN is virtually 8-bit clean - */ - if ((strncasecmp(p, "text/plain", 10) == 0) && (strncasecmp(q, "quoted-printable", 16) == 0)) - qp_or_base64 = 1; - /* - * turn the base64 decode mode on - */ - else if ((strncasecmp(p, "text/plain", 10) == 0) && (strncasecmp(q, "base64", 6) == 0)) - qp_or_base64 = 2; - - /* - * text/html support from FSC-HTML 001 proposal of Odinn Sorensen (2:236/77) - */ - if (strncasecmp(p, "text/html", 9) == 0) - html_message = TRUE; - for (tmp = msg; tmp; tmp = tmp->next) - if (((strcasecmp(tmp->key,"X-FTN-KLUDGE") == 0) && (strcasecmp(tmp->val,"FSCHTML") == 0)) || + /* + * text/html support from FSC-HTML 001 proposal of Odinn Sorensen (2:236/77) + */ + if (strncasecmp(p, "text/html", 9) == 0) + html_message = TRUE; + for (tmp = msg; tmp; tmp = tmp->next) + if (((strcasecmp(tmp->key,"X-FTN-KLUDGE") == 0) && (strcasecmp(tmp->val,"FSCHTML") == 0)) || (strcasecmp(tmp->key,"X-FTN-HTML") == 0)) - html_message = FALSE; + html_message = FALSE; - if ((readcharset(p) != CHRS_NOTSET ) && ((q == NULL) || (strncasecmp(q,"7bit",4) == 0) || + if ((readcharset(p) != CHRS_NOTSET ) && ((q == NULL) || (strncasecmp(q,"7bit",4) == 0) || ((!pgpsigned) && (qp_or_base64==1)) || ((!pgpsigned) && (qp_or_base64==2)) || (strncasecmp(q,"8bit",4) == 0))) - removemime=1; /* no need in MIME headers */ - /* - * some old MUA puts "text" instead of "text/plain; charset=..." - */ - else if ((strcasecmp(p,"text\n") == 0)) - removemime = TRUE; - } - if (removemime || qp_or_base64 || html_message) - Syslog('n', "removemime=%s, qp_or_base64 = %d, html_message=%s", removemime ? "True":"False", qp_or_base64, + removemime=1; /* no need in MIME headers */ + /* + * some old MUA puts "text" instead of "text/plain; charset=..." + */ + else if ((strcasecmp(p,"text\n") == 0)) + removemime = TRUE; + } + if (removemime || qp_or_base64 || html_message) + Syslog('n', "removemime=%s, qp_or_base64 = %d, html_message=%s", removemime ? "True":"False", qp_or_base64, html_message ? "True":"False"); - if ((p = hdr((char *)"Message-ID",msg))) { - if (!removemsgid) - removemsgid = chkftnmsgid(p); + if ((p = hdr((char *)"Message-ID",msg))) { + if (!removemsgid) + removemsgid = chkftnmsgid(p); + } + Syslog('n', "removemsgid = %s", removemsgid ? "True":"False"); + + if ((!removeref) && (p = hdr((char *)"References",msg))) { + p = xstrcpy(p); + q = strtok(p," \t\n"); + if ((q) && (strtok(NULL," \t\n") == NULL)) + removeref = chkftnmsgid(q); + free(p); + } + if (removeref) + Syslog('n', "removeref = %s", removeref ? "True":"False"); + + if ((p = hdr((char *)"Supersedes",msg))) + removesupersedes = chkftnmsgid(p); + if (removesupersedes) + Syslog('n', "removesupersedes = %s", removesupersedes ? "True":"False"); + + if ((p = hdr((char *)"Approved",msg))) { + while (*p && isspace(*p)) + p++; + if ((q = strchr(p,'\n'))) + *q='\0'; +// if (newsmode && strlen(msgs.Moderator) && (strcasestr(msgs.Moderator,p))) +// removeapproved = TRUE; + if (q) + *q='\n'; + } + if (removeapproved) + Syslog('n', "removeapproved = %s", removeapproved ? "True":"False"); + + if ((p = hdr((char *)"Reply-To",msg))) { + removereplyto = FALSE; + if ((q = hdr((char *)"From",msg))) { + char *r; + r = xstrcpy(p); + p = r; + while(*p && isspace(*p)) + p++; + if (p[strlen(p)-1] == '\n') + p[strlen(p)-1]='\0'; + if (strcasestr(q,p)) + removereplyto = TRUE; } - Syslog('n', "removemsgid = %s", removemsgid ? "True":"False"); + } + Syslog('n', "removereplyto = %s", removereplyto ? "True":"False"); - if ((!removeref) && (p = hdr((char *)"References",msg))) { - p = xstrcpy(p); - q = strtok(p," \t\n"); - if ((q) && (strtok(NULL," \t\n") == NULL)) - removeref = chkftnmsgid(q); - free(p); + if ((p = hdr((char *)"Return-Receipt-To",msg))) { + removereturnto = FALSE; + if ((q = hdr((char *)"From",msg))) { + char *r; + + r = xstrcpy(p); + p = r; + while (*p && isspace(*p)) + p++; + if (p[strlen(p)-1] == '\n') + p[strlen(p)-1]='\0'; + if (strcasestr(q,p)) + removereturnto = TRUE; } - if (removeref) - Syslog('n', "removeref = %s", removeref ? "True":"False"); + } + if (!removereturnto) + Syslog('n', "removereturnto = %s", removereturnto ? "True":"False"); - if ((p = hdr((char *)"Supersedes",msg))) - removesupersedes = chkftnmsgid(p); - if (removesupersedes) - Syslog('n', "removesupersedes = %s", removesupersedes ? "True":"False"); + p = ascfnode(fmsg->from,0x1f); + i = 79-11-3-strlen(p); + if (ftnorigin && fmsg->origin && (strlen(fmsg->origin) > i)) { + /* This is a kludge... I don't like it too much. But well, + if this is a message of FTN origin, the original origin (:) + line MUST have been short enough to fit in 79 chars... + So we give it a try. Probably it would be better to keep + the information about the address format from the origin + line in a special X-FTN-... header, but this seems even + less elegant. Any _good_ ideas, anyone? */ - if ((p = hdr((char *)"Approved",msg))) { - while (*p && isspace(*p)) - p++; - if ((q = strchr(p,'\n'))) - *q='\0'; -// if (newsmode && strlen(msgs.Moderator) && (strcasestr(msgs.Moderator,p))) -// removeapproved = TRUE; - if (q) - *q='\n'; - } - if (removeapproved) - Syslog('n', "removeapproved = %s", removeapproved ? "True":"False"); + /* OK, I am keeping this, though if should never be used + al long as X-FTN-Origin is used now */ - if ((p = hdr((char *)"Reply-To",msg))) { - removereplyto = FALSE; - if ((q = hdr((char *)"From",msg))) { - char *r; - r = xstrcpy(p); - p = r; - while(*p && isspace(*p)) - p++; - if (p[strlen(p)-1] == '\n') - p[strlen(p)-1]='\0'; - if (strcasestr(q,p)) - removereplyto = TRUE; -// free(r); - } - } - Syslog('n', "removereplyto = %s", removereplyto ? "True":"False"); - - if ((p = hdr((char *)"Return-Receipt-To",msg))) { - removereturnto = FALSE; - if ((q = hdr((char *)"From",msg))) { - char *r; - - r = xstrcpy(p); - p = r; - while (*p && isspace(*p)) - p++; - if (p[strlen(p)-1] == '\n') - p[strlen(p)-1]='\0'; - if (strcasestr(q,p)) - removereturnto = TRUE; -// free(r); - } - } - if (!removereturnto) - Syslog('n', "removereturnto = %s", removereturnto ? "True":"False"); - - p = ascfnode(fmsg->from,0x1f); + p = ascfnode(fmsg->from,0x0f); + Syslog('n', "checkorigin 3"); i = 79-11-3-strlen(p); - if (ftnorigin && fmsg->origin && (strlen(fmsg->origin) > i)) { - /* This is a kludge... I don't like it too much. But well, - if this is a message of FTN origin, the original origin (:) - line MUST have been short enough to fit in 79 chars... - So we give it a try. Probably it would be better to keep - the information about the address format from the origin - line in a special X-FTN-... header, but this seems even - less elegant. Any _good_ ideas, anyone? */ + tinyorigin = TRUE; + } + if (tinyorigin) + Syslog('n', "tinyorigin = %s", tinyorigin ? "True":"False"); - /* OK, I am keeping this, though if should never be used - al long as X-FTN-Origin is used now */ + if ((fmsg->origin) && (strlen(fmsg->origin) > i)) + fmsg->origin[i]='\0'; + forbidsplit = (ftnorigin || (hdr((char *)"X-FTN-Split",msg))); + needsplit = 0; + splitpart = 0; + hdrsize = 20; + hdrsize += (fmsg->subj)?strlen(fmsg->subj):0; + if (fmsg->from) + hdrsize += (fmsg->from->name)?strlen(fmsg->from->name):0; + if (fmsg->to) + hdrsize += (fmsg->to->name)?strlen(fmsg->to->name):0; + do { + Syslog('n', "split loop, splitpart = %d", splitpart); + datasize = 0; - p = ascfnode(fmsg->from,0x0f); - Syslog('n', "checkorigin 3"); - i = 79-11-3-strlen(p); - tinyorigin = TRUE; + if (splitpart) { + sprintf(newsubj,"[part %d] ",splitpart+1); + strncat(newsubj,fmsg->subj,MAXSUBJ-strlen(newsubj)); + } else { + strncpy(newsubj,fmsg->subj,MAXSUBJ); } - if (tinyorigin) - Syslog('n', "tinyorigin = %s", tinyorigin ? "True":"False"); + strcpy(newsubj, hdrnconv(newsubj, incode, outcode, MAXSUBJ)); + newsubj[MAXSUBJ]='\0'; - if ((fmsg->origin) && (strlen(fmsg->origin) > i)) - fmsg->origin[i]='\0'; - forbidsplit = (ftnorigin || (hdr((char *)"X-FTN-Split",msg))); - needsplit = 0; - splitpart = 0; - hdrsize = 20; - hdrsize += (fmsg->subj)?strlen(fmsg->subj):0; - if (fmsg->from) - hdrsize += (fmsg->from->name)?strlen(fmsg->from->name):0; - if (fmsg->to) - hdrsize += (fmsg->to->name)?strlen(fmsg->to->name):0; - do { - Syslog('n', "split loop, splitpart = %d", splitpart); - datasize = 0; + if (splitpart) { + hash_update_n(&fmsg->msgid_n,splitpart); + } + oldsubj = fmsg->subj; + fmsg->subj = newsubj; - if (splitpart) { - sprintf(newsubj,"[part %d] ",splitpart+1); - strncat(newsubj,fmsg->subj,MAXSUBJ-strlen(newsubj)); - } else { - strncpy(newsubj,fmsg->subj,MAXSUBJ); - } - strcpy(newsubj, hdrnconv(newsubj, incode, outcode, MAXSUBJ)); - newsubj[MAXSUBJ]='\0'; + /* + * Create a new temp message in FTN style format + */ + if ((ofp = tmpfile()) == NULL) { + WriteError("$Can't open second tmpfile"); + tidyrfc(msg); + return 1; + } - if (splitpart) { - hash_update_n(&fmsg->msgid_n,splitpart); - } - oldsubj = fmsg->subj; - fmsg->subj = newsubj; - - /* - * Create a new temp message in FTN style format - */ - if ((ofp = tmpfile()) == NULL) { - WriteError("$Can't open second tmpfile"); - tidyrfc(msg); - return 1; - } - -// Syslog('-', "1"); - - if (newsmode) { - -// Syslog('-', "1a"); - fprintf(ofp, "AREA:%s\n", msgs.Tag); -// Syslog('-', "1b"); - } else { - if (fmsg->to->point != 0) - fprintf(ofp, "\001TOPT %d\n", fmsg->to->point); - if (fmsg->from->point != 0) - fprintf(ofp, "\001FMPT %d\n", fmsg->from->point); - fprintf(ofp, "\001INTL %d:%d/%d %d:%d/%d\n", fmsg->to->zone, fmsg->to->net, fmsg->to->node, + if (newsmode) { + fprintf(ofp, "AREA:%s\n", msgs.Tag); + } else { + if (fmsg->to->point != 0) + fprintf(ofp, "\001TOPT %d\n", fmsg->to->point); + if (fmsg->from->point != 0) + fprintf(ofp, "\001FMPT %d\n", fmsg->from->point); + fprintf(ofp, "\001INTL %d:%d/%d %d:%d/%d\n", fmsg->to->zone, fmsg->to->net, fmsg->to->node, fmsg->from->zone, fmsg->from->net, fmsg->from->node); + } + fprintf(ofp, "\001MSGID: %s %08lx\n", MBSE_SS(fmsg->msgid_a),fmsg->msgid_n); + if (fmsg->reply_s) + fprintf(ofp, "\1REPLY: %s\n", fmsg->reply_s); + else if (fmsg->reply_a) + fprintf(ofp, "\1REPLY: %s %08lx\n", fmsg->reply_a, fmsg->reply_n); + Now = time(NULL) - (gmt_offset((time_t)0) * 60); + fprintf(ofp, "\001TZUTC: %s\n", gmtoffset(Now)); + fmsg->subj = oldsubj; + if ((p = hdr((char *)"X-FTN-REPLYADDR",msg))) { + hdrsize += 10+strlen(p); + fprintf(ofp,"\1REPLYADDR:"); + kludgewrite(p,ofp); + } else if (replyaddr) { + hdrsize += 10+strlen(replyaddr); + fprintf(ofp,"\1REPLYADDR: "); + kludgewrite(replyaddr,ofp); + } + if ((p = hdr((char *)"X-FTN-REPLYTO",msg))) { + hdrsize += 8+strlen(p); + fprintf(ofp,"\1REPLYTO:"); + kludgewrite(p,ofp); + } else if (replyaddr) { + hdrsize += 15; + if (newsmode) + fprintf(ofp,"\1REPLYTO: %s UUCP\n", aka2str(msgs.Aka)); + else { + fta = bestaka_s(fmsg->to); + fprintf(ofp,"\1REPLYTO: %s UUCP\n", ascfnode(fta, 0x1f)); + tidy_faddr(fta); + } + } else if ((p = hdr((char *)"Reply-To",msg))) { + if ((ta = parsefaddr(p))) { + if ((q = hdr((char *)"From",msg))) { + if (!strcasestr(q,p)) { + fprintf(ofp,"\1REPLYTO: %s %s\n", ascfnode(ta,0x1f), ta->name); + } } -// Syslog('-', "1c"); - fprintf(ofp, "\001MSGID: %s %08lx\n", MBSE_SS(fmsg->msgid_a),fmsg->msgid_n); - if (fmsg->reply_s) - fprintf(ofp, "\1REPLY: %s\n", fmsg->reply_s); - else if (fmsg->reply_a) - fprintf(ofp, "\1REPLY: %s %08lx\n", fmsg->reply_a, fmsg->reply_n); - Now = time(NULL) - (gmt_offset((time_t)0) * 60); - fprintf(ofp, "\001TZUTC: %s\n", gmtoffset(Now)); - fmsg->subj = oldsubj; - if ((p = hdr((char *)"X-FTN-REPLYADDR",msg))) { -// Syslog('n', "replyaddr 1 %s", p); - hdrsize += 10+strlen(p); - fprintf(ofp,"\1REPLYADDR:"); - kludgewrite(p,ofp); - } else if (replyaddr) { -// Syslog('n', "replyaddr 2"); - hdrsize += 10+strlen(replyaddr); - fprintf(ofp,"\1REPLYADDR: "); - kludgewrite(replyaddr,ofp); + tidy_faddr(ta); + } + } + if ((p=strip_flags(hdr((char *)"X-FTN-FLAGS",msg)))) { + hdrsize += 15; + fprintf(ofp,"\1FLAGS:%s\n",p); + free(p); + } + if (!hdr((char *)"X-FTN-PID", msg)) { + p = hdr((char *)"User-Agent", msg); + if (p == NULL) + p = hdr((char *)"X-Newsreader", msg); + if (p == NULL) + p = hdr((char *)"X-Mailer", msg); + if (p) { + hdrsize += 4 + strlen(p); + fprintf(ofp, "\1PID:"); + kludgewrite(p, ofp); + } else { + fprintf(ofp, "\001PID: MBSE-FIDO %s\n", VERSION); + } + } + + hdrsize += 8 + strlen(getchrs(outcode)); + fprintf(ofp, "\001CHRS: %s\n", getchrs(outcode)); + if (html_message) { + hdrsize += 9; + fprintf(ofp, "\1HTML: 5\n"); + } + + if (CFG.allowcontrol && (!hdr((char *)"X-FTN-ACUPDATE",msg)) && (p=hdr((char *)"Control",msg))) { + if (strstr(p,"cancel")) { + ftnmsgid(p,&acup_a,&acup_n,fmsg->area); + if (acup_a) { + hash_update_s(&acup_n,fmsg->area); + hdrsize += 26 + strlen(acup_a); + fprintf(ofp,"\1ACUPDATE: DELETE %s %08lx\n", acup_a,acup_n); } -// Syslog('-', "2"); - if ((p = hdr((char *)"X-FTN-REPLYTO",msg))) { - hdrsize += 8+strlen(p); - fprintf(ofp,"\1REPLYTO:"); - kludgewrite(p,ofp); - } else if (replyaddr) { - hdrsize += 15; - if (newsmode) - fprintf(ofp,"\1REPLYTO: %s UUCP\n", aka2str(msgs.Aka)); + } + } + if ((!hdr((char *)"X-FTN-ACUPDATE",msg)) && (p=hdr((char *)"Supersedes",msg))) { + ftnmsgid(p,&acup_a,&acup_n,fmsg->area); + if (acup_a) { + hash_update_s(&acup_n,fmsg->area); + hdrsize += 26 + strlen(acup_a); + fprintf(ofp,"\1ACUPDATE: MODIFY %s %08lx\n", acup_a,acup_n); + } + } + if (!(hdr((char *)"X-FTN-Tearline", msg)) && !(hdr((char *)"X-FTN-TID", msg))) { + sprintf(temp, " MBSE-FIDO %s", VERSION); + hdrsize += 4 + strlen(temp); + fprintf(ofp, "\1TID:"); + kludgewrite(temp, ofp); + } + if ((splitpart == 0) || (hdrsize < MAXHDRSIZE)) { + for (tmp = msg; tmp; tmp = tmp->next) { + if ((!strncmp(tmp->key,"X-Fsc-",6)) || (!strncmp(tmp->key,"X-FTN-",6) && + strcasecmp(tmp->key,"X-FTN-Tearline") && + strcasecmp(tmp->key,"X-FTN-Origin") && + strcasecmp(tmp->key,"X-FTN-Sender") && + strcasecmp(tmp->key,"X-FTN-Split") && + strcasecmp(tmp->key,"X-FTN-FLAGS") && + strcasecmp(tmp->key,"X-FTN-AREA") && + strcasecmp(tmp->key,"X-FTN-MSGID") && + strcasecmp(tmp->key,"X-FTN-REPLY") && + strcasecmp(tmp->key,"X-FTN-SEEN-BY") && + strcasecmp(tmp->key,"X-FTN-PATH") && + strcasecmp(tmp->key,"X-FTN-REPLYADDR") && + strcasecmp(tmp->key,"X-FTN-REPLYTO") && + strcasecmp(tmp->key,"X-FTN-To") && + strcasecmp(tmp->key,"X-FTN-From") && + strcasecmp(tmp->key,"X-FTN-CHARSET") && + strcasecmp(tmp->key,"X-FTN-CHRS") && + strcasecmp(tmp->key,"X-FTN-CODEPAGE") && + strcasecmp(tmp->key,"X-FTN-ORIGCHRS") && + strcasecmp(tmp->key,"X-FTN-SOT") && + strcasecmp(tmp->key,"X-FTN-EOT") && + strcasecmp(tmp->key,"X-FTN-Via"))) { + if ((strcasecmp(tmp->key,"X-FTN-KLUDGE") == 0)) { + if (!strcasecmp(tmp->val," SOT:\n")) + sot_kludge = TRUE; + else if (!strcasecmp(tmp->val," EOT:\n")) + eot_kludge = TRUE; else { - fta = bestaka_s(fmsg->to); - fprintf(ofp,"\1REPLYTO: %s UUCP\n", ascfnode(fta, 0x1f)); - tidy_faddr(fta); - } - } else if ((p = hdr((char *)"Reply-To",msg))) { - if ((ta = parsefaddr(p))) { - if ((q = hdr((char *)"From",msg))) { - if (!strcasestr(q,p)) { - fprintf(ofp,"\1REPLYTO: %s %s\n", ascfnode(ta,0x1f), ta->name); - } - tidy_faddr(ta); - } + hdrsize += strlen(tmp->val); + fprintf(ofp,"\1"); + /* we should have restored the original string here... */ + kludgewrite((tmp->val)+1,ofp); } + } else { + hdrsize += strlen(tmp->key)+strlen(tmp->val); + fprintf(ofp,"\1%s:",tmp->key+6); + kludgewrite(tmp->val,ofp); + } } - if ((p=strip_flags(hdr((char *)"X-FTN-FLAGS",msg)))) { - hdrsize += 15; - fprintf(ofp,"\1FLAGS:%s\n",p); - free(p); - } - if (!hdr((char *)"X-FTN-PID", msg)) { - p = hdr((char *)"User-Agent", msg); - if (p == NULL) - p = hdr((char *)"X-Newsreader", msg); - if (p == NULL) - p = hdr((char *)"X-Mailer", msg); - if (p) { - hdrsize += 4 + strlen(p); - fprintf(ofp, "\1PID:"); - kludgewrite(p, ofp); - } else { - fprintf(ofp, "\001PID: MBSE-FIDO %s\n", VERSION); - } - } -// Syslog('-', "3"); - hdrsize += 8 + strlen(getchrs(outcode)); - fprintf(ofp, "\001CHRS: %s\n", getchrs(outcode)); - if (html_message) { - hdrsize += 9; - fprintf(ofp, "\1HTML: 5\n"); + } + /* ZConnect are X-ZC-*: in usenet, \1ZC-*: in FTN */ + for (tmp=msg;tmp;tmp=tmp->next) + if ((!strncmp(tmp->key,"X-ZC-",5))) { + hdrsize += strlen(tmp->key)+strlen(tmp->val); + fprintf(ofp,"\1%s:",tmp->key+2); + kludgewrite(tmp->val,ofp); } - if (CFG.allowcontrol && (!hdr((char *)"X-FTN-ACUPDATE",msg)) && (p=hdr((char *)"Control",msg))) { - if (strstr(p,"cancel")) { - ftnmsgid(p,&acup_a,&acup_n,fmsg->area); - if (acup_a) { - hash_update_s(&acup_n,fmsg->area); - hdrsize += 26 + strlen(acup_a); - fprintf(ofp,"\1ACUPDATE: DELETE %s %08lx\n", acup_a,acup_n); - } - } - } - if ((!hdr((char *)"X-FTN-ACUPDATE",msg)) && (p=hdr((char *)"Supersedes",msg))) { - ftnmsgid(p,&acup_a,&acup_n,fmsg->area); - if (acup_a) { - hash_update_s(&acup_n,fmsg->area); - hdrsize += 26 + strlen(acup_a); - fprintf(ofp,"\1ACUPDATE: MODIFY %s %08lx\n", acup_a,acup_n); - } - } - if (!(hdr((char *)"X-FTN-Tearline", msg)) && !(hdr((char *)"X-FTN-TID", msg))) { - sprintf(temp, " MBSE-FIDO %s", VERSION); - hdrsize += 4 + strlen(temp); - fprintf(ofp, "\1TID:"); - kludgewrite(temp, ofp); - } - if ((splitpart == 0) || (hdrsize < MAXHDRSIZE)) { - for (tmp = msg; tmp; tmp = tmp->next) { - if ((!strncmp(tmp->key,"X-Fsc-",6)) || - (!strncmp(tmp->key,"X-FTN-",6) && - strcasecmp(tmp->key,"X-FTN-Tearline") && - strcasecmp(tmp->key,"X-FTN-Origin") && - strcasecmp(tmp->key,"X-FTN-Sender") && - strcasecmp(tmp->key,"X-FTN-Split") && - strcasecmp(tmp->key,"X-FTN-FLAGS") && - strcasecmp(tmp->key,"X-FTN-AREA") && - strcasecmp(tmp->key,"X-FTN-MSGID") && - strcasecmp(tmp->key,"X-FTN-REPLY") && - strcasecmp(tmp->key,"X-FTN-SEEN-BY") && - strcasecmp(tmp->key,"X-FTN-PATH") && - strcasecmp(tmp->key,"X-FTN-REPLYADDR") && - strcasecmp(tmp->key,"X-FTN-REPLYTO") && - strcasecmp(tmp->key,"X-FTN-To") && - strcasecmp(tmp->key,"X-FTN-From") && - strcasecmp(tmp->key,"X-FTN-CHARSET") && - strcasecmp(tmp->key,"X-FTN-CHRS") && - strcasecmp(tmp->key,"X-FTN-CODEPAGE") && - strcasecmp(tmp->key,"X-FTN-ORIGCHRS") && - strcasecmp(tmp->key,"X-FTN-SOT") && - strcasecmp(tmp->key,"X-FTN-EOT") && - strcasecmp(tmp->key,"X-FTN-Via"))) { - if ((strcasecmp(tmp->key,"X-FTN-KLUDGE") == 0)) { - if (!strcasecmp(tmp->val," SOT:\n")) - sot_kludge = TRUE; - else if (!strcasecmp(tmp->val," EOT:\n")) - eot_kludge = TRUE; - else { - hdrsize += strlen(tmp->val); - fprintf(ofp,"\1"); - /* we should have restored the original string here... */ - kludgewrite((tmp->val)+1,ofp); - } - } else { - hdrsize += strlen(tmp->key)+strlen(tmp->val); - fprintf(ofp,"\1%s:",tmp->key+6); - kludgewrite(tmp->val,ofp); - } - } - } - /* ZConnect are X-ZC-*: in usenet, \1ZC-*: in FTN */ - for (tmp=msg;tmp;tmp=tmp->next) - if ((!strncmp(tmp->key,"X-ZC-",5))) { - hdrsize += strlen(tmp->key)+strlen(tmp->val); - fprintf(ofp,"\1%s:",tmp->key+2); - kludgewrite(tmp->val,ofp); - } - - /* mondo.org gateway uses ".MSGID: ..." in usenet */ - for (tmp=msg;tmp;tmp=tmp->next) - if ((!strncmp(tmp->key,".",1)) && (strcasecmp(tmp->key,".MSGID"))) { - hdrsize += strlen(tmp->key)+strlen(tmp->val); - fprintf(ofp,"\1%s:",tmp->key+1); - kludgewrite(tmp->val,ofp); - } - -// Syslog('-', "4"); - /* - * Add the Received: header from this system to the mesage. - */ - if (!newsmode) { - Now = time(NULL); - fprintf(ofp, "\1RFC-Received: by %s (mbfido) via RFC2FTN; %s\n", CFG.sysdomain, rfcdate(Now)); - hdrsize += 72+strlen(CFG.sysdomain); - } - - for (tmp = msg; tmp; tmp = tmp->next) { - if ((needputrfc(tmp) == 1)) { - if (strcasestr((char *)"X-Origin-Newsgroups",tmp->key)) { - hdrsize += 10+strlen(tmp->val); - fprintf(ofp,"\1RFC-Newsgroups:"); - } else { - hdrsize += strlen(tmp->key)+strlen(tmp->val); - fprintf(ofp,"\1RFC-%s:",tmp->key); - } - kludgewrite(hdrconv(tmp->val, incode, outcode),ofp); - } - } -// Syslog('-', "5"); - rfcheaders=0; - for (tmp=msg;tmp;tmp=tmp->next) { - if ((needputrfc(tmp) > 1)) { - rfcheaders++; - if (strcasestr((char *)"X-Origin-Newsgroups",tmp->key)) { - hdrsize += 10+strlen(tmp->val); - fprintf(ofp,"Newsgroups:"); - } else { - hdrsize += strlen(tmp->key)+strlen(tmp->val); - fprintf(ofp,"%s:",tmp->key); - } - charwrite(hdrconv(tmp->val, incode, outcode),ofp); - } - } - if (rfcheaders) - charwrite((char *)"\n",ofp); - if ((hdr((char *)"X-FTN-SOT",msg)) || (sot_kludge)) - fprintf(ofp,"\1SOT:\n"); - if ((splitpart == 0) && (hdr((char *)"X-PGP-Signed",msg))) - fprintf(ofp,PGP_SIGNED_BEGIN"\n"); - } - if (replyaddr) { -// free(replyaddr); /* Gives SIGSEGV */ - replyaddr = NULL; + /* mondo.org gateway uses ".MSGID: ..." in usenet */ + for (tmp=msg;tmp;tmp=tmp->next) + if ((!strncmp(tmp->key,".",1)) && (strcasecmp(tmp->key,".MSGID"))) { + hdrsize += strlen(tmp->key)+strlen(tmp->val); + fprintf(ofp,"\1%s:",tmp->key+1); + kludgewrite(tmp->val,ofp); } -// Syslog('-', "6"); - if (needsplit) { - fprintf(ofp," * Continuation %d of a split message *\n\n", splitpart); - needsplit = FALSE; - } else if ((p=hdr((char *)"X-Body-Start",msg))) { - datasize += strlen(p); - if (qp_or_base64==1) - charwrite(strkconv(qp_decode(p), incode, outcode), ofp); - else if (qp_or_base64==2) - charwrite(strkconv(b64_decode(p), incode, outcode), ofp); - else - charwrite(strkconv(p, incode, outcode), ofp); + /* + * Add the Received: header from this system to the mesage. + */ + if (!newsmode) { + Now = time(NULL); + fprintf(ofp, "\1RFC-Received: by %s (mbfido) via RFC2FTN; %s\n", CFG.sysdomain, rfcdate(Now)); + hdrsize += 72+strlen(CFG.sysdomain); + } + + for (tmp = msg; tmp; tmp = tmp->next) { + if ((needputrfc(tmp) == 1)) { + if (strcasestr((char *)"X-Origin-Newsgroups",tmp->key)) { + hdrsize += 10+strlen(tmp->val); + fprintf(ofp,"\1RFC-Newsgroups:"); + } else { + hdrsize += strlen(tmp->key)+strlen(tmp->val); + fprintf(ofp,"\1RFC-%s:",tmp->key); + } + kludgewrite(hdrconv(tmp->val, incode, outcode),ofp); } - while (!(needsplit=(!forbidsplit) && (((splitpart && (datasize > (CFG.new_split * 1024))) || + } + + rfcheaders=0; + for (tmp=msg;tmp;tmp=tmp->next) { + if ((needputrfc(tmp) > 1)) { + rfcheaders++; + if (strcasestr((char *)"X-Origin-Newsgroups",tmp->key)) { + hdrsize += 10+strlen(tmp->val); + fprintf(ofp,"Newsgroups:"); + } else { + hdrsize += strlen(tmp->key)+strlen(tmp->val); + fprintf(ofp,"%s:",tmp->key); + } + charwrite(hdrconv(tmp->val, incode, outcode),ofp); + } + } + if (rfcheaders) + charwrite((char *)"\n",ofp); + if ((hdr((char *)"X-FTN-SOT",msg)) || (sot_kludge)) + fprintf(ofp,"\1SOT:\n"); + if ((splitpart == 0) && (hdr((char *)"X-PGP-Signed",msg))) + fprintf(ofp,PGP_SIGNED_BEGIN"\n"); + } + if (replyaddr) { + replyaddr = NULL; + } + + if (needsplit) { + fprintf(ofp," * Continuation %d of a split message *\n\n", splitpart); + needsplit = FALSE; + } else if ((p=hdr((char *)"X-Body-Start",msg))) { + datasize += strlen(p); + if (qp_or_base64==1) + charwrite(strkconv(qp_decode(p), incode, outcode), ofp); + else if (qp_or_base64==2) + charwrite(strkconv(b64_decode(p), incode, outcode), ofp); + else + charwrite(strkconv(p, incode, outcode), ofp); + } + while (!(needsplit=(!forbidsplit) && (((splitpart && (datasize > (CFG.new_split * 1024))) || (!splitpart && ((datasize+hdrsize) > (CFG.new_split * 1024)))))) && (bgets(temp,4096-1,fp))) { - datasize += strlen(temp); - if (qp_or_base64==1) - charwrite(strkconv(qp_decode(temp), incode, outcode), ofp); - else if (qp_or_base64==2) - charwrite(strkconv(b64_decode(temp), incode, outcode), ofp); - else - charwrite(strkconv(temp, incode, outcode), ofp); - } - if (needsplit) { - fprintf(ofp,"\n * Message split, to be continued *\n"); - splitpart++; - } else if ((p=hdr((char *)"X-PGP-Signed",msg))) { - fprintf(ofp,PGP_SIG_BEGIN"\n"); - if ((q=hdr((char *)"X-PGP-Version",msg))) { - fprintf(ofp,"Version:"); - charwrite(q,ofp); - } - if ((q=hdr((char *)"X-PGP-Charset",msg))) { - fprintf(ofp,"Charset:"); - charwrite(q,ofp); - } - if ((q=hdr((char *)"X-PGP-Comment",msg))) { - fprintf(ofp,"Comment:"); - charwrite(q,ofp); - } - fprintf(ofp,"\n"); - p=xstrcpy(p); - q=strtok(p," \t\n"); - fprintf(ofp,"%s\n",q); - while ((q=(strtok(NULL," \t\n")))) - fprintf(ofp,"%s\n",q); - fprintf(ofp,PGP_SIG_END"\n"); - } - if ((p=hdr((char *)"X-FTN-EOT",msg)) || (eot_kludge)) - fprintf(ofp,"\1EOT:\n"); + datasize += strlen(temp); + if (qp_or_base64==1) + charwrite(strkconv(qp_decode(temp), incode, outcode), ofp); + else if (qp_or_base64==2) + charwrite(strkconv(b64_decode(temp), incode, outcode), ofp); + else + charwrite(strkconv(temp, incode, outcode), ofp); + } + if (needsplit) { + fprintf(ofp,"\n * Message split, to be continued *\n"); + splitpart++; + } else if ((p=hdr((char *)"X-PGP-Signed",msg))) { + fprintf(ofp,PGP_SIG_BEGIN"\n"); + if ((q=hdr((char *)"X-PGP-Version",msg))) { + fprintf(ofp,"Version:"); + charwrite(q,ofp); + } + if ((q=hdr((char *)"X-PGP-Charset",msg))) { + fprintf(ofp,"Charset:"); + charwrite(q,ofp); + } + if ((q=hdr((char *)"X-PGP-Comment",msg))) { + fprintf(ofp,"Comment:"); + charwrite(q,ofp); + } + fprintf(ofp,"\n"); + p=xstrcpy(p); + q=strtok(p," \t\n"); + fprintf(ofp,"%s\n",q); + while ((q=(strtok(NULL," \t\n")))) + fprintf(ofp,"%s\n",q); + fprintf(ofp,PGP_SIG_END"\n"); + } + if ((p=hdr((char *)"X-FTN-EOT",msg)) || (eot_kludge)) + fprintf(ofp,"\1EOT:\n"); - if ((p=hdr((char *)"X-FTN-Tearline",msg))) { - fprintf(ofp,"---"); - if (strcasecmp(p," (none)\n") == 0) - charwrite((char *)"\n",ofp); - else - charwrite(p,ofp); - } else - fprintf(ofp,"%s\n", TearLine()); + if ((p=hdr((char *)"X-FTN-Tearline",msg))) { + fprintf(ofp,"---"); + if (strcasecmp(p," (none)\n") == 0) + charwrite((char *)"\n",ofp); + else + charwrite(p,ofp); + } else + fprintf(ofp,"%s\n", TearLine()); - if ((p = hdr((char *)"X-FTN-Origin",msg))) { - if (*(q=p+strlen(p)-1) == '\n') - *q='\0'; - origin = xstrcpy((char *)" * Origin: "); - origin = xstrcat(origin, hdrconv(p, incode, outcode)); - } else { - origin = xstrcpy((char *)" * Origin: "); - if (fmsg->origin) - origin = xstrcat(origin, hdrconv(fmsg->origin, incode, outcode)); - else - origin = xstrcat(origin, CFG.origin); - origin = xstrcat(origin, (char *)" ("); - origin = xstrcat(origin, ascfnode(fmsg->from,tinyorigin?0x0f:0x1f)); - origin = xstrcat(origin, (char *)")"); - } - fprintf(ofp, "%s", origin); + if ((p = hdr((char *)"X-FTN-Origin",msg))) { + if (*(q=p+strlen(p)-1) == '\n') + *q='\0'; + origin = xstrcpy((char *)" * Origin: "); + origin = xstrcat(origin, hdrconv(p, incode, outcode)); + } else { + origin = xstrcpy((char *)" * Origin: "); + if (fmsg->origin) + origin = xstrcat(origin, hdrconv(fmsg->origin, incode, outcode)); + else + origin = xstrcat(origin, CFG.origin); + origin = xstrcat(origin, (char *)" ("); + origin = xstrcat(origin, ascfnode(fmsg->from,tinyorigin?0x0f:0x1f)); + origin = xstrcat(origin, (char *)")"); + } + fprintf(ofp, "%s", origin); - if (newsmode) { - /* - * Setup SEEN-BY lines, first SEEN-BY from RFC message, then all matching AKA's - */ - for (tmsg = msg; tmsg; tmsg = tmsg->next) - if (strcasecmp(tmsg->key, "X-FTN-SEEN-BY") == 0) - fill_list(&sbl, tmsg->val, NULL); - for (i = 0; i < 40; i++) { - if (CFG.akavalid[i] && (CFG.aka[i].point == 0) && (msgs.Aka.zone == CFG.aka[i].zone) && + if (newsmode) { + /* + * Setup SEEN-BY lines, first SEEN-BY from RFC message, then all matching AKA's + */ + for (tmsg = msg; tmsg; tmsg = tmsg->next) + if (strcasecmp(tmsg->key, "X-FTN-SEEN-BY") == 0) + fill_list(&sbl, tmsg->val, NULL); + for (i = 0; i < 40; i++) { + if (CFG.akavalid[i] && (CFG.aka[i].point == 0) && (msgs.Aka.zone == CFG.aka[i].zone) && !((msgs.Aka.net == CFG.aka[i].net) && (msgs.Aka.node == CFG.aka[i].node))) { - sprintf(sbe, "%u/%u", CFG.aka[i].net, CFG.aka[i].node); - fill_list(&sbl, sbe, NULL); - } - } - if (msgs.Aka.point == 0) { - sprintf(sbe, "%u/%u", msgs.Aka.net, msgs.Aka.node); - fill_list(&sbl, sbe, NULL); - } - - /* - * Only add SEEN-BY lines if there are any - */ - if (sbl != NULL) { - uniq_list(&sbl); - sort_list(&sbl); - seenlen = MAXSEEN + 1; - memset(&sbe, 0, sizeof(sbe)); - /* ensure it will not match for the first entry */ - oldnet = sbl->addr->net-1; - for (tmpl = sbl; tmpl; tmpl = tmpl->next) { - if (tmpl->addr->net == oldnet) - sprintf(sbe," %u",tmpl->addr->node); - else - sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node); - oldnet = tmpl->addr->net; - seenlen += strlen(sbe); - if (seenlen > MAXSEEN) { - seenlen = 0; - fprintf(ofp,"\nSEEN-BY:"); - sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node); - seenlen = strlen(sbe); - } - fprintf(ofp,"%s",sbe); - } - tidy_falist(&sbl); - } - - /* - * Setup PATH lines - */ - for (tmp = msg; tmp; tmp = tmp->next) - if (!strcasecmp(tmp->key,"X-FTN-PATH")) - fill_path(&ptl,tmp->val); - if (msgs.Aka.point == 0) { - sprintf(sbe,"%u/%u",msgs.Aka.net, msgs.Aka.node); - fill_path(&ptl,sbe); - } - - /* - * Only add PATH line if there is something - */ - if (ptl != NULL) { - uniq_list(&ptl); - seenlen = MAXPATH+1; - /* ensure it will not match for the first entry */ - oldnet = ptl->addr->net-1; - for (tmpl = ptl; tmpl; tmpl = tmpl->next) { - if (tmpl->addr->net == oldnet) - sprintf(sbe," %u",tmpl->addr->node); - else - sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node); - oldnet = tmpl->addr->net; - seenlen += strlen(sbe); - if (seenlen > MAXPATH) { - seenlen = 0; - fprintf(ofp,"\n\1PATH:"); - sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node); - seenlen = strlen(sbe); - } - fprintf(ofp,"%s",sbe); - } - tidy_falist(&ptl); - } - } /* if (newsmode) */ - - /* - * Add newline and message is ready. - */ - fprintf(ofp,"\n"); - fflush(ofp); - rewind(ofp); - - Syslog('n', "========== Fido start"); - while (fgets(temp, 4096, ofp) != NULL) { - /* - * Only log kludges, skip the body - */ - if ((temp[0] == '\001') || !strncmp(temp, "AREA:", 5) || !strncmp(temp, "SEEN-BY", 7)) { - Striplf(temp); - Syslogp('n', printable(temp, 0)); - } + sprintf(sbe, "%u/%u", CFG.aka[i].net, CFG.aka[i].node); + fill_list(&sbl, sbe, NULL); } - Syslog('n', "========== Fido end"); + } + if (msgs.Aka.point == 0) { + sprintf(sbe, "%u/%u", msgs.Aka.net, msgs.Aka.node); + fill_list(&sbl, sbe, NULL); + } - if (newsmode) - rc = postecho(NULL, fmsg->from, fmsg->to, origin, fmsg->subj, fmsg->date, fmsg->flags, 0, ofp, FALSE); - else - rc = postnetmail(ofp, fmsg->from, fmsg->to, origin, fmsg->subj, fmsg->date, fmsg->flags, FALSE); + /* + * Only add SEEN-BY lines if there are any + */ + if (sbl != NULL) { + uniq_list(&sbl); + sort_list(&sbl); + seenlen = MAXSEEN + 1; + memset(&sbe, 0, sizeof(sbe)); + /* ensure it will not match for the first entry */ + oldnet = sbl->addr->net-1; + for (tmpl = sbl; tmpl; tmpl = tmpl->next) { + if (tmpl->addr->net == oldnet) + sprintf(sbe," %u",tmpl->addr->node); + else + sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node); + oldnet = tmpl->addr->net; + seenlen += strlen(sbe); + if (seenlen > MAXSEEN) { + seenlen = 0; + fprintf(ofp,"\nSEEN-BY:"); + sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node); + seenlen = strlen(sbe); + } + fprintf(ofp,"%s",sbe); + } + tidy_falist(&sbl); + } - free(origin); - fclose(ofp); - } while (needsplit); - free(temp); - tidyrfc(msg); - tidy_ftnmsg(fmsg); - UpdateMsgs(); + /* + * Setup PATH lines + */ + for (tmp = msg; tmp; tmp = tmp->next) + if (!strcasecmp(tmp->key,"X-FTN-PATH")) + fill_path(&ptl,tmp->val); + if (msgs.Aka.point == 0) { + sprintf(sbe,"%u/%u",msgs.Aka.net, msgs.Aka.node); + fill_path(&ptl,sbe); + } - return 0; + /* + * Only add PATH line if there is something + */ + if (ptl != NULL) { + uniq_list(&ptl); + seenlen = MAXPATH+1; + /* ensure it will not match for the first entry */ + oldnet = ptl->addr->net-1; + for (tmpl = ptl; tmpl; tmpl = tmpl->next) { + if (tmpl->addr->net == oldnet) + sprintf(sbe," %u",tmpl->addr->node); + else + sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node); + oldnet = tmpl->addr->net; + seenlen += strlen(sbe); + if (seenlen > MAXPATH) { + seenlen = 0; + fprintf(ofp,"\n\1PATH:"); + sprintf(sbe," %u/%u",tmpl->addr->net, tmpl->addr->node); + seenlen = strlen(sbe); + } + fprintf(ofp,"%s",sbe); + } + tidy_falist(&ptl); + } + } /* if (newsmode) */ + + /* + * Add newline and message is ready. + */ + fprintf(ofp,"\n"); + fflush(ofp); + rewind(ofp); + + Syslog('n', "========== Fido start"); + while (fgets(temp, 4096, ofp) != NULL) { + /* + * Only log kludges, skip the body + */ + if ((temp[0] == '\001') || !strncmp(temp, "AREA:", 5) || !strncmp(temp, "SEEN-BY", 7)) { + Striplf(temp); + Syslogp('n', printable(temp, 0)); + } + } + Syslog('n', "========== Fido end"); + + if (newsmode) + rc = postecho(NULL, fmsg->from, fmsg->to, origin, fmsg->subj, fmsg->date, fmsg->flags, 0, ofp, FALSE); + else + rc = postnetmail(ofp, fmsg->from, fmsg->to, origin, fmsg->subj, fmsg->date, + fmsg->flags, FALSE, fmsg->from->zone, fmsg->to->zone); + + free(origin); + fclose(ofp); + } while (needsplit); + free(temp); + tidyrfc(msg); + tidy_ftnmsg(fmsg); + UpdateMsgs(); + + return 0; } diff --git a/mbfido/tosspkt.c b/mbfido/tosspkt.c index 274d17fe..bf5ad249 100644 --- a/mbfido/tosspkt.c +++ b/mbfido/tosspkt.c @@ -92,7 +92,7 @@ static int at_zero = 0; * Internal prototypes */ char *aread(char *, int, FILE *); -int importmsg(faddr *, faddr *, faddr *, char *, char *, time_t, int, int, FILE *); +int importmsg(faddr *, faddr *, faddr *, char *, char *, time_t, int, int, FILE *, unsigned int); @@ -149,7 +149,8 @@ char *aread(char *s, int count, FILE *fp) * 5 - Locking error. * */ -int importmsg(faddr *p_from, faddr *f, faddr *t, char *orig, char *subj, time_t mdate, int flags, int cost, FILE *fp) +int importmsg(faddr *p_from, faddr *f, faddr *t, char *orig, char *subj, time_t mdate, + int flags, int cost, FILE *fp, unsigned int tzone) { char *buf, *marea = NULL; int echomail = FALSE, rc = 0, bad = FALSE, Known = FALSE, FirstLine; @@ -234,11 +235,12 @@ int importmsg(faddr *p_from, faddr *f, faddr *t, char *orig, char *subj, time_t FirstLine = FALSE; } /* end of checking kludges */ - - if (echomail) + if (echomail) { + f->zone = p_from->zone; + t->zone = tzone; rc = postecho(p_from, f, t, orig, subj, mdate, flags, cost, fp, TRUE); - else - rc = postnetmail(fp, f, t, orig, subj, mdate, flags, TRUE); + } else + rc = postnetmail(fp, f, t, orig, subj, mdate, flags, TRUE, p_from->zone, tzone); free(buf); return rc; @@ -418,9 +420,6 @@ int getmessage(FILE *pkt, faddr *p_from, faddr *p_to) return 3; } - f.zone = p_from->zone; - t.zone = p_to->zone; - if ((fp = tmpfile()) == NULL) { WriteError("$unable to open temporary file"); return 4; @@ -463,7 +462,7 @@ int getmessage(FILE *pkt, faddr *p_from, faddr *p_to) } } - rc = importmsg(p_from, &f,&t,orig,subj,mdate,flags,cost,fp); + rc = importmsg(p_from, &f, &t, orig, subj, mdate, flags, cost, fp, p_to->zone); if (rc) rc+=10; if (rc > maxrc)