Initial *.msg support works

This commit is contained in:
Michiel Broek 2004-07-24 15:32:30 +00:00
parent 1b7d41a802
commit 14e6739d68
5 changed files with 301 additions and 10 deletions

View File

@ -36,6 +36,7 @@ v0.61.2 11-Jul-2004
removed. With nodes that were marked crash, this will prevent removed. With nodes that were marked crash, this will prevent
continuous calling. continuous calling.
Changed to use direct instead of immediate mail. Changed to use direct instead of immediate mail.
Changed binkp IsDoing info.
mbfido: mbfido:
Added code to un_attach files during tic import that are Added code to un_attach files during tic import that are
@ -48,6 +49,11 @@ v0.61.2 11-Jul-2004
seems solved. seems solved.
In rfc2ftn added check for ".\n" to change to " .\n" instead of In rfc2ftn added check for ".\n" to change to " .\n" instead of
only check for ".\r\n". only check for ".\r\n".
Added support for *.msg files. If any are found, they are
processed and put in a netmail area. From there the mbfido scan
function is automatic called so that the message is sent out or
stays in the area if it has a local destination. File attaches
are supported.
mbout: mbout:
Changed to use direct instead of immediate mail. Changed to use direct instead of immediate mail.

View File

@ -201,5 +201,5 @@ msgflags.o: ../config.h ../lib/mbselib.h msgflags.h
dirsession.o: ../config.h ../lib/mbselib.h dirsession.h dirsession.o: ../config.h ../lib/mbselib.h dirsession.h
queue.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h fsort.h dirsession.h queue.h queue.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h fsort.h dirsession.h queue.h
dirlock.o: ../config.h ../lib/mbselib.h flock.h dirlock.h dirlock.o: ../config.h ../lib/mbselib.h flock.h dirlock.h
msg.o: ../config.h ../lib/mbselib.h msg.h msg.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h ../lib/msgtext.h ../lib/msg.h msgflags.h msg.h
# End of generated dependencies # End of generated dependencies

View File

