]> diplodocus.org Git - nmh/commitdiff
Added -v and -a switches to whatnow attach so the user can see
authorDavid Levine <levinedl@acm.org>
Sun, 12 Jan 2014 16:18:20 +0000 (10:18 -0600)
committerDavid Levine <levinedl@acm.org>
Sun, 12 Jan 2014 16:18:20 +0000 (10:18 -0600)
the mhbuild directive that send(1) will use.

docs/pending-release-notes
man/whatnow.man
test/whatnow/test-attach-detach
uip/whatnowsbr.c

index b4d3e63114f696672686acb451ba23385735fd1c..a2fd59876b2a519a63065e3fe9e26a92fe28eef6 100644 (file)
@@ -61,9 +61,10 @@ NEW FEATURES
 - mhbuild(1) can now encode 8-bit message headers using RFC-2047 encoding
   rules.
 - The whatnow(1) attach feature will determine the content type of an
 - mhbuild(1) can now encode 8-bit message headers using RFC-2047 encoding
   rules.
 - The whatnow(1) attach feature will determine the content type of an
-  attachment using a program such as file --mime, if available at
+  attachment using a program such as file --mime-type, if available at
   configuration time.  If not, it will use mhshow-suffix- entries as
   configuration time.  If not, it will use mhshow-suffix- entries as
-  before.
+  before.  The -v switch to attach causes it to display the mhbuild
+  directive for an attachformat specied by an optional -a switch.
 
 -----------------
 OBSOLETE FEATURES
 
 -----------------
 OBSOLETE FEATURES
index be8853d435a9f948d74a048ef86aa294dc912a92..76d93ba72914e5f27a174b0ce415f3745f529470 100644 (file)
@@ -1,4 +1,4 @@
-.TH WHATNOW %manext1% "December 13, 2013" "%nmhversion%"
+.TH WHATNOW %manext1% "January 12, 2014" "%nmhversion%"
 .\"
 .\" %nmhwarning%
 .\"
 .\"
 .\" %nmhwarning%
 .\"
@@ -108,8 +108,11 @@ print the working directory for attachment files
 .B ls [ls-options]
 list files in the attachment working directory using the ls command
 .TP \w'refilezzzzfolderz'u
 .B ls [ls-options]
 list files in the attachment working directory using the ls command
 .TP \w'refilezzzzfolderz'u
-.B attach files
-add the named files to the draft as MIME attachments
+.B attach [-v [-a 0|1|2]] files
+add the named files to the message as MIME attachments; -v displays
+the mhbuild directive, using the optionally specified attachformat
+[-a] if that is also provided to
+.IR send (1)
 .TP \w'refilezzzzfolderz'u
 .B alist [-ln]
 list the MIME attachments, either short, long [-l] or numbered [-n]
 .TP \w'refilezzzzfolderz'u
 .B alist [-ln]
 list the MIME attachments, either short, long [-l] or numbered [-n]
index f7c39e9d6dd40216c994be2655130db88b44973f..f674a4f5b95a6477bc7e337572a183d547fee0ff 100755 (executable)
@@ -45,7 +45,7 @@ whatnowtest=`echo cd | whatnow -prompt ''`
 set -e
 
 case ${whatnowtest} in
 set -e
 
 case ${whatnowtest} in
-    cd) cat > "$expected" <<EOF
+    cd) cat >"$expected" <<EOF
 attach $testname_quoted
 alist
 $testname
 attach $testname_quoted
 alist
 $testname
@@ -53,7 +53,7 @@ detach $testname_quoted
 alist
 EOF
     ;;
 alist
 EOF
     ;;
-    "") cat > "$expected" <<EOF
+    "") cat >"$expected" <<EOF
 $testname
 EOF
     ;;
 $testname
 EOF
     ;;
@@ -66,18 +66,86 @@ esac
 # whatnow's exit status is always 1 so that is not a failure
 set +e
 echo "attach $testname_quoted" | \
 # whatnow's exit status is always 1 so that is not a failure
 set +e
 echo "attach $testname_quoted" | \
-  run_prog whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual
+  run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual
 echo "alist" | \
 echo "alist" | \
