home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
PPPBCKP
/
SRC
/
SRC15B24.ZIP
/
EXP.C
< prev
next >
Wrap
Text File
|
1997-04-05
|
31KB
|
1,142 lines
#include <stdio.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 "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];
};
configrec syscfg;
char *net_name, postmaster[31], net_data[MAXPATH], POPNAME[21], DOMAIN[81], tagfile[MAXPATH], maindir[MAXPATH];
unsigned short net_sysnum, defuser, num_users, use_alias, instance, curuser, spam;
int multitasker = 0;
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();
}
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 *) _fstrchr(fmode, 'w')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT | O_TRUNC;
} else
if (((char *) _fstrchr(fmode, 'a')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT;
} else {
md = O_RDONLY;
}
if (((char *) _fstrchr(fmode, 'b')) != NULL) {
md |= O_BINARY;
}
if (((char *) _fstrchr(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 *) _fstrchr(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 *) _fstrchr(whitespace, s[i - 1]) != NULL))
--i;
while ((i > 0) && ((char *) _fstrchr(whitespace, *s) != NULL)) {
memmove(s, s + 1, --i);
}
s[i] = 0;
return (s);
}
int num_to_name(char *where, int whichuser, int alias);
void parse_net_ini(void)
{
char s[MAXPATH], line[121], *ss;
FILE *fp;
defuser = 1;
use_alias = 1;
sprintf(s, "%sNET.INI", maindir);
fp = fsh_open(s, "rt");
if (!fp) {
fprintf(stderr, "\n ■ Unable to open %s.", s);
return;
}
while (fgets(line, 80, fp)) {
ss = NULL;
stripspace(line);
/* fprintf(stderr, "\nCurrent : %s\n", line); */
if ((line[0] == ';') || (line[0] == '\n') || (line[0] == '['))
continue;
if (strlen(line) == 0)
continue;
if (strnicmp(line, "POSTMASTER", 10) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
if (ss)
defuser = atoi(ss);
}
}
if (strnicmp(line, "SPAMCONTROL", 11) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
if ((ss[0] == 'y') || (ss[0] == 'Y'))
spam = 1;
}
}
if (strnicmp(line, "SIGNATURE", 9) == 0) {
ss = strtok(line, "=");
if (ss) {
ss = strtok(NULL, "\n");
trimstr1(ss);
strcpy(tagfile, ss);
if (!exist(tagfile)) {
fprintf(stderr, "\n ■ Default signature file %s not found!", tagfile);
tagfile[0] = 0;
}
}
}
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);
fclose(fp);
return;
}
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) {
fprintf(stderr, "\n ■ Cannot open %s.", fn);
return (found);
}
num_users = ((int) (filelength(userfile) / sizeof(userrec)));
if (whichuser > num_users) {
fprintf(stderr, "\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)
fprintf(stderr, "\n ■ User #%d has blank real name field!", whichuser);
else {
if (ur.inact == inact_deleted)
fprintf(stderr, "\n ■ User #%d is marked as deleted!", whichuser);
else {
if (!alias)
strcpy(where, ur.realname);
else {
strlwr(ur.name);
strcpy(where, ur.name);
}
found = 1;
}
}
sh_close(userfile);
return (found);
}
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);
}
int name_to_num(char *name)
{
int userfile, usernum;
userrec ur;
long pos;
char fn[MAXPATH], ur_name[60], ur_realname[60];
sprintf(fn, "%sUSER.LST", syscfg.datadir);
userfile = sh_open1(fn, O_RDONLY | O_BINARY);
if (userfile < 0) {
fprintf(stderr, "\n ■ Cannot open %s", fn);
return (0);
} else
fprintf(stderr, "\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) {
fprintf(stderr, " user #%d is deleted account.", usernum);
usernum = 0;
break;
} else {
fprintf(stderr, " matched user #%d.", usernum);
break;
}
}
}
userfile = sh_close(userfile);
if (usernum >= num_users) {
fprintf(stderr, "... 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)) {
if ((strcspn(name, " ")) < (strcspn(name, "<"))) {
ss = strtok(name, "<");
trimstr1(ss);
strcpy(name, ss);
curuser = name_to_num(name);
} else {
fprintf(stderr, "\nName is *after* host in \"%s\"", name);
}
}
if (curuser == 0)
return ('\0');
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;
}
}
int import(char *fn)
{
char s[513], pktname[MAXPATH], msgdate[31], *ss, *p;
int f, from, subj, intext, done;
long textlen, reallen;
struct msghdr mh;
net_header_rec nh;
struct date dt;
struct time tm;
FILE *fp;
intext = 0;
f = sh_open1(fn, O_RDONLY | O_BINARY);
if (f < 0)
return (1);
textlen = filelength(f);
if (textlen > 32767L) {
fprintf(stderr, "\n ■ Skipping %s - greater than 32K.", fn);
return (1);
}
p = (char *) malloc(textlen + 1);
if (p == NULL) {
fprintf(stderr, "\n ■ Unable to allocate %ld bytes.", textlen);
return (1);
}
sh_read(f, (void *) p, textlen);
sh_close(f);
nh.tosys = net_sysnum;
nh.fromsys = 32767L;
nh.fromuser = 0;
nh.touser = defuser;
nh.main_type = main_type_email;
nh.minor_type = 0;
nh.list_len = 0;
gettime(&tm);
getdate(&dt);
nh.daten = dostounix(&dt, &tm);
nh.method = 0;
fp = fsh_open(fn, "rb");
if (!fp) {
free(p);
return (1);
}
from = subj = done = 0;
while ((fgets(s, 254, fp)) && !done) {
if ((s[0] == '\r') || (s[0] == '\n') || (s[0] == 0))
intext = 1;
if (s[0] == 4) {
ss = strtok(s, "R");
ss = strtok(NULL, "\r\n");
strcpy(s, ss);
}
if (!intext) {
if ((strncmpi(s, "reply-to:", 9) == 0)) {
from = 1;
ss = strtok(s, ": ");
ss = strtok(NULL, "\r\n");
trimstr1(ss);
/* strncpy(mh.fromUserName, ss, 46); */
strcpy(mh.fromUserName, ss);
if (strlen(mh.fromUserName) > 190)
mh.fromUserName[190] = '\0';
strcat(mh.fromUserName, "\r\n");
} else
if ((strncmpi(s, "from:", 5) == 0) && (!from)) {
from = 1;
ss = strtok(s, ": ");
ss = strtok(NULL, "\r\n");
trimstr1(ss);
/* strncpy(mh.fromUserName, ss, 46); */
strcpy(mh.fromUserName, ss);
if (strlen(mh.fromUserName) > 190)
mh.fromUserName[190] = '\0';
strcat(mh.fromUserName, "\r\n");
} else
if ((strncmpi(s, "return-path:", 12) == 0) && (!from)) {
ss = strtok(s, ": ");
ss = strtok(NULL, "\r\n");
trimstr1(ss);
/* strncpy(mh.fromUserName, ss, 46); */
strcpy(mh.fromUserName, ss);
if (strlen(mh.fromUserName) > 190)
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);
strcpy(mh.subject, ss);
if (strlen(mh.subject) > 72)
mh.subject[72] = '\0';
else
mh.subject[strlen(mh.subject)] = '\0';
} else
if ((strncmpi(s, "to:", 3) == 0) || (strncmpi(s, "cc:", 3) == 0)) {
ss = strtok(s, ": ");
ss = strtok(NULL, "\r\n");
strcpy(mh.toUserName, ss);
trimstr1(mh.toUserName);
if (_fstrstr(mh.toUserName, " "))
find_name(mh.toUserName);
else
mh.toUserName[0] = '\0';
if ((mh.toUserName[0] == 0) || (curuser == 0)) {
nh.touser = defuser;
strcpy(mh.toUserName, postmaster);
} else
nh.touser = curuser;
}
} else
done = 1;
}
fclose(fp);
fprintf(stderr, "\n ■ From : %s", mh.fromUserName);
fprintf(stderr, " ■ Sent to : %s #%hd", strupr(mh.toUserName), nh.touser);
fprintf(stderr, "\n ■ Subject : %s", mh.subject);
name_packet(pktname);
fp = fsh_open(pktname, "wb");
if (fp < 0) {
fprintf(stderr, "\n ■ Unable to create packet %s", pktname);
free(p);
return (1);
}
strncpy(msgdate, ctime(&(time_t) nh.daten), 24);
msgdate[24] = '\0';
strcat(msgdate, "\r\n");
nh.length = textlen + strlen(mh.fromUserName) + strlen(mh.subject) + strlen(msgdate) + 1;
fsh_write(&nh, sizeof(net_header_rec), 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);
reallen = fsh_write(p, sizeof(char), textlen, fp);
if (reallen != textlen)
fprintf(stderr, "\n ■ Expected %ld bytes, wrote %ld bytes.", textlen, reallen);
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 {
s[i1] = text[i];
i1++;
}
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;
unsigned stype, ttype;
int infile, outfile, inloc, outloc, term, ok, i, j;
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"
};
if ((infile = sh_open1(fn, O_RDONLY | O_BINARY)) == -1)
return (1);
if ((buffer = (char *) malloc(32 * 1024)) == NULL) {
fprintf(stderr, "\n ■ Out of memory allocating input buffer!");
return (1);
}
if ((text = (char *) malloc(32 * 1024)) == NULL) {
fprintf(stderr, "\n ■ Out of memory allocating output buffer!");
if (buffer)
free(buffer);
buffer = NULL;
return (1);
}
while (sh_read(infile, &nhr, sizeof(nhr))) {
sh_read(infile, buffer, nhr.length);
if (nhr.tosys != 32767) {
fprintf(stderr, "\n ■ Non-Internet system routing via @32767... aborting export.");
return (1);
}
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;
if ((nhr.main_type == main_type_email_name) ||
(nhr.main_type == main_type_ssm)) {
stype = nhr.minor_type;
inloc = strlen(buffer) + 1;
strcpy(mh.toUserName, buffer);
if (nhr.fromsys != net_sysnum) {
fprintf(stderr, "\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) {
if (!num_to_name(mh.fromUserName, nhr.fromuser, use_alias)) {
fprintf(stderr, "\n ■ No match for user #%hd... skipping message!",
nhr.fromuser);
continue;
}
} else {
if (!num_to_name(mh.fromUserName, nhr.fromuser, 1)) {
fprintf(stderr, "\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.fromsys != net_sysnum)) {
sprintf(_temp_buffer, " #%hd @%hu", nhr.fromuser, nhr.fromsys);
strcat(mh.fromUserName, _temp_buffer);
}
}
inloc = term + 2;
while (buffer[inloc] != '\n')
inloc++;
inloc++;
if (strncmp(&buffer[inloc], "0R", 3) == 0) {
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], sizeof(mh.subject));
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);
inloc = term + 2;
} else {
if (nhr.main_type != main_type_email_name) {
strcpy(mh.toUserName, "ALL\n");
}
}
outloc = 0;
do {
if (buffer[inloc] == 2) {
i = inloc + 1;
for (j = 1; j < 80; j++) {
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] == 4) && (buffer[inloc + 1] == '0')) {
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';
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_post:
case main_type_pre_post:
i = 1;
sprintf(outfn, "%sOUTBOUND\\%d.%d", net_data, stype, i);
while (exist(outfn))
sprintf(outfn, "%sOUTBOUND\\%d.%d", net_data, stype, ++i);
break;
default:
continue;
}
fprintf(stderr, "\n ■ Creating: %s", outfn);
fprintf(stderr, "\n ■ From : %s", mh.fromUserName);
if ((nhr.main_type == main_type_post) ||
(nhr.main_type == main_type_pre_post)) {
sprintf(fn1, "%sNEWS.RC", net_data);
fp = fsh_open(fn1, "rt");
if (!fp)
fprintf(stderr, "\n ■ %s not found!", fn1);
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");
ttype = atoi(ss);
if (ttype == stype)
ok = 1;
}
}
*ss = NULL;
fclose(fp);
}
}
if ((nhr.main_type == main_type_email) ||
(nhr.main_type == main_type_email_name) ||
(nhr.main_type == main_type_ssm)) {
fprintf(stderr, "\n ■ To : %s", strlwr(mh.toUserName));
} else {
if (groupname[0] == 0)
fprintf(stderr, "\n ■ No match for subtype %u in NEWS.RC", stype);
else
fprintf(stderr, "\n ■ Post to : %s", groupname);
}
fprintf(stderr, "\n ■ Subject : %s", mh.subject);
outfile = sh_open(outfn, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC | O_EXCL, S_IWRITE);
if (outfile == -1) {
if (buffer)
free(buffer);
if (text)
free(text);
fprintf(stderr, "\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);
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)))
sprintf(_temp_buffer, "From: nowhere@no.net (%s)\n",
mh.fromUserName);
else
sprintf(_temp_buffer, "From: %s@%s (%s)\n",
POPNAME, DOMAIN, mh.fromUserName);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
delay(2000);
sprintf(_temp_buffer, "Message-ID: <%lx-%s@%s>\n",
time(NULL), 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)) {
sprintf(_temp_buffer, "To: %s\n",
mh.toUserName);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
} 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, "Organization: %s * @%hu.%s * %s\n",
syscfg.systemname, net_sysnum, net_name, syscfg.systemphone);
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",
POPNAME, DOMAIN, mh.fromUserName);
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));
}
sh_write(outfile, text, strlen(text));
sprintf(tagfn, "%sI%u.TAG", syscfg.datadir, stype);
if (exist(tagfn))
strcpy(tagfile, tagfn);
if (tagfile[0] == 0) {
sprintf(_temp_buffer, "\n\nOrigin: %s * %s * @%hu.FILEnet\n\n",
syscfg.systemname, syscfg.systemphone, net_sysnum);
sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
} else {
fp = fsh_open(tagfile, "rt");
if (!fp)
fprintf(stderr, "\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));
}
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 <= 0x14))
fprintf(stderr, "\n ■ %s message skipped",
main_type[nhr.main_type - 1]);
else
fprintf(stderr, "\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, maxmail, i;
struct ffblk ff;
/* 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 */
fprintf(stderr, "\n ■ PPP Import/Export %s", VERSION);
if (argc != 7) {
fprintf(stderr, "\n ■ EXP <filename> <net_data> <net_sysnum> <POPNAME> <DOMAIN> <net_name>\n\n");
if (argc > 1) {
fprintf(stderr, "Command line was: ");
for (i = 0; i < argc; i++)
fprintf(stderr, "%s ", argv[i]);
fprintf(stderr, "\n\n");
}
return (1);
}
if (get_nb_version())
multitasker = 8;
else
detect_multitask();
switch (multitasker) {
case 1:
get_dv_version();
break;
case 2:
get_win_version();
break;
case 3:
get_dv_version();
break;
case 4:
case 5:
case 6:
case 7:
break;
case 8:
multitasker = 1;
break;
default:
break;
}
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) {
fprintf(stderr, "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) {
fprintf(stderr, "\n ■ WWIV_INSTANCE set to %hd. Can only be 1..999!",
instance);
instance = 1;
}
} else
instance = 1;
parse_net_ini();
fprintf(stderr, "\n ■ Postmaster default account set to %s #%hd.",
strupr(postmaster), defuser);
fprintf(stderr, "\n ■ Using user %s on outbound Internet mail.",
use_alias ? "aliases" : "real names");
if (spam)
fprintf(stderr, "\n ■ Using bogus originating address on newsgroup posts.");
if (tagfile[0] != 0)
fprintf(stderr, "\n ■ Using signature file : %s", tagfile);
export(fn);
sprintf(fn, "%sSPOOL\\UNK*.*", net_data);
f1 = findfirst(fn, &ff, 0);
maxmail = 14;
while ((f1 == 0) && maxmail) {
sprintf(fn, "%sSPOOL\\%s", net_data, ff.ff_name);
if (!import(fn)) {
unlink(fn);
--maxmail;
}
f1 = findnext(&ff);
}
return 0;
}