@ -521,6 +521,8 @@ int main(int argc, char **argv)
if (Notify(Options)) { if (Notify(Options)) {
do_flush = TRUE; do_flush = TRUE;
} }
if (do_tic || do_toss)
toss_msgs();
if (do_tic) { if (do_tic) {
if (IsSema((char *)"mailin")) if (IsSema((char *)"mailin"))
RemoveSema((char *)"mailin"); RemoveSema((char *)"mailin");

View File

@ -30,10 +30,19 @@
#include "../config.h" #include "../config.h"
#include "../lib/mbselib.h" #include "../lib/mbselib.h"
#include "../lib/users.h"
#include "../lib/mbsedb.h"
#include "../lib/msgtext.h"
#include "../lib/msg.h"
#include "msgflags.h"
#include "msg.h" #include "msg.h"
extern int net_msgs; extern int net_msgs;
extern int do_scan;
int toss_onemsg(char *);
int toss_msgs(void) int toss_msgs(void)
@ -58,8 +67,8 @@ int toss_msgs(void)
} }
Syslog('m', "Process %s", de->d_name); Syslog('m', "Process %s", de->d_name);
toss_onemsg(de->d_name);
files++; files++;
} }
} }
closedir(dp); closedir(dp);
@ -73,3 +82,276 @@ int toss_msgs(void)
} }
/*
* Toss one message and post into a JAM messagebase. Returns:
* 0 = Ok
* 1 = Can't open *.msg
* 2 = Can't read message
* 3 = Missing zone info
* 4 = No ftn network or netmailboard in setup
* 5 = Can't open JAM area
*/
int toss_onemsg(char *msgname)
{
int rc = 0;
char *temp, *dospath, *flagstr = NULL, *l, *r, *msgid = NULL;
char fromUserName[36], toUserName[36], subject[72], DateTime[20];
FILE *fp, *np;
faddr *ta;
unsigned char buf[0xbd];
unsigned short destNode = 0, destNet = 0, destZone = 0, destPoint = 0;
unsigned short origNode = 0, origNet = 0, origZone = 0, origPoint = 0;
unsigned short Attribute = 0;
struct stat sb;
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/%s", CFG.msgs_path, msgname);
if ((fp = fopen(temp, "r")) == NULL) {
WriteError("$Can't open %s", temp);
free(temp);
return 1;
}
/*
* First read message header information we need.
*/
memset(&fromUserName, 0, sizeof(fromUserName));
memset(&toUserName, 0, sizeof(toUserName));
memset(&subject, 0, sizeof(subject));
memset(&DateTime, 0, sizeof(DateTime));
if (fread(&buf, 1, 0xbe, fp) != 0xbe) {
WriteError("$Could not read header (%s)", temp);
fclose(fp);
free(temp);
return 2;
}
strncpy(fromUserName, buf, 36);
strncpy(toUserName, buf+0x24, 36);
strncpy(subject, buf+0x48, 72);
strncpy(DateTime, buf+0x90, 20);
Syslog('m', "\"%s\"", printable(fromUserName, 0));
Syslog('m', "\"%s\"", printable(toUserName, 0));
Syslog('m', "\"%s\"", printable(subject, 0));
Syslog('m', "\"%s\"", printable(DateTime, 0));
destNode = (buf[0xa7] << 8) + buf[0xa6];
origNode = (buf[0xa9] << 8) + buf[0xa8];
origNet = (buf[0xad] << 8) + buf[0xac];
destNet = (buf[0xaf] << 8) + buf[0xae];
destZone = (buf[0xb1] << 8) + buf[0xb0];
origZone = (buf[0xb3] << 8) + buf[0xb2];
destPoint = (buf[0xb5] << 8) + buf[0xb4];
origPoint = (buf[0xb7] << 8) + buf[0xb6];
Attribute = (buf[0xbb] << 8) + buf[0xba];
Syslog('m', "From %d:%d/%d.%d to %d:%d/%d.%d", origZone, origNet, origNode, origPoint, destZone, destNet, destNode, destPoint);
while (fgets(temp, PATH_MAX-1, fp)) {
Striplf(temp);
if (temp[strlen(temp)-1] == '\r')
temp[strlen(temp)-1] = '\0';
Syslogp('m', printable(temp, 0));
if (!strncmp(temp, "\001MSGID: ", 8)) {
msgid = xstrcpy(temp + 8);
/*
* Extra test to see if the mail comes from a pointaddress.
*/
l = strtok(temp," \0");
l = strtok(NULL," \0");
if ((ta = parsefnode(l))) {
if (ta->net == origNet && ta->node == origNode && !origPoint && ta->point) {
Syslog('m', "Setting pointinfo (%d) from MSGID", ta->point);
origPoint = ta->point;
}
if ((ta->net == origNet) && (ta->node == origNode) && (origZone == 0) && ta->zone) {
/*
* Missing zone info, maybe later we will see a INTL kludge or so, but for
* now, just in case we fix it. And we need that for some Aka collecting
* sysop who doesn't know how to configure his system right.
*/
Syslog('m', "No from zone set, setting zone %d from MSGID", ta->zone);
origZone = ta->zone;
/*
* 99.9 % chance that the destination zone is also missing.
*/
if (destZone == 0) {
destZone = ta->zone;
Syslog('m', "No dest zone set, setting zone %d from MSGID", ta->zone);
}
}
tidy_faddr(ta);
}
if (msgid)
free(msgid);
msgid = NULL;
}
if (!strncmp(temp, "\001FMPT", 5)) {
l = strtok(temp, " \0");
l = strtok(NULL, " \0");
origPoint = atoi(l);
}
if (!strncmp(temp, "\001TOPT", 5)) {
l = strtok(temp, " \0");
l = strtok(NULL, " \0");
destPoint = atoi(l);
}
if (!strncmp(temp, "\001INTL", 5)) {
Syslog('m', "Setting addresses from INTL kludge");
l = strtok(temp," \0");
l = strtok(NULL," \0");
r = strtok(NULL," \0");
if ((ta = parsefnode(l))) {
destPoint = ta->point;
destNode = ta->node;
destNet = ta->net;
destZone = ta->zone;
tidy_faddr(ta);
}
if ((ta = parsefnode(r))) {
origPoint = ta->point;
origNode = ta->node;
origNet = ta->net;
origZone = ta->zone;
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);
}
}
Syslog('m', "From %d:%d/%d.%d to %d:%d/%d.%d", origZone, origNet, origNode, origPoint, destZone, destNet, destNode, destPoint);
if ((origZone == 0) || (destZone == 0)) {
WriteError("No zone info in %s/%s", CFG.msgs_path, msgname);
fclose(fp);
free(temp);
return 3;
}
if (SearchFidonet(origZone) == FALSE) {
WriteError("Can't find network for zone %d", origZone);
fclose(fp);
free(temp);
return 4;
}
if (SearchNetBoard(origZone, origNet) == FALSE) {
WriteError("Can't find netmail board for zone:net %d:%d", origZone, origNet);
fclose(fp);
free(temp);
return 4;
}
if (Msg_Open(msgs.Base) && Msg_Lock(30L)) {
Msg_New();
strcpy(Msg.From, fromUserName);
strcpy(Msg.To, toUserName);
strcpy(Msg.Subject, subject);
if (Attribute & M_FILE) {
if ((stat(subject, &sb) == 0) && (S_ISREG(sb.st_mode))) {
dospath = xstrcpy(Unix2Dos(subject));
Syslog('+', "Fileattach %s in message %s", subject, msgname);
if (strlen(CFG.dospath))
strcpy(Msg.Subject, dospath);
Msg.FileAttach = TRUE;
free(dospath);
} else {
WriteError("Fileattach %s in message %s not found", subject, msgname);
}
}
Msg.Written = parsefdate(DateTime, NULL);
Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60);
Msg.Local = TRUE;
Msg.KillSent = ((Attribute & M_KILLSENT));
Msg.Hold = ((Attribute & M_HOLD));
Msg.Crash = ((Attribute & M_CRASH) || flag_on((char *)"CRA", flagstr));
Msg.ReceiptRequest = ((Attribute & M_RRQ) || flag_on((char *)"RRQ", flagstr));
Msg.Orphan = ((Attribute & M_ORPHAN));
Msg.Intransit = ((Attribute & M_TRANSIT));
Msg.FileRequest = ((Attribute & M_REQ) || flag_on((char *)"FRQ", flagstr));
Msg.ConfirmRequest = ((Attribute & M_AUDIT) || flag_on((char *)"CFM", flagstr));
Msg.Immediate = flag_on((char *)"IMM", flagstr);
Msg.Direct = flag_on((char *)"DIR", flagstr);
Msg.Gate = flag_on((char *)"ZON", flagstr);
Msg.Private = TRUE;
if (origPoint)
sprintf(Msg.FromAddress, "%d:%d/%d.%d@%s", origZone, origNet, origNode, origPoint, fidonet.domain);
else
sprintf(Msg.FromAddress, "%d:%d/%d@%s", origZone, origNet, origNode, fidonet.domain);
if (SearchFidonet(destZone)) {
if (destPoint)
sprintf(Msg.ToAddress, "%d:%d/%d.%d@%s", destZone, destNet, destNode, destPoint, fidonet.domain);
else
sprintf(Msg.ToAddress, "%d:%d/%d@%s", destZone, destNet, destNode, fidonet.domain);
} else {
if (destPoint)
sprintf(Msg.ToAddress, "%d:%d/%d.%d", destZone, destNet, destNode, destPoint);
else
sprintf(Msg.ToAddress, "%d:%d/%d", destZone, destNet, destNode);
}
/*
* Add original message text
*/
fseek(fp, 0xbe, SEEK_SET);
while (fgets(temp, PATH_MAX-1, fp)) {
Striplf(temp);
if (temp[strlen(temp)-1] == '\r')
temp[strlen(temp)-1] = '\0';
MsgText_Add2(temp);
}
Msg_AddMsg();
Msg_UnLock();
Syslog('+', "%s => %s (%ld) to \"%s\", \"%s\"", msgname, msgs.Name, Msg.Id, Msg.To, Msg.Subject);
msgs.LastPosted = time(NULL);
msgs.Posted.total++;
msgs.Posted.tweek++;
msgs.Posted.tdow[Diw]++;
msgs.Posted.month[Miy]++;
UpdateMsgs();
do_scan = TRUE;
sprintf(temp, "%s/tmp/netmail.jam", getenv("MBSE_ROOT"));
if ((np = fopen(temp, "a")) != NULL) {
fprintf(np, "%s %lu\n", msgs.Base, Msg.Id);
fclose(np);
}
Msg_Close();
} else {
WriteError("Can't open JAM %s", msgs.Base);
rc = 5;
}
fclose(fp);
if (rc == 0) {
sprintf(temp, "%s/%s", CFG.msgs_path, msgname);
Syslog('m', "unlink(%s) rc=%d", temp, unlink(temp));
}
free(temp);
return rc;
}

