home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / nn.tar / nn-6.5.1 / nnmail.c < prev    next >
C/C++ Source or Header  |  1995-04-29  |  2KB  |  106 lines

  1. /*
  2.  *    (c) Copyright 1990, Kim Fabricius Storm.  All rights reserved.
  3.  *
  4.  *     nnmail - a mailer that understands @ addressing
  5.  *         when you don't have sendmail or smail
  6.  */
  7.  
  8. #include "config.h"
  9. #include "library.h"
  10.  
  11. #include "options.h"
  12.  
  13. char * MAILER = MAILX;
  14. static int print_vers, test_mode;
  15.  
  16. Option_Description( mail_options ) {
  17.  
  18.     'v', Bool_Option( print_vers ),
  19.     'm', String_Option( MAILER ),
  20.     't', Bool_Option( test_mode ),
  21.  
  22.     '\0',
  23. };
  24.  
  25. extern char **environ;
  26. extern FILE *route_trace;
  27.  
  28. main(argc, argv)
  29. int argc;
  30. char **argv;
  31. {
  32.     int i, n;
  33.     char route[512];
  34.     char *getenv(), *envmail;
  35.  
  36.     if (envmail = getenv("NNMAILER"))
  37.     MAILER = envmail;
  38.  
  39.     n = parse_options(argc, argv, (char *)NULL,
  40.               mail_options, (char *)NULL, NULL_FCT);
  41.  
  42.     if (print_vers) {
  43.     printf("Release %s\n", version_id);
  44.     nn_exit(0);
  45.     }
  46.  
  47. #ifndef HAVE_ROUTING
  48.     if (test_mode) {
  49.     route_trace = stdout;
  50.     }
  51. #endif
  52.  
  53.     argv[0] = MAILER;
  54.  
  55. #ifndef HAVE_ROUTING
  56.     for (i = 1; i <= n; i++)
  57.     if (reroute(route, argv[i])) {
  58.         if (test_mode) {
  59.         printf("%s \t-->  %s\n", argv[i], route);
  60.         continue;
  61.         }
  62.         argv[i] = newstr(strlen(route)+1);
  63.         strcpy(argv[i], route);
  64.     } else
  65.         if (test_mode)
  66.         printf("%s \t***  no route found\n", argv[i]);
  67. #endif
  68.  
  69.     if (test_mode) nn_exit(0);
  70.  
  71.     execve(MAILER, argv, environ);
  72.     fprintf(stderr, "Mailer '%s' not found\n", MAILER);
  73.     nn_exit(7);
  74. }
  75.  
  76. void
  77. nn_exit(n)
  78. {
  79.     exit(n);
  80. }
  81.  
  82. /*VARARGS*/
  83. nn_exitmsg(va_alist)
  84. va_dcl
  85. {
  86.     char *fmt;
  87.     int n;
  88.     use_vararg;
  89.  
  90.     start_vararg;
  91.     n = va_arg1(int);
  92.     fmt = va_arg2(char *);
  93.     vprintf(fmt, va_args3toN);
  94.     putchar(NL);
  95.     end_vararg;
  96.  
  97.     nn_exit(n);
  98.     /*NOTREACHED*/
  99. }
  100.  
  101. #ifdef HAVE_JOBCONTROL
  102. void
  103. suspend_nn()
  104. {}
  105. #endif
  106.