home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / com / utils / elm / sources / remail.c < prev    next >
C/C++ Source or Header  |  1992-04-06  |  5KB  |  167 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);
  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. #ifdef SITE_HIDING
  120.         && ! is_a_hidden_user(username))
  121. #else
  122.                      )
  123. #endif
  124.       strcpy(mailerflags, (sendmail_verbose ? smflagsv : smflags));
  125.     else if (strcmp(submitmail, mailer) == 0) {
  126.       strcpy(mailerflags, submitflags);
  127.           strcpy(expanded, " ");
  128.     } else
  129.       mailerflags[0] = '\0';
  130.  
  131.     sprintf(buffer,"%s -f %s %s %s 2>nul", mailer, filename,
  132.               mailerflags, strip_parens(strip_commas(expanded)));
  133.  
  134.     PutLine0(LINES,0,"Resending mail...");
  135.  
  136.     if ( sys_status = system_call(buffer, SH, FALSE, FALSE) ) {
  137.         /* problem case: */
  138.         sprintf(buffer, "mailer returned error status %d", sys_status);
  139.         set_error(buffer);
  140.     } else {
  141.             set_error("Mail resent.");
  142.         }
  143.  
  144.         unlink(filename);
  145.  
  146.     return(1);
  147. }
  148.  
  149. #ifdef MMDF
  150. do_mmdf_addresses(dest_file,buffer)
  151. FILE *dest_file;
  152. char *buffer;
  153. {
  154.     char old[VERY_LONG_STRING], first[VERY_LONG_STRING],
  155.         rest[VERY_LONG_STRING];
  156.  
  157.     strcpy(old,buffer);
  158.     split_word(old, first, rest);
  159.     while (strcmp(first, "") != 0) {
  160.       fprintf(dest_file, "%s\n", first);
  161.       strcpy(old, rest);
  162.       split_word(old, first, rest);
  163.     }
  164.     fprintf(dest_file, "\n");
  165. }
  166. #endif /* MMDF */
  167.