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

Defined functions

main defined in line 45; never used

Defined variables

Debug defined in line 41; used 4 times
SccsId defined in line 18; never used
copyright defined in line 12; never used

Defined typedef's

bool defined in line 33; used 1 times
  • in line 41

Defined macros

FALSE defined in line 35; never used
MAILER defined in line 43; used 1 times
TRUE defined in line 34; used 1 times
  • in line 62
Last modified: 1985-06-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1349
Valid CSS Valid XHTML 1.0 Strict