home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / src / remail.c < prev    next >
C/C++ Source or Header  |  1995-03-05  |  5KB  |  164 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: remail.c,v 4.1.1.2 90/10/10 12:45:07 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1.1.2 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  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 4.1.1.2  90/10/10  12:45:07  syd
  18.  * Make the symbol look less like a typo, its real
  19.  * From: Syd
  20.  *
  21.  * Revision 4.1.1.1  90/10/07  19:48:15  syd
  22.  * fix the bounce problem reported earlier when using MMDF submit as the MTA.
  23.  * From: Jim Clausing <jac%brahms.tinton.ccur.com@RELAY.CS.NET>
  24.  *
  25.  * Revision 4.1  90/04/28  22:43:50  syd
  26.  * checkin of Elm 2.3 as of Release PL0
  27.  *
  28.  *
  29.  ******************************************************************************/
  30.  
  31. /** For those cases when you want to have a message continue along
  32.     to another person in such a way as they end up receiving it with
  33.     the return address the person YOU received the mail from (does
  34.     this comment make any sense yet??)...
  35.  
  36. **/
  37.  
  38. #include "headers.h"
  39. #include <errno.h>
  40.  
  41. #ifndef OS2
  42. extern int errno;
  43. #endif
  44.  
  45. char *error_name(), *error_description();
  46.  
  47. int
  48. remail()
  49. {
  50.     /** remail a message... returns TRUE if new foot needed ... **/
  51.  
  52.     FILE *mailfd;
  53.     char entered[VERY_LONG_STRING], expanded[VERY_LONG_STRING];
  54.     char *filename, buffer[VERY_LONG_STRING], ch;
  55.     char mailerflags[NLEN];
  56.     extern char *tempnam();
  57.         int sys_status;
  58.  
  59.     entered[0] = '\0';
  60.  
  61.     get_to(entered, expanded);
  62.     if (strlen(entered) == 0)
  63.       return(0);
  64.  
  65.     display_to(expanded);
  66.  
  67.     if((filename=tempnam(temp_dir, "snd")) == NULL) {
  68.       dprint(1, (debugfile, "couldn't make temp file nam! (remail)\n"));
  69.       sprintf(buffer, "Sorry - couldn't make file temp file name.");
  70.       set_error(buffer);
  71.       return(1);
  72.     }
  73.  
  74.     if ((mailfd = fopen(filename, "w")) == NULL) {
  75.       dprint(1, (debugfile, "couldn't open temp file %s! (remail)\n",
  76.           filename));
  77.       dprint(1, (debugfile, "** %s - %s **\n", error_name(errno),
  78.           error_description(errno)));
  79.       sprintf(buffer, "Sorry - couldn't open file %s for writing (%s).",
  80.           error_name(errno));
  81.       set_error(buffer);
  82.       return(1);
  83.     }
  84.  
  85.     /** now let's copy the message into the newly opened
  86.         buffer... **/
  87.  
  88.     chown (filename, userid, groupid);
  89.  
  90. #ifdef _MMDF
  91.     if (strcmp(submitmail, mailer) == 0)
  92.       do_mmdf_addresses(mailfd, strip_parens(strip_commas(expanded)));
  93. #endif /* MMDF */
  94.  
  95.     copy_message("", mailfd, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE);
  96.  
  97.     fclose(mailfd);
  98.  
  99.     /** Got the messsage, now let's ensure the person really wants to
  100.         remail it... **/
  101.  
  102.     ClearLine(LINES-1);
  103.     ClearLine(LINES);
  104.     PutLine1(LINES-1,0,
  105.         "Are you sure you want to remail this message (y/n)? y%c",
  106.         BACKSPACE);
  107.     fflush(stdin);
  108.     fflush(stdout);
  109.     ch = ReadCh();
  110.     if (tolower(ch) == 'n') { /* another day, another No... */
  111.       Write_to_screen("No.", 0);
  112.       set_error("Bounce of message cancelled.");
  113.       (void) unlink(filename);
  114.       return(1);
  115.     }
  116.     Write_to_screen("Yes.", 0);
  117.  
  118.     if (strcmp(sendmail, mailer) == 0)
  119.     {
  120.       sprintf(buffer,"sndmail %s -af %s -f %s@%s %s >nul 2>&1", 
  121.           background ? "-bg" : "",
  122.           filename, username, hostfromname, 
  123.           strip_parens(strip_commas(expanded)));
  124.     }
  125.     else {
  126.       sprintf(buffer,"%s -f %s %s 2>nul", 
  127.           mailer, filename, strip_parens(strip_commas(expanded)));
  128.     }
  129.  
  130.     PutLine0(LINES,0,"Resending mail...");
  131.  
  132.     if ( sys_status = system_call(buffer, SH, FALSE, FALSE) ) {
  133.         /* problem case: */
  134.         sprintf(buffer, "mailer returned error status %d", sys_status);
  135.         set_error(buffer);
  136.     } else {
  137.             set_error("Mail resent.");
  138.         }
  139.  
  140.     if (!background)
  141.       unlink(filename);
  142.  
  143.     return(1);
  144. }
  145.  
  146. #ifdef MMDF
  147. do_mmdf_addresses(dest_file,buffer)
  148. FILE *dest_file;
  149. char *buffer;
  150. {
  151.     char old[VERY_LONG_STRING], first[VERY_LONG_STRING],
  152.         rest[VERY_LONG_STRING];
  153.  
  154.     strcpy(old,buffer);
  155.     split_word(old, first, rest);
  156.     while (strcmp(first, "") != 0) {
  157.       fprintf(dest_file, "%s\n", first);
  158.       strcpy(old, rest);
  159.       split_word(old, first, rest);
  160.     }
  161.     fprintf(dest_file, "\n");
  162. }
  163. #endif /* MMDF */
  164.