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

Defined functions

main defined in line 39; never used

Defined variables

Debug defined in line 37; used 4 times
SccsId defined in line 16; never used
copyright defined in line 12; never used

Defined typedef's

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

Defined macros

FALSE defined in line 35; never used
TRUE defined in line 34; used 1 times
  • in line 56
Last modified: 1996-10-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2730
Valid CSS Valid XHTML 1.0 Strict