2001-08-25 20:32:59 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* File ..................: tosser/storenet.c
|
|
|
|
* Purpose ...............: Import a netmail message
|
2001-10-22 17:32:44 +00:00
|
|
|
* Last modification date : 22-Oct-2001
|
2001-08-25 20:32:59 +00:00
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (C) 1997-2001
|
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
|
|
|
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "../lib/libs.h"
|
|
|
|
#include "../lib/structs.h"
|
|
|
|
#include "../lib/records.h"
|
|
|
|
#include "../lib/common.h"
|
|
|
|
#include "../lib/clcomm.h"
|
|
|
|
#include "../lib/msg.h"
|
|
|
|
#include "../lib/msgtext.h"
|
|
|
|
#include "../lib/dbmsgs.h"
|
|
|
|
#include "../lib/dbuser.h"
|
|
|
|
#include "rollover.h"
|
|
|
|
#include "storenet.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
|
|
|
extern int net_imp; /* Netmails imported */
|
|
|
|
extern int net_bad; /* Bad netmails (tracking errors */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store netmail into the JAM base.
|
|
|
|
*
|
|
|
|
* 0 - All seems well.
|
|
|
|
* 1 - Can't access messagebase.
|
|
|
|
* 2 - Can't find a netmail board.
|
|
|
|
*
|
|
|
|
*/
|
2001-10-04 20:25:37 +00:00
|
|
|
int storenet(faddr *f, faddr *t, time_t mdate, int flags, char *Subj, char *msgid, char *reply, FILE *fp, char *flagstr)
|
2001-08-25 20:32:59 +00:00
|
|
|
{
|
|
|
|
int result, i, empty = TRUE;
|
|
|
|
unsigned long crc2;
|
|
|
|
char *Buf;
|
|
|
|
|
|
|
|
if (SearchNetBoard(t->zone, t->net)) {
|
|
|
|
StatAdd(&msgs.Received, 1L);
|
|
|
|
time(&msgs.LastRcvd);
|
|
|
|
UpdateMsgs();
|
|
|
|
|
|
|
|
result = Msg_Open(msgs.Base);
|
|
|
|
if (!result) {
|
|
|
|
WriteError("Can't open msgbase %s", msgs.Base);
|
|
|
|
net_bad++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Msg_Lock(30L)) {
|
|
|
|
Msg_New();
|
|
|
|
|
|
|
|
Syslog('m', "Flagfield 0x%04x", flags);
|
|
|
|
strcpy(Msg.From, f->name);
|
|
|
|
strcpy(Msg.To, usr.sUserName);
|
|
|
|
strcpy(Msg.FromAddress, ascfnode(f,0x1f));
|
|
|
|
strcpy(Msg.ToAddress, ascfnode(t,0x1f));
|
|
|
|
strcpy(Msg.Subject, Subj);
|
|
|
|
Msg.Written = mdate;
|
|
|
|
Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60);
|
|
|
|
Msg.Netmail = TRUE;
|
|
|
|
|
|
|
|
/*
|
2001-10-04 20:25:37 +00:00
|
|
|
* Set flags for the message base.
|
2001-08-25 20:32:59 +00:00
|
|
|
*/
|
|
|
|
if ((msgs.MsgKinds == BOTH) || (msgs.MsgKinds == PRIVATE))
|
2001-10-04 20:25:37 +00:00
|
|
|
Msg.Private = (((flags & M_PVT) ? TRUE:FALSE) || flag_on((char *)"PVT", flagstr));
|
2001-08-25 20:32:59 +00:00
|
|
|
else
|
|
|
|
Msg.Private = TRUE; /* Allways */
|
2001-10-04 20:25:37 +00:00
|
|
|
Msg.Crash = ((flags & M_CRASH) || flag_on((char *)"CRA", flagstr));
|
|
|
|
Msg.FileAttach = ((flags & M_FILE) || flag_on((char *)"FIL", flagstr));
|
|
|
|
Msg.Intransit = ((flags & M_TRANSIT));
|
|
|
|
Msg.FileRequest = ((flags & M_REQ) || flag_on((char *)"FRQ", flagstr));
|
|
|
|
Msg.ReceiptRequest = ((flags & M_RRQ) || flag_on((char *)"RRQ", flagstr));
|
|
|
|
Msg.KillSent = ((flags & M_KILLSENT) || flag_on((char *)"K/S", flagstr));
|
|
|
|
Msg.ArchiveSent = flag_on((char *)"A/S", flagstr);
|
|
|
|
Msg.Hold = ((flags & M_HOLD) || flag_on((char *)"HLD", flagstr));
|
|
|
|
Msg.Immediate = flag_on((char *)"IMM", flagstr);
|
|
|
|
Msg.Direct = flag_on((char *)"DIR", flagstr);
|
|
|
|
Msg.Gate = flag_on((char *)"ZON", flagstr);
|
|
|
|
Msg.TruncFile = flag_on((char *)"TFS", flagstr);
|
|
|
|
Msg.KillFile = flag_on((char *)"KFS", flagstr);
|
2001-10-22 17:32:44 +00:00
|
|
|
Msg.ConfirmRequest = ((flags & M_AUDIT) || flag_on((char *)"CFM", flagstr));
|
2001-10-04 20:25:37 +00:00
|
|
|
Msg.Orphan = ((flags & M_ORPHAN));
|
|
|
|
|
|
|
|
if (Msg.ReceiptRequest) {
|
|
|
|
Syslog('+', "Netmail has ReceiptRequest flag, no message created");
|
|
|
|
}
|
2001-08-25 20:32:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set MSGID and REPLY crc.
|
|
|
|
*/
|
|
|
|
if (msgid != NULL) {
|
|
|
|
crc2 = -1;
|
|
|
|
Msg.MsgIdCRC = upd_crc32(msgid, crc2, strlen(msgid));
|
|
|
|
}
|
|
|
|
if (reply != NULL) {
|
|
|
|
crc2 = -1;
|
|
|
|
Msg.ReplyCRC = upd_crc32(reply, crc2, strlen(reply));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if this is an empty netmail
|
|
|
|
*/
|
|
|
|
rewind(fp);
|
|
|
|
Buf = calloc(2049, sizeof(char));
|
|
|
|
while ((fgets(Buf, 2048, fp)) != NULL) {
|
|
|
|
|
|
|
|
for (i = 0; i < strlen(Buf); i++) {
|
|
|
|
if (*(Buf + i) == '\0')
|
|
|
|
break;
|
|
|
|
if (*(Buf + i) == '\n')
|
|
|
|
*(Buf + i) = '\0';
|
|
|
|
if (*(Buf + i) == '\r')
|
|
|
|
*(Buf + i) = '\0';
|
|
|
|
}
|
|
|
|
if (*(Buf) != '\0') {
|
|
|
|
if ((*(Buf) != '\001') &&
|
|
|
|
(strcmp(Buf, (char *)"--- ")))
|
|
|
|
empty = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(Buf);
|
|
|
|
|
|
|
|
if (!empty) {
|
|
|
|
Syslog('+', "Import netmail to %s", usr.sUserName);
|
|
|
|
rewind(fp);
|
|
|
|
Msg_Write(fp);
|
|
|
|
Msg_AddMsg();
|
|
|
|
net_imp++;
|
|
|
|
} else {
|
|
|
|
Syslog('+', "Empty netmail for %s dropped", usr.sUserName);
|
|
|
|
}
|
|
|
|
Msg_UnLock();
|
|
|
|
Msg_Close();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
WriteError("Can't lock msgbase %s", msgs.Base);
|
|
|
|
Msg_Close();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
WriteError("Can't find a netmail board");
|
|
|
|
net_bad++;
|
|
|
|
return 2;
|
|
|
|
} /* if SearchNetBoard() */
|
|
|
|
}
|
|
|
|
|
|
|
|
|