-  run_prog whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual
+  run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual
 echo "detach $testname_quoted" | \
 echo "detach $testname_quoted" | \
-  run_prog whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual
+  run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual
 echo "alist" | \
 echo "alist" | \
-  run_prog whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual
+  run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual
 set -e
 
 check "$expectederr" "$actualerr"
 check "$expected" "$actual"
 
 set -e
 
 check "$expectederr" "$actualerr"
 check "$expected" "$actual"
 
+cat >"$expected" <<EOF
+
+What now? at
+whatnow: attach command requires file argument(s).
+
+What now? at -v
+whatnow: attach command requires file argument(s).
+
+What now? at -v -a
+whatnow: ignoring attach -a without format argument.
+whatnow: attach command requires file argument(s).
+
+What now? at -v -a 0
+whatnow: attach command requires file argument(s).
+
+What now? at -a
+whatnow: ignoring attach -a without format argument.
+whatnow: attach command requires file argument(s).
+
+What now? at -a -v
+whatnow: ignoring attach -a without format argument.
+whatnow: attach command requires file argument(s).
+
+What now? at -a 0 -v
+whatnow: attach command requires file argument(s).
+
+What now? at -a 0 Mail/context
+
+What now? at -v -a Mail/context
+whatnow: ignoring attach -a without format argument.
+#text/plain; charset=us-ascii; name="context" <> [context]{attachment} ${MH_TEST_DIR}/Mail/context
+
+What now? at -v -a 3 Mail/context
+whatnow: ingoring invalid attachformat value of 3
+#text/plain; charset=us-ascii; name="context" <> [context]{attachment} ${MH_TEST_DIR}/Mail/context
+
+What now? at -v Mail/context
+#text/plain; charset=us-ascii; name="context" <> [context]{attachment} ${MH_TEST_DIR}/Mail/context
+
+What now? at -v -a 1 Mail/context
+#text/plain; charset=us-ascii; name="context" <> [context]{attachment} ${MH_TEST_DIR}/Mail/context
+
+What now? at -v -a 0 Mail/context
+#text/plain; charset=us-ascii; name="context"; x-unix-mode=0644 [  ASCII text ] ${MH_TEST_DIR}/Mail/context
+
+What now? quit -delete
+EOF
+
+set +e
+printf '%s\n' \
+'at' \
+'at -v' \
+'at -v -a' \
+'at -v -a 0' \
+'at -a' \
+'at -a -v' \
+'at -a 0 -v' \
+'at -a 0 Mail/context' \
+'at -v -a Mail/context' \
+'at -v -a 3 Mail/context' \
+'at -v Mail/context' \
+'at -v -a 1 Mail/context' \
+'at -v -a 0 Mail/context' \
+'quit -delete' | whatnow >$actual 2>&1
+set -e
+
+check "$expected" "$actual"
+
 test ${failed:-0} -eq 0  &&  rm "$testname"
 
 exit $failed
 test ${failed:-0} -eq 0  &&  rm "$testname"
 
 exit $failed
index 85ba4b9029fbcbab67e0e013ceb4176d24a763da..7b20925a055d98707f87cfbdaa5f65d170f9cfc3 100644 (file)
  *                             pwd command and exists to allow the user
  *                             to verify the directory.
  *
  *                             pwd command and exists to allow the user
  *                             to verify the directory.
  *
- *     attach files            This option attaches the named files to
- *                             the draft.
+ *     attach [-v [-a 0|1|2]] files
+ *                             This option attaches the named files to
+ *                             the draft.  -v displays the mhbuild
+ *                             directive, using the optionally specified
+ *                             attachformat [-a] if that is also provided
+ *                             to send(1).
  *
  *     alist [-ln]             This option lists the attachments on the
  *                             draft.  -l gets long listings, -n gets
  *
  *     alist [-ln]             This option lists the attachments on the
  *                             draft.  -l gets long listings, -n gets
