home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume9 / elm2 / part01 / src / remail.c < prev    next >
C/C++ Source or Header  |  1987-03-08  |  2KB  |  86 lines

  1. /**            remail.c            **/
  2.  
  3. /** For those cases when you want to have a message continue along
  4.     to another person in such a way as they end up receiving it with
  5.     the return address the person YOU received the mail from (does
  6.     this comment make any sense yet??)...
  7.  
  8.     (C) Copyright 1986  Dave Taylor
  9. **/
  10.  
  11. #include "headers.h"
  12. #include <errno.h>
  13.  
  14. extern int errno;
  15.  
  16. char *error_name(), *error_description();
  17.  
  18. int
  19. remail()
  20. {
  21.     /** remail a message... returns TRUE if new foot needed ... **/
  22.     
  23.     FILE *mailfd;
  24.     char entered[VERY_LONG_STRING], expanded[VERY_LONG_STRING];
  25.     char filename[SLEN], buffer[VERY_LONG_STRING];
  26.  
  27.     entered[0] = '\0';
  28.  
  29.     get_to(entered, expanded);
  30.     if (strlen(entered) == 0)
  31.       return(0);
  32.  
  33.     display_to(expanded);
  34.  
  35.     /** now the munge... **/
  36.  
  37.     sprintf(filename, "%s%d", temp_file, getpid());
  38.  
  39.     if ((mailfd = fopen(filename, "w")) == NULL) {
  40.       dprint1(1,"couldn't open temp file %s! (remail)\n", filename);
  41.       dprint2(1,"** %s - %s **\n", error_name(errno),
  42.           error_description(errno));
  43.       sprintf(buffer, "Sorry - couldn't open file %s for writing (%s)",
  44.           error_name(errno));
  45.       set_error(buffer);
  46.       return(1);
  47.     }
  48.  
  49.     /** now let's copy the message into the newly opened
  50.         buffer... **/
  51.  
  52.     copy_message("", mailfd, FALSE, TRUE);  
  53.  
  54.     fclose(mailfd);
  55.  
  56.     /** Got the messsage, now let's ensure the person really wants to 
  57.         remail it... **/
  58.  
  59.     ClearLine(LINES-1);
  60.     ClearLine(LINES);
  61.     PutLine1(LINES-1,0,
  62.         "Are you sure you want to remail this message (y/n) ? y%c",
  63.         BACKSPACE);
  64.     fflush(stdin);
  65.     fflush(stdout);
  66.     if (tolower(ReadCh()) == 'n') { /* another day, another No... */
  67.       Write_to_screen("No", 0);
  68.       set_error("Bounce of message cancelled");
  69.           return(1);
  70.     }
  71.     Write_to_screen("Yes!", 0);
  72.  
  73.     sprintf(buffer, "%s %s < %s", mailer, expanded, filename);
  74.  
  75.     PutLine0(LINES,0,"resending mail...");
  76.  
  77.     if ((errno = system_call(buffer, SH)) != 0) {
  78.       sprintf(buffer, "Remail failed with error %d!", errno);
  79.       set_error(buffer);
  80.     }
  81.     else
  82.       set_error("mail resent");
  83.  
  84.     return(1);
  85. }
  86.