home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
PPPBCKP
/
SRC15B43.ZIP
/
EXP.C
< prev
next >
Wrap
Text File
|
1997-09-30
|
41KB
|
1,426 lines
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <ctype.h>
#include <mem.h>
#include <conio.h>
#include <io.h>
#include <share.h>
#include <errno.h>
#include <dir.h>
#include <time.h>
#include <malloc.h>
#include <process.h>
#include <direct.h>
#include "vardec.h"
#include "net.h"
#include "retcode.h"
#include "version.h"
#define WAIT_TIME 10
#define TRIES 100
#define SHARE_LEVEL 10
#define MT_DESQVIEW 0x01
#define MT_WINDOWS 0x02
#define MT_OS2 0x04
#define MT_NB 0x40
struct msghdr {
char fromUserName[205];
char toUserName[81];
char subject[81];
char dateTime[81];
};
typedef struct {
char ownername[60];
char subtype[8];
} MAILLISTREC;
MAILLISTREC *maillist;
configrec syscfg;
char *net_name, postmaster[31], net_data[MAXPATH], POPNAME[21], DOMAIN[81], tagfile[MAXPATH], maindir[MAXPATH], spamname[81];
unsigned short net_sysnum, defuser, num_users, use_alias, instance, curuser, spam;
int multitasker = 0;
int nlists = 0;
char alphasubtype[8];
unsigned long cur_daten;
void dv_pause(void)
{
__emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
__emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
__emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
}
void win_pause(void)
{
__emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
}
int get_dos_version(void)
{
_AX = 0x3000;
geninterrupt(0x21);
if (_AX % 256 >= 10) {
multitasker |= MT_OS2;
}
return (_AX);
}
int get_dv_version(void)
{
int v;
if (multitasker & MT_OS2)
return 0;
_AX = 0x2b01;
_CX = 0x4445;
_DX = 0x5351;
geninterrupt(0x21);
if (_AL == 0xff) {
return 0;
} else {
v = _BX;
multitasker |= MT_DESQVIEW;
return v;
}
}
int get_win_version(void)
{
int v = 0;
__emit__(0x55, 0x06, 0x53);
_AX = 0x352f;
geninterrupt(0x21);
_AX = _ES;
if (_AX | _BX) {
_AX = 0x1600;
geninterrupt(0x2f);
v = _AX;
if (v % 256 <= 1)
v = 0;
}
__emit__(0x5b, 0x07, 0x5d);
if (v != 0)
multitasker |= MT_WINDOWS;
return (v);
}
int get_nb_version(void)
{
_AX = 0;
geninterrupt(0x2A);
return (_AH);
}
void detect_multitask(void)
{
get_dos_version();
get_win_version();
get_dv_version();
if (multitasker < 2)
if (get_nb_version())
multitasker = MT_NB;
}
void giveup_timeslice(void)
{
if (multitasker) {
switch (multitasker) {
case 1:
case 3:
dv_pause();
break;
case 2:
case 4:
case 5:
case 6:
case 7:
win_pause();
break;
default:
break;
}
}
}
int sh_write(int handle, void *buffer, unsigned long len)
{
if (handle == -1) {
return (-1);
}
return (write(handle, buffer, (unsigned) len));
}
int sh_open(char *path, int file_access, unsigned fmode)
{
int handle, count, share;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
share = SH_DENYRW;
} else {
share = SH_DENYWR;
}
handle = open(path, file_access | share, fmode);
if (handle < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if (access(path, 0) != -1) {
delay(WAIT_TIME);
handle = open(path, file_access | share, fmode);
while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
if (count % 2)
delay(WAIT_TIME);
else
giveup_timeslice();
count++;
handle = open(path, file_access | share, fmode);
}
}
}
return (handle);
}
int sh_open1(char *path, int access)
{
unsigned fmode;
fmode = 0;
if ((access & O_RDWR) || (access & O_WRONLY))
fmode |= S_IWRITE;
if ((access & O_RDWR) || (access & O_RDONLY))
fmode |= S_IREAD;
return (sh_open(path, access, fmode));
}
int sh_close(int f)
{
if (f != -1)
close(f);
return (-1);
}
int sh_read(int handle, void *buf, unsigned len)
{
if (handle == -1) {
return (-1);
}
return (read(handle, buf, len));
}
long sh_lseek(int handle, long offset, int fromwhere)
{
if (handle == -1) {
return (-1L);
}
return (lseek(handle, offset, fromwhere));
}
FILE *fsh_open(char *path, char *fmode)
{
FILE *f;
int count, share, md, fd;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
share = SH_DENYWR;
md = 0;
if (((char *) strchr(fmode, 'w')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT | O_TRUNC;
} else
if (((char *) strchr(fmode, 'a')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT;
} else {
md = O_RDONLY;
}
if (((char *) strchr(fmode, 'b')) != NULL) {
md |= O_BINARY;
}
if (((char *) strchr(fmode, '+')) != NULL) {
md &= ~O_RDONLY;
md |= O_RDWR;
share = SH_DENYRD;
}
fd = open(path, md | share, S_IREAD | S_IWRITE);
if (fd < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if ((access(path, 0)) != -1) {
delay(WAIT_TIME);
fd = open(path, md | share, S_IREAD | S_IWRITE);
while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
delay(WAIT_TIME);
count++;
fd = open(path, md | share, S_IREAD | S_IWRITE);
}
}
}
if (fd > 0) {
if (((char *) strchr(fmode, 'a')) != NULL)
sh_lseek(fd, 0L, SEEK_END);
f = fdopen(fd, fmode);
if (!f) {
close(fd);
}
} else
f = 0;
return (f);
}
size_t fsh_write(void *ptr, size_t size, size_t n, FILE * stream)
{
if (stream == NULL) {
return (0);
}
return (fwrite(ptr, size, n, stream));
}
int exist(char *s)
{
int i;
struct ffblk ff;
i = findfirst(s, &ff, 0);
if (i)
return (0);
else
return (1);
}
char *stripspace(char *str)
{
char *obuf, *nbuf;
if (str) {
for (obuf = str, nbuf = str; *obuf; ++obuf) {
if (!isspace(*obuf))
*nbuf++ = *obuf;
}
*nbuf = NULL;
}
return (str);
}
static unsigned char *trimstr1(unsigned char *s)
{
int i;
static char *whitespace = " \r\n\t\"";
i = (int) strlen(s);
while ((i > 0) && ((char *) strchr(whitespace, s[i - 1]) != NULL))
--i;
while ((i > 0) && ((char *) strchr(whitespace, *s) != NULL)) {
memmove(s, s + 1, --i);
}
s[i] = 0;
return (s);
}
void output(char *fmt,...)
{
va_list v;
char s[255];
va_start(v, fmt);
vsprintf(s, fmt, v);
va_end(v);
fputs(s, stderr);
}
int num_to_name(char *where, int whichuser, int alias)
{
int userfile, num_users, found;
userrec ur;
long pos;
char fn[MAXPATH];
found = 0;
sprintf(fn, "%sUSER.LST", syscfg.datadir);
userfile = sh_open1(fn, O_RDONLY | O_BINARY);
if (userfile < 0) {
output("\n ■ Cannot open %s.", fn);
return (found);
}
num_users = ((int) (filelength(userfile) / sizeof(userrec)));
if (whichuser > num_users) {
output("\n ■ User #%d out of range.", whichuser);
return (found);
}
pos = ((long) sizeof(userrec) * ((long) whichuser));
lseek(userfile, pos, SEEK_SET);
sh_read(userfile, &ur, sizeof(userrec));
if (ur.realname[0] == 0)
output("\n ■ User #%d has blank real name field!", whichuser);
else {
if (ur.inact == inact_deleted)
output("\n ■ User #%d is marked as deleted!", whichuser);
else {
if (!alias)
strcpy(where, ur.realname);
else {
strcpy(where, ur.name);
strlwr(where);
}
found = 1;
}
}
sh_close(userfile);
return (found);
}
void parse_net_ini(void)
{
char s[MAXPATH], line[121], *ss, inlist = 0;
FILE *fp;
long fptr;
defuser = 1;
use_alias = 1;
nlists = 0;
maillist = NULL;
sprintf(s, "%sNET.INI", maindir);
if ((fp = fsh_open(s, "rt")) == NULL) {
output("\n ■ Unable to open %s.", s);
return;
}
while (fgets(line, 80, fp)) {
ss = NULL;
stripspace(line);
if ((line[0] == ';') || (line[0] == '\n') || (line[0] == 0))
continue;
if (strnicmp(line, "[MAILLIST]", 10) == 0) {
fptr = ftell(fp);
while ((fgets(line, 80, fp)) && (line[0] != '[')) {
if ((line[0] != '[') && (line[0] != ';') && (line[0] != 0))
++nlists;
}
fseek(fp, fptr, SEEK_SET);
maillist = (MAILLISTREC *) malloc((nlists + 1) * sizeof(MAILLISTREC));
if (maillist == NULL)
output("\n ■ Not enough memory to process %d mailing lists.", nlists);
else {
output("\n ■ Reading %d defined mailing lists.", nlists);
inlist = 1;
}
nlists = 0;
continue;
} else
if (line[0] == '[') {
inlist = 0;
continue;
}
if (inlist) {
if ((line[0] != ';') && (line[0] != 0)) {
ss = strtok(line, "*\n");
trimstr1(ss);
strcpy(maillist[nlists].ownername, ss);
ss = strtok(NULL, "\n");
trimstr1(ss);
if (ss[0]) {
strlwr(maillist[nlists].ownername);
strcpy(maillist[nlists++].subtype, ss);
} else
output("\n ■ Missing *subtype in maillist for %s.",
maillist[nlists].ownername);
}
continue;
}
if (strnicmp(line, "POSTMASTER", 10) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
if (ss)
defuser = atoi(ss);
}
continue;
}
if (strnicmp(line, "SPAMCONTROL", 11) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
if ((ss[0] == 'y') || (ss[0] == 'Y'))
spam = 1;
}
continue;
}
if (strnicmp(line, "SPAMADDRESS", 9) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(spamname, ss);
if (stricmp(spamname, "DEFAULT") == 0)
strcpy(spamname, "WWIV_BBS@nospam.net");
}
continue;
}
if (strnicmp(line, "SIGNATURE", 9) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(tagfile, ss);
if (!exist(tagfile)) {
output("\n ■ Default signature file %s not found!", tagfile);
tagfile[0] = 0;
}
}
continue;
}
if (strnicmp(line, "REALNAME", 8) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
if ((ss[0] == 'y') || (ss[0] == 'Y'))
use_alias = 0;
}
}
}
num_to_name(postmaster, defuser, 1);
if (fp != NULL)
fclose(fp);
return;
}
unsigned char *strrep(char *str, char old, char New)
{
int i;
for (i = 0; str[i]; i++)
if (str[i] == old)
str[i] = New;
return (str);
}
unsigned int name_to_num(char *name)
{
int userfile, usernum;
userrec ur;
long pos;
char fn[MAXPATH], ur_name[60], ur_realname[60];
sprintf(fn, "%sM%s.NET", net_data, name);
if (exist(fn)) {
strcpy(alphasubtype, name);
return (65535L);
}
sprintf(fn, "%sUSER.LST", syscfg.datadir);
userfile = sh_open1(fn, O_RDONLY | O_BINARY);
if (userfile < 0) {
output("\n ■ Cannot open %s", fn);
return (0);
} else
output("\n ■ Searching for user \"%s\"...", name);
num_users = ((int) (filelength(userfile) / sizeof(userrec)));
for (usernum = 1; usernum < num_users; usernum++) {
pos = ((long) sizeof(userrec) * ((long) usernum));
lseek(userfile, pos, SEEK_SET);
sh_read(userfile, &ur, sizeof(userrec));
strcpy(ur_realname, ur.realname);
strrep(ur_realname, ' ', '_');
strcpy(ur_name, ur.name);
strrep(ur_name, ' ', '_');
if ((strcmpi(ur.realname, name) == 0) || (strcmpi(ur_realname, name) == 0) ||
(strcmpi(ur.name, name) == 0) || (strcmpi(ur_name, name) == 0)) {
if (ur.inact == inact_deleted) {
output(" user #%d is deleted account.", usernum);
usernum = 0;
break;
} else {
output(" matched user #%d.", usernum);
break;
}
}
}
userfile = sh_close(userfile);
if (usernum >= num_users) {
output("... no match found.");
return (0);
}
return (usernum);
}
char *find_name(char *name)
{
char *ss;
curuser = 0;
if (strcspn(name, "(") != strlen(name)) {
ss = strtok(name, "(");
ss = strtok(NULL, ")");
strcpy(name, ss);
curuser = name_to_num(name);
} else
if (strcspn(name, "\"") != strlen(name)) {
ss = strtok(name, "\"");
ss = strtok(NULL, "\"");
strcpy(name, ss);
curuser = name_to_num(name);
} else
if (strcspn(name, "<") != strlen(name)) {
ss = strtok(name, "<");
trimstr1(ss);
strcpy(name, ss);
curuser = name_to_num(name);
}
if (curuser == 0)
return ('\0');
else
if (curuser == 65535L)
return (alphasubtype);
else
return (ss);
}
void name_packet(char *pktname)
{
int ok;
struct stat info;
unsigned i;
ok = 0;
for (i = 0; ((i < 1000) && (!ok)); i++) {
sprintf(pktname, "%sP0-%u.%3.3hu", net_data, i, instance);
if (stat(pktname, &info) == -1)
ok = 1;
}
}
#define FROM_RETURN 0x01
#define FROM_FROM 0x02
#define FROM_REPLY 0x04
int import(char *fn)
{
char s[513], s1[121], pktname[MAXPATH], msgdate[61], *ss, *p, *id, *name;
char alphatype[21], recvdate[81];
int i, f, from, match, subj, intext, done, tolist;
long textlen, reallen;
struct msghdr mh;
net_header_rec nh;
FILE *fp;
tolist = 0;
intext = 0;
f = sh_open1(fn, O_RDONLY | O_BINARY);
if (f < 0)
return (1);
textlen = filelength(f);
if (textlen > 32767L) {
output("\n ■ Skipping %s - greater than 32K.", fn);
return (1);
}
p = (char *) malloc((int) (textlen + 1));
if (p == NULL) {
output("\n ■ Unable to allocate %ld bytes.", textlen);
return (1);
}
sh_read(f, (void *) p, (int) textlen);
sh_close(f);
nh.tosys = net_sysnum;
nh.fromsys = 32767;
nh.fromuser = 0;
nh.touser = defuser;
nh.main_type = main_type_email;
nh.minor_type = 0;
nh.list_len = 0;
++cur_daten;
nh.daten = cur_daten;
strncpy(msgdate, ctime(&(time_t) nh.daten), 24);
msgdate[24] = '\0';
sprintf(recvdate, "0RReceived: by PPP Project %s, %s\r\n", VERSION, msgdate);
strcat(msgdate, "\r\n");
nh.method = 0;
strcpy(mh.fromUserName, "Unknown");
strcpy(mh.toUserName, "Unknown");
strcpy(mh.subject, "None");
if ((fp = fsh_open(fn, "rb")) == NULL) {
free(p);
return (1);
}
match = subj = done = 0;
while ((fgets(s, 254, fp)) && !done) {
if (s[0] == 4) {
ss = strtok(s, "R");
ss = strtok(NULL, "\r\n");
if (ss == NULL)
s[0] = 0;
else
strcpy(s, ss);
} else
intext = 1;
if (!intext) {
if (strncmpi(s, "from:", 5) == 0)
from = FROM_FROM;
else
if (strncmpi(s, "return-path:", 12) == 0)
from = FROM_RETURN;
else
if (strncmpi(s, "sender:", 7) == 0)
from = FROM_RETURN;
else
if (strncmpi(s, "x-sender:", 9) == 0)
from = FROM_RETURN;
else
if (strncmpi(s, "x-to:", 5) == 0)
from = FROM_RETURN;
else
if (strncmpi(s, "reply-to:", 9) == 0)
from = FROM_REPLY;
else
from = 0;
if (from) {
ss = strtok(s, ": ");
ss = strtok(NULL, "\r\n");
trimstr1(ss);
if ((from & (FROM_RETURN | FROM_REPLY)) &&
(nh.main_type == main_type_email)) {
strcpy(s1, ss);
strlwr(s1);
for (i = 0; (i < nlists) && (nh.main_type == main_type_email); i++) {
if (strstr(s1, maillist[i].ownername) != NULL) {
if (atoi(maillist[i].subtype)) {
nh.main_type = main_type_pre_post;
nh.minor_type = atoi(maillist[i].subtype);
} else {
nh.main_type = main_type_new_post;
nh.minor_type = 0;
strcpy(alphatype, maillist[i].subtype);
}
strcpy(alphasubtype, maillist[i].subtype);
nh.touser = 0;
from = 0;
}
}
}
if (from > match) {
match = from;
if (strcspn(ss, "<") != strlen(ss)) {
if ((strcspn(ss, " ")) < (strcspn(ss, "<"))) {
name = strtok(ss, "<");
trimstr1(name);
id = strtok(NULL, ">");
trimstr1(id);
sprintf(mh.fromUserName, "%s (%s)", id, name);
} else {
strncpy(mh.fromUserName, ss, 205);
trimstr1(mh.fromUserName);
if (strcspn(ss, " ") != strlen(ss))
output("\nName is *after* host in \"%s\"", name);
}
} else
strncpy(mh.fromUserName, ss, 205);
mh.fromUserName[190] = 0;
strcat(mh.fromUserName, "\r\n");
}
} else
if ((strncmpi(s, "subject:", 8) == 0) && (!subj)) {
ss = strtok(s, ": ");
ss = strtok(NULL, "\r\n");
trimstr1(ss);
strncpy(mh.subject, ss, 81);
mh.subject[72] = 0;
subj = 1;
} else
if (strncmpi(s, "date:", 5) == 0) {
ss = strtok(s, ": ");
ss = strtok(NULL, "\r\n");
trimstr1(ss);
strncpy(msgdate, ss, 58);
msgdate[58] = '\0';
strcat(msgdate, "\r\n");
} else
if ((strncmpi(s, "to:", 3) == 0) || (strncmpi(s, "cc:", 3) == 0)) {
ss = strtok(s, ": ");
ss = strtok(NULL, "\r\n");
strncpy(mh.toUserName, ss, 81);
mh.toUserName[80] = 0;
curuser = 0;
trimstr1(mh.toUserName);
if (strstr(mh.toUserName, " "))
find_name(mh.toUserName);
else
mh.toUserName[0] = 0;
if ((curuser == 65535L) && (nh.main_type == main_type_email)) {
strcpy(alphatype, alphasubtype);
nh.main_type = main_type_new_post;
nh.minor_type = 0;
nh.touser = 0;
tolist = 1;
} else
if ((mh.toUserName[0] == 0) || (curuser == 0)) {
nh.touser = defuser;
strcpy(mh.toUserName, postmaster);
} else
nh.touser = curuser;
}
} else
done = 1;
}
if (fp != NULL)
fclose(fp);
output("\n ■ From : %s", strlwr(mh.fromUserName));
if ((nh.main_type == main_type_pre_post) ||
(nh.main_type == main_type_new_post))
output(" ■ Post to : Sub %s", alphasubtype);
else
output(" ■ Sent to : %s #%hd", strupr(mh.toUserName), nh.touser);
output("\n ■ Subject : %s", mh.subject);
name_packet(pktname);
if ((fp = fsh_open(pktname, "wb")) == NULL) {
output("\n ■ Unable to create packet %s", pktname);
free(p);
return (1);
}
nh.length = textlen + strlen(mh.fromUserName) + strlen(mh.subject)
+ strlen(msgdate) + strlen(recvdate) + 1;
if (nh.main_type == main_type_new_post)
nh.length += strlen(alphatype) + 1;
while (tolist >= 0) {
fsh_write(&nh, sizeof(net_header_rec), 1, fp);
if (nh.main_type == main_type_new_post)
fsh_write(alphatype, sizeof(char), strlen(alphatype) +1, fp);
fsh_write(mh.subject, sizeof(char), strlen(mh.subject) +1, fp);
fsh_write(mh.fromUserName, sizeof(char), strlen(mh.fromUserName), fp);
fsh_write(msgdate, sizeof(char), strlen(msgdate), fp);
fsh_write(recvdate, sizeof(char), strlen(recvdate), fp);
reallen = fsh_write(p, sizeof(char), (int) textlen, fp);
if (reallen != textlen)
output("\n ■ Expected %ld bytes, wrote %ld bytes.", textlen, reallen);
nh.tosys = 32767;
--tolist;
}
if (fp != NULL)
fclose(fp);
free(p);
return (0);
}
unsigned char *stripcolors(unsigned char *text)
{
static unsigned char s[161];
int i, i1;
if (strlen(text) == 0)
return ("");
i = 0;
i1 = 0;
do {
if (text[i] == 3)
i++;
else {
if ((text[i] > 32) && (text[i] < 128) || (text[i] == 9))
s[i1++] = text[i];
}
i++;
} while (i < strlen(text));
s[i1] = 0;
return (s);
}
int export(char *fn)
{
char fn1[121], tagfn[121], groupname[81], outfn[121], _temp_buffer[256];
char *ss, *buffer, *text, alphatype[21], hold[21], tempoutfn[21];
unsigned stype, ttype;
int infile, outfile, inloc, outloc, term, ok, i, j, ns, i6, tolist;
net_header_rec nhr;
struct msghdr mh;
struct tm *time_msg;
FILE *fp;
time_t some;
char *main_type[] =
{
"Network Update", "email by usernum", "post from sub host", "file",
"post to sub host", "external message", "email by name",
"NetEdit message", "SUBS.LST", "Extra Data", "BBSLIST from GC",
"CONNECT from GC", "Unused_1", "Info from GC", "SSM", "Sub Add Request",
"Sub Drop Request", "Sub Add Response", "Sub Drop Response", "Sub Info",
"Unused 1", "Unused 2", "Unused 3", "Unused 4", "Unused 5", "new post",
"new external"
};
if ((infile = sh_open1(fn, O_RDONLY | O_BINARY)) == -1)
return 1;
if ((buffer = (char *) malloc(32 * 1024)) == NULL) {
sh_close(infile);
output("\n ■ Out of memory allocating input buffer!");
return 1;
}
if ((text = (char *) malloc(32 * 1024)) == NULL) {
output("\n ■ Out of memory allocating output buffer!");
sh_close(infile);
if (buffer != NULL)
free(buffer);
return 1;
}
while (sh_read(infile, &nhr, sizeof(nhr))) {
sh_read(infile, buffer, (int) nhr.length);
if (nhr.tosys != 32767) {
output("\n ■ Non-Internet system routing via @32767... aborting export.");
sh_close(infile);
if (text)
free(text);
if (buffer)
free(buffer);
return (1);
}
tolist = 0;
if (nhr.main_type == main_type_pre_post)
nhr.main_type = main_type_post;
if ((nhr.main_type == main_type_post) ||
(nhr.main_type == main_type_new_post) ||
(nhr.main_type == main_type_email_name) ||
(nhr.main_type == main_type_ssm)) {
inloc = 0;
sprintf(hold, "%hu", nhr.minor_type);
if ((nhr.main_type == main_type_email_name) ||
(nhr.main_type == main_type_ssm) ||
(nhr.main_type == main_type_new_post)) {
stype = nhr.minor_type;
inloc = strlen(buffer) + 1;
if (nhr.main_type == main_type_new_post) {
strcpy(alphasubtype, buffer);
strcpy(hold, alphasubtype);
} else
strcpy(mh.toUserName, buffer);
if ((nhr.fromsys != net_sysnum) && (nhr.fromsys != 32767)) {
output("\n ■ Gate from #%hd@%hd to %s not yet supported",
nhr.fromuser, nhr.fromsys, mh.toUserName);
continue;
}
} else
if (nhr.main_type == main_type_post) {
stype = nhr.minor_type;
} else {
stype = atoi(&buffer[inloc]);
sprintf(_temp_buffer, "%u", stype);
inloc += strlen(_temp_buffer) + 1;
}
strncpy(mh.subject, &buffer[inloc], sizeof(mh.subject));
stripcolors(mh.subject);
inloc += strlen(&buffer[inloc]) + 1;
for (term = inloc; buffer[term] != '\r'; term++);
buffer[term] = '\0';
if ((nhr.fromsys == net_sysnum) && (nhr.fromuser)) {
if ((nhr.main_type != main_type_post) &&
(nhr.main_type != main_type_new_post)) {
if (!num_to_name(mh.fromUserName, nhr.fromuser, use_alias)) {
output("\n ■ No match for user #%hd... skipping message!",
nhr.fromuser);
continue;
}
} else {
if (!num_to_name(mh.fromUserName, nhr.fromuser, use_alias)) {
output("\n ■ No match for user #%hd... skipping message!",
nhr.fromuser);
continue;
}
}
} else {
strncpy(mh.fromUserName, &buffer[inloc], sizeof(mh.fromUserName));
stripcolors(mh.fromUserName);
strtok(mh.fromUserName, "#");
if ((nhr.main_type == main_type_post) &&
(nhr.main_type == main_type_new_post) &&
(nhr.fromsys != net_sysnum)) {
sprintf(_temp_buffer, " #%hd @%hu", nhr.fromuser, nhr.fromsys);
strcat(mh.fromUserName, _temp_buffer);
output("\nFrom: %s\n", mh.fromUserName);
}
}
inloc = term + 2;
while (buffer[inloc] != '\n')
inloc++;
inloc++;
if (strnicmp(&buffer[inloc], "RE: ", 4) == 0) {
for (term = inloc; buffer[term] != '\r'; term++);
buffer[term] = '\0';
strncpy(mh.subject, &buffer[inloc + 4], sizeof(mh.subject));
if (strnicmp(mh.subject, "RE: ", 4) != 0) {
strcpy(_temp_buffer, "Re: ");
strcat(_temp_buffer, mh.subject);
}
strcpy(mh.subject, _temp_buffer);
inloc = term + 2;
}
if ((strncmp(&buffer[inloc], "BY: ", 4) == 0) ||
(strncmp(&buffer[inloc], "TO: ", 4) == 0)) {
for (term = inloc; buffer[term] != '\r'; term++);
buffer[term] = '\0';
strncpy(mh.toUserName, &buffer[inloc + 4], sizeof(mh.toUserName));
stripcolors(mh.toUserName);
if (strcspn(mh.toUserName, "<") != strlen(mh.toUserName)) {
if ((strstr(mh.toUserName, "\"") == 0) && (strstr(mh.toUserName, "(") == 0)) {
ss = strtok(mh.toUserName, "<");
ss = strtok(NULL, ">");
strcpy(mh.toUserName, ss);
}
}
inloc = term + 2;
} else {
if (nhr.main_type != main_type_email_name) {
strcpy(mh.toUserName, "ALL");
}
}
outloc = 0;
do {
if (buffer[inloc] == 2) {
i = inloc + 1;
for (j = 1; j < 80; j++) {
if (buffer[i] == 227)
buffer[i] = '\r';
if ((buffer[i] == '\r') || (i > nhr.length))
break;
i++;
}
if (j < 80) {
i = (80 - j) / 2;
for (j = 1; j <= i; j++)
text[outloc++] = ' ';
}
inloc++;
} else
if (buffer[inloc] == 3)
inloc += 2;
else
if ((buffer[inloc] == 124) && (isdigit(buffer[inloc + 1])) && (isdigit(buffer[inloc + 2])))
inloc += 3;
else
if ((buffer[inloc] == 4) && (isdigit(buffer[inloc + 1]))) {
i = inloc;
for (j = 1; j < 80; j++) {
if ((buffer[i] == '\r') || (i > nhr.length))
break;
i++;
inloc++;
}
inloc++;
} else
if (buffer[inloc] >= 127)
inloc++;
else
if (buffer[inloc] == 1)
inloc++;
else
text[outloc++] = buffer[inloc++];
} while (inloc < nhr.length);
text[outloc] = '\0';
if ((nhr.main_type == main_type_post) ||
(nhr.main_type == main_type_pre_post) ||
(nhr.main_type == main_type_new_post)) {
if (nhr.main_type == main_type_new_post) {
sprintf(fn1, "%sM%s.NET", net_data, alphasubtype);
if (exist(fn1)) {
tolist = 1;
nhr.main_type = main_type_email_name;
}
}
for (i = 0; (i < nlists) && (nhr.main_type != main_type_email_name); i++) {
if (nhr.main_type == main_type_new_post) {
if (strcmpi(alphasubtype, maillist[i].subtype) == 0) {
nhr.main_type = main_type_email_name;
strcpy(mh.toUserName, maillist[i].ownername);
}
} else {
ttype = atoi(maillist[i].subtype);
if (ttype == stype) {
nhr.main_type = main_type_email_name;
strcpy(mh.toUserName, maillist[i].ownername);
}
}
}
}
switch (nhr.main_type) {
case main_type_email:
case main_type_email_name:
case main_type_ssm:
i = 1;
sprintf(outfn, "%sMQUEUE\\MSG.%d", net_data, i);
while (exist(outfn))
sprintf(outfn, "%sMQUEUE\\MSG.%d", net_data, ++i);
break;
case main_type_new_post:
case main_type_post:
case main_type_pre_post:
i = 1;
strcpy(tempoutfn, hold);
sprintf(outfn, "%sOUTBOUND\\%s.%d", net_data, tempoutfn, i);
while (exist(outfn))
sprintf(outfn, "%sOUTBOUND\\%s.%d", net_data, tempoutfn, ++i);
break;
default:
continue;
}
output("\n ■ Creating: %s", outfn);
output("\n ■ From : %s", mh.fromUserName);
if ((nhr.main_type == main_type_post) ||
(nhr.main_type == main_type_pre_post) ||
(nhr.main_type == main_type_new_post)) {
sprintf(fn1, "%sNEWS.RC", net_data);
if ((fp = fsh_open(fn1, "rt")) == NULL) {
output("\n ■ %s not found!", fn1);
sh_close(infile);
if (text)
free(text);
if (buffer)
free(buffer);
return 1;
} else {
ok = 0;
while ((fgets(_temp_buffer, 80, fp) != NULL) && (!ok)) {
groupname[0] = 0;
ss = strtok(_temp_buffer, " ");
if (ss) {
strcpy(groupname, ss);
ss = strtok(NULL, " ");
ss = strtok(NULL, "\r");
if (nhr.main_type == main_type_new_post) {
strcpy(alphatype, ss);
if (strncmpi(alphasubtype, alphatype, strlen(alphasubtype)) == 0)
ok = 1;
} else {
ttype = atoi(ss);
if (ttype == stype)
ok = 1;
}
}
}
*ss = NULL;
if (fp != NULL)
fclose(fp);
if (!ok) {
if (nhr.main_type != main_type_new_post)
sprintf(alphatype, "%u", stype);
output("\n ■ Subtype %s not found in NEWS.RC!", alphatype);
sh_close(infile);
if (text)
free(text);
if (buffer)
free(buffer);
return 1;
}
}
}
if ((nhr.main_type == main_type_email) ||
(nhr.main_type == main_type_email_name) ||
(nhr.main_type == main_type_ssm)) {
output("\n ■ To : %s", mh.toUserName);
} else
output("\n ■ Post to : %s", groupname);
strcpy(_temp_buffer, mh.subject);
j = 0;
for (i = 0; i < strlen(mh.subject); i++) {
if (_temp_buffer[i] == 3)
++i;
else
mh.subject[j++] = _temp_buffer[i];
}
mh.subject[j] = '\0';
output("\n ■ Subject : %s", mh.subject);
outfile = sh_open(outfn, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC | O_EXCL, S_IWRITE);
if (outfile == -1) {
sh_close(infile);
if (buffer)
free(buffer);
if (text)
free(text);
output("\n ■ Unable to open output file %s", outfn);
return 1;
}
time(&some);
time_msg = localtime(&some);
strftime(mh.dateTime, 80, "%a, %d %b %y %H:%M:%S (%Z)", time_msg);
if (nhr.fromsys != net_sysnum) {
sprintf(_temp_buffer, "From: %s@%s (%s)\n", POPNAME, DOMAIN,
mh.fromUserName);
} else {
for (j = 0; j < strlen(mh.fromUserName); j++)
if (mh.fromUserName[j] == ' ')
mh.fromUserName[j] = '_';
if ((spam) && ((nhr.main_type == main_type_post) || (nhr.main_type == main_type_new_post)))
if (spamname[0] == 0)
sprintf(_temp_buffer, "From: %s@dont.spam.me.%s (%s)\n",
POPNAME, DOMAIN,
mh.fromUserName);
else
sprintf(_temp_buffer, "From: %s (%s)\n",
spamname,
mh.fromUserName);
else
sprintf(_temp_buffer, "From: %s@%s (%s)\n",
POPNAME, DOMAIN, mh.fromUserName);
}
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
++cur_daten;
sprintf(_temp_buffer, "Message-ID: <%lx-%s@%s>\n",
cur_daten, POPNAME, DOMAIN);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
if ((nhr.main_type == main_type_email) ||
(nhr.main_type == main_type_email_name) ||
(nhr.main_type == main_type_ssm)) {
if (!tolist) {
sprintf(_temp_buffer, "To: %s\n", mh.toUserName);
if (_temp_buffer[strlen(_temp_buffer) - 1] != '\n')
strcat(_temp_buffer, "\n");
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
} else {
sprintf(fn1, "%sM%s.NET", net_data, alphasubtype);
i = 0;
if ((fp = fsh_open(fn1, "rt")) != NULL) {
while (fgets(_temp_buffer, 80, fp) != NULL) {
if (strstr(_temp_buffer, "@")) {
strcpy(mh.toUserName, _temp_buffer);
sprintf(_temp_buffer, "To: %s", mh.toUserName);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
i = 1;
}
}
if (fp != NULL)
fclose(fp);
}
if (!i) {
sh_close(infile);
if (buffer)
free(buffer);
if (text)
free(text);
output("\n ■ Error processing mailing list %s.", alphasubtype);
return (1);
}
}
} else {
sprintf(_temp_buffer, "Newsgroups: %s\n", groupname);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
}
sprintf(_temp_buffer, "Subject: %s\n", mh.subject);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
sprintf(_temp_buffer, "Date: %s\n", mh.dateTime);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
sprintf(_temp_buffer, "Path: %s!%s\n", POPNAME, DOMAIN);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
sprintf(_temp_buffer, "Organization: %s * %s\n",
syscfg.systemname, syscfg.systemphone);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
if (tolist) {
sprintf(_temp_buffer, "Reply-To: %s@%s (%s)\n",
POPNAME, DOMAIN, alphasubtype);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
} else
if ((!spam) && ((nhr.main_type != main_type_post) || (nhr.main_type != main_type_new_post))) {
sprintf(_temp_buffer, "Reply-To: %s@%s (%s)\n",
POPNAME, DOMAIN, mh.fromUserName);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
}
if (tolist) {
sprintf(_temp_buffer, "Source: %s Mail List\n", alphasubtype);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
}
sprintf(_temp_buffer, "Version: WWIV PPP Project %s\n\n", VERSION);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
if ((spam) && ((nhr.main_type == main_type_post) || (nhr.main_type == main_type_new_post))) {
sprintf(_temp_buffer, "Reply-to: %s@%s (%s)\n\n",
POPNAME, DOMAIN, mh.fromUserName);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
}
if ((nhr.main_type != main_type_email) &&
(nhr.main_type != main_type_email_name) &&
(strncmp(mh.toUserName, "ALL", 3) != 0)) {
sprintf(_temp_buffer, "Responding to: %s\n", mh.toUserName);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
}
for (i = 0; i < strlen(text); i++)
if (text[i] == 227)
text[i] = '\n';
sh_write(outfile, text, strlen(text));
sprintf(tagfn, "%sI%u.TAG", syscfg.datadir, stype);
if (exist(tagfn))
strcpy(tagfile, tagfn);
tagfn[0] = 0;
ns = 0;
for (i6 = 0; i6 < 99; i6++) {
sprintf(tagfn, "%sI%u.T%d", syscfg.datadir, i6);
if (exist(tagfn))
ns++;
else
break;
}
sprintf(tagfn, "%sI%u.T%d", syscfg.datadir, random(ns));
if (exist(tagfn))
strcpy(tagfile, tagfn);
if (tagfile[0] == 0) {
sprintf(_temp_buffer, "\n\nOrigin: %s * %s\n\n",
syscfg.systemname, syscfg.systemphone);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
} else {
if ((fp = fsh_open(tagfile, "rt")) == NULL)
output("\n ■ Error reading %s.", tagfile);
else {
sprintf(_temp_buffer, "\n\n");
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
while (fgets(_temp_buffer, 120, fp)) {
for (i = 0; ((i < strlen(_temp_buffer)) &&
(_temp_buffer[i] != '\r') && (_temp_buffer[i] != '\n')); i++)
if ((_temp_buffer[i] < 32) || (_temp_buffer[i] > 126))
_temp_buffer[i] = 32;
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
}
if (fp != NULL)
fclose(fp);
sprintf(_temp_buffer, "\n\n");
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
}
}
sh_close(outfile);
} else {
if ((nhr.main_type >= 0x01) && (nhr.main_type <= 0x1b))
output("\n ■ %s message skipped",
main_type[nhr.main_type - 1]);
else
output("\n ■ Unknown Main_type %hd skipped", nhr.main_type);
}
}
sh_close(infile);
unlink(fn);
if (text)
free(text);
if (buffer)
free(buffer);
return (0);
}
void get_dir(char *s, int be)
{
strcpy(s, "X:\\");
s[0] = 'A' + getdisk();
getcurdir(0, s + 3);
if (be) {
if (s[strlen(s) - 1] != '\\')
strcat(s, "\\");
}
}
int main(int argc, char *argv[])
{
char fn[MAXPATH], *ss;
int f, f1, i;
struct ffblk ff;
struct date dt;
struct time tm;
/* 0 1 2 3 4 5 6 */
/* exp s32767.net, net_data, net_sysnum, popname, domain, net_name */
/* exp netlog/contact, net_data, sysnum, sent recd totaltime */
output("\n ■ PPP Import/Export %s", VERSION);
if (argc != 7) {
output("\n ■ EXP <filename> <net_data> <net_sysnum> <POPNAME> <DOMAIN> <net_name>\n\n");
if (argc > 1) {
output("Command line was: ");
for (i = 0; i < argc; i++)
output("%s ", argv[i]);
output("\n\n");
}
return (1);
}
detect_multitask();
get_dir(maindir, 1);
strcpy(net_data, argv[2]);
sprintf(fn, "%s%s", net_data, argv[1]);
net_name = argv[6];
strcpy(POPNAME, argv[4]);
strcpy(DOMAIN, argv[5]);
net_sysnum = atoi(argv[3]);
tagfile[0] = 0;
spam = 0;
f = sh_open1("CONFIG.DAT", O_RDONLY | O_BINARY);
if (f < 0) {
output("Could not open CONFIG.DAT!\n\n");
return (1);
}
sh_read(f, (void *) &syscfg, sizeof(configrec));
sh_close(f);
ss = getenv("WWIV_INSTANCE");
if (ss) {
instance = atoi(ss);
if (instance >= 1000) {
output("\n ■ WWIV_INSTANCE set to %hd. Can only be 1..999!",
instance);
instance = 1;
}
} else
instance = 1;
parse_net_ini();
gettime(&tm);
getdate(&dt);
cur_daten = dostounix(&dt, &tm);
/*
output("\n ■ Postmaster default account set to %s #%hd.",
strupr(postmaster), defuser);
output("\n ■ Using user %s on outbound Internet mail.",
use_alias ? "aliases" : "real names");
if (spam)
output("\n ■ Using bogus originating address on newsgroup posts.");
if (tagfile[0] != 0)
output("\n ■ Using signature file : %s", tagfile);
*/
strupr(postmaster);
export(fn);
sprintf(fn, "%sSPOOL\\UNK*.*", net_data);
f1 = findfirst(fn, &ff, 0);
while (f1 == 0) {
sprintf(fn, "%sSPOOL\\%s", net_data, ff.ff_name);
if (!import(fn)) {
unlink(fn);
}
f1 = findnext(&ff);
}
if (maillist != NULL)
free(maillist);
return 0;
}