/* Path to the 'uudecode' utility (needed for network file transfers) */
#define UUDECODE "/usr/bin/uudecode"
+/* Files used by the networker */
+#define MAILSYSINFO "./network/mail.sysinfo"
+
/* Uncomment the DEBUG def to see noisy traces */
#define DEBUG 1
struct filterlist *filter = NULL;
struct syslist *slist = NULL;
+struct msglist *purgelist = NULL;
struct config config;
extern char bbs_home_directory[];
/*
- * we also load the network/mail.sysinfo table into memory, make changes
+ * we also load the mail.sysinfo table into memory, make changes
* as we learn more about the network from incoming messages, and write
* the table back to disk when we're done.
*/
char insys = 0;
char buf[128];
- fp = fopen("network/mail.sysinfo", "r");
+ fp = fopen(MAILSYSINFO, "r");
if (fp == NULL)
return (1);
time_t now;
time(&now);
- newfp = fopen("network/mail.sysinfo", "w");
+ newfp = fopen(MAILSYSINFO, "w");
for (stemp = slist; stemp != NULL; stemp = stemp->next) {
if (!strcasecmp(stemp->s_name, config.c_nodename)) {
time(&stemp->s_lastcontact);
syslog(LOG_ERR, "Magic number check failed for this message");
goto END;
}
+
+ memset(buffer, 0, sizeof(struct minfo));
mtype = getc(fp);
aflag = getc(fp);
- buffer->I = 0L;
- buffer->R[0] = 0;
- buffer->E[0] = 0;
- buffer->H[0] = 0;
- buffer->S[0] = 0;
- buffer->B[0] = 0;
- buffer->G[0] = 0;
BONFGM: b = getc(fp);
if (b < 0)
strcpy(buffer->G, bbb);
if (b == 'E')
strcpy(buffer->E, bbb);
+ if (b == 'Z')
+ strcpy(buffer->Z, bbb);
goto BONFGM;
END:
+
+
/*
* process incoming files in ./network/spoolin
*/
char buf[256];
long msglen;
int bloklen;
+ int valid_msg;
/* temp file names */
sprintf(tname, tmpnam(NULL));
/* Make sure we're in the right directory */
chdir(bbs_home_directory);
-
/* temporary file to contain a log of rejected dups */
duplist = tmpfile();
goto ENDSTR;
/* This crates the temporary file. */
+ valid_msg = 1;
message = fopen(tname, "wb");
if (message == NULL) {
syslog(LOG_ERR, "error creating %s: %s",
a = getc(fp);
putc(a, message); /* mode */
do {
- FieldID = getc(fp); /* Header field ID */
- putc(FieldID, message);
- do {
- a = getc(fp);
- putc(a, message);
- } while (a > 0);
+ FieldID = getc(fp); /* Header field ID */
+ if (isalpha(FieldID)) {
+ putc(FieldID, message);
+ do {
+ a = getc(fp);
+ if (a < 127) putc(a, message);
+ } while (a > 0);
+ if (a != 0) putc(0, message);
+ }
+ else { /* Invalid field ID; flush it */
+ do {
+ a = getc(fp);
+ } while (a > 0);
+ valid_msg = 0;
+ }
} while ((FieldID != 'M') && (a >= 0));
/* M is always last */
+ if (FieldID != 'M') valid_msg = 0;
msglen = ftell(message);
fclose(message);
+ if (!valid_msg) {
+ unlink(tname);
+ goto NXMSG;
+ }
+
/* process the individual mesage */
- minfo.D[0] = 0;
- minfo.C[0] = 0;
- minfo.B[0] = 0;
- minfo.G[0] = 0;
- minfo.R[0] = 0;
msgfind(tname, &minfo);
strncpy(recentmsg.RMnodename, minfo.N, 9);
recentmsg.RMnodename[9] = 0;
/* otherwise process it as a normal message */
else {
-
if (!strcasecmp(minfo.R, "postmaster")) {
strcpy(minfo.R, "");
strcpy(minfo.C, "Aide");
}
fclose(message);
+
}
unlink(tname);
+
+/*
+ * Add a message to the list of messages to be deleted off the local server
+ * at the end of this run.
+ */
+void delete_locally(long msgid, char *roomname) {
+ struct msglist *mptr;
+
+ mptr = (struct msglist *) malloc(sizeof(struct msglist));
+ mptr->next = purgelist;
+ mptr->m_num = msgid;
+ strcpy(mptr->m_rmname, roomname);
+ purgelist = mptr;
+}
+
+
+
+/*
+ * Delete all messages on the purge list from the local server.
+ */
+void process_purgelist(void) {
+ char curr_rm[ROOMNAMELEN];
+ char buf[256];
+ struct msglist *mptr;
+
+
+ strcpy(curr_rm, "__nothing__");
+ while (purgelist != NULL) {
+ if (strcasecmp(curr_rm, purgelist->m_rmname)) {
+ sprintf(buf, "GOTO %s", purgelist->m_rmname);
+ serv_puts(buf);
+ serv_gets(buf);
+ if (buf[0] == '2') extract(curr_rm, &buf[4], 0);
+ }
+ if (strcasecmp(curr_rm, purgelist->m_rmname)) {
+ sprintf(buf, "DELE %ld", purgelist->m_num);
+ serv_puts(buf);
+ serv_gets(buf);
+ }
+ mptr = purgelist->next;
+ free(purgelist);
+ purgelist = mptr;
+ }
+}
+
+
+
+
/* spool list of messages to a file */
/* returns # of msgs spooled */
int spool_out(struct msglist *cmlist, FILE * destfp, char *sysname)
fprintf(destfp, "%s!", NODENAME);
if (a != 'C')
fwrite(fbuf, strlen(fbuf) + 1, 1, destfp);
+ if (a == 'S') if (!strcasecmp(fbuf, "CANCEL")) {
+ delete_locally(cmptr->m_num, cmptr->m_rmname);
+ }
}
if (a == 'M') {
fprintf(destfp, "C%s%c",
/* Update mail.sysinfo with new information we learned */
rewrite_syslist();
+ /* Delete any messages which need to be purged locally */
+ process_purgelist();
+
/* Close the use table */
purge_use_table(use_table);
gdbm_close(use_table);