[comp.mail.mh] New "-ask/-noask" options for 'refile'

brent@telebit.com (Brent Chapman) (04/30/91)

Appended is a patch to add a "-ask" and "-noask" options to the 'refile'
command (the patch is for both the source code and the documentation).
Basicly, the "-ask" switch controls whether or not 'refile' will ask
you whether or not to create a folder that doesn't yet exist.  If "-ask"
is set (which I've made the default), then behavior is exactly the same
as in the unmodified "refile": you are asked whether or not you want to
create the folder.  If, however, "-noask" is set, "refile" simply creates
the folder without bothering to ask you.

I added this because I use a wrapper around MH (the "mh-e" mode of GNU
Emacs) that doesn't allow me (at least not as far as I've found) to respond
to the "Create new folder foobar?" query from "refile" when "refile" is
invoked from "send" because I specified a folder on the "Fcc:" line that
doesn't exist yet.

Anyway, I'd like to see this get rolled into the standard MH release,
particularly since it is totally backwards compatible (the default preserves
the old behavior), but I don't know who to send it to in order to make
that happen, so I'm posting it here.  The patch can be applied from the
top level of the MH directory, with "patch -p0".


-Brent
--
Brent Chapman                                   Telebit Corporation
Sun Network Specialist				1315 Chesapeake Terrace
brent@telebit.com				Sunnyvale, CA  94089
                                                Phone:  408/745-3264


*** uip/refile.c.orig	Fri Dec 14 13:26:09 1990
--- uip/refile.c	Mon Apr 29 14:22:08 1991
***************
*** 31,37 ****
  #define	FILESW	6
      "file file", 0,
  
! #define	HELPSW	7
      "help", 4,
  
      NULL, NULL
--- 31,42 ----
  #define	FILESW	6
      "file file", 0,
  
! #define ASKSW   7
!     "ask", 0,
! #define NASKSW  8
!     "noask", 0,
! 
! #define	HELPSW	9
      "help", 4,
  
      NULL, NULL
