X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/8a14191c0a0ad15bb8f35b49748c75c1e0a8c2f4..986abcee996d486db0b9c753974f3cb0eac2e9b2:/uip/whatnowsbr.c diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index e2e0ceb6..8b0b2ac7 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -1,6 +1,4 @@ - -/* - * whatnowsbr.c -- the WhatNow shell +/* whatnowsbr.c -- the WhatNow shell * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -43,10 +41,13 @@ #include #include #include - #ifdef OAUTH_SUPPORT # include #endif +#include "h/done.h" +#include "sbr/m_maildir.h" +#include "sbr/m_mktemp.h" +#include "sbr/mime_type.h" #define WHATNOW_SWITCHES \ X("draftfolder +folder", 0, DFOLDSW) \ @@ -57,8 +58,6 @@ X("prompt string", 4, PRMPTSW) \ X("version", 0, VERSIONSW) \ X("help", 0, HELPSW) \ - X("attach header-field-name", -6, ATTACHSW) \ - X("noattach", -8, NOATTACHSW) \ #define X(sw, minchars, id) id, @@ -124,7 +123,7 @@ WhatNow (int argc, char **argv) int isdf = 0, nedit = 0, use = 0, atfile = 1; char *cp, *dfolder = NULL, *dmsg = NULL; char *ed = NULL, *drft = NULL, *msgnam = NULL; - char buf[BUFSIZ], prompt[BUFSIZ]; + char buf[BUFSIZ]; char **argp, **arguments; struct stat st; char cwd[PATH_MAX + 1]; /* current working directory */ @@ -155,7 +154,7 @@ WhatNow (int argc, char **argv) ambigsw (cp, whatnowswitches); done (1); case UNKWNSW: - adios (NULL, "-%s unknown", cp); + die("-%s unknown", cp); case HELPSW: snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name); @@ -167,17 +166,17 @@ WhatNow (int argc, char **argv) case DFOLDSW: if (dfolder) - adios (NULL, "only one draft folder at a time!"); + die("only one draft folder at a time!"); if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, *cp != '@' ? TFOLDER : TSUBCWF); continue; case DMSGSW: if (dmsg) - adios (NULL, "only one draft message at a time!"); + die("only one draft message at a time!"); if (!(dmsg = *argp++) || *dmsg == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); continue; case NDFLDSW: dfolder = NULL; @@ -186,7 +185,7 @@ WhatNow (int argc, char **argv) case EDITRSW: if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); nedit = 0; continue; case NEDITSW: @@ -195,26 +194,17 @@ WhatNow (int argc, char **argv) case PRMPTSW: if (!(myprompt = *argp++) || *myprompt == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case ATTACHSW: - inform("The -attach switch is deprecated"); - continue; - - case NOATTACHSW: - inform("The -noattach switch is deprecated"); + die("missing argument to %s", argp[-2]); continue; } } if (drft) - adios (NULL, "only one draft at a time!"); - else - drft = cp; + die("only one draft at a time!"); + drft = cp; } if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0) - drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf)); + drft = mh_xstrdup(m_draft(dfolder, dmsg, 1, &isdf)); msgnam = (cp = getenv ("mhaltmsg")) && *cp ? mh_xstrdup(cp) : NULL; @@ -234,12 +224,11 @@ WhatNow (int argc, char **argv) NULL, 1, atfile) < 0) done (1); - snprintf (prompt, sizeof(prompt), myprompt, invo_name); for (;;) { #ifdef READLINE_SUPPORT - if (!(argp = read_switch_multiword_via_readline (prompt, aleqs))) { + if (!(argp = read_switch_multiword_via_readline(myprompt, aleqs))) { #else /* ! READLINE_SUPPORT */ - if (!(argp = read_switch_multiword (prompt, aleqs))) { + if (!(argp = read_switch_multiword(myprompt, aleqs))) { #endif /* READLINE_SUPPORT */ (void) m_unlink (LINK); done (1); @@ -562,7 +551,7 @@ writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp) */ int trailln = strlen(trailcmd) + 4; if (ln < 0 || ln + trailln > bufsz) - adios(NULL, "arguments too long"); + die("arguments too long"); cp = buf + ln; @@ -570,7 +559,7 @@ writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp) ln = strlen(*argp); /* +1 for leading space */ if (ln + trailln + 1 > bufsz - (cp-buf)) - adios(NULL, "arguments too long"); + die("arguments too long"); *cp++ = ' '; memcpy(cp, *argp, ln+1); cp += ln; @@ -718,8 +707,8 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp, } if (altmsg) { if (mp) - m_putenv ("mhfolder", mp->foldpath); - m_putenv ("editalt", altpath); + setenv("mhfolder", mp->foldpath, 1); + setenv("editalt", altpath, 1); } vec = argsplit(*ed, &prog, &vecp); @@ -733,7 +722,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp, execvp (prog, vec); fprintf (stderr, "unable to exec "); perror (*ed); - _exit (-1); + _exit(1); default: if ((status = pidwait (pid, NOTOK))) { @@ -812,7 +801,7 @@ static int sendfile (char **arg, char *file, int pushsw) { pid_t child_id; - int i, vecp; + int vecp; char *cp, *sp, **vec, *program; /* @@ -829,12 +818,11 @@ sendfile (char **arg, char *file, int pushsw) context_save (); /* save the context file */ fflush (stdout); - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + child_id = fork(); switch (child_id) { case NOTOK: - inform("unable to fork, so sending directly..."); - /* FALLTHRU */ + adios("fork", "failed:"); + case OK: vec = argsplit(sendproc, &program, &vecp); if (pushsw) @@ -848,7 +836,7 @@ sendfile (char **arg, char *file, int pushsw) execvp (program, vec); fprintf (stderr, "unable to exec "); perror (sendproc); - _exit (-1); + _exit(1); default: if (pidwait(child_id, OK) == 0) @@ -876,7 +864,7 @@ buildfile (char **argp, char *file) while (argp[i]) i++; } - args = (char **) mh_xmalloc((i + 2) * sizeof(char *)); + args = mh_xmalloc((i + 2) * sizeof(char *)); /* * For backward compatibility, we need to add -build @@ -894,7 +882,7 @@ buildfile (char **argp, char *file) i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0, 0); free (args); - return (i ? NOTOK : OK); + return i ? NOTOK : OK; } @@ -948,9 +936,6 @@ buildfile (char **argp, char *file) X("saslmech", SASLminc(5), SASLMECHSW) \ X("authservice", SASLminc(0), AUTHSERVICESW) \ X("user username", SASLminc(4), USERSW) \ - X("attach fieldname", 6, SNDATTACHSW) \ - X("noattach", 0, SNDNOATTACHSW) \ - X("attachformat", 7, SNDATTACHFORMAT) \ X("port server-port-name/number", 4, PORTSW) \ X("tls", TLSminc(-3), TLSSW) \ X("initialtls", TLSminc(-10), INITTLSSW) \ @@ -994,10 +979,6 @@ sendit (char *sp, char **arg, char *file, int pushed) int snoop = 0; struct stat st; -#ifndef lint - int distsw = 0; -#endif - /* * Make sure these are defined. In particular, we need * savearg[1] to be NULL, in case "arg" is NULL below. It @@ -1047,7 +1028,7 @@ sendit (char *sp, char **arg, char *file, int pushed) vec = argsplit(postproc, &program, &vecp); vec[vecp++] = "-library"; - vec[vecp++] = getcpy (m_maildir ("")); + vec[vecp++] = mh_xstrdup(m_maildir("")); if ((cp = context_find ("fileproc"))) { vec[vecp++] = "-fileproc"; @@ -1151,11 +1132,11 @@ sendit (char *sp, char **arg, char *file, int pushed) case AUTHSERVICESW: #ifdef OAUTH_SUPPORT if (!(auth_svc = *argp++) || *auth_svc == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); #else NMH_UNUSED (user); NMH_UNUSED (auth_svc); - adios (NULL, "not built with OAuth support"); + die("not built with OAuth support"); #endif continue; @@ -1187,19 +1168,8 @@ sendit (char *sp, char **arg, char *file, int pushed) inform("missing argument to %s", argp[-2]); return; } - /* FALLTHRU */ - case SNDRFSW: continue; - - case SNDATTACHSW: - inform("The -attach switch is deprecated"); - continue; - case SNDNOATTACHSW: - inform("The -noattach switch is deprecated"); - continue; - - case SNDATTACHFORMAT: - inform("The -attachformat switch is deprecated"); + case SNDRFSW: continue; } } @@ -1220,7 +1190,7 @@ sendit (char *sp, char **arg, char *file, int pushed) if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0) if ((cp = context_find ("signature")) && *cp) - m_putenv ("SIGNATURE", cp); + setenv("SIGNATURE", cp, 1); if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0) annotext = NULL; @@ -1231,14 +1201,11 @@ sendit (char *sp, char **arg, char *file, int pushed) if ((cp = getenv ("mhdist")) && *cp -#ifndef lint - && (distsw = atoi (cp)) -#endif /* not lint */ + && atoi(cp) && altmsg) { vec[vecp++] = "-dist"; if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) { - adios(NULL, "unable to create temporary file in %s", - get_temp_dir()); + die("unable to create temporary file"); } distfile = mh_xstrdup(cp); (void) m_unlink(distfile); @@ -1251,11 +1218,11 @@ sendit (char *sp, char **arg, char *file, int pushed) #ifdef OAUTH_SUPPORT if (auth_svc == NULL) { if (saslmech && ! strcasecmp(saslmech, "xoauth2")) { - adios (NULL, "must specify -authservice with -saslmech xoauth2"); + die("must specify -authservice with -saslmech xoauth2"); } } else { if (user == NULL) { - adios (NULL, "must specify -user with -saslmech xoauth2"); + die("must specify -user with -saslmech xoauth2"); } } #else @@ -1306,10 +1273,10 @@ whomfile (char **arg, char *file) execvp (program, vec); fprintf (stderr, "unable to exec "); perror (whomproc); - _exit (-1); /* NOTREACHED */ + _exit(1); /* NOTREACHED */ default: - return (pidwait (pid, NOTOK) & 0377 ? 1 : 0); + return pidwait(pid, NOTOK) & 0377 ? 1 : 0; } } @@ -1336,18 +1303,19 @@ static int checkmimeheader (char *drft) { FILE *f; - m_getfld_state_t gstate = 0; - char buf[BUFSIZ], name[NAMESZ]; + m_getfld_state_t gstate; + char buf[NMH_BUFSIZ], name[NAMESZ]; int state, retval = 0; if ((f = fopen(drft, "r")) == NULL) { admonish(drft, "unable to read draft"); - return (0); + return 0; } + gstate = m_getfld_state_init(f); for (;;) { int bufsz = sizeof(buf); - switch (state = m_getfld(&gstate, name, buf, &bufsz, f)) { + switch (state = m_getfld2(&gstate, name, buf, &bufsz)) { case FLD: case FLDPLUS: if (strcasecmp(name, VRSN_FIELD) == 0) {