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
/
makemsg.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-16
|
4KB
|
179 lines
#include <stdio.h>
#include <ctype.h>
#include <modes.h>
#include <errno.h>
#include "mailbox.h"
struct userstruct user;
char *maildir = "MAIL/";
char line[256];
main (argc, argv)
char *argv[];
{
struct msg_header *head;
char title[81], to[7], from[7], bbs[7], bid[13];
int type, stat;
int infile, outfile;
int blocksize = 5;
int filesize;
int fromflag = 0;
char *p, w[40], w2[40];
if (argc < 2) {
printf ("makemsg - turns a file into a mailbox message\n");
printf ("\n form: makemsg <filename>\n");
exit (0);
}
strcpy (user.uscall, MYCALL);
if ((infile = open (argv[1], 1)) < 0) {
printf ("Can't find %s.\n", argv[1]);
exit (0);
}
printf (" Type: ");
getline ();
if (*line)
type = toupper (*line);
else
type = ' ';
stat = 'N';
do {
printf (" To: ");
getline ();
if (*line) {
scanword (line, to, 7);
upper (to);
get_ssid (to);
}
} while (!*line);
printf (" From: ");
getline ();
if (*line) {
scanword (line, from, 7);
upper (from);
get_ssid (from);
fromflag++;
}
else
strcpy (from, MYCALL);
printf (" BBS: ");
getline ();
if (*line) {
scanword (line, bbs, 7);
upper (bbs);
get_ssid (bbs);
}
else
*bbs = '\0';
printf (" BID: ");
getline ();
if (*line) {
scanword (line, bid, 7);
upper (bid);
get_ssid (bid);
}
else
*bid = '\0';
printf ("Title: ");
getline ();
if (*line)
strncpy (title, line, 80);
else
strcpy (title, argv[1]);
printf ("Block: ");
getline ();
if (*line)
blocksize = atoi (line);
filesize = lseek (infile, 0L, 2);
lseek (infile, 0L, 0);
blocksize = 1024 * blocksize;
chdir (HOME);
if (filesize > blocksize) {
int i, nparts, size, total;
nparts = (filesize + blocksize - 1) / blocksize;
printf ("Creating %d parts\n", nparts);
for (i = 0; i < nparts; i++) {
open_mail ();
head = new_mail ();
printf ("%d\n", head->mhnr);
if (strcmp (bid, "$") == 0)
sprintf (head->mhbid, "%d_%s", head->mhnr, MYCALL);
else
strcpy (head->mhbid, bid);
update_mail ();
head->mhtype = type;
strcpy (head->mhfrom, from);
strcpy (head->mhto, to);
strcpy (head->mhbbs, bbs);
sprintf (head->mhtit, "%s (part %d of %d)", title, i+1, nparts);
strcpy (w, maildir);
header_to_name (head, w + strlen (maildir));
if ((outfile = create (w, S_IWRITE, S_IREAD+S_IWRITE)) == -1) {
printf ("Error %d creating message file %s.\n", errno, w);
close_mail ();
exit;
}
for (total = 0; total < (filesize / nparts); total += size) {
if ((size = readln (infile, line, 256)) == 0)
break;
write (outfile, line, size);
}
head->mhsize = _gs_size (outfile);
close (outfile);
head->mhstat = 'N';
update_mail ();
close_mail ();
log_send (head, fromflag);
}
}
else {
int i;
open_mail ();
head = new_mail ();
printf ("%d\n", head->mhnr);
if (strcmp (bid, "$") == 0)
sprintf (head->mhbid, "%d_%s", head->mhnr, MYCALL);
else
strcpy (head->mhbid, bid);
update_mail ();
head->mhtype = type;
strcpy (head->mhfrom, from);
strcpy (head->mhto, to);
strcpy (head->mhbbs, bbs);
strcpy (head->mhtit, title);
strcpy (w, maildir);
header_to_name (head, w + strlen (maildir));
if ((outfile = create (w, S_IWRITE, S_IREAD+S_IWRITE)) == -1) {
printf ("Error %d creating message file %s.\n", errno, w);
close_mail ();
exit;
}
while ((i = read (infile, line, 256)) > 0)
write (outfile, line, i);
head->mhsize = _gs_size (outfile);
close (outfile);
head->mhstat = 'N';
update_mail ();
close_mail ();
log_send (head, fromflag);
}
close (infile);
}
getline ()
{
fgets (line, 256, stdin);
line[strlen (line) - 1] = '\0';
}