View File

@ -160,16 +160,17 @@ long Msg_Top(char *template, int language, fidoaddr aka)
Msg_Macro(fi); Msg_Macro(fi);
fileptr = ftell(fi); fileptr = ftell(fi);
MacroVars("pqrf", "dsss", 0, "", "", "");
if (strlen(CFG.IP_Flags) && strlen(CFG.IP_Phone)) {
MacroVars("pqrf", "dsds", 2, CFG.IP_Phone, CFG.IP_Speed, CFG.IP_Flags);
fseek(fi, fileptr, SEEK_SET);
Msg_Macro(fi);
hasmodems = TRUE;
}
sprintf(temp, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT")); sprintf(temp, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) != NULL) { if ((fp = fopen(temp, "r")) != NULL) {
fread(&ttyinfohdr, sizeof(ttyinfohdr), 1, fp); fread(&ttyinfohdr, sizeof(ttyinfohdr), 1, fp);
MacroVars("pqrf", "dsss", 0, "", "", "");
if (strlen(CFG.IP_Flags) && strlen(CFG.IP_Phone)) {
MacroVars("pqrf", "dsds", 2, CFG.IP_Phone, CFG.IP_Speed, CFG.IP_Flags);
fseek(fi, fileptr, SEEK_SET);
Msg_Macro(fi);
}
while (fread(&ttyinfo, ttyinfohdr.recsize, 1, fp) == 1) { while (fread(&ttyinfo, ttyinfohdr.recsize, 1, fp) == 1) {
if (((ttyinfo.type == POTS) || (ttyinfo.type == ISDN)) && ttyinfo.available && strlen(ttyinfo.phone)) { if (((ttyinfo.type == POTS) || (ttyinfo.type == ISDN)) && ttyinfo.available && strlen(ttyinfo.phone)) {
MacroVars("pqrf", "dsss", ttyinfo.type, ttyinfo.phone, ttyinfo.speed, ttyinfo.flags); MacroVars("pqrf", "dsss", ttyinfo.type, ttyinfo.phone, ttyinfo.speed, ttyinfo.flags);