X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/a2c417d3e1641ba4ab151b7945b90f55176705b1..07916b2ff:/uip/sendsbr.c?ds=sidebyside diff --git a/uip/sendsbr.c b/uip/sendsbr.c index 5da67fc9..41060100 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -1,6 +1,4 @@ - -/* - * sendsbr.c -- routines to help WhatNow/Send along +/* sendsbr.c -- routines to help WhatNow/Send along * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -25,7 +23,12 @@ #ifdef OAUTH_SUPPORT #include +#endif +#include "../sbr/m_maildir.h" +#include "../sbr/m_mktemp.h" +#include "../sbr/message_id.h" +#ifdef OAUTH_SUPPORT static int setup_oauth_params(char *[], int *, const char *, const char **); #endif /* OAUTH_SUPPORT */ @@ -76,22 +79,12 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st, by longjmp. */ volatile int nvecs = vecp; int *nvecsp = (int *) &nvecs; - int eai = 0; /* * Run the mimebuildproc (which is by default mhbuild) on the message * with the addition of the "-auto" flag */ - /* Make sure that EAI support is set up before calling buildmimeproc. */ - for (i = 0; i < vecp; ++i) { - if (strcasecmp (vec[i], "-eai") == 0) { - eai = 1; - } else if (strcasecmp (vec[i], "-noeai") == 0) { - eai = 0; - } - } - switch (child = fork()) { case NOTOK: adios("fork", "unable to"); @@ -103,17 +96,6 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st, if (distfile) buildvec[i++] = "-dist"; buildvec[i++] = (char *) drft; - if (eai) { - /* Add eai profile entry, to pass 8bit setting to - getname()/getadrx(). This doesn't seem to be necessary - now, but it's here just in case the code changes - later. */ - add_profile_entry("eai", "8bit"); - - /* Add mhbuild switch to enable 8bit headers. */ - buildvec[i++] = "-headerencoding"; - buildvec[i++] = "8bit"; - } buildvec[i] = NULL; execvp(buildprogram, buildvec); fprintf(stderr, "unable to exec "); @@ -153,7 +135,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st, #ifdef OAUTH_SUPPORT const char *errmsg; if (setup_oauth_params(vec, nvecsp, auth_svc, &errmsg) != OK) { - adios(NULL, errmsg); + adios(NULL, "%s", errmsg); } #else adios(NULL, "send built without OAUTH_SUPPORT, " @@ -212,11 +194,11 @@ splitmsg (char **vec, int vecp, char *program, char *drft, int compnum, nparts, partno, state, status; long pos, start; time_t clock; - char *cp, *dp, buffer[BUFSIZ], msgid[BUFSIZ]; + char *cp, *dp, buffer[NMH_BUFSIZ], msgid[BUFSIZ]; char subject[BUFSIZ]; char name[NAMESZ], partnum[BUFSIZ]; FILE *in; - m_getfld_state_t gstate = 0; + m_getfld_state_t gstate; if ((in = fopen (drft, "r")) == NULL) adios (drft, "unable to open for reading"); @@ -228,10 +210,11 @@ splitmsg (char **vec, int vecp, char *program, char *drft, * Scan through the message and examine the various header fields, * as well as locate the beginning of the message body. */ - m_getfld_track_filepos (&gstate, in); + gstate = m_getfld_state_init(in); + m_getfld_track_filepos2(&gstate); for (compnum = 1;;) { int bufsz = sizeof buffer; - switch (state = m_getfld (&gstate, name, buffer, &bufsz, in)) { + switch (state = m_getfld2(&gstate, name, buffer, &bufsz)) { case FLD: case FLDPLUS: compnum++; @@ -242,7 +225,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, if (!strcasecmp (name, "Message-ID")) { while (state == FLDPLUS) { bufsz = sizeof buffer; - state = m_getfld (&gstate, name, buffer, &bufsz, in); + state = m_getfld2(&gstate, name, buffer, &bufsz); } } else if (uprf (name, XXX_FIELD_PRF) || !strcasecmp (name, VRSN_FIELD) @@ -268,7 +251,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, dp = add (concat (name, ":", buffer, NULL), dp); while (state == FLDPLUS) { bufsz = sizeof buffer; - state = m_getfld (&gstate, name, buffer, &bufsz, in); + state = m_getfld2(&gstate, name, buffer, &bufsz); dp = add (buffer, dp); } } else { @@ -279,7 +262,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, cp = add (concat (name, ":", buffer, NULL), cp); while (state == FLDPLUS) { bufsz = sizeof buffer; - state = m_getfld (&gstate, name, buffer, &bufsz, in); + state = m_getfld2(&gstate, name, buffer, &bufsz); cp = add (buffer, cp); } } @@ -307,7 +290,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, nparts = 1; pos = start; - while (fgets (buffer, sizeof(buffer) - 1, in)) { + while (fgets (buffer, sizeof buffer, in)) { long len; if ((pos += (len = strlen (buffer))) > CPERMSG) { @@ -319,8 +302,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, /* Only one part, nothing to split */ if (nparts == 1) { free (cp); - if (dp) - free (dp); + mh_xfree(dp); fclose (in); return sendaux (vec, vecp, program, drft, st); @@ -378,7 +360,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, for (;;) { long len; - if (!fgets (buffer, sizeof(buffer) - 1, in)) { + if (!fgets (buffer, sizeof buffer, in)) { if (partno == nparts) break; adios (NULL, "premature eof"); @@ -398,7 +380,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, fclose (out); if (!pushsw && verbsw) { - printf ("\n"); + putchar('\n'); fflush (stdout); } @@ -426,8 +408,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, } free (cp); - if (dp) - free (dp); + mh_xfree(dp); fclose (in); /* close the draft */ return status; @@ -455,8 +436,8 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st) snprintf (buf, sizeof(buf), "%d", fd2); vec[vecp++] = buf; } else { - admonish (NULL, "unable to create temporary file in %s " - "for annotation list", get_temp_dir()); + inform("unable to create temporary file in %s for " + "annotation list, continuing...", get_temp_dir()); } } vec[vecp++] = drft; @@ -477,7 +458,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st) /* * child process -- send it * - * If fd is ok, then we are pushing and fd points to temp + * If fd is OK, then we are pushing and fd points to temp * file, so capture anything on stdout and stderr there. */ if (fd != NOTOK) { @@ -507,7 +488,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st) alert (drft, fd); close (fd); } else { - advise (NULL, "message not delivered to anyone"); + inform("message not delivered to anyone"); } if (annotext && fd2 != NOTOK) close (fd2); @@ -545,6 +526,7 @@ alert (char *file, int out) case NOTOK: /* oops -- fork error */ advise ("fork", "unable to"); + /* FALLTHRU */ case OK: /* child process -- send it */ @@ -556,7 +538,7 @@ alert (char *file, int out) if ((in = open (file, O_RDONLY)) == NOTOK) { admonish (file, "unable to re-open"); } else { - lseek (out, (off_t) 0, SEEK_END); + lseek(out, 0, SEEK_END); strncpy (buf, "\nMessage not delivered to anyone.\n", sizeof(buf)); if (write (out, buf, strlen (buf)) < 0) { advise (file, "write"); @@ -575,7 +557,7 @@ alert (char *file, int out) admonish (buf, "unable to rename %s to", file); } } - lseek (out, (off_t) 0, SEEK_SET); + lseek(out, 0, SEEK_SET); dup2 (out, fileno (stdin)); close (out); /* create subject for error notification */ @@ -609,10 +591,9 @@ tmp_fd (void) if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) return NOTOK; if (debugsw) - advise (NULL, "temporary file %s selected", tfile); - else - if (m_unlink (tfile) == NOTOK) - advise (tfile, "unable to remove"); + inform("temporary file %s selected", tfile); + else if (m_unlink (tfile) == NOTOK) + advise (tfile, "unable to remove"); return fd; } @@ -632,7 +613,7 @@ anno (int fd, struct stat *st) || st->st_dev != st2.st_dev || st->st_ino != st2.st_ino)) { if (debugsw) - admonish (NULL, "$mhaltmsg mismatch"); + inform("$mhaltmsg mismatch, continuing..."); return; } @@ -640,10 +621,10 @@ anno (int fd, struct stat *st) switch (child_id) { case NOTOK: /* oops */ if (!debugsw) - advise (NULL, - "unable to fork, so doing annotations by hand..."); + inform("unable to fork, so doing annotations by hand..."); if (cwd == NULL) - cwd = getcpy (pwd ()); + cwd = mh_xstrdup(pwd ()); + /* FALLTHRU */ case OK: /* block a few signals */ @@ -686,7 +667,7 @@ annoaux (int fd) if ((folder = getenv ("mhfolder")) == NULL || *folder == 0) { if (debugsw) - admonish (NULL, "$mhfolder not set"); + inform("$mhfolder not set, continuing..."); return; } maildir = m_maildir (folder); @@ -697,20 +678,20 @@ annoaux (int fd) } if (!(mp = folder_read (folder, 0))) { if (debugsw) - admonish (NULL, "unable to read folder %s", folder); + inform("unable to read folder %s, continuing...", folder); return; } /* check for empty folder */ if (mp->nummsg == 0) { if (debugsw) - admonish (NULL, "no messages in %s", folder); + inform("no messages in %s, continuing...", folder); goto oops; } if ((cp = getenv ("mhmessages")) == NULL || *cp == 0) { if (debugsw) - admonish (NULL, "$mhmessages not set"); + inform("$mhmessages not set, continuing..."); goto oops; } if (!debugsw /* MOBY HACK... */ @@ -722,21 +703,21 @@ annoaux (int fd) } else fd2 = NOTOK; - for (ap = brkstring (cp = getcpy (cp), " ", NULL); *ap; ap++) + for (ap = brkstring (cp = mh_xstrdup(cp), " ", NULL); *ap; ap++) m_convert (mp, *ap); free (cp); if (fd2 != NOTOK) dup2 (fd2, fileno (stderr)); if (mp->numsel == 0) { if (debugsw) - admonish (NULL, "no messages to annotate"); + inform("no messages to annotate, continuing..."); goto oops; } - lseek (fd, (off_t) 0, SEEK_SET); + lseek(fd, 0, SEEK_SET); if ((fp = fdopen (fd, "r")) == NULL) { if (debugsw) - admonish (NULL, "unable to fdopen annotation list"); + inform("unable to fdopen annotation list, continuing..."); goto oops; } cp = NULL; @@ -745,12 +726,12 @@ annoaux (int fd) fclose (fp); if (debugsw) - advise (NULL, "annotate%s with %s: \"%s\"", + inform("annotate%s with %s: \"%s\"", inplace ? " inplace" : "", annotext, cp); for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (is_selected(mp, msgnum)) { if (debugsw) - advise (NULL, "annotate message %d", msgnum); + inform("annotate message %d", msgnum); annotate (m_name (msgnum), annotext, cp, inplace, 1, -2, 0); } } @@ -770,7 +751,7 @@ handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) { /* Extract address and host from From: header line in draft. */ if (get_from_header_info(draft, &addr, &host, &message) != OK) { - adios(draft, message); + adios(draft, "%s", message); } /* Merge in any address or host specific switches to post(1) from profile. */ @@ -787,7 +768,7 @@ handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) { if (strcmp(*vp, "xoauth2") == 0) { #ifdef OAUTH_SUPPORT if (setup_oauth_params(vec, vecp, auth_svc, &message) != OK) { - adios(NULL, message); + adios(NULL, "%s", message); } break; #else @@ -843,21 +824,21 @@ setup_oauth_params(char *vec[], int *vecp, const char *auth_svc, adios(NULL, "Unable to retrieve oauth profile entries: %s", errbuf); - vec[(*vecp)++] = getcpy("-authservice"); - vec[(*vecp)++] = getcpy(auth_svc); - vec[(*vecp)++] = getcpy("-oauthcredfile"); - vec[(*vecp)++] = getcpy(mh_oauth_cred_fn(auth_svc)); - vec[(*vecp)++] = getcpy("-oauthclientid"); + vec[(*vecp)++] = mh_xstrdup("-authservice"); + vec[(*vecp)++] = mh_xstrdup(auth_svc); + vec[(*vecp)++] = mh_xstrdup("-oauthcredfile"); + vec[(*vecp)++] = mh_xstrdup(mh_oauth_cred_fn(auth_svc)); + vec[(*vecp)++] = mh_xstrdup("-oauthclientid"); vec[(*vecp)++] = getcpy(svc.client_id); - vec[(*vecp)++] = getcpy("-oauthclientsecret"); + vec[(*vecp)++] = mh_xstrdup("-oauthclientsecret"); vec[(*vecp)++] = getcpy(svc.client_secret); - vec[(*vecp)++] = getcpy("-oauthauthendpoint"); + vec[(*vecp)++] = mh_xstrdup("-oauthauthendpoint"); vec[(*vecp)++] = getcpy(svc.auth_endpoint); - vec[(*vecp)++] = getcpy("-oauthredirect"); + vec[(*vecp)++] = mh_xstrdup("-oauthredirect"); vec[(*vecp)++] = getcpy(svc.redirect_uri); - vec[(*vecp)++] = getcpy("-oauthtokenendpoint"); + vec[(*vecp)++] = mh_xstrdup("-oauthtokenendpoint"); vec[(*vecp)++] = getcpy(svc.token_endpoint); - vec[(*vecp)++] = getcpy("-oauthscope"); + vec[(*vecp)++] = mh_xstrdup("-oauthscope"); vec[(*vecp)++] = getcpy(svc.scope); } } @@ -888,7 +869,7 @@ get_from_header_info(const char *filename, const char **addr, const char **host, char *hostformat = "%(host{Envelope-From})"; if ((*addr = get_message_header_info (in, addrformat)) == NULL || - strlen (*addr) == 0) { + !**addr) { addrformat = distfile == NULL ? "%(addr{Sender})" : "%(addr{Resent-Sender})"; hostformat = distfile == NULL ? "%(host{Sender})" : "%(host{Resent-Sender})"; @@ -906,18 +887,17 @@ get_from_header_info(const char *filename, const char **addr, const char **host, /* Use the hostformat that corresponds to the successful addrformat. */ if ((*host = get_message_header_info(in, hostformat)) == NULL) { - fclose(in); - *message = "unable to find sender host in"; + *message = "unable to find sender host"; fclose(in); return NOTOK; } fclose(in); return OK; - } else { - *message = "unable to open"; - return NOTOK; } + + *message = "unable to open"; + return NOTOK; } @@ -932,7 +912,7 @@ get_message_header_info(FILE *in, char *format) { struct format *fmt; struct stat st; int parsing_header; - m_getfld_state_t gstate = 0; + m_getfld_state_t gstate; charstring_t buffer = charstring_create(0); char *retval; @@ -948,10 +928,11 @@ get_message_header_info(FILE *in, char *format) { */ rewind (in); parsing_header = 1; + gstate = m_getfld_state_init(in); do { char name[NAMESZ], rbuf[NMH_BUFSIZ]; int bufsz = sizeof rbuf; - int state = m_getfld(&gstate, name, rbuf, &bufsz, in); + int state = m_getfld2(&gstate, name, rbuf, &bufsz); switch (state) { case FLD: @@ -961,14 +942,14 @@ get_message_header_info(FILE *in, char *format) { if (bucket != -1) { while (state == FLDPLUS) { bufsz = sizeof rbuf; - state = m_getfld(&gstate, name, rbuf, &bufsz, in); + state = m_getfld2(&gstate, name, rbuf, &bufsz); fmt_appendcomp(bucket, name, rbuf); } } while (state == FLDPLUS) { bufsz = sizeof rbuf; - state = m_getfld(&gstate, name, rbuf, &bufsz, in); + state = m_getfld2(&gstate, name, rbuf, &bufsz); } break; } @@ -984,12 +965,11 @@ get_message_header_info(FILE *in, char *format) { /* Trim trailing newline, if any. */ retval = rtrim(charstring_buffer_copy((buffer))); charstring_free(buffer); - if (strlen (retval) > 0) { + if (*retval) return retval; - } else { - free (retval); - return NULL; - } + + free(retval); + return NULL; } @@ -1019,7 +999,7 @@ merge_profile_entry(const char *addr, const char *host, char *vec[], int *vecp) } /* Use argsplit() to do the real work of splitting the args in the profile entry. */ - if (profile_entry && strlen(profile_entry) > 0) { + if (profile_entry && *profile_entry) { int profile_vecp; char *file; char **profile_vec = argsplit(profile_entry, &file, &profile_vecp); @@ -1034,7 +1014,7 @@ merge_profile_entry(const char *addr, const char *host, char *vec[], int *vecp) } -static void +static void NORETURN armed_done (int status) { longjmp (env, status ? status : NOTOK);