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 >
C/C++ Source or Header  |  1991-04-16  |  4KB  |  179 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <modes.h>
  4. #include <errno.h>
  5. #include "mailbox.h"
  6.  
  7. struct userstruct user;
  8. char *maildir = "MAIL/";
  9. char line[256];
  10.  
  11. main (argc, argv)
  12. char *argv[];
  13. {
  14.     struct msg_header *head;
  15.     char title[81], to[7], from[7], bbs[7], bid[13];
  16.     int type, stat;
  17.     int infile, outfile;
  18.     int blocksize = 5;
  19.     int filesize;
  20.     int fromflag = 0;
  21.     char *p, w[40], w2[40];
  22.  
  23.     if (argc < 2) {
  24.         printf ("makemsg - turns a file into a mailbox message\n");
  25.         printf ("\n    form:  makemsg <filename>\n");
  26.         exit (0);
  27.         }
  28.     strcpy (user.uscall, MYCALL);
  29.     if ((infile = open (argv[1], 1)) < 0) {
  30.         printf ("Can't find %s.\n", argv[1]);
  31.         exit (0);
  32.         }
  33.  
  34.     printf (" Type: ");
  35.     getline ();
  36.     if (*line)
  37.         type = toupper (*line);
  38.     else
  39.         type = ' ';
  40.  
  41.     stat = 'N';
  42.  
  43.     do {
  44.         printf ("   To: ");
  45.         getline ();
  46.         if (*line) {
  47.             scanword (line, to, 7);
  48.             upper (to);
  49.             get_ssid (to);
  50.             }
  51.         } while (!*line);
  52.  
  53.     printf (" From: ");
  54.     getline ();
  55.     if (*line) {
  56.         scanword (line, from, 7);
  57.         upper (from);
  58.         get_ssid (from);
  59.         fromflag++;
  60.         }
  61.     else
  62.         strcpy (from, MYCALL);
  63.  
  64.     printf ("  BBS: ");
  65.     getline ();
  66.     if (*line) {
  67.         scanword (line, bbs, 7);
  68.         upper (bbs);
  69.         get_ssid (bbs);
  70.         }
  71.     else
  72.         *bbs = '\0';
  73.  
  74.     printf ("  BID: ");
  75.     getline ();
  76.     if (*line) {
  77.         scanword (line, bid, 7);
  78.         upper (bid);
  79.         get_ssid (bid);
  80.         }
  81.     else
  82.         *bid = '\0';
  83.  
  84.     printf ("Title: ");
  85.     getline ();
  86.     if (*line)
  87.         strncpy (title, line, 80);
  88.     else
  89.         strcpy (title, argv[1]);
  90.  
  91.     printf ("Block: ");
  92.     getline ();
  93.     if (*line)
  94.         blocksize = atoi (line);
  95.  
  96.     filesize = lseek (infile, 0L, 2);
  97.     lseek (infile, 0L, 0);
  98.     blocksize = 1024 * blocksize;
  99.     chdir (HOME);
  100.     if (filesize > blocksize) {
  101.         int i, nparts, size, total;
  102.  
  103.         nparts = (filesize + blocksize - 1) / blocksize;
  104.         printf ("Creating %d parts\n", nparts);
  105.         for (i = 0; i < nparts; i++) {
  106.             open_mail ();
  107.             head = new_mail ();
  108.             printf ("%d\n", head->mhnr);
  109.             if (strcmp (bid, "$") == 0)
  110.                 sprintf (head->mhbid, "%d_%s", head->mhnr, MYCALL);
  111.             else
  112.                 strcpy (head->mhbid, bid);
  113.             update_mail ();
  114.             head->mhtype = type;
  115.             strcpy (head->mhfrom, from);
  116.             strcpy (head->mhto, to);
  117.             strcpy (head->mhbbs, bbs);
  118.             sprintf (head->mhtit, "%s (part %d of %d)", title, i+1, nparts);
  119.             strcpy (w, maildir);
  120.             header_to_name (head, w + strlen (maildir));
  121.             if ((outfile = create (w, S_IWRITE, S_IREAD+S_IWRITE)) == -1) {
  122.                 printf ("Error %d creating message file %s.\n", errno, w);
  123.                 close_mail ();
  124.                 exit;
  125.                 }
  126.             for (total = 0; total < (filesize / nparts); total += size) {
  127.                 if ((size = readln (infile, line, 256)) == 0)
  128.                     break;
  129.                 write (outfile, line, size);
  130.                 }
  131.             head->mhsize = _gs_size (outfile);
  132.             close (outfile);
  133.             head->mhstat = 'N';
  134.             update_mail ();
  135.             close_mail ();
  136.             log_send (head, fromflag);
  137.             }
  138.         }
  139.     else {
  140.         int i;
  141.  
  142.         open_mail ();
  143.         head = new_mail ();
  144.         printf ("%d\n", head->mhnr);
  145.         if (strcmp (bid, "$") == 0)
  146.             sprintf (head->mhbid, "%d_%s", head->mhnr, MYCALL);
  147.         else
  148.             strcpy (head->mhbid, bid);
  149.         update_mail ();
  150.         head->mhtype = type;
  151.         strcpy (head->mhfrom, from);
  152.         strcpy (head->mhto, to);
  153.         strcpy (head->mhbbs, bbs);
  154.         strcpy (head->mhtit, title);
  155.         strcpy (w, maildir);
  156.         header_to_name (head, w + strlen (maildir));
  157.         if ((outfile = create (w, S_IWRITE, S_IREAD+S_IWRITE)) == -1) {
  158.             printf ("Error %d creating message file %s.\n", errno, w);
  159.             close_mail ();
  160.             exit;
  161.             }
  162.         while ((i = read (infile, line, 256)) > 0)
  163.             write (outfile, line, i);
  164.         head->mhsize = _gs_size (outfile);
  165.         close (outfile);
  166.         head->mhstat = 'N';
  167.         update_mail ();
  168.         close_mail ();
  169.         log_send (head, fromflag);
  170.         }
  171.     close (infile);
  172.     }
  173.  
  174. getline ()
  175. {
  176.     fgets (line, 256, stdin);
  177.     line[strlen (line) - 1] = '\0';
  178.     }
  179.