-
-/*
- * 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
#ifdef OAUTH_SUPPORT
#include <h/oauth.h>
+#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 */
#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, "
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");
* 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++;
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)
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 {
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);
}
}
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) {
/* Only one part, nothing to split */
if (nparts == 1) {
free (cp);
- if (dp)
- free (dp);
+ free(dp);
fclose (in);
return sendaux (vec, vecp, program, drft, st);
for (;;) {
long len;
- if (!fgets (buffer, sizeof(buffer) - 1, in)) {
+ if (!fgets (buffer, sizeof buffer, in)) {
if (partno == nparts)
break;
adios (NULL, "premature eof");
}
free (cp);
- if (dp)
- free (dp);
+ free(dp);
fclose (in); /* close the draft */
return status;
sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
{
pid_t child_id;
- int i, status, fd, fd2;
+ int status, fd, fd2;
char backup[BUFSIZ], buf[BUFSIZ];
fd = pushsw ? tmp_fd () : NOTOK;
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;
done (1);
vec[vecp] = NULL;
- for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
- sleep (5);
-
+ child_id = fork();
switch (child_id) {
case -1:
/* oops -- fork error */
/*
* 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) {
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);
alert (char *file, int out)
{
pid_t child_id;
- int i, in, argp;
+ int in, argp;
char buf[BUFSIZ];
char *program;
char **arglist;
- for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
- sleep (5);
-
+ child_id = fork();
switch (child_id) {
case NOTOK:
/* oops -- fork error */
advise ("fork", "unable to");
+ /* FALLTHRU */
case OK:
/* child process -- send it */
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");
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 */
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;
}
|| st->st_dev != st2.st_dev
|| st->st_ino != st2.st_ino)) {
if (debugsw)
- admonish (NULL, "$mhaltmsg mismatch");
+ inform("$mhaltmsg mismatch, continuing...");
return;
}
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 = mh_xstrdup(pwd ());
+ /* FALLTHRU */
case OK:
/* block a few signals */
if ((folder = getenv ("mhfolder")) == NULL || *folder == 0) {
if (debugsw)
- admonish (NULL, "$mhfolder not set");
+ inform("$mhfolder not set, continuing...");
return;
}
maildir = m_maildir (folder);
}
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... */
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;
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);
}
}
/* 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. */
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
/* 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;
}
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;
*/
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:
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;
}
}
-static void
+static void NORETURN
armed_done (int status)
{
longjmp (env, status ? status : NOTOK);