ftp.nice.ch/pub/next/unix/mail/elm2.4/elm.2.4pl17.s.tar.gz#/src/mailmsg1.c

This is mailmsg1.c in view mode; [Download] [Up]

static char rcsid[] = "@(#)$Id: mailmsg1.c,v 5.1 1992/10/03 22:58:40 syd Exp $";

/*******************************************************************************
 *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
 *
 *			Copyright (c) 1988-1992 USENET Community Trust
 *			Copyright (c) 1986,1987 Dave Taylor
 *******************************************************************************
 * Bug reports, patches, comments, suggestions should be sent to:
 *
 *	Syd Weinstein, Elm Coordinator
 *	elm@DSI.COM			dsinc!elm
 *
 *******************************************************************************
 * $Log: mailmsg1.c,v $
 * Revision 5.1  1992/10/03  22:58:40  syd
 * Initial checkin as of 2.4 Release at PL0
 *
 *
 ******************************************************************************/

/** Interface to allow mail to be sent to users.  Part of ELM  **/


#include "headers.h"
#include "s_elm.h"

/** strings defined for the hdrconfg routines **/

char subject[SLEN], in_reply_to[SLEN], expires[SLEN],
     action[SLEN], priority[SLEN], reply_to[SLEN], to[VERY_LONG_STRING], 
     cc[VERY_LONG_STRING], expanded_to[VERY_LONG_STRING], 
     expanded_reply_to[LONG_STRING],
     expanded_cc[VERY_LONG_STRING], user_defined_header[SLEN],
     bcc[VERY_LONG_STRING], expanded_bcc[VERY_LONG_STRING],
     precedence[SLEN], expires_days[SLEN];

char *format_long(), *strip_commas(), *tail_of_string(), *strcpy();
unsigned long sleep();

static int to_line, to_col;

void
output_abbreviated_to(address)
char *address;
{
	/** Output just the fields in parens, separated by commas if need
	    be, and up to COLUMNS-50 characters...This is only used if the
	    user is at level BEGINNER.
	**/

	char newaddress[LONG_STRING];
	register int iindex, newindex = 0, in_paren = 0, add_len;

	iindex = 0;

	add_len = strlen(address);
	while (newindex < 55 && iindex < add_len) {
	  if (address[iindex] == '(') in_paren++;
	  else if (address[iindex] == ')') { 
	    in_paren--;
	    if (iindex < add_len-4) {
	      newaddress[newindex++] = ',';
	      newaddress[newindex++] = ' ';
	    }
	  }
	  
	  /* copy if in_paren but not at the opening outer parens */
	  if (in_paren && !(address[iindex] == '(' && in_paren == 1))
	      newaddress[newindex++] = address[iindex];
	     
	  iindex++;
	}

	newaddress[newindex] = '\0';

	if (mail_only)
	  if (strlen(newaddress) > 80) 
	    PutLine1(to_line, to_col, "To: (%s)", 
	       tail_of_string(newaddress, 60));
	  else
	    PutLine1(to_line, to_col, "To: %s", newaddress);
	else if (strlen(newaddress) > 50) 
	   PutLine1(to_line, to_col, "To: (%s)", 
	       tail_of_string(newaddress, 40));
	 else {
	   if (strlen(newaddress) > 30)
	     PutLine1(to_line, to_col, "To: %s", newaddress);
	   else
	     PutLine1(to_line, to_col, "          To: %s", newaddress);
	   CleartoEOLN();
	 }

	return;
}

void
display_to(address)
char *address;
{
	/** Simple routine to display the "To:" line according to the
	    current configuration (etc) 			      
	 **/
	register int open_paren;

	to_line = mail_only ? 3 : LINES - 3;
	to_col = mail_only ? 0 : COLUMNS - 50;
	if (names_only)
	  if ((open_paren = chloc(address, '(')) > 0) {
	    if (open_paren < chloc(address, ')')) {
	      output_abbreviated_to(address);
	      return;
	    } 
	  }
	if(mail_only)
	  if(strlen(address) > 80)
	    PutLine1(to_line, to_col, "To: (%s)", 
	        tail_of_string(address, 75));
	  else
	    PutLine1(to_line, to_col, "To: %s", address);
	else if (strlen(address) > 45) 
	  PutLine1(to_line, to_col, "To: (%s)", 
	      tail_of_string(address, 40));
	else {
	  if (strlen(address) > 30) 
	    PutLine1(to_line, to_col, "To: %s", address);
	  else
	    PutLine1(to_line, to_col, "          To: %s", address);
	  CleartoEOLN();
	}
}

