home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / uucp-1.04 / unix / mail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-13  |  2.0 KB  |  86 lines

  1. /* mail.c
  2.    Send mail to a user.
  3.  
  4.    Copyright (C) 1992 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP package.
  7.  
  8.    This program is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
  24.    */
  25.  
  26. #include "uucp.h"
  27.  
  28. #include "uudefs.h"
  29. #include "sysdep.h"
  30. #include "system.h"
  31.  
  32. #include <errno.h>
  33.  
  34. #if HAVE_TIME_H
  35. #include <time.h>
  36. #endif
  37.  
  38. #ifndef ctime
  39. extern char *ctime ();
  40. #endif
  41.  
  42. /* Mail a message to a user.  */
  43.  
  44. boolean
  45. fsysdep_mail (zto, zsubject, cstrs, paz)
  46.      const char *zto;
  47.      const char *zsubject;
  48.      int cstrs;
  49.      const char **paz;
  50. {
  51.   const char *az[3];
  52.   FILE *e;
  53.   pid_t ipid;
  54.   time_t itime;
  55.   int i;
  56.  
  57.   az[0] = MAIL_PROGRAM;
  58.   az[1] = zto;
  59.   az[2] = NULL;
  60.  
  61.   e = espopen (az, FALSE, &ipid);
  62.   if (e == NULL)
  63.     {
  64.       ulog (LOG_ERROR, "espopen (%s): %s", MAIL_PROGRAM,
  65.         strerror (errno));
  66.       return FALSE;
  67.     }
  68.  
  69.   fprintf (e, "Subject: %s\n", zsubject);
  70.   fprintf (e, "To: %s\n", zto);
  71.  
  72.   fprintf (e, "\n");
  73.  
  74.   (void) time (&itime);
  75.   /* Remember that ctime includes a \n, so this skips a line.  */
  76.   fprintf (e, "Message from UUCP on %s %s\n", zSlocalname,
  77.        ctime (&itime));
  78.  
  79.   for (i = 0; i < cstrs; i++)
  80.     fputs (paz[i], e);
  81.  
  82.   (void) fclose (e);
  83.  
  84.   return ixswait ((unsigned long) ipid, MAIL_PROGRAM) == 0;
  85. }
  86.