1: #if !defined(lint) && defined(DOSCCS)
   2: static char sccsid[] =  "@(#)rmail.c	4.8.1 (2.11BSD) 1996/10/21";
   3: #endif
   4: 
   5: /*
   6: **  RMAIL -- UUCP mail server.
   7: **
   8: **	This program reads the >From ... remote from ... lines that
   9: **	UUCP is so fond of and turns them into something reasonable.
  10: **	It calls sendmail giving it a -f option built from these
  11: **	lines.
  12: */
  13: 
  14: #include <stdio.h>
  15: #include <string.h>
  16: #include <sysexits.h>
  17: #include <paths.h>
  18: 
  19: typedef char    bool;
  20: #define TRUE    1
  21: #define FALSE   0
  22: 
  23: bool    Debug;
  24: 
  25: main(argc, argv)
  26:     char **argv;
  27: {
  28:     FILE *out;  /* output to sendmail */
  29:     char lbuf[1024];    /* one line of the message */
  30:     char from[512];     /* accumulated path of sender */
  31:     char ufrom[512];    /* user on remote system */
  32:     char sys[512];      /* a system in path */
  33:     char junk[1024];    /* scratchpad */
  34:     char cmd[2000];
  35:     register char *cp;
  36:     register char *uf = ufrom;  /* ptr into ufrom */
  37:     int i;
  38: 
  39: # ifdef DEBUG
  40:     if (argc > 1 && strcmp(argv[1], "-T") == 0)
  41:     {
  42:         Debug = TRUE;
  43:         argc--;
  44:         argv++;
  45:     }
  46: # endif DEBUG
  47: 
  48:     if (argc < 2)
  49:     {
  50:         fprintf(stderr, "Usage: rmail user ...\n");
  51:         exit(EX_USAGE);
  52:     }
  53: 
  54:     (void) strcpy(from, "");
  55:     (void) strcpy(ufrom, "/dev/null");
  56: 
  57:     for (;;)
  58:     {
  59:         (void) fgets(lbuf, sizeof lbuf, stdin);
  60:         if (strncmp(lbuf, "From ", 5) != 0 && strncmp(lbuf, ">From ", 6) != 0)
  61:             break;
  62:         (void) sscanf(lbuf, "%s %s", junk, ufrom);
  63:         cp = lbuf;
  64:         for (;;)
  65:         {
  66:             cp = index(cp+1, 'r');
  67:             if (cp == NULL)
  68:             {
  69:                 register char *p = rindex(uf, '!');
  70: 
  71:                 if (p != NULL)
  72:                 {
  73:                     *p = '\0';
  74:                     (void) strcpy(sys, uf);
  75:                     uf = p + 1;
  76:                     break;
  77:                 }
  78:                 cp = "remote from somewhere";
  79:             }
  80: #ifdef DEBUG
  81:             if (Debug)
  82:                 printf("cp='%s'\n", cp);
  83: #endif
  84:             if (strncmp(cp, "remote from ", 12)==0)
  85:                 break;
  86:         }
  87:         if (cp != NULL)
  88:             (void) sscanf(cp, "remote from %s", sys);
  89:         (void) strcat(from, sys);
  90:         (void) strcat(from, "!");
  91: #ifdef DEBUG
  92:         if (Debug)
  93:             printf("ufrom='%s', sys='%s', from now '%s'\n", uf, sys, from);
  94: #endif
  95:     }
  96:     (void) strcat(from, uf);
  97: 
  98:     (void) sprintf(cmd, "%s -ee -f%s -i", _PATH_SENDMAIL, from);
  99:     while (*++argv != NULL)
 100:     {
 101:         (void) strcat(cmd, " '");
 102:         if (**argv == '(')
 103:             (void) strncat(cmd, *argv + 1, strlen(*argv) - 2);
 104:         else
 105:             (void) strcat(cmd, *argv);
 106:         (void) strcat(cmd, "'");
 107:     }
 108: #ifdef DEBUG
 109:     if (Debug)
 110:         printf("cmd='%s'\n", cmd);
 111: #endif
 112:     out = popen(cmd, "w");
 113:     fputs(lbuf, out);
 114:     while (fgets(lbuf, sizeof lbuf, stdin))
 115:         fputs(lbuf, out);
 116:     i = pclose(out);
 117:     if ((i & 0377) != 0)
 118:     {
 119:         fprintf(stderr, "pclose: status 0%o\n", i);
 120:         exit(EX_OSERR);
 121:     }
 122: 
 123:     exit((i >> 8) & 0377);
 124: }

Defined functions

main defined in line 25; never used

Defined variables

Debug defined in line 23; used 4 times
sccsid defined in line 2; never used

Defined typedef's

bool defined in line 19; used 1 times
  • in line 23

Defined macros

FALSE defined in line 21; never used
TRUE defined in line 20; used 1 times
  • in line 42
Last modified: 1996-10-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3392
Valid CSS Valid XHTML 1.0 Strict