int
get_to(to_field, address)
char *to_field, *address;
{
	/** prompt for the "To:" field, expanding into address if possible.
	    This routine returns ZERO if errored, or non-zero if okay **/

	if (strlen(to_field) == 0) {
	  if (user_level < 2) {
	    PutLine0(LINES-2, 0, catgets(elm_msg_cat, ElmSet, ElmSendTheMessageTo,
		"Send the message to: "));
	    (void) optionally_enter(to_field, LINES-2, 21, FALSE, FALSE); 
	  }
	  else {
	    PutLine0(LINES-2, 0, catgets(elm_msg_cat, ElmSet, ElmTo, "To: "));
	    (void) optionally_enter(to_field, LINES-2, 4, FALSE, FALSE); 
	  }
	  if (strlen(to_field) == 0) {
	    ClearLine(LINES-2);	
	    return(0);
	  }
	  (void) build_address(strip_commas(to_field), address); 
	}
	else if (mail_only) 
	  (void) build_address(strip_commas(to_field), address); 
	else 
	  strcpy(address, to_field);
	
	if (strlen(address) == 0) {	/* bad address!  Removed!! */
	  ClearLine(LINES-2);
	  return(0);
	}

	return(1);		/* everything is okay... */
}

int
send_msg(given_to, given_cc, given_subject, edit_message, form_letter, replying)
char *given_to, *given_cc, *given_subject;
int   edit_message, form_letter, replying;
{
	/** Prompt for fields and then call mail() to send the specified
	    message.  If 'edit_message' is true then don't allow the
            message to be edited. 'form_letter' can be "YES" "NO" or "MAYBE".
	    if YES, then add the header.  If MAYBE, then add the M)ake form
	    option to the last question (see mailsg2.c) etc. etc. 
	    if (replying) then add an In-Reply-To: header...
	    Return TRUE if the main part of the screen has been changed
	    (useful for knowing whether a redraw is needed.
	**/

	int  copy_msg = FALSE, is_a_response = FALSE;

	/* First: zero all current global message strings */

	cc[0] = bcc[0] = reply_to[0] = expires[0] = '\0';
	action[0] = priority[0] = user_defined_header[0] = in_reply_to[0] ='\0';
	expanded_to[0] = expanded_cc[0] = expanded_bcc[0] = '\0';
	expanded_reply_to[0] = precedence[0] = expires_days[0] = '\0';

	strcpy(subject, given_subject);		/* copy given subject */
	strcpy(to, given_to);			/* copy given to:     */
	strcpy(cc, given_cc);			/*  and so on..       */

	/******* And now the real stuff! *******/

	copy_msg=copy_the_msg(&is_a_response); /* copy msg into edit buffer? */

	if (get_to(to, expanded_to) == 0)   /* get the To: address and expand */
	  return(0);
	if ( cc[0] != '\0' )			/* expand out CC addresses */
	  build_address(strip_commas(cc), expanded_cc);

	/** if we're batchmailing, let's send it and GET OUTTA HERE! **/

	if (batch_only) {
	  return(mail(FALSE, FALSE, form_letter));
	}

	display_to(expanded_to);	/* display the To: field on screen... */

	if (get_subject(subject) == 0)	    /* get the Subject: field */
	  return(0);

	if (prompt_for_cc) {
	  if (get_copies(cc, expanded_to, expanded_cc, copy_msg) == 0)
	    return(0);
	}

	MoveCursor(LINES,0);	/* so you know you've hit <return> ! */

	/** generate the In-Reply-To: header... **/

	if (is_a_response && replying)
	  generate_reply_to(current-1);

	/* and mail that puppy outta here! */
	
	dprint(3, (debugfile, "\nsend_msg() ready to mail...\n"));
	dprint(3, (debugfile, "to=\"%s\" expanded_to=\"%s\"\n",to,expanded_to));
	dprint(4, (debugfile, "subject=\"%s\"\n",subject));
	dprint(5, (debugfile, "cc=\"%s\" expanded_cc=\"%s\"\n",cc,expanded_cc));
	dprint(5, (debugfile, "bcc=\"%s\" expanded_bcc=\"%s\"\n",bcc,expanded_bcc));
	return(mail(copy_msg, edit_message, form_letter));
}

