home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / aix-rs6000 / elm2.3.11.AIX3.1.5.Z / elm2.3.11.AIX3.1.5 / src / savecopy.c < prev    next >
C/C++ Source or Header  |  1991-11-26  |  7KB  |  244 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: savecopy.c,v 4.1 90/04/28 22:44:02 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1 $   $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:    savecopy.c,v $
  17.  * Revision 4.1  90/04/28  22:44:02  syd
  18.  * checkin of Elm 2.3 as of Release PL0
  19.  * 
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** Save a copy of the specified message in a folder.
  24.  
  25. **/
  26.  
  27. #include "headers.h"
  28. #ifdef I_TIME
  29. #  include <time.h>
  30. #endif
  31. #ifdef I_SYSTIME
  32. #  include <sys/time.h>
  33. #endif
  34.  
  35. #include <errno.h>
  36.  
  37. char *format_long();
  38. char *error_name(), *error_description();
  39. char *ctime();
  40.  
  41. extern char in_reply_to[SLEN];    /* In-Reply-To: string */
  42. extern int errno;
  43.  
  44. /* char *strcat(), *strcpy(); */
  45. unsigned long sleep();
  46. long  time();
  47.  
  48. save_copy(to, cc, bcc, filename, copy_file, form)
  49. char *to, *cc, *bcc, *filename, *copy_file;
  50. int form;
  51. {
  52.     /** This routine appends a copy of the outgoing message to the
  53.         file specified.  **/
  54.  
  55.     FILE *save,        /* file id for file to save to */
  56.          *message,        /* file id for file with message body */
  57.          *write_header_info();
  58.     char  buffer[SLEN],    /* read buffer                */
  59.           savename[SLEN];    /* name of file saving into    */
  60.   
  61.  
  62.     /* presume copy_file is okay as is for now */
  63.     strcpy(savename, copy_file);
  64.  
  65.     /* if save-by-name wanted */
  66.     if((strcmp(copy_file, "=") == 0)  || (strcmp(copy_file, "=?") == 0)) {
  67.  
  68.       get_return_name(to, buffer, TRUE);    /* determine 'to' login */
  69.       if (strlen(buffer) == 0) {
  70.  
  71.         /* can't get file name from 'to' -- use sent_mail instead */
  72.         dprint(3, (debugfile,
  73.         "Warning: get_return_name couldn't break down %s\n", to));
  74.         error1(
  75. "Cannot determine `to' name to save by! Saving to \"sent\" folder %s instead.",
  76.           sent_mail);
  77.         strcpy(savename, "<");
  78.         sleep(3);
  79.       } else
  80.         sprintf(savename, "=%s", buffer);        /* good! */
  81.     }
  82.  
  83.     expand_filename(savename, TRUE);    /* expand special chars */
  84.  
  85.     /* If saving conditionally by logname but folder doesn't exist
  86.      * save to sent folder instead. */
  87.     if((strcmp(copy_file, "=?") == 0)
  88.           && (access(savename, ACCESS_EXISTS) != 0)) {
  89.       dprint(5, (debugfile,
  90.         "Conditional save by name: file %s doesn't exist - using \"<\".\n",
  91.         savename));
  92.       strcpy(savename, "<");
  93.       expand_filename(savename, TRUE);
  94.     }
  95.  
  96.     if ((errno = can_open(savename, "a"))) {
  97.       dprint(2, (debugfile,
  98.       "Error: attempt to autosave to a file that can't be appended to!\n"));
  99.       dprint(2, (debugfile, "\tfilename = \"%s\"\n", savename));
  100.       dprint(2, (debugfile, "** %s - %s **\n", error_name(errno),
  101.           error_description(errno)));
  102.  
  103.       /* Lets try sent_mail before giving up */
  104.       if(strcmp(sent_mail, savename) == 0) {
  105.         /* we are ALREADY using sent_mail! */
  106.         error1("Cannot save to %s!", savename);
  107.         sleep(3);
  108.         return(FALSE);
  109.       }
  110.  
  111.       if ((errno = can_open(sent_mail, "a"))) {
  112.         dprint(2, (debugfile,
  113.       "Error: attempt to autosave to a file that can't be appended to!\n"));
  114.         dprint(2, (debugfile, "\tfilename = \"%s\"\n", sent_mail));
  115.         dprint(2, (debugfile, "** %s - %s **\n", error_name(errno),
  116.             error_description(errno)));
  117.         error2("Cannot save to %s nor to \"sent\" folder %s!",
  118.             savename, sent_mail);
  119.         sleep(3);
  120.         return(FALSE);
  121.       }
  122.       error2("Cannot save to %s! Saving to \"sent\" folder %s instead.",
  123.           savename, sent_mail);
  124.       sleep(3);
  125.       strcpy(savename, sent_mail);
  126.     }
  127.  
  128.     save_file_stats(savename);
  129.  
  130.     /* Write header */
  131.     if ((save = write_header_info(savename, to, cc, bcc,
  132.           form == YES, TRUE)) == NULL)
  133.       return(FALSE);
  134.  
  135.     /* Now add file with message as handed to mailer */
  136.     if ((message = fopen(filename, "r")) == NULL) {
  137.       fclose(save);
  138.       dprint(1, (debugfile,
  139.          "Error: Couldn't read folder %s (save_copy)\n", filename));
  140.       dprint(1, (debugfile, "** %s - %s **\n", error_name(errno),
  141.           error_description(errno)));
  142.       error1("Couldn't read folder %s!", filename);
  143.       sleep(3);
  144.       return(FALSE);
  145.     }
  146.  
  147.         copy_message_across(message, save, TRUE);
  148.  
  149.  
  150.     fclose(save);
  151.     fclose(message);
  152.  
  153.     restore_file_stats(savename);
  154.  
  155.     return(TRUE);
  156. }
  157. char *
  158. cf_english(fn)
  159. char *fn;
  160. {
  161.     /** Return "English" expansion for special copy file name abbreviations
  162.     or just the file name  **/
  163.  
  164.     if(!*fn)
  165.       return("<no save>");
  166.     else if(!fn[1]) {
  167.       if(*fn == '=')
  168.     return("<unconditionally save by name>");
  169.       else if(*fn == '<')
  170.     return("<\"sent\" folder>");
  171.     } else if ((fn[0] == '=') && (fn[1] == '?'))
  172.       return("<conditionally save by name>");
  173.  
  174.     return(fn);
  175. }
  176.  
  177. #define NCF_PROMPT    "Save copy in (use '?' for help/to list folders): "
  178. int
  179. name_copy_file(fn)
  180. char *fn;
  181. {
  182.     /** Prompt user for name of file for saving copy of outbound msg to.
  183.     Return true if we need a redraw. **/
  184.  
  185.     int redraw = 0;    /* set when we ask for help = need redraw */
  186.     char buffer[SLEN], origbuffer[SLEN];
  187.     static char helpmsg[LONG_STRING];
  188.  
  189.     /* expand passed copy file name into English */
  190.     strcpy(buffer, cf_english(fn));
  191.  
  192.     /* prepare screen with instructions */
  193.     MoveCursor(LINES-2, 0);
  194.     CleartoEOS();
  195.     PutLine0(LINES-2, 0, NCF_PROMPT);
  196.  
  197.     while(1) {
  198.  
  199.       /* get file name from user input */
  200.       strcpy(origbuffer, buffer);
  201.       optionally_enter(buffer, LINES-2, strlen(NCF_PROMPT), FALSE, FALSE);
  202.  
  203.       if(strcmp(buffer, "?") != 0) { /* got what we wanted - non-help choice */
  204.  
  205.     if(strcmp(origbuffer, buffer) != 0)
  206.       /* user changed from our English expansion 
  207.        * so we'd better copy user input to fn
  208.        */
  209.       strcpy(fn, buffer);
  210.  
  211.     /* else user presumably left our English expansion - no change in fn */
  212.  
  213.     /* display English expansion of new user input a while */
  214.     PutLine1(LINES-2, strlen(NCF_PROMPT), cf_english(fn));
  215.     MoveCursor(LINES, 0);
  216.     sleep(1);
  217.     MoveCursor(LINES-2, 0);
  218.     CleartoEOS();
  219.  
  220.     return(redraw);
  221.       }
  222.  
  223.       /* give help and list folders */
  224.       redraw = TRUE;
  225.       if(!*helpmsg)     /* help message not yet formulated */
  226.         sprintf(helpmsg,
  227.     "\n\r%s\n\r%s%s%s\n\r%s\n\r%s\n\r%s\n\r%s\n\r%s\n\r\n\r",
  228.     "Enter: <nothing> to not save a copy of the message,",
  229.     "       '<'       to save in your \"sent\" folder (", sent_mail, "),",
  230.     "       '='       to save by name (the folder name depends on whom the",
  231.     "                     message is to, in the end),",
  232.     "       '=?'      to save by name if the folder already exists,",
  233.     "                     and if not, to your \"sent\" folder,",
  234.     "       or a filename (a leading '=' denotes your folder directory).");
  235.  
  236.       list_folders(4, helpmsg);
  237.       PutLine0(LINES-2, 0, NCF_PROMPT);
  238.  
  239.       /* restore as default to English version of the passed copy file name */
  240.       strcpy(buffer, cf_english(fn));
  241.  
  242.     }
  243. }
  244.