home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
lan
/
netx
/
bm
/
main.c
< prev
next >
Wrap
Text File
|
1987-08-25
|
8KB
|
310 lines
/* bm.c
* Simple mail user interface for KA9Q IP/TCP package.
* A.D. Barksdale Garbee II, aka Bdale, N3EUA
* Copyright 1986 Bdale Garbee, All Rights Reserved.
* Permission granted for non-commercial copying and use, provided
* this notice is retained.
*
* revision history:
*
* v2.6 870826 Bdale
* integrate PA0GRI's interface/gateway to the WA7MBL PBBS
* v2.5 870713 Bdale
* integrate additional patches from PA0GRI, minor cleanup
* v2.4 870614 - P. Karn
* "smart gateway" function moved to smtp client code in net.exe.
* User interface for sending mail reworked to resemble Berkeley Mail
* v2.3 870524
* Extensive addition/revision by Gerard PA0GRI. Now supports a healthy
* set of real commands.
* v2.1,2.2
* exact change history lost.
* v2.0 c.870115
* First version with command parser, only send and quit work.
* v1.0
* First attempt. Send messages only.
*/
#include <stdio.h>
#include "../src/smtp.h"
#include "bm.h"
extern char version[];
static char copyright[] =
"Copyright 1987 Bdale Garbee, permission granted for non-commercial use.";
FILE *rcfp; /* handle for the configuration file */
FILE *mfile;
char rcline[LINELEN], /* buffer for config file reading routines */
hostname[SLINELEN], /* name of this host from rc file */
username[SLINELEN], /* name of this user from rc file */
timezone[4], /* users time zone */
maildir[LINELEN], /* defined mail directory */
editor[SLINELEN]; /* user's favorite text editor */
/* command parser, handle at least read, send, headers, delete */
main(argc,argv)
int argc;
char *argv[];
{
char command[80]; /* command line */
char line[80];
char notename[9]; /* name of notesfile */
char notefile[80]; /* temorary for building strings */
char *notel, *tch, *index();
int notes, msgnum;
static int printer; /* printer switch */
/* announce ourselves */
printf("\t\t%s\n%s\n\n",version,copyright);
/* initialize globals from config file */
*editor = 0x00; /* default no editor? */
*maildir = 0x00;
strcpy(timezone,"GMT");
printer = 0;
read_rc();
if(*maildir == '\0')
strcpy(maildir,"/spool/mail");
strncpy(notename,username,8);
if(argc > 1){
dosmtpsend(NULL,argv[1]);
exit(0);
}
printf(" Type ? for help.\n");
sprintf(notefile,"%s/%s.txt",maildir,notename);
/* command parsing loop */
do {
printf("\"%s\"> ",notename);
gets(command);
switch (command[0]) {
case 's': /* send msg */
dosmtpsend(NULL,NULL);
break;
case 't': /* transmit msg in file*/
printf("Enter filename containing message :");
gets(command);
if((mfile = fopen(command,"r")) == NULL)
printf("\n Cannot open file %s\n",command);
else {
dosmtpsend(mfile,NULL);
fclose(mfile);
}
command[0] = 't'; /* just in case file started with q */
break;
case 'q': /* quit */
break;
case 'p': /* printer on or off */
if(printer) {
/* Bdale, i dont have the description of dos function to set
printer echo on or off, but it looks nice to me if
it would be possible to do it.. gerard */
} else {
}
printer = !printer;
printf("Printer is now %s.\n", printer ? "on" : "off" );
break;
case 'r': /* read all messages */
if((mfile = fopen(notefile,"r")) == NULL)
printf(" Cannot open notesfile \"%s\" \n",notename);
else {
msgnum = 0;
while(!feof(mfile)) {
fgets(line,80,mfile);
rip(line);
if((strncmp(line,"Subject:",8)) == 0)
msgnum++;
printf("%s\n",line);
}
fclose(mfile);
seqset(notename,msgnum);
}
break;
case 'u':
updmsg(notename);
break;
case 'f': /* forward a message */
notel = command;
/* skip forward command */
while(*notel != '\0') {
if(*notel != ' ' && *notel != '\t')
notel++;
else
break;
}
if(*notel != '\0') {
msgnum = atoi(notel);
if((mfile = fopen("zqxwgri.tmp","w")) == NULL)
printf("\n Cannot open temp file \n");
else {
tmpmsg(notename,msgnum,mfile);
fclose(mfile);
mfile = fopen("zqxwgri.tmp","r");
dosmtpsend(mfile,NULL);
fclose(mfile);
unlink("zqxwgri.tmp");
}
}
break;
case 'l': /* display unsent messages */
printf("List of unsent messages.\n");
filedir("/spool/mqueue/*.txt",0,line);
while(line[0] != '\0') {
printf("message in -> %s \n",line);
filedir("/spool/mqueue/*.txt",1,line);
}
break;
case 'n': /* display or change notefiles */
if(strlen(command) > 2) {
notel = command;
/* skip notefile command */
while(*notel != '\0') {
if(*notel != ' ' && *notel != '\t')
notel++;
else
break;
}
if(*notel == '\0')
break;
/* skip white space */
while(*notel == ' ' || *notel == '\t')
notel++;
if(*notel != '\0') {
strncpy(notename,notel,8);
sprintf(notefile,"%s/%s.txt",maildir,notename);
}
} else { /* he wants to see what notefiles there are */
sprintf(notefile,"%s/*.txt",maildir);
filedir(notefile,0,line);
while(line[0] != '\0') {
tch = index(line,'.');
*tch = '\0';
printf("notesfile -> %s \n",line);
filedir(notefile,1,line);
}
/* after using notefile reset it to current */
sprintf(notefile,"%s/%s.txt",maildir,notename);
}
break;
case 'd': /* delete a message */
notel = command;
/* skip delete command */
while(*notel != '\0') {
if(*notel != ' ' && *notel != '\t')
notel++;
else
break;
}
if(*notel != '\0') {
msgnum = atoi(notel);
delmsg(notename,msgnum);
}
break;
case 'h': /* list message headers in notesfile */
listnotes(notename);
break;
case '?': /* help */
printf(" d nn delete a message\n");
printf(" s send a message\n");
printf(" t send a message from a file\n");
printf(" r read message in notesfile\n");
printf(" f forward a message \n");
printf(" u update me for new messages\n");
printf(" p printer on or off (toggle) n.y.i.\n");
printf(" h display message headers in notefile\n");
printf(" l list unsent messages\n");
printf(" n file display or set notesfile\n");
printf(" # number of message to read in notesfile\n");
printf(" ? print this help screen\n");
printf(" q quit\n");
break;
default:
if(( msgnum = atoi(command)) != 0 )
readmsg(notename,msgnum);
else
printf(" commands <d,s,t,r,f,u,p,h,l,n,#,?,q>\n");
break;
}
} while (command[0] != 'q');
}
read_rc()
{
if((rcfp = fopen("/bm.rc","r")) == NULL) { /* open config file */
printf("Cannot open BM.RC in root, check your installation\n");
exit(-1);
} else
while (!feof(rcfp)) {
fgets(rcline,LINELEN,rcfp);
if (rcline[0] == ';') continue;
if (strlen(rcline) < 5) continue;
switch (rc_line_type(rcline)) {
case HOST:
strcpy(hostname,&rcline[5]);
rip(hostname);
break;
case USER:
strcpy(username,&rcline[5]);
rip(username);
break;
case EDIT:
strcpy(editor,&rcline[5]);
rip(editor);
break;
case ZONE:
strncpy(timezone,&rcline[5],3);
timezone[3] = '\0';
break;
case SMTP:
strcpy(maildir,&rcline[5]);
rip(maildir);
break;
case FIDO:
default:
/* handle these cases in v2.0! */
break;
}
}
fclose(rcfp);
}
/* return the line_type from a line of the configuration file */
rc_line_type(s)
char *s;
{
if (strncmp("fido",s,4) == 0) return (FIDO);
if (strncmp("smtp",s,4) == 0) return (SMTP);
if (strncmp("host",s,4) == 0) return (HOST);
if (strncmp("user",s,4) == 0) return (USER);
if (strncmp("edit",s,4) == 0) return (EDIT);
if (strncmp("zone",s,4) == 0) return (ZONE);
return (NONE);
}
/* replace terminating end of line marker(s) with null */
rip(s)
register char *s;
{
register char *cp;
char *index();
if((cp = index(s,'\r')) != NULL)
*cp = '\0';
if((cp = index(s,'\n')) != NULL)
*cp = '\0';
}