int
get_subject(subject_field)
char *subject_field;
{
	char	ch, msgbuf[SLEN];

	/** get the subject and return non-zero if all okay... **/
	int len = 9, prompt_line;

	prompt_line = mail_only ? 4 : LINES-2;

	if (user_level == 0) {
	  PutLine0(prompt_line,0, catgets(elm_msg_cat, ElmSet, ElmSubjectOfMessage,
		"Subject of message: "));
	  len = 20;
	}
	else
	  PutLine0(prompt_line,0, catgets(elm_msg_cat, ElmSet, ElmSubject, "Subject: "));

	CleartoEOLN();

	if(optionally_enter(subject_field, prompt_line, len, TRUE, FALSE)==-1){
	  /** User hit the BREAK key! **/
	  MoveCursor(prompt_line,0); 	
	  CleartoEOLN();
	  error(catgets(elm_msg_cat, ElmSet, ElmMailNotSent, "Mail not sent."));
	  return(0);
	}

	if (strlen(subject_field) == 0) {	/* zero length subject?? */
	  MCsprintf(msgbuf, catgets(elm_msg_cat, ElmSet, ElmNoSubjectContinue,
	    "No subject - Continue with message? (%c/%c) %c%c"),
	    *def_ans_yes, *def_ans_no, *def_ans_no, BACKSPACE);
	  PutLine0(prompt_line, 0, msgbuf);

	  ch = ReadCh();
	  if (tolower(ch) != *def_ans_yes) {	/* user says no! */
	    Write_to_screen(catgets(elm_msg_cat, ElmSet, ElmNo, "No."), 0);
	    ClearLine(prompt_line);
	    error(catgets(elm_msg_cat, ElmSet, ElmMailNotSend, "Mail not sent."));
	    return(0);
	  }
	  else {
	    Write_to_screen(catgets(elm_msg_cat, ElmSet, ElmYes, "Yes."), 0);
	    PutLine0(prompt_line,0,"Subject: <none>");
	    CleartoEOLN();
	  }
	}

	return(1);		/** everything is cruising along okay **/
}

int
get_copies(cc_field, address, addressII, copy_message)
char *cc_field, *address, *addressII;
int   copy_message;
{
	/** Get the list of people that should be cc'd, returning ZERO if
	    any problems arise.  Address and AddressII are for expanding
	    the aliases out after entry! 
	    If 'bounceback' is nonzero, add a cc to ourselves via the remote
	    site, but only if hops to machine are > bounceback threshold.
	    If copy-message, that means that we're going to have to invoke
	    a screen editor, so we'll need to delay after displaying the
	    possibly rewritten Cc: line...
	**/
	int prompt_line;

	prompt_line = mail_only ? 5 : LINES - 1;
	PutLine0(prompt_line,0, catgets(elm_msg_cat, ElmSet, ElmCopiesTo, "Copies to: "));

	fflush(stdout);

	if (optionally_enter(cc_field, prompt_line, 11, FALSE, FALSE) == -1) {
	  ClearLine(prompt_line-1);
	  ClearLine(prompt_line);
	  
	  error(catgets(elm_msg_cat, ElmSet, ElmMailNotSend, "Mail not sent."));
	  return(0);
	}
	
	/** The following test is that if the build_address routine had
	    reason to rewrite the entry given, then, if we're mailing only
	    print the new Cc line below the old one.  If we're not, then
	    assume we're in screen mode and replace the incorrect entry on
	    the line above where we are (e.g. where we originally prompted
	    for the Cc: field).
	**/

	if (build_address(strip_commas(cc_field), addressII)) {
	  PutLine1(prompt_line, 11, "%s", addressII);
	  if ((strcmp(editor, "builtin") != 0 && strcmp(editor, "none") != 0)
	      || copy_message)
	    sleep(2);
	}

	if (strlen(address) + strlen(addressII) > VERY_LONG_STRING) {
	  dprint(2, (debugfile, 
		"String length of \"To:\" + \"Cc\" too long! (get_copies)\n"));
	  error(catgets(elm_msg_cat, ElmSet, ElmTooManyPeople, "Too many people. Copies ignored."));
	  sleep(2);
	  cc_field[0] = '\0';
	}

	return(1);		/* everything looks okay! */
}
	
