home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / remail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-20  |  6.3 KB  |  208 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: remail.c,v 5.10 1993/04/21 01:25:45 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.10 $   $State: Exp $
  6.  *
  7.  *            Copyright (c) 1988-1992 USENET Community Trust
  8.  *            Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: remail.c,v $
  17.  * Revision 5.10  1993/04/21  01:25:45  syd
  18.  * I'm using Elm 2.4.21 under Linux.  Linux has no Bourne shell.  Each
  19.  * user installs her favorite shell as /bin/sh.  I use Bash 1.12.
  20.  *
  21.  * Elm invokes the mail transport (MTA) like so:
  22.  *
  23.  *    ( ( MTA destination; rm -f tempfile ) & ) < tempfile &
  24.  *
  25.  * This form of command doesn't work with my Bash, in which any command
  26.  * which is backgrounded ("&") gets its stdin attached to /dev/null.
  27.  *
  28.  * The below patch arranges for Elm to call the MTA thusly:
  29.  *
  30.  *    ( MTA destination <tempfile; rm -f tempfile ) &
  31.  * From: decwrl!uunet.UU.NET!fin!chip (Chip Salzenberg)
  32.  *
  33.  * Revision 5.9  1993/04/12  02:34:36  syd
  34.  * I have now added a parameter which controls whether want_to clears the
  35.  * line and centers the question or behaves like it did before. I also
  36.  * added a 0 at the end of the parameter list to all the other calls to
  37.  * want_to where a centered question on a clean line is not desirable.
  38.  * From: Jukka Ukkonen <ukkonen@csc.fi>
  39.  *
  40.  * Revision 5.8  1993/01/20  03:37:16  syd
  41.  * Nits and typos in the NLS messages and corresponding default messages.
  42.  * From: dwolfe@pffft.sps.mot.com (Dave Wolfe)
  43.  *
  44.  * Revision 5.7  1992/12/24  21:42:01  syd
  45.  * Fix messages and nls messages to match.  Plus use want_to
  46.  * where appropriate.
  47.  * From: Syd, via prompting from Jan Djarv <Jan.Djarv@sa.erisoft.se>
  48.  *
  49.  * Revision 5.6  1992/11/26  01:46:26  syd
  50.  * add Decode option to copy_message, convert copy_message to
  51.  * use bit or for options.
  52.  * From: Syd and bjoerns@stud.cs.uit.no (Bjoern Stabell)
  53.  *
  54.  * Revision 5.5  1992/11/26  00:49:04  syd
  55.  * fix use of errno
  56.  * From: Syd
  57.  *
  58.  * Revision 5.4  1992/11/22  01:14:20  syd
  59.  * Allow SCO MMDF to use the mmdf library for mailer via execmail.
  60.  * From: Larry Philps <larryp@sco.com>
  61.  *
  62.  * Revision 5.3  1992/10/24  13:35:39  syd
  63.  * changes found by using codecenter on Elm 2.4.3
  64.  * From: Graham Hudspith <gwh@inmos.co.uk>
  65.  *
  66.  * Revision 5.2  1992/10/11  00:59:39  syd
  67.  * Fix some compiler warnings that I receive compiling Elm on my SVR4
  68.  * machine.
  69.  * From: Tom Moore <tmoore@fievel.DaytonOH.NCR.COM>
  70.  *
  71.  * Revision 5.1  1992/10/03  22:58:40  syd
  72.  * Initial checkin as of 2.4 Release at PL0
  73.  *
  74.  *
  75.  ******************************************************************************/
  76.  
  77. /** For those cases when you want to have a message continue along
  78.     to another person in such a way as they end up receiving it with
  79.     the return address the person YOU received the mail from (does
  80.     this comment make any sense yet?)...
  81.  
  82. **/
  83.  
  84. #include "headers.h"
  85. #include "s_elm.h"
  86. #include <errno.h>
  87.  
  88. extern int errno;
  89.  
  90. char *error_description();
  91. extern void display_to();
  92.  
  93. int
  94. remail()
  95. {
  96.     /** remail a message... returns TRUE if new foot needed ... **/
  97.     
  98.     FILE *mailfd;
  99.     char entered[VERY_LONG_STRING], expanded[VERY_LONG_STRING];
  100.     char *filename, buffer[VERY_LONG_STRING], ch;
  101.     char mailerflags[NLEN];
  102.     int  err;
  103.     extern char *tempnam();
  104.  
  105.     entered[0] = '\0';
  106.  
  107.     get_to(entered, expanded);
  108.     if (strlen(entered) == 0)
  109.       return(0);
  110.  
  111.     display_to(expanded);
  112.  
  113.     if((filename=tempnam(temp_dir, "snd.")) == NULL) {
  114.       dprint(1, (debugfile, "couldn't make temp file nam! (remail)\n"));
  115.       sprintf(buffer, catgets(elm_msg_cat, ElmSet, ElmCouldntMakeTempFileName,
  116.         "Sorry - couldn't make file temp file name."));
  117.       set_error(buffer);
  118.       return(1);
  119.     }
  120.  
  121.     if ((mailfd = fopen(filename, "w")) == NULL) {
  122.       err = errno;
  123.       dprint(1, (debugfile, "couldn't open temp file %s! (remail)\n", 
  124.           filename));
  125.       dprint(1, (debugfile, "** %s **\n", error_description(err)));
  126.       sprintf(buffer, catgets(elm_msg_cat, ElmSet, ElmCouldntOpenForWriting,
  127.             "Sorry - couldn't open file %s for writing (%s)."),
  128.           error_description(err));
  129.       set_error(buffer);
  130.       return(1);
  131.     }
  132.  
  133.     /** now let's copy the message into the newly opened
  134.         buffer... **/
  135.  
  136.     chown (filename, userid, groupid);
  137.  
  138. #ifdef MMDF
  139.     if (strcmp(submitmail, mailer) == 0)
  140.       do_mmdf_addresses(mailfd, strip_parens(strip_commas(expanded)));
  141. #endif /* MMDF */
  142.  
  143.     copy_message("", mailfd, CM_REMOTE | CM_MMDF_HEAD | CM_REMAIL);
  144.  
  145.     fclose(mailfd);
  146.  
  147.     /** Got the messsage, now let's ensure the person really wants to 
  148.         remail it... **/
  149.  
  150.     ClearLine(LINES-1);
  151.     ClearLine(LINES);
  152.     MCsprintf(buffer, catgets(elm_msg_cat, ElmSet, ElmSureYouWantToRemail,
  153.         "Are you sure you want to remail this message (%c/%c)? "),
  154.         *def_ans_yes, *def_ans_no);
  155.     fflush(stdin);
  156.     ch = want_to(buffer, *def_ans_yes, LINES-1, 0);
  157.     if (ch == *def_ans_no) { /* another day, another No... */
  158.       set_error(catgets(elm_msg_cat, ElmSet, ElmBounceCancelled,
  159.         "Bounce of message canceled."));
  160.       (void) unlink(filename);
  161.       return(1);
  162.     }
  163.  
  164.     if (strcmp(sendmail, mailer) == 0
  165. #ifdef SITE_HIDING
  166.         && ! is_a_hidden_user(username))
  167. #else
  168.                      )
  169. #endif
  170.       strcpy(mailerflags, (sendmail_verbose ? smflagsv : smflags));
  171.     else if (strcmp(submitmail, mailer) == 0) {
  172.       strcpy(mailerflags, submitflags_s);
  173.       strcpy(expanded, " ");
  174.     } else if (strcmp(execmail, mailer) == 0) {
  175.       strcpy(mailerflags, (sendmail_verbose ? emflagsv : emflags));
  176.     } else
  177.       mailerflags[0] = '\0';
  178.     
  179.     sprintf(buffer,"( %s %s %s < %s ; %s %s) &", 
  180.           mailer, mailerflags, strip_parens(strip_commas(expanded)), 
  181.           filename, remove_cmd, filename);
  182.  
  183.     PutLine0(LINES, 0, catgets(elm_msg_cat, ElmSet, ElmResendingMail,
  184.         "Resending mail..."));
  185.     (void) system_call(buffer, 0);
  186.     set_error(catgets(elm_msg_cat, ElmSet, ElmMailResent, "Mail resent."));
  187.  
  188.     return(1);
  189. }
  190. #ifdef MMDF
  191. do_mmdf_addresses(dest_file,buffer)
  192. FILE *dest_file;
  193. char *buffer;
  194. {
  195.     char old[VERY_LONG_STRING], first[VERY_LONG_STRING], 
  196.         rest[VERY_LONG_STRING];
  197.  
  198.     strcpy(old,buffer);
  199.     split_word(old, first, rest);
  200.     while (strcmp(first, "") != 0) {
  201.       fprintf(dest_file, "%s\n", first);
  202.       strcpy(old, rest);
  203.       split_word(old, first, rest);
  204.     }
  205.     fprintf(dest_file, "\n");
  206. }
  207. #endif /* MMDF */
  208.