home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
BTMTSRC3.ZIP
/
MAILER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-25
|
21KB
|
785 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was written by Bob Hartman */
/* */
/* */
/* BinkleyTerm Mail Control Routines */
/* */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.240. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:132/491, 1:141/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n132.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <conio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <process.h>
#include <stdlib.h>
#include <io.h>
#include "com.h"
#include "xfer.h"
#include "zmodem.h"
#include "keybd.h"
#include "sbuf.h"
#include "sched.h"
#include "externs.h"
#include "prototyp.h"
#include "vfossil.h"
int unattended()
{
MAILP mp;
int i, j, m, r, tmp;
long init_timer, t, t1; /* used for the timeouts */
int done = 1; /* if we exit with this, get out of BT */
FILE *tfile;
char jbuf[60];
un_attended = 1;
clear_statusline ();
comm_bits = BITS_8;
parity = NO_PARITY;
stop_bits = STOP_1;
set_prior(4); /* Always High */
MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
set_prior(2); /* Regular */
if (fullscreen)
{
screen_clear();
sb_dirty();
}
opening_banner();
if (fullscreen)
mailer_banner();
if ((tfile = fopen ("BINKLEY.BAN", "rb")) != NULL)
{
fread (BBSwelcome, 1, 1000, tfile);
fclose (tfile);
}
else
BBSwelcome[0] = '\0';
/* Initialize the random number generator */
i = (int) time (NULL);
srand ((unsigned int) i);
status_line ("+begin, %s", xfer_id);
set_xy ("");
set_prior(4); /* Always High */
XON_DISABLE ();
set_prior(2); /* Regular */
/* Turn off forced events */
if (noforce)
{
find_event ();
noforce = 0;
}
if (redo_dynam)
{
for (i = 0; i < num_events; i++)
e_ptrs[i]->behavior &= ~MAT_SKIP;
redo_dynam = 0;
}
/*
* See if we should exit before initializing the modem (and therefore
* possibly letting a call sneak through)
*/
find_event ();
do_ready (msgtxt[M_READY_INIT]);
/* Make sure we have all necessary parameters and that the nodelist
* index gets read in. If not, then we must exit right now.
*/
if (!net_params || !nodefind (&boss_addr, 0))
if (boss_addr.Net != -1)
{
status_line (msgtxt[M_MISCONFIGURED]);
errl_exit (254);
}
/* Set up outbound mail */
list_next_event ();
set_up_outbound ();
if (!CARRIER)
{
set_prior(4); /* Always High */
mdm_init (modem_init); /* Reinitialize the modem */
set_prior(2); /* Regular */
}
init_timer = timerset ((unsigned int)60000); /* Set a 10 minute timer */
t1 = timerset ((unsigned) next_minute ()); /* Set a 1 minute timer */
top_of_mail:
un_attended = 1;
i = 0;
m = 1;
/* As long as we don't press a key */
bad_char:
r = 0;
more_mail = 1;
while (!(KEYPRESS () || ctrlc_ctr))
{
find_event ();
/* Show that we are ready */
if (m)
{
if (fullscreen)
{
do_ready (msgtxt[M_READY_WAITING]);
list_next_event ();
}
else
status_line (msgtxt[M_EVENT_WAITING], cur_event + 1);
init_timer = timerset ((unsigned int)60000); /* Set a 10 minute timer */
t1 = timerset ((unsigned) next_minute ()); /* Set a 1 minute timer */
}
if (timeup (t1))
{
put_up_time ();
list_next_event ();
t1 = timerset ((unsigned) next_minute ()); /* Set a 1 minute timer */
}
/* If we haven't gotten anything in 10 minutes, re-init the modem */
if (timeup (init_timer))
{
set_prior(4); /* Always High */
mdm_init (modem_init);
set_prior(2); /* Regular */
init_timer = timerset ((unsigned int)60000); /* Set a 10 minute timer */
/*
* Say that we have more mail so that things entered through other
* side of a multi-tasker will still go out
*/
set_up_outbound ();
more_mail = 1;
screen_blank = 1;
if (fullscreen)
sb_show ();
}
m = 0;
if (cur_event >= 0)
{
i = (e_ptrs[cur_event]->behavior & MAT_OUTONLY);
t = random_time (e_ptrs[cur_event]->wait_time);
}
else
{
i = 1;
t = random_time (5);
}
/* variable 'i' will be TRUE if we are either manually dialing out
* or if we are in an event where we do not want incoming stuff.
*/
while ((!timeup (t)) && (!KEYPRESS ()) && (m == 0) && !ctrlc_ctr)
{
find_event ();
time_release ();
if (timeup (t1))
{
put_up_time ();
list_next_event ();
t1 = timerset ((unsigned) next_minute ()); /* Set a 1 minute timer */
}
/* If we want inbound, see if there is any. If we send anything, clean up afterwards ... */
if (!i)
{
m = handle_inbound_mail ();
if (m)
xmit_sameplace ();
}
}
if ((m) && (fullscreen))
{
do_ready (msgtxt[M_READY_WAITING]);
list_next_event ();
}
immed_call:
find_event ();
/* If we are not in an event, loop again */
if (cur_event < 0)
{
time_release ();
continue;
}
/* If we have pressed a key, get out */
if (KEYPRESS () || ctrlc_ctr)
break;
/* See if we are supposed to do any mail */
if (cur_event >= 0)
if (e_ptrs[cur_event]->behavior & MAT_NOOUT)
continue;
if (more_mail)
{
more_mail = xmit_next (&next_addr);
if (more_mail)
{
/* save the next call in the list in case we exit */
if ((next_mail == NULL) || (next_mail->next == NULL))
{
mp = mail_top;
}
else
{
mp = next_mail->next;
}
hist.next_zone = mp->mail_addr.Zone;
hist.next_net = mp->mail_addr.Net;
hist.next_node = mp->mail_addr.Node;
set_prior(4); /* Always High */
m = do_mail (&next_addr, 0);
set_prior(2); /* Regular */
r = (m == 1) ? 1 : 0;
if (r) /* Did we connect? */
{
if (!sent_mail)
{
/* We connected but the transfer didn't work */
bad_call (&next_addr, 1);
}
else
{
/* We got through, so delete his status file */
bad_call (&next_addr, -1);
xmit_delete ();
}
}
else if (m == 2) /* Nothing happened */
bad_call (&next_addr, 2);
/* If we did some processing */
if (m > 0)
{
/* We got inbound mail */
if (got_arcmail || got_packet || got_mail)
receive_exit ();
}
else if (m == -1)
{
status_line (msgtxt[M_INCOMING_CALL]);
}
}
}
if (!more_mail)
{
/* No more mail to do, was it dynamic? */
if (cur_event >= 0)
if (e_ptrs[cur_event]->behavior & MAT_DYNAM)
{
if (!blank_on_key)
screen_blank = 0;
e_ptrs[cur_event]->behavior |= MAT_SKIP;
status_line (":%s %s %d", msgtxt[M_END_OF], msgtxt[M_DYNAMIC_EVENT], cur_event + 1);
goto top_of_mail;
}
}
}
screen_blank = 0;
if (fullscreen)
sb_show ();
/* Eat the character we pressed */
if (ctrlc_ctr || !KEYPRESS ())
{
/*
* Be serious, there had to be a key pressed or we wouldn't be here I
* know it sounds silly, but ^C will sometimes do crap like this
*/
status_line (msgtxt[M_EXIT_REQUEST]);
}
else
{
i = (int) FOSSIL_CHAR ();
if ((i & 0xff) == 0)
{
switch (i)
{
case PF1:
case PF2:
case PF3:
case PF4:
case PF5:
case PF6:
case PF7:
case PF8:
case PF9:
case PF10:
j = (int) (((unsigned) i) >> 8);
status_line (msgtxt[M_FUNCTION_KEY], (j - 0x3a) * 10);
errl_exit ((j - 0x3a) * 10);
break;
case ALTB:
screen_blank = 1;
if (fullscreen)
sb_show ();
goto bad_char;
case ALTC:
tmp = hist.which_day;
memset (&hist, 0, sizeof (HISTORY));
hist.which_day = tmp;
if (fullscreen)
{
do_today ();
sb_show ();
}
goto bad_char;
case ALTE:
if (BBSreader != NULL)
{
vfossil_cursor (1);
status_line (msgtxt[M_DISABLE_MODEM]);
set_prior(4); /* Always High */
mdm_init (modem_busy);
exit_DTR ();
set_prior(2); /* Regular */
status_line (msgtxt[M_BEGIN_MESSAGE_READER]);
vfossil_close ();
b_spawn (BBSreader);
come_back(); /* CML */
vfossil_init ();
if (fullscreen)
{
screen_clear ();
sb_dirty ();
opening_banner ();
mailer_banner ();
}
status_line (msgtxt[M_END_MESSAGE_READER]);
set_up_outbound ();
m = 1;
more_mail = 1;
status_line (msgtxt[M_ENABLE_MODEM]);
set_prior(4); /* Always High */
DTR_ON ();
mdm_init (modem_init);
set_prior(2); /* Regular */
goto immed_call;
}
else
{
set_xy (NULL);
status_line (msgtxt[M_NO_MESSAGE_READER]);
set_xy (NULL);
m = 1;
goto bad_char;
}
case ALTG:
if (sb_popup (10, 10, 7, 60, Do_Get, 0))
status_line (msgtxt[M_NO_GET]);
else
{
set_up_outbound ();
m = 1;
more_mail = 1;
}
goto bad_char;
case ALTI:
/* The idea for this code came from Holger Schurig */
mdm_hangup ();
set_up_outbound ();
m = 1;
more_mail = 1;
goto bad_char;
case ALTJ: /* CML took out stupid ESC to shell -- what kind of *IDIOT* would use ESC to shell? */
status_line (msgtxt[M_SHELLING]);
if (fullscreen)
gotoxy (0, SB_ROWS);
vfossil_cursor (1);
cputs (msgtxt[M_TYPE_EXIT]);
DTR_OFF ();
change_prompt ();
b_spawn (NULL);
come_back(); /* CML */
if (fullscreen)
{
screen_clear ();
sb_dirty ();
opening_banner ();
mailer_banner ();
}
status_line (msgtxt[M_BINKLEY_BACK]);
m = 1;
set_up_outbound ();
set_prior(4); /* Always High */
DTR_ON ();
set_prior(2); /* Regular */
goto bad_char;
case ALTK:
if (sb_popup (10, 5, 4, 70, Do_Kill, 0))
status_line (msgtxt[M_NO_KILL]);
else
{
set_up_outbound ();
m = 1;
more_mail = 1;
}
goto bad_char;
case ALTY:
next_addr = boss_addr;
goto polling;
case ALTM:
status_line (msgtxt[M_POLL_MODE]);
if (fullscreen)
gotoxy (0, SB_ROWS - 2);
vfossil_cursor (1);
scr_printf ("\r\n");
clear_eol ();
scr_printf (msgtxt[M_ENTER_NET_NODE]);
m = get_number (jbuf);
if (m)
m = find_address (jbuf, &next_addr);
if (fullscreen)
{
gotoxy (0, SB_ROWS - 1);
clear_eol ();
bottom_line ();
vfossil_cursor (0);
sb_show ();
}
if (m >= 1 && nodefind (&next_addr, 1))
{
if (!next_addr.Zone)
next_addr.Zone = found_zone;
polling:
doing_poll = 1;
if (fullscreen)
{
sb_move (filewin, 1, 2);
sb_puts (filewin, (unsigned char *) msgtxt[M_CURRENTLY_POLLING]);
sb_puts (filewin, (unsigned char *) Full_Addr_Str (&next_addr));
}
set_prior(4); /* Always High */
if ((do_mail (&next_addr, 1) == 1) && sent_mail)
{
next_mail = find_mail (&next_addr);
bad_call (&next_addr, -1);
xmit_delete ();
}
set_prior(2); /* Regular */
doing_poll = 0;
}
status_line (msgtxt[M_POLL_COMPLETED]);
if (fullscreen)
{
clear_filetransfer ();
}
set_prior(4); /* Always High */
DTR_ON ();
mdm_init (modem_init);
set_prior(2); /* Regular */
m = 1;
goto bad_char;
case ALTQ:
if (cur_event >= 0)
e_ptrs[cur_event]->behavior |= MAT_SKIP;
goto top_of_mail;
case ALTR:
for (j = 0; j < num_events; j++)
{
/* Don't redo forced events */
if (!(e_ptrs[j]->behavior & MAT_FORCED))
{
e_ptrs[j]->last_ran = -1;
e_ptrs[j]->behavior &= ~MAT_SKIP;
}
}
goto top_of_mail;
case ALTS:
if (sb_popup (10, 5, 6, 70, Do_Send, 0))
status_line (msgtxt[M_NO_SEND]);
else
{
set_up_outbound ();
m = 1;
more_mail = 1;
}
goto bad_char;
case ALTT:
status_line (msgtxt[M_ENTER_TERMINAL_MODE]);
b_init ();
done = 0; /* We won't exit now */
goto mail_done;
case ALTW:
if (fullscreen)
{
screen_clear ();
sb_dirty ();
sb_show ();
}
goto bad_char;
case ALTF10:
mailer_help ();
if (fullscreen)
{
screen_clear ();
sb_dirty ();
opening_banner ();
mailer_banner ();
}
m = 1;
goto bad_char;
case ALTX:
status_line (msgtxt[M_EXIT_REQUEST]);
goto mail_done;
case ALTF1:
case ALTF2:
case ALTF3:
case ALTF4:
case ALTF5:
case ALTF6:
case ALTF7:
case ALTF8:
case ALTF9:
j = (int) (((unsigned) i) >> 8) - 0x68;
if (shells[j] != NULL)
{
status_line (msgtxt[M_KEYBOARD_SHELL], j + 1);
set_prior(3); /* Foreground-Server */
mdm_init (modem_busy);
exit_DTR ();
set_prior(2); /* Regular */
close_up ();
vfossil_cursor (1);
b_spawn (shells[j]);
come_back(); /* CML */
m = 1;
status_line (msgtxt[M_END_KEYBOARD_SHELL]);
screen_clear ();
if (fullscreen)
sb_dirty ();
opening_banner ();
mailer_banner ();
set_up_outbound ();
set_prior(4); /* Always High */
DTR_ON ();
mdm_init (modem_init);
set_prior(2); /* Regular */
goto immed_call;
}
status_line (msgtxt[M_NO_KEYBOARD_SHELL], j + 1);
goto bad_char;
case PGUP:
if (next_mail == NULL)
next_mail = mail_top;
if (next_mail != NULL)
{
for (j = 0; j < 4; j++)
{
if (next_mail->prev != NULL)
next_mail = next_mail->prev;
}
xmit_window (next_mail);
}
goto bad_char;
case PGDN:
if (next_mail == NULL)
next_mail = mail_top;
if (next_mail != NULL)
{
for (j = 0; j < 4; j++)
{
if (next_mail->next != NULL)
next_mail = next_mail->next;
}
xmit_window (next_mail);
}
goto bad_char;
case UPAR:
if (next_mail == NULL)
next_mail = mail_top;
if (next_mail != NULL)
{
if (next_mail->prev != NULL)
next_mail = next_mail->prev;
xmit_window (next_mail);
}
goto bad_char;
case DNAR:
if (next_mail == NULL)
next_mail = mail_top;
if (next_mail != NULL)
{
if (next_mail->next != NULL)
next_mail = next_mail->next;
xmit_window (next_mail);
}
goto bad_char;
case HOME:
next_mail = mail_top;
xmit_window (next_mail);
goto bad_char;
case END:
if (next_mail == NULL)
next_mail = mail_top;
if (next_mail != NULL)
{
while (next_mail->next != NULL)
next_mail = next_mail->next;
}
for (j = 0; j < 3; j++)
{
if (next_mail->prev != NULL)
next_mail = next_mail->prev;
}
xmit_window (next_mail);
goto bad_char;
default:
status_line (msgtxt[M_JUNK_CHARACTER]);
m = 1;
goto bad_char;
}
}
else
{
switch (i & 0xff)
{
case 'C':
case 'c':
if (cur_event >= 0)
if (e_ptrs[cur_event]->behavior & MAT_NOOUT)
{
status_line (msgtxt[M_NO_CALLS_NOW]);
goto immed_call;
}
status_line (msgtxt[M_IMMEDIATE_CALL]);
m = 0;
more_mail = 1;
goto immed_call;
case 3:
status_line (msgtxt[M_EXIT_REQUEST]);
goto mail_done;
case 0x20:
m = 1;
goto bad_char;
default:
status_line (msgtxt[M_JUNK_CHARACTER]);
m = 1;
goto bad_char;
}
}
}
mail_done:
write_sched ();
status_line ("+end, %s", xfer_id);
un_attended = 0;
if (fullscreen)
gotoxy (0, SB_ROWS);
set_prior(4); /* Always High */
XON_ENABLE ();
set_prior(2); /* Regular */
return (done);
}