@@ -80,7 +84,7 @@ DEFINE_SWITCH_ARRAY(WHATNOW, whatnowswitches);
     X("cd [directory]", 0, CDCMDSW) \
     X("pwd", 0, PWDCMDSW) \
     X("ls", 2, LSCMDSW) \
     X("cd [directory]", 0, CDCMDSW) \
     X("pwd", 0, PWDCMDSW) \
     X("ls", 2, LSCMDSW) \
-    X("attach", 0, ATTACHCMDSW) \
+    X("attach [-v [-a 0|1|2]]", 0, ATTACHCMDSW) \
     X("detach [-n]", 0, DETACHCMDSW) \
     X("alist [-ln] ", 2, ALISTCMDSW) \
 
     X("detach [-n]", 0, DETACHCMDSW) \
     X("alist [-ln] ", 2, ALISTCMDSW) \
 
@@ -393,18 +397,47 @@ WhatNow (int argc, char **argv)
 
            break;
 
 
            break;
 
-       case ATTACHCMDSW:
+       case ATTACHCMDSW: {
            /*
             *  Attach files to current draft.
             */
 
            /*
             *  Attach files to current draft.
             */
 
+            int verbose = 0;
+            int attachformat = 1;
+            char **ap;
+
            if (attach == (char *)0) {
                advise((char *)0, "can't attach because no header field name was given.");
                break;
            }
 
            if (attach == (char *)0) {
                advise((char *)0, "can't attach because no header field name was given.");
                break;
            }
 
+           for (ap = argp+1; *ap; ++ap) {
+               if (strcmp(*ap, "-v") == 0) {
+                   ++argp;
+                   verbose = 1;
+               } else if (strcmp(*ap, "-a") == 0) {
+                   ++argp;
+                   if (*(ap+1) == NULL  ||
+                       ! isdigit ((unsigned char) *(ap+1)[0])) {
+                       advise(NULL,
+                              "ignoring attach -a without format argument.");
+                   } else {
+                       ++argp;
+                       ++ap;
+                       if ((attachformat = atoi(*ap)) > 2) {
+                           advise(NULL,
+                                  "ingoring invalid attachformat value of %d",
+                                  attachformat);
+                           attachformat = 1;
+                       }
+                   }
+               } else if (*ap[0] != '-') {
+                   break;
+               }
+           }
+
            if (*(argp+1) == (char *)0) {
            if (*(argp+1) == (char *)0) {
-               advise((char *)0, "attach command requires file argument(s).");
+               advise(NULL, "attach command requires file argument(s).");
                break;
            }
 
                break;
            }
 
@@ -424,13 +457,30 @@ WhatNow (int argc, char **argv)
 
            if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
                while (fgets(shell, sizeof (shell), f) != (char *)0) {
 
            if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
                while (fgets(shell, sizeof (shell), f) != (char *)0) {
+                   char *build_directive;
+
                    *(strchr(shell, '\n')) = '\0';
 
                    *(strchr(shell, '\n')) = '\0';
 
-                   if (*shell == '/')
+                   if (*shell == '/') {
                        (void)annotate(drft, attach, shell, 1, 0, -2, 1);
                        (void)annotate(drft, attach, shell, 1, 0, -2, 1);
-                   else {
+                       if (verbose) {
+                           build_directive =
+                               construct_build_directive (shell, NULL,
+                                                          attachformat);
+                       }
+                   } else {
                        (void)sprintf(file, "%s/%s", cwd, shell);
                        (void)annotate(drft, attach, file, 1, 0, -2, 1);
                        (void)sprintf(file, "%s/%s", cwd, shell);
                        (void)annotate(drft, attach, file, 1, 0, -2, 1);
+                       if (verbose) {
+                           build_directive =
+                               construct_build_directive (file, NULL,
+                                                          attachformat);
+                       }
+                   }
+
+                   if (verbose) {
+                       printf ("%s", build_directive);
+                       free (build_directive);
                    }
                }
 
                    }
                }
 
@@ -441,7 +491,7 @@ WhatNow (int argc, char **argv)
            }
 
            break;
            }
 
            break;
-
+       }
        case DETACHCMDSW:
            /*
             *  Detach files from current draft.
        case DETACHCMDSW:
            /*
             *  Detach files from current draft.