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
/
msgproc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-25
|
11KB
|
459 lines
#include <stdio.h>
#include <dir.h>
#include <errno.h>
#include <ctype.h>
#include <modes.h>
#include "mailbox.h"
#define MAX_AGE 5 /* Max #days for SALE, @ALLUS and @WW */
struct userstruct user;
int debugflag = 0;
int bbsflag = 0;
int sysopflag = 0;
int quietflag = 0;
extern int xflag;
main (argc, argv)
char *argv[];
{
chdir (HOME);
strcpy (user.uscall, "MPROC");
user.usopt = ISSUPER;
xflag = 1;
if (argc < 2)
{
printf ("Process a new BBS message.\n\n");
printf ("form: msgproc [<options>] <message #>\n");
printf ("\nOptions are:\n");
printf (" -b Sender is a BBS\n");
printf (" -s Sender is a sysop\n");
printf (" -q Supress output of messages\n");
printf (" -d[d...] Provide debugging output\n");
exit (0);
}
while (--argc > 0 && (++argv)[0][0]=='-')
{
char *cp = argv[0] + 1;
while (*cp)
switch (*cp++)
{
case 'd':
debugflag++;
continue;
case 'b':
bbsflag++;
continue;
case 's':
sysopflag++;
continue;
case 'q':
quietflag++;
continue;
default:
fprintf(stderr, "Unknown flag '%c'\n", *(cp-1));
continue;
}
}
if (argc<=0)
{
fprintf (stderr, "Insufficient arguments\n");
exit(0);
}
open_mail ();
while (argc--)
msgproc (atoi (*argv++));
close_mail ();
}
msgproc (msgnum)
{
struct msg_header *head;
int file;
reset_mail ();
if (!(head = next_mail (is_num, msgnum)))
reject ("No record", msgnum);
if ((file = open_msg (head)) <= 0)
reject ("Can't open file", msgnum);
read_dist_list ();
copy_msg (head);
check_file (head, file);
check_hold (head);
build_haddr (head);
close (file);
}
check_file (head, f)
struct msg_header *head;
{
char str[256], out[256];
int len;
char bbs[7], *p;
int msg_num;
int repeat = 0;
int orig = 0, jorig;
if (debugflag) printf ("check_file %d\n", head->mhnr);
lseek (f, 0L, 0);
while (len = readln (f, str, 256))
{
str[len-1] = '\0';
if (parse_head (str, out) > 1 && *out == 'R')
{
for (p = out; *p; p += strlen (p) + 1)
{
if (*p == '@')
{
scanword (p+1, bbs, sizeof (bbs));
get_ssid (bbs);
upper (bbs);
if (strcmp (bbs, MYCALL) == 0)
repeat++;
checkoff (head, bbs);
}
else if (*p == 'R')
orig = strToDate (p+1);
else if (*p == '#')
msg_num = atoi (p+1);
}
}
}
if (debugflag) printf (" repeat=%d orig =%02d/%02d/%02d\n", repeat,
(orig>>8)&0xff, orig & 0xff, (orig>>16)-1900);
if (repeat > 1)
{
head->mhstat = 'H';
update_mail ();
notify (head, "Seen this one already");
reject ("Seen this one already", head->mhnr);
}
if ((is_to (head, "SALE") || is_at (head, "WW") || is_at (head, "ALLUS")) && orig)
{
int i;
int time, date, tick, day;
_sysdate (1, &time, &date, &day, &tick);
_julian (&i, &orig);
orig += MAX_AGE;
gregorian (&i, &orig);
head->mhdate_xpir = orig;
update_mail ();
_julian (&i, &orig);
if (orig < date)
{
head->mhstat = 'X';
update_mail ();
log ("K %d %s", head->mhnr, "Too old");
reject ("Bulletin too old", head->mhnr);
}
}
if (bulletin (head) && *head->mhbid == '\0')
{
sprintf (head->mhbid, "%d_%s", msg_num, bbs);
if (debugflag) printf (" synthesized bid='%s'\n", head->mhbid);
update_mail ();
log ("M %d $ %s", head->mhnr, head->mhbid);
}
}
test_hold (head, line, action)
struct msg_header *head;
char *line;
char **action;
{
char w[40], w2[40], *p = line;
while (*p)
{
p += scanword (p, w, 40);
if (w[0] == ':') break;
if (debugflag > 1)
printf (" test %s\n", w);
if (w[0] == '!')
switch (toupper (w[1]))
{
case '>': if (is_to (head, w+2)) return 0; break;
case '<': if (is_from (head, w+2)) return 0; break;
case '@': if (is_at (head, w+2)) return 0; break;
case '$': if (strncmp (head->mhbid, w+2, strlen (w+2)) == 0) return 0; break;
case 'L': sprintf (w2, "*%s*", w+2);
if (is_title (head, w2)) return 0;
break;
case 'T': if (head->mhtype == toupper (w[2])) return 0; break;
case '-': switch (toupper (w[2]))
{
case 'B': if (bbsflag) return 0; break;
case 'S': if (sysopflag) return 0; break;
}
break;
}
else
switch (toupper (w[0]))
{
case '>': if (!is_to (head, w+1)) return 0; break;
case '<': if (!is_from (head, w+1)) return 0; break;
case '@': if (!is_at (head, w+1)) return 0; break;
case '$': if (strncmp (head->mhbid, w+1, strlen (w+1)) != 0) return 0; break;
case 'L': sprintf (w2, "*%s*", w+1);
if (!is_title (head, w2)) return 0;
break;
case 'T': if (head->mhtype != toupper (w[1])) return 0; break;
case '-': switch (toupper (w[1]))
{
case 'B': if (!bbsflag) return 0; break;
case 'S': if (!sysopflag) return 0; break;
}
break;
}
}
if (debugflag > 1)
printf (" passed\n");
if (action)
*action = p;
return 1;
}
check_hold (head)
struct msg_header *head;
{
int f, len;
char line[80], w[40], *action, *comment = 0;
if (debugflag) printf ("check_hold %d\n", head->mhnr);
sprintf (line, "%s/%s", DISDIR, "hold.lst");
if ((f = open (line, 1)) < 0)
return;
while (len = readln (f, line, 80))
{
line[len-1] = '\0';
if (debugflag>1) printf (" %s?\n", line);
for (action = line; *action; action++)
if (*action == ';') break;
if (*action)
{
comment = action + 1;
*action = '\0';
if (debugflag>1) printf (" comment='%s'\n", comment);
}
else
comment = 0;
if (test_hold (head, line, &action))
{
while (*action)
{
action += scanword (action, w, 40);
if (debugflag > 1)
printf (" action = %s\n", w);
switch (toupper (w[0]))
{
case '>': strncpy (head->mhto, w+1, sizeof (head->mhto));
update_mail ();
break;
case '<': strncpy (head->mhfrom, w+1, sizeof (head->mhfrom));
update_mail ();
break;
case '@': strncpy (head->mhbbs, w+1, sizeof (head->mhbbs));
update_mail ();
break;
case 'T': head->mhtype = toupper (w[1]);
update_mail ();
break;
case 'R': head->mhstat = toupper (w[1]);
update_mail ();
if (head->mhstat == 'H')
{
if (comment)
notify (head, comment);
else
notify (head, "On sysop's hold list");
}
break;
}
if (toupper (w[0]) == 'R' && toupper (w[1]) == 'X')
log ("K %d", head->mhnr);
else
log ("M %d %c %s", head->mhnr, toupper (w[0]), w+1);
}
}
}
close (f);
return;
}
notify (head, msg)
struct msg_header *head;
char *msg;
{
struct msg_header savehead, sendhead, *new_head;
char str[80];
int file;
_strass (&savehead, head, sizeof (struct msg_header));
strcpy (sendhead.mhfrom, user.uscall);
strcpy (sendhead.mhto, MYCALL);
sendhead.mhtype = 'P';
sendhead.mhstat = 'N';
sendhead.mhbbs[0] = '\0';
sprintf (str, "Hold notification: Msg. #%d", savehead.mhnr);
strcpy (sendhead.mhtit, str);
reset_mail ();
if ((file = creat_msg (&sendhead, &new_head)) == -1)
return;
sprintf (str, "The following message has been put on hold for review:\n\n");
write (file, str, strlen (str));
print_header (&savehead, file, 1);
sprintf (str, "\nReason: %s\n", msg);
write (file, str, strlen (str));
new_head->mhsize = _gs_size (file);
close (file);
log_send (new_head, 0);
update_mail ();
reset_mail ();
next_mail (is_num, savehead.mhnr);
}
build_haddr (head)
struct msg_header *head;
{
char w[40], *p;
if (debugflag) printf ("build_haddr %d\n", head->mhnr);
scanaddr (head->mhbbs, w, 40);
if (*w && strcmp (w, head->mhbbs) == 0
&& strcmp (w, MYCALL) != 0
&& !bulletin (head))
{
/* Try to build hierarchical address for BBS */
DIR *dirptr;
struct direct *entry;
char *pat = "*";
int len, f1;
char name[40], line[80];
if (debugflag) printf (" BBS='%s', needs H-addr\n", head->mhbbs);
if ((dirptr = opendir ("statebbs")) == NULL)
return; /* Error opening directory */
while (entry = readdir (dirptr))
if (_cmpnam (entry->d_name, pat, strlen (pat)) == 0)
{
sprintf (name, "statebbs/%s", entry->d_name);
if ((f1 = open (name, 1)) > 0)
{
if (debugflag > 1) printf (" trying '%s':", entry->d_name);
while ((len = readln (f1, line, 256)) > 0)
{
line[len-1] = '\0';
scanword (line, name, 40);
upper (name);
get_ssid (name);
if (debugflag > 2) printf (" %s", name);
if (_cmpnam (w, name, strlen (name)) == 0)
{
sprintf (head->mhbbs, "%s.%s", w, entry->d_name);
upper (head->mhbbs);
for (p = head->mhbbs; *p; p++)
if (*p == '_')
*p = '#';
update_mail ();
log ("M %d @ %s", head->mhnr, head->mhbbs);
close (f1);
if (debugflag) printf (" New='%s'\n", head->mhbbs);
goto gotit;
}
}
close (f1);
if (debugflag > 1) printf ("\n");
}
}
gotit: closedir (dirptr);
}
}
copy_msg (head)
struct msg_header *head;
{
struct msg_header newhead;
int f1, f2, len;
char line[256];
int msgnum = head->mhnr;
if (debugflag) printf ("copy_msg %d\n", head->mhnr);
if ((is_to (head, "SYSOP") && is_at (head, "NCPA")) ||
(is_to (head, "SYSOP") && is_at (head, "ALLCAN")) ||
(is_to (head, "SYSOP") && is_at (head, "NBAY")) ||
(is_to (head, "SYSOP") && is_at (head, "NCGATE")) ||
(is_to (head, "SYSOP") && is_at (head, "ALLCA")) ||
(is_to (head, "SYSOP") && is_at (head, "ALLUS")) ||
(is_to (head, "BOARD") && is_at (head, "NCPA")))
{
if (debugflag) printf (" Copying to %s\n", MYCALL);
if ((f1 = open_msg (head)) == -1)
{
if (debugflag) printf (" Error %d opening message file\n", errno);
return;
}
strcpy (newhead.mhfrom, head->mhfrom);
strcpy (newhead.mhto, MYCALL);
strcpy (newhead.mhbbs, MYCALL);
sprintf (line, "Copy of #%d: %s", head->mhnr, head->mhtit);
strncpy (newhead.mhtit, line, 80);
strcpy (newhead.mhbid, "");
newhead.mhsize = head->mhsize;
newhead.mhtype = 'P';
newhead.mhstat = 'N';
if ((f2 = creat_msg (&newhead, &head)) == -1) {
if (debugflag) printf (" Error %d creating message file\n", errno);
return;
}
while ((len = readln (f1, line, 256)) > 0)
writeln (f2, line, len);
close (f1);
close (f2);
log_send (head, 1);
update_mail ();
reset_mail ();
next_mail (is_num, msgnum);
}
}
reject (msg, msgnum)
char *msg;
{
if (!quietflag)
printf ("%d: %s\n", msgnum, msg);
close_mail ();
exit (0);
}
strToDate (s)
char *s;
{
char *p;
int year, month, day;
if (sscanf (s, "%2d%2d%2d", &year, &month, &day) != 3)
return (0);
return (((1900+year) << 16) + (month << 8) + day);
}