From: Ken Hornstein Date: Wed, 22 Jan 2014 20:22:07 +0000 (-0500) Subject: Convert whatnow over to using the new Attach header. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/035c5db3403da8a955b2c8f525076f89de9f2713?ds=inline;hp=-c Convert whatnow over to using the new Attach header. Mark the old -attach switches as deprecated (and make them not show up in help). Still more documentation cleanup to do. --- 035c5db3403da8a955b2c8f525076f89de9f2713 diff --git a/h/mh.h b/h/mh.h index a47b7c20..999d600a 100644 --- a/h/mh.h +++ b/h/mh.h @@ -122,8 +122,6 @@ struct swit { extern struct swit anoyes[]; /* standard yes/no switches */ -#define ATTACHFORMATS 3 /* Number of send attach formats. */ - /* * general folder attributes */ @@ -359,8 +357,6 @@ typedef struct m_getfld_state *m_getfld_state_t; #define LINK "@" /* Name of link to file to which you are */ /* replying. */ -#define NMH_ATTACH_HEADER "Nmh-Attachment" /* Default header for -attach */ - /* * credentials management */ diff --git a/man/send.man b/man/send.man index 83cf19ae..b7016a41 100644 --- a/man/send.man +++ b/man/send.man @@ -54,11 +54,6 @@ send \- send a message \&...] .RB [ \-version ] .RB [ \-help ] -.RB [ \-attach -.IR header-field-name ] -.RB [ \-noattach ] -.RB [ \-attachformat -.IR 0 " | " 1 " | " 2 ] .ad .SH DESCRIPTION .B Send diff --git a/man/whatnow.man b/man/whatnow.man index 367a3267..3d5806bf 100644 --- a/man/whatnow.man +++ b/man/whatnow.man @@ -21,9 +21,6 @@ whatnow \- prompting front-end for sending messages .RI [ file ] .RB [ \-version ] .RB [ \-help ] -.RB [ \-attach -.IR header-field-name ] -.RB [ \-noattach ] .ad .SH DESCRIPTION .B Whatnow @@ -243,7 +240,6 @@ commands for managing MIME attachments. .SH DEFAULTS .nf .RB ` \-prompt "' defaults to \*(lqWhat\ Now?\ \*(rq" -.RB ` \-attach "' defaults to \*(lqNmh-Attachment\*(rq" .fi .SH BUGS If the initial edit fails, diff --git a/test/whatnow/test-attach-detach b/test/whatnow/test-attach-detach index 3181f21b..ba22a19c 100755 --- a/test/whatnow/test-attach-detach +++ b/test/whatnow/test-attach-detach @@ -68,13 +68,13 @@ esac # 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 -noedit -prompt '' 2>>$actualerr >>$actual echo "alist" | \ - run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual + run_prog whatnow -noedit -prompt '' 2>>$actualerr >>$actual echo "detach $testname_quoted" | \ - run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual + run_prog whatnow -noedit -prompt '' 2>>$actualerr >>$actual echo "alist" | \ - run_prog whatnow -attach foo -noedit -prompt '' 2>>$actualerr >>$actual + run_prog whatnow -noedit -prompt '' 2>>$actualerr >>$actual set -e check "$expectederr" "$actualerr" @@ -84,7 +84,7 @@ if [ "$readline" = 0 ]; then cat >"$expected" < [context]{attachment} ${MH_TEST_DIR}/Mail/context +Attaching ${MH_TEST_DIR}/Mail/context as a text/plain EOF else cat >"$expected" < [context]{attachment} ${MH_TEST_DIR}/Mail/context +Attaching ${MH_TEST_DIR}/Mail/context as a text/plain quit -delete EOF fi diff --git a/uip/attach.c b/uip/attach.c index 29024997..e7046fe5 100644 --- a/uip/attach.c +++ b/uip/attach.c @@ -15,6 +15,7 @@ static int get_line(FILE *, char *, size_t); static char *get_file_info(const char *, const char *); #endif /* MIMETYPEPROC */ +#if 0 int attach(char *attachment_header_field_name, char *draft_file_name, char *body_file_name, size_t body_file_name_len, @@ -277,6 +278,8 @@ get_line(FILE *draft_file, char *field, size_t field_size) return (c); } +#endif + /* * Try to use external command to determine mime type, and possibly * encoding. Caller is responsible for free'ing returned memory. @@ -383,6 +386,7 @@ get_file_info(const char *proc, const char *file_name) { #endif /* MIMETYPEPROC */ +#if 0 /* * Construct an mhbuild directive for the draft file. This starts * with the content type. Append a file name attribute, and depending @@ -590,3 +594,4 @@ construct_build_directive (char *file_name, const char *default_content_type, return build_directive; } +#endif diff --git a/uip/send.c b/uip/send.c index 31718392..3ba82fb5 100644 --- a/uip/send.c +++ b/uip/send.c @@ -62,8 +62,8 @@ X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \ X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \ X("user username", SASLminc(-4), USERSW) \ - X("attach", 6, ATTACHSW) \ - X("noattach", 0, NOATTACHSW) \ + X("attach", -6, ATTACHSW) \ + X("noattach", -8, NOATTACHSW) \ X("attachformat", 7, ATTACHFORMATSW) \ X("port server-port-name/number", 4, PORTSW) \ X("tls", TLSminc(-3), TLSSW) \ diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 3010bff0..e67ad53a 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -53,8 +53,9 @@ X("prompt string", 4, PRMPTSW) \ X("version", 0, VERSIONSW) \ X("help", 0, HELPSW) \ - X("attach header-field-name", 0, ATTACHSW) \ - X("noattach", 0, NOATTACHSW) \ + X("attach header-field-name", -6, ATTACHSW) \ + X("noattach", -8, NOATTACHSW) \ + #define X(sw, minchars, id) id, DEFINE_SWITCH_ENUM(WHATNOW); @@ -122,7 +123,6 @@ WhatNow (int argc, char **argv) char buf[BUFSIZ], prompt[BUFSIZ]; char **argp, **arguments; struct stat st; - char *attach = NMH_ATTACH_HEADER;/* attachment header field name */ char cwd[PATH_MAX + 1]; /* current working directory */ char file[PATH_MAX + 1]; /* file name buffer */ char shell[PATH_MAX + 1]; /* shell response buffer */ @@ -197,12 +197,11 @@ WhatNow (int argc, char **argv) continue; case ATTACHSW: - if (!(attach = *argp++) || *attach == '-') - adios (NULL, "missing argument to %s", argp[-2]); + advise(NULL, "The -attach switch is deprecated"); continue; case NOATTACHSW: - attach = NULL; + advise(NULL, "The -noattach switch is deprecated"); continue; } } @@ -360,11 +359,6 @@ WhatNow (int argc, char **argv) * -n numbers listing */ - if (attach == (char *)0) { - advise((char *)0, "can't list because no header field name was given."); - break; - } - l = (char *)0; n = 0; @@ -390,7 +384,7 @@ WhatNow (int argc, char **argv) advise((char *)0, "usage is alist [-ln]."); else - annolist(drft, attach, l, n); + annolist(drft, ATTACH_FIELD, l, n); break; @@ -402,11 +396,6 @@ WhatNow (int argc, char **argv) int verbose = 0; 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; @@ -437,28 +426,25 @@ 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; + char *ctype; *(strchr(shell, '\n')) = '\0'; if (*shell == '/') { - (void)annotate(drft, attach, shell, 1, 0, -2, 1); - if (verbose) { - build_directive = - construct_build_directive (shell, NULL, 1); - } + strncpy(file, shell, sizeof(file)); + file[sizeof(file) - 1] = '\0'; } 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, 1); - } + snprintf(file, sizeof(file), "%s/%s", cwd, shell); + } + + annotate(drft, ATTACH_FIELD, file, 1, 0, -2, 1); + if (verbose) { + ctype = mime_type(file); } if (verbose) { - printf ("%s", build_directive); - free (build_directive); + printf ("Attaching %s as a %s", file, ctype); + free (ctype); } } @@ -475,11 +461,6 @@ WhatNow (int argc, char **argv) * Detach files from current draft. */ - if (attach == (char *)0) { - advise((char *)0, "can't detach because no header field name was given."); - break; - } - /* * Scan the arguments for a -n. Mixed file names and numbers aren't allowed, * so this catches a -n anywhere in the argument list. @@ -506,7 +487,7 @@ WhatNow (int argc, char **argv) if (**arguments != '\0') { n = atoi(*arguments); - (void)annotate(drft, attach, (char *)0, 1, 0, n, 1); + annotate(drft, ATTACH_FIELD, (char *)0, 1, 0, n, 1); for (argp = arguments + 1; *argp != (char *)0; argp++) { if (atoi(*argp) > n) { @@ -533,7 +514,7 @@ WhatNow (int argc, char **argv) if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) { while (fgets(shell, sizeof (shell), f) != (char *)0) { *(strchr(shell, '\n')) = '\0'; - (void)annotate(drft, attach, shell, 1, 0, 0, 1); + annotate(drft, ATTACH_FIELD, shell, 1, 0, 0, 1); } pclose(f); } else {