home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / net / mmail.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  75 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. # include "defs.h"
  3. /* mmail -command -time user fmach user1 user2 ... usern */
  4. /* command and time are optional */
  5. main(argc,argv)
  6.   char **argv; {
  7.     int pip[2], n, sargc, ret, i;
  8.     char *sargv[20], *cst = 0, buf[BUFSIZ], *s = 0;
  9.     long timesent,el;
  10.     int roption = 0;
  11.  
  12. # ifdef ROPTION
  13.     /* only use roption if super-user or "network" */
  14.     i = getuid();
  15.     if(i == 0 || i == NUID)roption++;
  16. # endif
  17.     if(argv[1][0] == '-'){
  18.         cst = argv[1] + 1;
  19.         argv++;
  20.         argc--;
  21.         if(argv[1][0] == '-'){
  22.             timesent = atol(argv[1] + 1);
  23.             s = ctime(×ent);
  24.             s[strlen(s) - 6] = 0;
  25.             el = gettime() - timesent;
  26.             argv++;
  27.             argc--;
  28.             }
  29.         }
  30.     argv[argc] = 0;
  31.     sargc = argc-2;
  32.     sargv[sargc] = 0;
  33.  
  34.     if(roption){
  35.         sargv[1] = "-r";
  36.         sargv[2] = argv[2];
  37.         sargv[3] = argv[1];
  38.         for (i = 3; i < argc; i++)
  39.             sargv[i+1] = argv[i];
  40.         sargv[argc+1] = 0;
  41.         }
  42.     else {
  43.         for(i=0; i< sargc; i++)
  44.         sargv[i] = argv[i+2];
  45.         }
  46.     sargv[0] = "mail";
  47.     pipe(pip);
  48.     if(fork() == 0){
  49.         close(pip[1]);
  50.         close(0);
  51.         dup(pip[0]);
  52.         execv("/bin/mail", sargv);
  53.         execv("/usr/bin/mail", sargv);
  54.         exit(1);
  55.         }
  56.     close(pip[0]);
  57.     close(1);
  58.     dup(pip[1]);
  59.     if(!roption)
  60.         printf("(from %s on the %s machine)\n",argv[1],argv[2]);
  61.     if(cst != 0){
  62.         printf("(command: %s",cst);
  63.         if(s != 0) printf(", sent %s, took %s",s,comptime(el));
  64.         printf(")\n");
  65.         }
  66.     fflush(stdout);
  67.     while((n = read(0,buf,512)) > 0)
  68.         write(pip[1],buf,n);
  69.     close(pip[1]);
  70.     close(1);
  71.     wait(&ret);
  72.     fprintf(stderr,"Mail sent successfully.\n");
  73.     exit(ret>>8);
  74.     }
  75.