#include <errno.h>
#include <signal.h>
#include <h/signals.h>
-#include <setjmp.h>
#include <h/mime.h>
#include <h/tws.h>
#include <h/utils.h>
#include <time.h>
int debugsw = 0; /* global */
-int verbosesw = 0;
-char *altmsg = NULL;
+char *altmsg = NULL;
char *annotext = NULL;
char *distfile = NULL;
-static jmp_buf env;
-
/* name of temp file for body content */
static char body_file_name[MAXPATHLEN + 1];
/* name of mhbuild composition temporary file */
** static prototypes
*/
static int sendsbr(char **, int, char *, struct stat *);
-static void armed_done(int) NORETURN;
static void anno(struct stat *);
static int sendaux(char **, int, char *, struct stat *);
static int attach(char *);
switch (smatch(++cp, switches)) {
case AMBIGSW:
ambigsw(cp, switches);
- done(1);
+ exit(1);
case UNKWNSW:
adios(NULL, "-%s unknown\n", cp);
"%s [file] [switches]",
invo_name);
print_help(buf, switches, 1);
- done(1);
+ exit(0);
case VERSIONSW:
print_version(invo_name);
- done(1);
+ exit(0);
case DEBUGSW:
debugsw++;
/* fall */
case VERBSW:
- verbosesw += 2;
case NVERBSW:
- verbosesw--;
vec[vecp++] = --cp;
continue;
}
/* parse all the msgranges/sequences and set SELECTED */
for (msgnum = 0; msgnum < nmsgs; msgnum++) {
if (!m_convert(mp, msgs[msgnum])) {
- done(1);
+ exit(1);
}
}
seq_setprev(mp);
for (n = 0; n < nfiles; n++) {
switch (sendsbr(vec, vecp, files[n], &st)) {
case DONE:
- done(++status);
+ exit(++status);
case NOTOK:
status++; /* fall */
case OK:
}
context_save();
- done(status);
- return 1;
+ return status;
}
static int
sendsbr(char **vec, int vecp, char *drft, struct stat *st)
{
- int status;
- char buffer[BUFSIZ];
+ int status, dupfd;
char *original_draft;
/*
break;
}
- done=armed_done;
- switch (setjmp(env)) {
- case OK:
- status = sendaux(vec, vecp, drft, st) ? NOTOK : OK;
- if (status == OK) {
- /* move original draft to +trash folder */
- snprintf(buffer, sizeof buffer,
- "</dev/null refile -file %s +trash",
- original_draft);
- if (system(buffer) != 0) {
- advise(NULL, "unable to trash the draft");
- }
+ if ((status = sendaux(vec, vecp, drft, st)) == OK) {
+ /* move original draft to +trash folder */
+ /* temporary close stdin, for refile not to ask */
+ dupfd = dup(0);
+ close(0);
+ if (execprogl("refile", "refile", "-file",
+ original_draft, "+trash",
+ (char *)NULL) != 0) {
+ advise(NULL, "unable to trash the draft");
}
- break;
-
- default:
+ dup2(dupfd, 0);
+ close(dupfd);
+ } else {
status = DONE;
- break;
}
- done=exit;
if (distfile) {
unlink(distfile);
}
vec[vecp++] = drft;
if (distfile && distout(drft, distfile, backup) == NOTOK) {
- done(1);
+ return DONE;
}
vec[vecp] = NULL;
switch (child_id = fork()) {
case -1:
/* oops -- fork error */
- adios("fork", "unable to");
- break; /* NOT REACHED */
+ advise("fork", "unable to");
+ return DONE;
case 0:
/* child process -- send it */
if (annotext) {
anno(st);
}
- }
- else {
+ } else {
+ /* spost failed */
advise(NULL, "%s", strexit(status));
- if (verbosesw <= 0) {
- advise(NULL, "Try using -v to get better output");
- }
if (distfile) {
unlink(drft);
if (rename(backup, drft) == NOTOK) {
}
- return status;
+ return status ? NOTOK : status;
}
struct stat st2;
char *msgs, *folder;
char buf[BUFSIZ];
+ char *vec[MAXARGS];
+ int vecp = 0;
+ char *cp, *dp;
if (altmsg && (stat(altmsg, &st2) == NOTOK ||
st->st_mtime != st2.st_mtime ||
advise(NULL, "annotate as `%s': %s %s", annotext,
folder, msgs);
}
- snprintf(buf, sizeof buf, "anno -comp '%s' '+%s' %s",
- annotext, folder, msgs);
- if (system(buf) != 0) {
+ vec[vecp++] = "anno";
+ vec[vecp++] = "-comp";
+ vec[vecp++] = annotext;
+ snprintf(buf, sizeof buf, "+%s", folder);
+ vec[vecp++] = buf;
+
+ while (isspace(*msgs)) {
+ msgs++;
+ }
+ for (cp=dp=msgs; *cp; cp++) {
+ if (isspace(*cp)) {
+ while (isspace(*cp)) {
+ *cp++ = '\0';
+ }
+ vec[vecp++] = dp;
+ dp = cp;
+ }
+ }
+ vec[vecp++] = dp;
+ vec[vecp] = NULL;
+ if (execprog(*vec, vec) != 0) {
advise(NULL, "unable to annotate");
}
}
return "spost or sendmail killed by signal";
}
if (!WIFEXITED(status)) {
- return "sendmail stopt for unknown reasen, message not deliverd to anyone";
+ return "message not delivered to anyone";
}
switch (WEXITSTATUS(status)) {
- case EX_TEMPFAIL:
- return "Temporary error, maby the MTA hase queued the Mail";
- default:
- return "sendmail stopt for unknown reasen, message not deliverd to anyone";
+ case EX_TEMPFAIL:
+ return "Temporary error, maybe the MTA has queued the message";
+ default:
+ return "message not delivered to anyone";
}
}
-
-
-static void
-armed_done(int status)
-{
- longjmp(env, status ? status : NOTOK);
-
- exit(status);
-}