home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
OSKBox.lzh
/
MAILBOX
/
CC
/
reverse.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-25
|
7KB
|
364 lines
#include <stdio.h>
#include <ctype.h>
#include <direct.h>
#include <setjmp.h>
#include <signal.h>
#include <dir.h>
#include <errno.h>
#include "mailbox.h"
#define MAXCALLS 3500 /* maximum number of calls to be forwarded */
#define TIMEOUT (5 * 60) /* maximum # of seconds to wait for response */
#define MAXTIME (20 * 60) /* maximum # of seconds to forward */
struct userstruct user;
char fwdcalls[MAXCALLS][7];
int call_count = 0;
jmp_buf disconnected;
int start_fwd, sec;
char *fwdfile;
int fwdsize;
int cmpcall();
int tnc_in = 0, tnc_out = 1;
int mid_flag, bid_flag, hflag;
extern struct dist_list *distboxes;
main (argc, argv)
char *argv[];
{
int i;
chdir (HOME);
if (argc < 4) {
printf ("Insufficient arguments.\n");
exit (0);
}
strcpy (user.uscall, "RVRSFW");
user.usopt = ISSUPER;
mid_flag = atoi (argv[2]);
bid_flag = atoi (argv[3]);
hflag = atoi (argv[4]);
upper (argv[1]);
get_ssid (argv[1]);
read_dist_list ();
read_fwd_files (argv[1]);
open_mail ();
forward (argv[1], fwdfile, fwdsize);
close_mail ();
}
find_call (target)
char *target;
{
int i, p1, p2, comp;
p1 = 0; p2 = call_count-1;
/* printf ("find_call (%s)\n", target); */
while (p1 <= p2) {
i = p1 + ((p2 - p1) >> 1);
comp = cmpcall (target, fwdcalls[i]);
/* printf (" %d %d %d %s %d\n", p1, i, p2, fwdcalls[i], comp); */
if (comp < 0)
p2 = i-1;
else if (comp > 0)
p1 = i+1;
else
break;
}
if (comp != 0) {
return -1;
}
while (i > 0 && cmpcall (target, fwdcalls[i-1]) == 0)
i--;
return (i);
}
test (head, mbox)
struct msg_header *head;
char *mbox;
{
int i;
char *target, bbs[7];
struct dist_list *dp;
scanaddr (head->mhbbs, bbs, 7);
target = (*(head->mhbbs)) ? bbs : head->mhto;
if ((i = find_call (target)) != -1)
for ( ; i < call_count && cmpcall (target, fwdcalls[i]) == 0; i++)
if (_cmpnam (target, fwdcalls[i], strlen (fwdcalls[i])) == 0)
goto found;
if (!bulletin (head) && *(head->mhbbs)) {
char *p, hfield[7];
int len;
p = head->mhbbs + scanaddr (head->mhbbs, hfield, 7);
while (len = scanaddr (p, hfield, 7)) {
#ifdef DEBUG
printf (" hfield '%s'\n", hfield);
#endif
p += len;
if ((i = find_call (hfield)) != -1) {
for (dp = distboxes; dp; dp = dp->dlnext)
if (strcmp (hfield, dp->dlname) == 0) break;
if (dp) continue;
for ( ; i < call_count && cmpcall (hfield, fwdcalls[i]) == 0; i++)
if (_cmpnam (hfield, fwdcalls[i], strlen (fwdcalls[i])) == 0)
goto found;
}
}
}
return 0;
found:
for (dp = distboxes; dp; dp = dp->dlnext)
if (strcmp (bbs, dp->dlname) == 0) break;
if (dp) {
char w[10];
strcpy (w, mbox);
upper (w);
get_ssid (w);
for (i = 0; i < dp->dlcount; i++)
if (strcmp (w, dp->dlbbs[i]) == 0) break;
if ((1 << i) & head->mhdist)
return 0;
}
return 1;
}
forward (mbox, file, size)
char *mbox, *file;
{
struct msg_header *head;
int flag;
read_fwd_file (mbox, file, size);
flag = 0;
reset_mail ();
while ((head = next_mail (is_nforwarded, 0)) != NULL)
if (test (head, mbox)) {
flag = 1;
break;
}
if (!flag) return 0;
reset_mail ();
while ((head = next_mail (is_nforwarded, 0)) != NULL) {
if (test (head, mbox))
send_msg (head, mbox);
}
}
send_msg (head, mbox)
struct msg_header *head;
char *mbox;
{
char str[256], name[32], *p;
int f, len;
char *maildir = "MAIL/";
int time, date, tick;
short day;
struct fildes buffer;
struct dist_list *dp;
char bbs[7];
if ((f = open_msg (head)) < 0)
return 0;
p = str;
p += sprintf (p, "S%c %s", head->mhtype, head->mhto);
scanaddr (head->mhbbs, bbs, 7);
if (*(head->mhbbs))
if (hflag)
p+= sprintf (p, " @ %s", head->mhbbs);
else
p+= sprintf (p, " @ %s", bbs);
p += sprintf (p, " < %s", head->mhfrom);
if (*(head->mhbid) && bid_flag && head->mhtype != 'T')
p += sprintf (p, " $%s", head->mhbid);
printf ("%s\n", str);
get_line (str);
p = str + scanword (str, name, 32);
if (strcmp (name, "OK") != 0) {
log ("r %d %s %s", head->mhnr, mbox, p);
get_prompt ();
goto sent;
}
printf ("%s\n", head->mhtit);
ztime (&head->mhtime, &head->mhdate, &day);
printf ("R:%02d%02d%02d/%02d%02dz @:%s.%s %s #:%d Z:%s\n",
(head->mhdate >> 16) % 100,
(head->mhdate >> 8) & 0xff,
head->mhdate & 0xff,
(head->mhtime >> 16) & 0xff,
(head->mhtime >> 8) & 0xff,
MYCALL, MYHADDR, MYQTH,
head->mhnr,
MYZIP);
while ((len = readln (f, str, 256)) > 0)
writeln (tnc_out, str, len);
close (f);
printf ("\032\n");
get_prompt ();
log ("f %d %s", head->mhnr, mbox);
sent:
if (!checkoff (head, mbox))
if (bulletin (head))
head->mhstat = 'F';
else
head->mhstat = 'X';
update_mail ();
return 1;
}
get_prompt ()
{
char str[256];
while (1) {
get_line (str);
if (str[strlen (str) - 1] == '>')
return;
}
}
get_line (str)
char *str;
{
int len;
int time = 0;
time = tick ();
while (1) {
if (_gs_eof (tnc_in) == 1)
exit (0);
if (_gs_rdy (tnc_in) > 0)
break;
sleep (3);
if ((tick() - time) / sec > TIMEOUT)
exit (0);
}
read_path (tnc_in, str, 80);
}
write_path (path, str)
char *str;
{
write (path, str, strlen (str));
}
read_path (path, str, len)
char *str;
{
int i;
i = readln (path, str, len);
if (i)
str[i-1] = '\0';
return i;
}
read_fwd_file (mbox, file, size)
char *mbox, *file;
{
char str[80], w[7], *p, *p2;
int i, f, len;
call_count = 0;
strcpy (str, mbox);
get_ssid (str);
strcpy (fwdcalls[call_count++], str);
for (p2 = file; p2 < file + size; p2 += strlen (p2) + 1) {
strcpy (str, p2);
p = str + scanword (str, w, 7);
if (strcmp (w, "VIA") == 0) {
continue;
}
else if (*w && *w != '@' && *w != ';') {
get_ssid (w);
if (call_count < MAXCALLS)
strcpy (fwdcalls[call_count++], w);
}
}
qsort (fwdcalls, call_count, 7, cmpcall);
}
read_fwd_files (call)
char *call;
{
DIR *dirptr;
struct direct *entry;
char str[80], w[7], *p;
int i, f, len;
if ((dirptr = opendir (FWDIR)) == NULL)
exit (_errmsg (0, "Error %d opening mailbox directory.\n", errno));
sprintf (str, "%s*.fwd", call);
while (entry = readdir (dirptr)) {
if (_cmpnam (entry->d_name, str, strlen (str)) == 0) break;
}
closedir (dirptr);
if (entry == NULL)
exit (_errmsg (0, "No matching .fwd file found.\n"));
fwdfile = (char *)malloc (1);
fwdsize = read_file (entry->d_name, &fwdfile, 0);
return (1);
}
read_file (name, pptr, size)
char *name, **pptr;
{
int f, fsize, tsize;
char *fptr, *p, line[80];
if (*name == '/')
strcpy (line, name);
else
sprintf (line, "%s/%s", FWDIR, name);
if ((f = open (line, 1)) < 0)
return (size);
fsize = _gs_size (f);
fptr = (char *)malloc (size + fsize);
if (size) movmem (*pptr, fptr, size);
read (f, fptr + size, fsize);
close (f);
for (p = fptr + size; p - fptr < size + fsize; p++) {
*p = toupper (*p);
if (*p == '\n')
*p = '\0';
}
free (*pptr);
*pptr = fptr;
tsize = size + fsize;
for (p = fptr + size; p - fptr < size + fsize; p += strlen (p) + 1) {
if (*p == '@') {
strcpy (line, p+1);
tsize = read_file (line, pptr, tsize);
p = *pptr + (p - fptr);
fptr = *pptr;
}
}
return (tsize);
}
tick ()
{
int time, date, i_tick;
short day;
_sysdate (3, &time, &date, &day, &i_tick);
sec = i_tick >> 16;
return (time * sec + (i_tick & 0xFFFF));
}
cmpcall (c1, c2)
register char *c1, *c2;
{
while (*c1 == *c2) {
if (*c1 == '\0') return 0;
c1++;
c2++;
}
if (*c1 == '?' || *c1 == '*' || *c2 == '?' || *c2 == '*')
return 0;
else
return (*c1 - *c2);
}