home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / src / mailmsg1.c < prev    next >
C/C++ Source or Header  |  1993-09-16  |  11KB  |  373 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: mailmsg1.c,v 4.1.1.1 90/06/05 20:52:21 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1.1.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:    mailmsg1.c,v $
  17.  * Revision 4.1.1.1  90/06/05  20:52:21  syd
  18.  * Fixes the 'g' Group Reply command to send to the cc list also.
  19.  * A bad variable name caused it to be ignored.
  20.  * From: chip@chinacat.Unicom.COM (Chip Rosenthal)
  21.  *
  22.  * Revision 4.1  90/04/28  22:43:26  syd
  23.  * checkin of Elm 2.3 as of Release PL0
  24.  *
  25.  *
  26.  ******************************************************************************/
  27.  
  28. /** Interface to allow mail to be sent to users.  Part of ELM  **/
  29.  
  30.  
  31. #include "headers.h"
  32.  
  33. /** strings defined for the hdrconfg routines **/
  34.  
  35. char subject[SLEN], in_reply_to[SLEN], expires[SLEN],
  36.      action[SLEN], priority[SLEN], reply_to[SLEN], to[VERY_LONG_STRING],
  37.      cc[VERY_LONG_STRING], expanded_to[VERY_LONG_STRING],
  38.      expanded_cc[VERY_LONG_STRING], user_defined_header[SLEN],
  39.      bcc[VERY_LONG_STRING], expanded_bcc[VERY_LONG_STRING];
  40.  
  41. char *format_long(), *strip_commas(), *tail_of_string(), *strcpy();
  42. unsigned long sleep();
  43.  
  44. int
  45. sendmsg(given_to, given_cc, given_subject, edit_message, form_letter, replying)
  46. char *given_to, *given_cc, *given_subject;
  47. int   edit_message, form_letter, replying;
  48. {
  49.     /** Prompt for fields and then call mail() to send the specified
  50.         message.  If 'edit_message' is true then don't allow the
  51.             message to be edited. 'form_letter' can be "YES" "NO" or "MAYBE".
  52.         if YES, then add the header.  If MAYBE, then add the M)ake form
  53.         option to the last question (see mailsg2.c) etc. etc.
  54.         if (replying) then add an In-Reply-To: header...
  55.         Return TRUE if the main part of the screen has been changed
  56.         (useful for knowing whether a redraw is needed.
  57.     **/
  58.  
  59.     int  copy_msg = FALSE, is_a_response = FALSE;
  60.  
  61.     /* First: zero all current global message strings */
  62.  
  63.     cc[0] = bcc[0] = reply_to[0] = expires[0] = '\0';
  64.     action[0] = priority[0] = user_defined_header[0] = in_reply_to[0] ='\0';
  65.     expanded_to[0] = expanded_cc[0] = expanded_bcc[0] = '\0';
  66.  
  67.     strcpy(subject, given_subject);        /* copy given subject */
  68.     strcpy(to, given_to);            /* copy given to:     */
  69.     strcpy(cc, given_cc);            /*  and so on..       */
  70.  
  71.     /******* And now the real stuff! *******/
  72.  
  73.     copy_msg=copy_the_msg(&is_a_response); /* copy msg into edit buffer? */
  74.  
  75.     if (get_to(to, expanded_to) == 0)   /* get the To: address and expand */
  76.       return(0);
  77.     if ( cc[0] != '\0' )            /* expand out CC addresses */
  78.       build_address(strip_commas(cc), expanded_cc);
  79.  
  80.     /** if we're batchmailing, let's send it and GET OUTTA HERE! **/
  81.  
  82.     if (batch_only) {
  83.       return(mail(FALSE, FALSE, form_letter));
  84.     }
  85.  
  86.     display_to(expanded_to);    /* display the To: field on screen... */
  87.  
  88.     dprint(3, (debugfile, "\nMailing to \"%s\"\n", expanded_to));
  89.  
  90.     if (get_subject(subject) == 0)        /* get the Subject: field */
  91.       return(0);
  92.  
  93.     dprint(4, (debugfile, "Subject is %s\n", subject));
  94.  
  95.     if (prompt_for_cc) {
  96.       if (get_copies(cc, expanded_to, expanded_cc, copy_msg) == 0)
  97.         return(0);
  98.  
  99.       if (strlen(cc) > 0)
  100.         dprint(4, (debugfile, "Copies to %s\n", expanded_cc));
  101.     }
  102.  
  103.     MoveCursor(LINES,0);    /* so you know you've hit <return> ! */
  104.  
  105.     /** generate the In-Reply-To: header... **/
  106.  
  107.     if (is_a_response && replying)
  108.       generate_reply_to(current-1);
  109.  
  110. #ifdef OS2
  111.     /* Reply-To: from UUPC.RC (see os2util.c), from Frank Behrens */
  112.     if (strlen(_reply_to) > 0)
  113.         {
  114.        strcpy(reply_to, _reply_to);
  115.        dprint(4, (debugfile, "Add default Reply-To: %s\n", _reply_to));
  116.     }
  117. #endif
  118.  
  119.     /* and mail that puppy outta here! */
  120.  
  121.     return(mail(copy_msg, edit_message, form_letter));
  122. }
  123.  
  124. get_to(to_field, address)
  125. char *to_field, *address;
  126. {
  127.     /** prompt for the "To:" field, expanding into address if possible.
  128.         This routine returns ZERO if errored, or non-zero if okay **/
  129.  
  130.     if (strlen(to_field) == 0) {
  131.       if (user_level < 2) {
  132.         PutLine0(LINES-2, 0, "Send the message to: ");
  133.         (void) optionally_enter(to_field, LINES-2, 21, FALSE, FALSE);
  134.       }
  135.       else {
  136.         PutLine0(LINES-2, 0, "To: ");
  137.         (void) optionally_enter(to_field, LINES-2, 4, FALSE, FALSE);
  138.       }
  139.       if (strlen(to_field) == 0) {
  140.         ClearLine(LINES-2);
  141.         return(0);
  142.       }
  143.       (void) build_address(strip_commas(to_field), address);
  144.     }
  145.     else if (mail_only)
  146.       (void) build_address(strip_commas(to_field), address);
  147.     else
  148.       strcpy(address, to_field);
  149.  
  150.     if (strlen(address) == 0) {    /* bad address!  Removed!! */
  151.       ClearLine(LINES-2);
  152.       return(0);
  153.     }
  154.  
  155.     return(1);        /* everything is okay... */
  156. }
  157.  
  158. get_subject(subject_field)
  159. char *subject_field;
  160. {
  161.     char    ch;
  162.  
  163.     /** get the subject and return non-zero if all okay... **/
  164.     int len = 9, prompt_line;
  165.  
  166.     prompt_line = mail_only ? 4 : LINES-2;
  167.  
  168.     if (user_level == 0) {
  169.       PutLine0(prompt_line,0,"Subject of message: ");
  170.       len = 20;
  171.     }
  172.     else
  173.       PutLine0(prompt_line,0,"Subject: ");
  174.  
  175.     CleartoEOLN();
  176.  
  177.     if(optionally_enter(subject_field, prompt_line, len, TRUE, FALSE)==-1){
  178.       /** User hit the BREAK key! **/
  179.       MoveCursor(prompt_line,0);
  180.       CleartoEOLN();
  181.       error("Mail not sent.");
  182.       return(0);
  183.     }
  184.  
  185.     if (strlen(subject_field) == 0) {    /* zero length subject?? */
  186.       PutLine1(prompt_line,0,
  187.         "No subject - Continue with message? (y/n) n%c", BACKSPACE);
  188.  
  189.       ch = ReadCh();
  190.       if (tolower(ch) != 'y') {    /* user says no! */
  191.         Write_to_screen("No.", 0);
  192.         ClearLine(prompt_line);
  193.         error("Mail not sent.");
  194.         return(0);
  195.       }
  196.       else {
  197.         Write_to_screen("Yes.", 0);
  198.         PutLine0(prompt_line,0,"Subject: <none>");
  199.         CleartoEOLN();
  200.       }
  201.     }
  202.  
  203.     return(1);        /** everything is cruising along okay **/
  204. }
  205.  
  206. get_copies(cc_field, address, addressII, copy_message)
  207. char *cc_field, *address, *addressII;
  208. int   copy_message;
  209. {
  210.     /** Get the list of people that should be cc'd, returning ZERO if
  211.         any problems arise.  Address and AddressII are for expanding
  212.         the aliases out after entry!
  213.         If 'bounceback' is nonzero, add a cc to ourselves via the remote
  214.         site, but only if hops to machine are > bounceback threshold.
  215.         If copy-message, that means that we're going to have to invoke
  216.         a screen editor, so we'll need to delay after displaying the
  217.         possibly rewritten Cc: line...
  218.     **/
  219.     int prompt_line;
  220.  
  221.     prompt_line = mail_only ? 5 : LINES - 1;
  222.     PutLine0(prompt_line,0,"Copies to: ");
  223.  
  224.     fflush(stdout);
  225.  
  226.     if (optionally_enter(cc_field, prompt_line, 11, FALSE, FALSE) == -1) {
  227.       ClearLine(prompt_line-1);
  228.       ClearLine(prompt_line);
  229.  
  230.       error("Mail not sent.");
  231.       return(0);
  232.     }
  233.  
  234.     /** The following test is that if the build_address routine had
  235.         reason to rewrite the entry given, then, if we're mailing only
  236.         print the new Cc line below the old one.  If we're not, then
  237.         assume we're in screen mode and replace the incorrect entry on
  238.         the line above where we are (e.g. where we originally prompted
  239.         for the Cc: field).
  240.     **/
  241.  
  242.     if (build_address(strip_commas(cc_field), addressII)) {
  243.       PutLine1(prompt_line, 11, "%s", addressII);
  244.       if ((strcmp(editor, "builtin") != 0 && strcmp(editor, "none") != 0)
  245.           || copy_message)
  246.         sleep(2);
  247.     }
  248.  
  249.     if (strlen(address) + strlen(addressII) > VERY_LONG_STRING) {
  250.       dprint(2, (debugfile,
  251.         "String length of \"To:\" + \"Cc\" too long! (get_copies)\n"));
  252.       error("Too many people. Copies ignored.");
  253.       sleep(2);
  254.       cc_field[0] = '\0';
  255.     }
  256.  
  257.     return(1);        /* everything looks okay! */
  258. }
  259.  
  260. int
  261. copy_the_msg(is_a_response)
  262. int *is_a_response;
  263. {
  264.     /** Returns True iff the user wants to copy the message being
  265.         replied to into the edit buffer before invoking the editor!
  266.         Sets "is_a_response" to true if message is a response...
  267.     **/
  268.  
  269.     int answer = FALSE;
  270.  
  271.     if (forwarding)
  272.       answer = TRUE;
  273.     else if (strlen(to) > 0 && !mail_only) {  /* predefined 'to' line! */
  274.       if (auto_copy)
  275.         answer = TRUE;
  276.       else
  277.         answer = (want_to("Copy message? (y/n) ", 'n') == 'y');
  278.       *is_a_response = TRUE;
  279.     }
  280.  
  281.     return(answer);
  282. }
  283.  
  284. static int to_line, to_col;
  285.  
  286. display_to(address)
  287. char *address;
  288. {
  289.     /** Simple routine to display the "To:" line according to the
  290.         current configuration (etc)
  291.      **/
  292.     register int open_paren;
  293.  
  294.     to_line = mail_only ? 3 : LINES - 3;
  295.     to_col = mail_only ? 0 : COLUMNS - 50;
  296.     if (names_only)
  297.       if ((open_paren = chloc(address, '(')) > 0) {
  298.         if (open_paren < chloc(address, ')')) {
  299.           output_abbreviated_to(address);
  300.           return;
  301.         }
  302.       }
  303.     if(mail_only)
  304.       if(strlen(address) > 80)
  305.         PutLine1(to_line, to_col, "To: (%s)",
  306.             tail_of_string(address, 75));
  307.       else
  308.         PutLine1(to_line, to_col, "To: %s", address);
  309.     else if (strlen(address) > 45)
  310.       PutLine1(to_line, to_col, "To: (%s)",
  311.           tail_of_string(address, 40));
  312.     else {
  313.       if (strlen(address) > 30)
  314.         PutLine1(to_line, to_col, "To: %s", address);
  315.       else
  316.         PutLine1(to_line, to_col, "          To: %s", address);
  317.       CleartoEOLN();
  318.     }
  319. }
  320.  
  321. output_abbreviated_to(address)
  322. char *address;
  323. {
  324.     /** Output just the fields in parens, separated by commas if need
  325.         be, and up to COLUMNS-50 characters...This is only used if the
  326.         user is at level BEGINNER.
  327.     **/
  328.  
  329.     char newaddress[LONG_STRING];
  330.     register int iindex, newindex = 0, in_paren = 0, add_len;
  331.  
  332.     iindex = 0;
  333.  
  334.     add_len = strlen(address);
  335.     while (newindex < 55 && iindex < add_len) {
  336.       if (address[iindex] == '(') in_paren++;
  337.       else if (address[iindex] == ')') {
  338.         in_paren--;
  339.         if (iindex < add_len-4) {
  340.           newaddress[newindex++] = ',';
  341.           newaddress[newindex++] = ' ';
  342.         }
  343.       }
  344.  
  345.       /* copy if in_paren but not at the opening outer parens */
  346.       if (in_paren && !(address[iindex] == '(' && in_paren == 1))
  347.           newaddress[newindex++] = address[iindex];
  348.  
  349.       iindex++;
  350.     }
  351.  
  352.     newaddress[newindex] = '\0';
  353.  
  354.     if (mail_only)
  355.       if (strlen(newaddress) > 80)
  356.         PutLine1(to_line, to_col, "To: (%s)",
  357.            tail_of_string(newaddress, 60));
  358.       else
  359.         PutLine1(to_line, to_col, "To: %s", newaddress);
  360.     else if (strlen(newaddress) > 50)
  361.        PutLine1(to_line, to_col, "To: (%s)",
  362.            tail_of_string(newaddress, 40));
  363.      else {
  364.        if (strlen(newaddress) > 30)
  365.          PutLine1(to_line, to_col, "To: %s", newaddress);
  366.        else
  367.          PutLine1(to_line, to_col, "          To: %s", newaddress);
  368.        CleartoEOLN();
  369.      }
  370.  
  371.     return;
  372. }
  373.