From: David Levine Date: Sun, 12 Jan 2014 16:18:20 +0000 (-0600) Subject: Added -v and -a switches to whatnow attach so the user can see X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/fcadfe1323db62daea7b943b8a1e4e6a3c8640fa?hp=9cdb320102bf8f24a4b564c5ed2b35879e5ccf62 Added -v and -a switches to whatnow attach so the user can see the mhbuild directive that send(1) will use. --- diff --git a/docs/pending-release-notes b/docs/pending-release-notes index b4d3e631..a2fd5987 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -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 - 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 - 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 diff --git a/man/whatnow.man b/man/whatnow.man index be8853d4..76d93ba7 100644 --- a/man/whatnow.man +++ b/man/whatnow.man @@ -1,4 +1,4 @@ -.TH WHATNOW %manext1% "December 13, 2013" "%nmhversion%" +.TH WHATNOW %manext1% "January 12, 2014" "%nmhversion%" .\" .\" %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 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] diff --git a/test/whatnow/test-attach-detach b/test/whatnow/test-attach-detach index f7c39e9d..f674a4f5 100755 --- a/test/whatnow/test-attach-detach +++ b/test/whatnow/test-attach-detach @@ -45,7 +45,7 @@ whatnowtest=`echo cd | whatnow -prompt ''` set -e case ${whatnowtest} in - cd) cat > "$expected" <"$expected" < "$expected" <"$expected" <> $actualerr >> $actual + run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual 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" | \ - run_prog whatnow -attach foo -noedit -prompt '' 2>> $actualerr >> $actual + run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual 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" +cat >"$expected" < [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 diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 85ba4b90..7b20925a 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -26,8 +26,12 @@ * 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 @@ -80,7 +84,7 @@ DEFINE_SWITCH_ARRAY(WHATNOW, whatnowswitches); 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) \ @@ -393,18 +397,47 @@ WhatNow (int argc, char **argv) break; - case ATTACHCMDSW: + case ATTACHCMDSW: { /* * 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; } + 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) { - advise((char *)0, "attach command requires file argument(s)."); + advise(NULL, "attach command requires file argument(s)."); 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) { + char *build_directive; + *(strchr(shell, '\n')) = '\0'; - if (*shell == '/') + if (*shell == '/') { (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); + 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; - + } case DETACHCMDSW: /* * Detach files from current draft.