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

Defined functions

main defined in line 29; never used

Defined variables

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

Defined typedef's

bool defined in line 17; used 1 times
  • in line 25

Defined macros

FALSE defined in line 19; never used
MAILER defined in line 27; used 1 times
TRUE defined in line 18; used 1 times
  • in line 46
Last modified: 1986-05-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1262
Valid CSS Valid XHTML 1.0 Strict