int
copy_the_msg(is_a_response)
int *is_a_response;
{
	/** Returns True iff the user wants to copy the message being
	    replied to into the edit buffer before invoking the editor! 
	    Sets "is_a_response" to true if message is a response...
	**/

	char msg[SLEN];
	int answer = FALSE;

	if (forwarding)
	  answer = TRUE;
	else if (strlen(to) > 0 && !mail_only) {  /* predefined 'to' line! */
	  if (auto_copy) 
	    answer = TRUE;
	  else {
	    MCsprintf(msg, catgets(elm_msg_cat, ElmSet, ElmCopyMessageYN,
		"Copy message? (%c/%c) "), *def_ans_yes, *def_ans_no);
	    answer = (want_to(msg, *def_ans_no) == *def_ans_yes);
	  }
	  *is_a_response = TRUE;
	}

	return(answer);
}

int
a_sendmsg(edit_message, form_letter)
int   edit_message, form_letter;
{
	/** Prompt for fields and then call mail() to send the specified
	    message.  If 'edit_message' is true then don't allow the
            message to be edited. 'form_letter' can be "YES" "NO" or "MAYBE".
	    if YES, then add the header.  If MAYBE, then add the M)ake form
	    option to the last question (see mailsg2.c) etc. etc. 

	    Return TRUE if the main part of the screen has been changed
	    (useful for knowing whether a redraw is needed.
	**/

	register int tagged = 0, i;

	/* First: zero all current global message strings */

	cc[0] = bcc[0] = reply_to[0] = expires[0] = '\0';
	action[0] = priority[0] = user_defined_header[0] = in_reply_to[0] ='\0';
	expanded_to[0] = expanded_cc[0] = expanded_bcc[0] = '\0';
	cc[0] = subject[0] = to[0] = '\0';
	expanded_reply_to[0] = precedence[0] = expires_days[0] = '\0';

	for (i=0; i < message_count; i++) {
	  if (ison(aliases[i]->status, TAGGED)) {
	    strcat(to, aliases[i]->alias);
	    strcat(to, " ");
	    clearit(aliases[i]->status, TAGGED);
	    show_msg_tag(i);
	    tagged++;
	  }
	}

	if (tagged == 0) {
	  strcpy(to, aliases[current-1]->alias);
	  tagged = 1;
	}

	dprint(4, (debugfile, "%d message%s tagged for mailing (a_sndmsg)\n",
	        tagged, plural(tagged)));

	/******* And now the real stuff! *******/

	if (build_address(to, expanded_to) == 0)   /* build the To: address and expand */
	  return(0);
	if ( cc[0] != '\0' )			/* expand out CC addresses */
	  build_address(strip_commas(cc), expanded_cc);

	display_to(expanded_to);	/* display the To: field on screen... */

	if (get_subject(subject) == 0)	    /* get the Subject: field */
	  return(0);

	if (prompt_for_cc) {
	  if (get_copies(cc, expanded_to, expanded_cc, FALSE) == 0)
	    return(0);
	}

	MoveCursor(LINES,0);	/* so you know you've hit <return> ! */

	/* and mail that puppy outta here! */
	
	dprint(3, (debugfile, "\na_sendmsg() ready to mail...\n"));
	dprint(3, (debugfile, "to=\"%s\" expanded_to=\"%s\"\n",to,expanded_to));
	dprint(4, (debugfile, "subject=\"%s\"\n",subject));
	dprint(5, (debugfile, "cc=\"%s\" expanded_cc=\"%s\"\n",cc,expanded_cc));
	dprint(5, (debugfile, "bcc=\"%s\" expanded_bcc=\"%s\"\n",bcc,expanded_bcc));

	main_state();
	i = mail(FALSE, edit_message, form_letter);
	main_state();

	return(i);
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.