[comp.mail.elm] Deletion of aliases

Andy.Linton@newcastle.ac.uk (Andy Linton) (12/22/88)

It seems at bit remiss that aliases can be added inside 'Elm' but that you
need to edit the .elm/aliases_text file to delete an alias.
Patches follow:-

*** src/alias.c.orig	Fri Nov 18 10:08:09 1988
--- src/alias.c	Wed Dec  7 12:46:49 1988
***************
*** 40,45 ****
--- 40,47 ----
  #undef        tolower
  #endif
  
+ #define	ECHOIT	1 	/* echo on for prompting */
+ 
  char *expand_group(), *get_alias_address(), *expand_system(), *get_token();
  char *error_name(), *error_description(), *strip_parens();
  
***************
*** 148,153 ****
--- 150,202 ----
  }
  
  int
+ delete_alias()
+ {
+ 	/** delete an alias from the user alias text file.  Return zero 
+ 	    if alias not deleted in actuality **/
+ 
+ 	char name[SLEN], *address;
+ 	char *strcpy();
+ 
+ 	PutLine0(LINES-2,0,"Enter alias name for deletion: ");
+ 	CleartoEOLN();
+ 	Raw(OFF);
+ 	gets(name);
+ 	Raw(ON);
+ 	if (strlen(name) == 0) 
+ 	  return(0);
+         if ((address = get_alias_address(name, 0, 0))!=NULL)
+         {
+                 if (address[0] == '!')
+                 {
+                   address[0] = ' ';
+                   PutLine1(LINES-1,0,"Group alias:%-60.60s", address);
+                   CleartoEOLN();
+ 	        }
+ 		else
+ 		  PutLine1(LINES-1,0,"Aliased address: %-60.60s", address);
+ 	}
+         else 
+ 	{
+ 		  dprint(3, (debugfile, 
+ 		 "Attempt to delete a non-existent alias [%s] in delete_alias\n",
+ 		 name)); 
+ 		 error1("Non-existent alias for %s", name);
+ 	  	return(0);
+ 	}
+ 	if (want_to("Delete this alias? (y/n) ", 'y', ECHOIT) == 'y')
+ 	{
+ 		if (!delete_from_alias_text(name))
+ 		{
+ 			CleartoEOS();
+ 			return(1);
+ 		}
+ 	}
+ 	CleartoEOS();
+ 	return(0);
+ }
+ 
+ int
  add_current_alias()
  {
  	/** alias the current message to the specified name and
***************
*** 229,243 ****
  	return(0);
  }
  
! show_alias_menu()
  {
! 	MoveCursor(LINES-7,0); CleartoEOLN();	
! 	MoveCursor(LINES-6,0); CleartoEOLN();	
! 	MoveCursor(LINES-5,0); CleartoEOLN();
  	
  	PutLine0(LINES-7,COLUMNS-45, "Alias commands");
  	Centerline(LINES-5,
! "A)lias current msg, Check a P)erson or S)ystem, M)ake new alias, or R)eturn"
  	);
  }
  
--- 278,359 ----
  	return(0);
  }
  
! delete_from_alias_text(name)
! char *name;
  {
! 	/** Delete the data from the user alias text file.  Return zero if we
! 	    succeeded, 1 if not **/
  	
+ 	FILE *file, *tmpfile;
+ 	char fname[SLEN], tmpfname[SLEN];
+ 	char line_in_file[SLEN+3+SLEN+3+LONG_STRING]; /* name = comment = address */
+ 	char name_with_equals[SLEN+2];
+ 
+ 	strcpy(name_with_equals, name);
+ 	strcat(name_with_equals, " ="); 
+ 
+ 	sprintf(fname,"%s/%s", home, ALIAS_TEXT);
+ 	sprintf(tmpfname,"%s/%s.tmp", home, ALIAS_TEXT);
+ 	
+ 	if ((file = fopen(fname, "r")) == NULL) {
+ 	  dprint(2, (debugfile, 
+ 		 "Failure attempting to delete alias from file %s within %s",
+ 		   fname, "delete_from_alias_text"));
+ 	  dprint(2, (debugfile, "** %s - %s **\n", error_name(errno), 
+ 		   error_description(errno)));
+ 	  error1("couldn't open %s to delete alias!", fname);
+ 	  return(1);
+ 	}
+ 
+ 	if ((tmpfile = fopen(tmpfname, "w")) == NULL) {
+ 	  dprint(2, (debugfile, 
+ 		 "Failure attempting to open temp file %s within %s",
+ 		   tmpfname, "delete_from_alias_text"));
+ 	  dprint(2, (debugfile, "** %s - %s **\n", error_name(errno), 
+ 		   error_description(errno)));
+ 	  error1("couldn't open tempfile %s to delete alias!", tmpfname);
+ 	  return(1);
+ 	}
+ 
+ 	while (fgets(line_in_file, sizeof(line_in_file), file) != (char *)NULL)
+ 	{
+ 		if (strncmp(name_with_equals, line_in_file,
+ 				strlen(name_with_equals)) != 0)
+ 			fprintf(tmpfile,"%s", line_in_file);
+ 	}
+ 	fclose(file);
+ 	fclose(tmpfile);
+ #ifdef V9
+ 	(void) unlink(fname);
+ 	if (link(tmpfname, fname) != 0)
+ 	{
+ 		error1("couldn't rename tempfile %s after deleting alias!", tmpfname);
+ 		return(1);
+ 	}
+ 	(void) unlink(tmpfname);
+ #else
+ 	if (rename(tmpfname, fname) != 0)
+ 	{
+ 		error1("couldn't rename tempfile %s after deleting alias!", tmpfname);
+ 		return(1);
+ 	}
+ #endif V9
+ 
+ 	chown(fname, userid, groupid);
+ 
+ 	return(0);
+ }
+ 
+ show_alias_menu()
+ {
+ 	MoveCursor(LINES-7,0); CleartoEOS();	
+ 		
  	PutLine0(LINES-7,COLUMNS-45, "Alias commands");
+ 	Centerline(LINES-6,
+ "A)lias current msg, D)elete an alias, Check a P)erson or S)ystem"
+ 	);
  	Centerline(LINES-5,
! "M)ake new alias, or R)eturn"
  	);
  }
  
