home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
_
/
7plus
/
!Send7+
/
c
/
send7+
< prev
Wrap
Text File
|
1995-06-23
|
12KB
|
518 lines
/* ------------------------------------------------------------ */
/* Send7+.c Major re-write of the utility that was lost */
/* during a hard disk backup in Aug 93 */
/* ------------------------------------------------------------ */
/* Purpose Make 7+ files mail-files transmittable by !TCPIP*/
/* Author Rainer Schubert, DL6HBO */
/* Copyright © 1993 by DL6HBO, free for non-commercial copy- */
/* ing and use as long as this message is retained.*/
/* Date 05-Sep-1993 07:23:43 */
/* Last edited 13-Sep-1993 16:01:09 */
/* New version 26-Dec-1993 11:48:46 adapt to DB0HHT & WAMPES */
/* New version 29-Jan-1995 10:50:20 adapt for systems without */
/* !BM and ALIAS files. */
/* New version 18-Jun-1995 11:45:23 corrected Date&Time bug */
/* on RiscPC with RO 3.5 */
/* Last edited 23-Jun-1995 09:33:44 CET */
/* ------------------------------------------------------------ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "os.h"
/* #define DEBUG 1 */
/* #define WAMPES 0*/ /* Use WAMPES's mailing convention for mail */
/* addressed to 'boards' like 'archim@eu' */
#define NO_BM 1 /* Adapt for systems NOT using !BM & ALIAS */
char path[FILENAME_MAX], textpath[FILENAME_MAX], workpath[FILENAME_MAX];
char lockpath[FILENAME_MAX], sevenplus[FILENAME_MAX];
#ifndef NO_BM
char bmpath[FILENAME_MAX], aliaspath[FILENAME_MAX];
#endif
char hostname[FILENAME_MAX], callsign[10];
char receiver[80], receiverpath[256];
char infile[FILENAME_MAX];
int parts, partscnt, quit;
long seq;
struct tm *tp;
time_t *ttp;
int tttp[2];
#ifndef WAMPES
const char version[] ="Send7Plus 0.5";
#else
const char version[] ="Send7Plus 0.6 WAMPES";
#endif
const char copyr[] ="© 1993-95 by DL6HBO";
/* replace terminating end of line marker(s) with null */
void rip(register char *s)
{
for (; *s; s++)
if (*s == '\r' || *s == '\n') {
*s = '\0';
break;
}
}
char *readvar(char *s)
{
char *c;
if ((c = getenv(s)) == NULL)
printf("System variable %s not found\n",s);
return c;
}
char *fn_tolower(char *any)
{
char *p;
p = any;
while ( *p++ != '\0')
tolower(*p);
return any;
}
int process(FILE *infil,int witch,char *search,long sequence)
{
FILE *msgfile, *wrkfile;
char msgfilename[FILENAME_MAX], wrkfilename[FILENAME_MAX];
char from[80], to[80], mesid[80], date[90], mstime[81], sender[80];
char reply_to[80], subject[80], x_mail[80], ln[132];
char *p;
sprintf(from,"%s","From: ");
rip(receiverpath);
sprintf(to,"To: %s",receiverpath);
#ifdef DEBUG
puts(to);
putchar('\n');
#endif
sprintf(date,"%s","Date: ");
tttp[0] = 3;
os_word(14,tttp);
printf("%d\n",time((time_t *)tttp));
printf("%s",asctime(gmtime((time_t *)tttp)));
printf("%s",ctime((time_t *)tttp));
strftime(mstime, 80, "%a, %d %b %H:%M:%S %Y %Z",gmtime((time_t *)tttp));
strcat(date,mstime);
#ifdef DEBUG
puts(date);
putchar('\n');
#endif
sprintf(mesid,"Message-Id: <%ld@%s>",sequence,hostname);
sprintf(reply_to,"Reply-To: %s@%s",fn_tolower(callsign),hostname);
#ifdef DEBUG
puts(mesid);
putchar('\n');
puts(reply_to);
putchar('\n');
#endif
if (parts == 1) {
#ifndef WAMPES
sprintf(subject,"Subject: %s.%s",infile,"7pl");
#else
sprintf(subject,"Subject: [%s] %s.%s",receiverpath,infile,"7pl");
#endif
}
else {
#ifndef WAMPES
sprintf(subject,"Subject: %s.p%02X of %02X",infile,partscnt,parts);
#else
sprintf(subject,"Subject: [%s] %s.p%02X of %02X",receiverpath,infile,partscnt,parts);
#endif
}
#ifdef DEBUG
puts(subject);
putchar('\n');
#endif
sprintf(x_mail,"%s%s %s","X-Mailer: ",version,copyr);
#ifdef DEBUG
puts(x_mail);
putchar('\n');
#endif
printf("Processing file %s part %02X\n",infile,partscnt);
sprintf(msgfilename,"%s%d",textpath,(int)sequence);
#ifdef DEBUG
puts(msgfilename);
putchar('\n');
#endif
if ((msgfile = fopen(msgfilename,"w")) == NULL) {
printf("Unable to write to %s\n",msgfilename);
return -1;
}
sprintf(wrkfilename,"%s%d",workpath,(int)sequence);
#ifdef DEBUG
puts(wrkfilename);
putchar('\n');
#endif
if ((wrkfile = fopen(wrkfilename,"w")) == NULL) {
printf("Unable to write to %s\n",wrkfilename);
return -1;
}
rip(from);
rip(date);
rip(mesid);
rip(callsign);
rip(hostname);
fprintf(msgfile,"%s\n",date);
fprintf(msgfile,"%s\n",mesid);
fprintf(msgfile,"%s%s%s%s\n",from,fn_tolower(callsign),"@",hostname);
if (strlen(from) > 6) {
p = strchr(from,' ');
if (*p) strcpy(sender, ++p);
}
rip(reply_to);
rip(sender);
rip(to);
rip(subject);
rip(x_mail);
strcpy(sender,fn_tolower(sender));
fprintf(msgfile,"%s\n",reply_to);
fprintf(msgfile,"%s\n",to);
fprintf(msgfile,"%s\n",subject);
fprintf(msgfile,"%s\n\n",x_mail);
if ((p = strchr(receiverpath,'@')) != NULL) {
fprintf(wrkfile,"%s\n",++p);
} else {
fprintf(wrkfile,"%s\n",receiverpath);
}
fprintf(wrkfile,"%s@%s\n",fn_tolower(callsign),hostname);
#ifndef WAMPES
fprintf(wrkfile,"%s\n",receiverpath);
#else
fprintf(wrkfile,"%s\n","bbs@db0hht"); /* edit this NODE's callsign */
#endif
fclose(wrkfile);
rewind(infil);
fgets(ln,132,infil);
while (!feof(infil)) {
fprintf(msgfile,"%s",ln);
fgets(ln,132,infil);
}
fclose(msgfile);
return 0;
}
long get_sequence(void)
{
FILE *sequf;
char sequen[20], filenam[FILENAME_MAX];
sprintf(filenam,"%s%s",path,"sequence");
if ((sequf = fopen(filenam,"r")) != NULL) {
fgets(sequen,19,sequf);
fclose(sequf);
printf("Sequence no. %s\n",sequen);
return atol(sequen);
}
return 0;
}
int exists(char *any)
{
FILE *file;
#ifdef DEBUG
printf("Does file %s exist ?",any);
#endif
if ((file = fopen(any,"r")) !=(FILE *) NULL) {
#ifdef DEBUG
puts(" Yes !\n");
#endif
fclose(file);
return 1;
}
#ifdef DEBUG
puts(" No !\n");
#endif
return 0;
}
int key(void)
{
int c;
printf("Press any key to continue......\n");
c = getchar();
return c;
}
char *filename(char *fi,int pts)
{
char fo[FILENAME_MAX], fa[FILENAME_MAX];
char pa[6];
if (pts == 1) {
sprintf(fo,"%s.%s.%s",fi,"7pl","7pl");
if (! exists(fo)) {
strcpy(fa,fi);
strcat(fa,".p");
sprintf(pa,"%02X",pts);
pa[1] = '\0';
strcat(fa,pa);
pa[0] = '\0';
sprintf(pa,"_.p%02X",pts);
strcat(fa,pa);
return(fa);
}
return fo;
}
else {
strcpy(fa,fi);
strcat(fa,".p");
sprintf(pa,"%02X",pts);
pa[1] = '\0';
strcat(fa,pa);
pa[0] = '\0';
sprintf(pa,"_.p%02X",pts);
strcat(fa,pa);
return fa;
}
}
int get_parts(char *file, int parts)
{
char localfname[FILENAME_MAX];
char localpart[6];
sprintf(localfname,"%s.%s",file,"7pl.7pl");
if (exists(localfname)) {
return 1;
}
else {
do {
sprintf(localfname,"%s.p",file);
sprintf(localpart,"%02X",parts);
localpart[1] = '\0';
strcat(localfname,localpart);
localpart[0] = '\0';
sprintf(localpart,"_.p%02X",parts);
strcat(localfname,localpart);
parts++;
}
while (exists(localfname));
--parts;
}
return (--parts);
}
#ifndef NO_BM
char *scan_alias(char *name, char *look_up)
{
FILE *file;
char *pos, line[80], mypath[80];
if (strchr(look_up,'@') == NULL) {
line[0] = '\0';
mypath[0] = '\0';
pos = (char *)0;
if ((file = fopen(name,"r")) == NULL) {
printf("Unable to open file %s\n",name);
return pos;
}
do {
fgets(line,79,file);
if (line[0] != '#')
pos = strstr(line,look_up);
} while ((pos == NULL) && (! feof(file)));
fclose(file);
if (pos != NULL) {
pos += strlen(look_up);
pos++;
while (isspace(*pos))
pos++;
strcpy(mypath,pos);
}
return mypath;
}
return look_up;
}
#endif
int main()
{
char *p;
char search1[10];
char line[132];
int found;
FILE *inf, *seqf;
strcpy(path,readvar("Mail$Dir"));
strcat(path,".spool.mqueue.");
strcpy(textpath,path);
strcat(textpath,"text.");
strcpy(workpath,path);
strcat(workpath,"work.");
strcpy(lockpath,path);
strcat(lockpath,"lock.");
strc