***************
*** 61,66 ****
--- 66,72 ----
  {
      int	    linkf = 0,
              prsrvf = 0,
+ 	    askf = 1,
  	    filep = 0,
              foldp = 0,
              msgp = 0,
***************
*** 139,144 ****
--- 145,157 ----
  			adios (NULLCP, "missing argument to %s", argp[-2]);
  		    files[filep++] = path (cp, TFILE);
  		    continue;
+ 		
+ 		case ASKSW:
+ 		    askf++;
+ 		    continue;
+ 		case NASKSW:
+ 		    askf = 0;
+ 		    continue;
  	    }
  	if (*cp == '+' || *cp == '@') {
  	    if (foldp > NFOLDERS)
***************
*** 165,171 ****
      if (filep > 0) {
  	if (folder || msgp)
  	    adios (NULLCP, "use -file or some messages, not both");
! 	opnfolds (folders, foldp);
  	for (i = 0; i < filep; i++)
  	    if (m_file (files[i], folders, foldp, prsrvf))
  		done (1);
--- 178,184 ----
      if (filep > 0) {
  	if (folder || msgp)
  	    adios (NULLCP, "use -file or some messages, not both");
! 	opnfolds (folders, foldp, askf);
  	for (i = 0; i < filep; i++)
  	    if (m_file (files[i], folders, foldp, prsrvf))
  		done (1);
***************
*** 192,198 ****
  	    done (1);
      m_setseq (mp);
  
!     opnfolds (folders, foldp);
      for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
  	if (mp -> msgstats[msgnum] & SELECTED) {
  	    cp = getcpy (m_name (msgnum));
--- 205,211 ----
  	    done (1);
      m_setseq (mp);
  
!     opnfolds (folders, foldp, askf);
      for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
  	if (mp -> msgstats[msgnum] & SELECTED) {
  	    cp = getcpy (m_name (msgnum));
***************
*** 225,233 ****
  
  /*  */
  
! static	opnfolds (folders, nfolders)
  register struct st_fold *folders;
  int	nfolders;
  {
      register char  *cp;
      char    nmaildir[BUFSIZ];
--- 238,247 ----
  
  /*  */
  
! static	opnfolds (folders, nfolders, askf)
  register struct st_fold *folders;
  int	nfolders;
+ int	askf;
  {
      register char  *cp;
      char    nmaildir[BUFSIZ];
***************
*** 243,252 ****
  	if (stat (nmaildir, &st) == NOTOK) {
  	    if (errno != ENOENT)
  		adios (nmaildir, "error on folder");
! 	    cp = concat ("Create folder \"", nmaildir, "\"? ", NULLCP);
! 	    if (!getanswer (cp))
! 		done (1);
! 	    free (cp);
  	    if (!makedir (nmaildir))
  		adios (NULLCP, "unable to create folder %s", nmaildir);
  	}
--- 257,268 ----
  	if (stat (nmaildir, &st) == NOTOK) {
  	    if (errno != ENOENT)
  		adios (nmaildir, "error on folder");
! 	    if (askf) {
! 		cp = concat ("Create folder \"", nmaildir, "\"? ", NULLCP);
! 		if (!getanswer (cp))
! 		    done (1);
! 		free (cp);
! 	    }
  	    if (!makedir (nmaildir))
  		adios (NULLCP, "unable to create folder %s", nmaildir);
  	}
*** conf/doc/refile.rf.orig	Fri Dec 14 13:24:00 1990
--- conf/doc/refile.rf	Mon Apr 29 14:40:10 1991
***************
*** 9,14 ****
--- 9,15 ----
  \%[\-draft]
  \%[\-link] \%[\-nolink] 
  \%[\-preserve] \%[\-nopreserve]
+ \%[\-ask] \%[\-noask]
  \%[\-src\ +folder] 
  \%[\-file\ file] 
  +folder ...
***************
*** 44,52 ****
  (to convert a file in mail drop format to a folder of \fIMH\fR messages,
  see \fIinc\fR\0(1)).
  
! If a destination folder doesn't exist, \fIrefile\fR will ask if you
! want to create it.
! A negative response will abort the file operation.
  
  The option `\-link' preserves the source folder copy of the message
  (i.e., it does a \fIln\fR(1) rather than a \fImv\fR(1)), whereas,
--- 45,54 ----
  (to convert a file in mail drop format to a folder of \fIMH\fR messages,
  see \fIinc\fR\0(1)).
  
! If a destination folder doesn't exist, and the `\-ask' option is set
! (the default), \fIrefile\fR will ask if you want to create it;
! a negative response will abort the file operation.
! If the `\-noask' option is set, the folder will be created without asking.
  
  The option `\-link' preserves the source folder copy of the message
  (i.e., it does a \fIln\fR(1) rather than a \fImv\fR(1)), whereas,
***************
*** 92,97 ****
--- 94,101 ----
  `\-nolink'
  .Ds
  `\-nopreserve'
+ .Ds
+ `\-ask'
  .Co
  If `\-src\ +folder' is given, it will become the
  current folder.

ziegast@ENG.UMD.EDU (Eric Ziegast) (05/11/91)

Brent Chapman writes:
>Anyway, I'd like to see this get rolled into the standard MH release,
>particularly since it is totally backwards compatible (the default preserves
>the old behavior), but I don't know who to send it to in order to make
>that happen, so I'm posting it here. 

Generally, that is the purpose of mh-workers, a mailing list
designated for MH "workers".  If you would like to be added to the
list, send mail to mh-workers-request@ics.uci.edu.

Your patch, from what I scanned through briefly, looks good.
I do recommend to the powers that be (aka jromine) that the switch
be called "-silent" and "-nosilent" to conform with what is
already used in other programs like inc(1).  I would also suggest
that in future releases, that this kind of switch be standard-
ized across all programs.  For example, rmf uses -interactive
to do the same thing as -silent and -ask.  Of course the old
switches could still exist (but be hidden) to provide backward
compatability until a major release (like MH7).

Just my $0.03.
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
| Eric W. Ziegast     Internet: ziegast@eng.umd.edu |
| Univ. of Merryland  Phonenet: Eric@[301.405.3689] |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+