***************
*** 284,289 ****
--- 400,406 ----
  	    case '?': redraw += alias_help();			break;
  
  	    case 'a': newaliases += add_current_alias();	break;
+ 	    case 'd': if (delete_alias()) install_aliases();	break;
  	    case 'm': newaliases += add_alias(); 		break;
  
  	    case RETURN:
***************
*** 364,376 ****
  
  install_aliases()
  {
! 	/** run the 'newalias' program and install the newly
! 	    added aliases before going back to the main
! 	    program! 
  	**/
  
  
! 	error("Adding new aliases...");
  	sleep(2);
  
  	if (system_call(newalias, SH) == 0) {
--- 481,492 ----
  
  install_aliases()
  {
! 	/** run the 'newalias' program and update the
! 	    aliases before going back to the main program! 
  	**/
  
  
! 	error("Updating aliases...");
  	sleep(2);
  
  	if (system_call(newalias, SH) == 0) {
***************
*** 377,383 ****
  	  error("Re-reading the database in...");
  	  sleep(2);
  	  read_alias_files();
! 	  set_error("New aliases installed successfully");
  	}
  	else
  	  set_error("'newalias' failed.  Please check alias_text");
--- 493,499 ----
  	  error("Re-reading the database in...");
  	  sleep(2);
  	  read_alias_files();
! 	  set_error("Aliases updated successfully");
  	}
  	else
  	  set_error("'newalias' failed.  Please check alias_text");
***************
*** 410,415 ****
--- 526,533 ----
  		       return(redraw);
  	    case 'a': error(
  "a = Add return address of current message to alias database");	break;
+ 	    case 'd': error(
+ "d = Delete user alias from alias database");	break;
  	    case 'm': error(
  "m = Make new user alias, adding to alias database when done");	break;
  
*** doc/elm-help.2.orig	Tue Nov 15 09:47:22 1988
--- doc/elm-help.2	Wed Dec  7 12:48:10 1988
***************
*** 8,13 ****
--- 8,15 ----
  
    a     Add return address of current message to alias database
  
+   d     Delete user alias from alias database
+ 
    m     Make new user alias, adding to alias database when done
  
    r,x   return from the alias menu
*** doc/Ref.guide.orig	Thu Dec  8 14:12:14 1988
--- doc/Ref.guide	Thu Dec  8 14:12:13 1988
***************
*** 1166,1172
  Alias commands
  .sp
  .ce 
! A)lias current message, Check a P)erson or S)ystem, M)ake new alias or R)eturn
  .sp 2
  Alias: @
  .ce

--- 1166,1174 -----
  Alias commands
  .sp
  .ce 
! A)lias current msg, D)elete an alias, Check a P)erson or S)ystem
! .ce
! M)ake new alias, or R)eturn
  .sp 2
  Alias: @
  .ce
***************
*** 1190,1195
  machines in the pathalias database.  Once it finds an entry
  the address will be saved at that point.   For further 
  information, please see \fIThe Elm Alias System Users Guide\fR.
  .LI p
  Check personal alias.  This is a simple way of checking what is in the alias
  database \(em it prompts for an alias name, and returns the address

--- 1192,1201 -----
  machines in the pathalias database.  Once it finds an entry
  the address will be saved at that point.   For further 
  information, please see \fIThe Elm Alias System Users Guide\fR.
+ .LI d
+ Delete user alias. This will prompt the user for an existing
+ entry in the alias database, display the mapping and ask for
+ confirmation that the alias is to be destroyed.
  .LI p
  Check personal alias.  This is a simple way of checking what is in the alias
  database \(em it prompts for an alias name, and returns the address
--
Andy Linton		ARPA  = Andy.Linton@newcastle.ac.uk
"The Postmaster"	UUCP  =	...!ukc!newcastle.ac.uk!Andy.Linton
			PHONE =	+44 91 222 7784