X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fsend.c;h=1529c0faa13e16cdf96f6d1fbf6b2abe83a2716b;hp=a79e34fe7954fabae9bbc66d1b568deaf170e9c3;hb=f3cb7cde0e6f10451b6848678d95860d512224b9;hpb=275c6bc6c87156ea8ce804ae2c7d45e2d9294fe5 diff --git a/uip/send.c b/uip/send.c index a79e34f..1529c0f 100644 --- a/uip/send.c +++ b/uip/send.c @@ -29,7 +29,6 @@ int debugsw = 0; /* global */ int forwsw = 1; -int inplace = 1; int pushsw = 0; int verbsw = 0; char *altmsg = NULL; @@ -55,8 +54,7 @@ static int sendsbr(char **, int, char *, struct stat *, int); static void armed_done(int) NORETURN; static void alert(char *, int); static int tmp_fd(void); -static void anno(int, struct stat *); -static void annoaux(int); +static void anno(struct stat *); static int sendaux(char **, int, char *, struct stat *); static int attach(char *); static void clean_up_temporary_files(void); @@ -69,33 +67,25 @@ static struct swit switches[] = { { "alias aliasfile", 0 }, #define DEBUGSW 1 { "debug", -5 }, -#define FILTSW 2 - { "filter filterfile", 0 }, -#define NFILTSW 3 - { "nofilter", 0 }, -#define FRMTSW 4 - { "format", 0 }, -#define NFRMTSW 5 - { "noformat", 0 }, -#define FORWSW 6 +#define FORWSW 2 { "forward", 0 }, -#define NFORWSW 7 +#define NFORWSW 3 { "noforward", 0 }, -#define PUSHSW 8 +#define PUSHSW 4 { "push", 0 }, -#define NPUSHSW 9 +#define NPUSHSW 5 { "nopush", 0 }, -#define VERBSW 10 +#define VERBSW 6 { "verbose", 0 }, -#define NVERBSW 11 +#define NVERBSW 7 { "noverbose", 0 }, -#define WATCSW 12 +#define WATCSW 8 { "watch", 0 }, -#define NWATCSW 13 +#define NWATCSW 9 { "nowatch", 0 }, -#define VERSIONSW 14 +#define VERSIONSW 10 { "version", 0 }, -#define HELPSW 15 +#define HELPSW 11 { "help", 0 }, { NULL, 0 } }; @@ -174,16 +164,12 @@ main(int argc, char **argv) case DEBUGSW: debugsw++; /* fall */ - case NFILTSW: - case FRMTSW: - case NFRMTSW: case WATCSW: case NWATCSW: vec[vecp++] = --cp; continue; case ALIASW: - case FILTSW: vec[vecp++] = --cp; if (!(cp = *argp++) || *cp == '-') { adios(NULL, "missing argument to %s", @@ -260,9 +246,6 @@ main(int argc, char **argv) if (!(annotext = getenv("mhannotate")) || !*annotext) { annotext = NULL; } - if (annotext && ((cp = getenv("mhinplace")) && *cp)) { - inplace = atoi(cp); - } if (!(altmsg = getenv("mhaltmsg")) || !*altmsg) { altmsg = NULL; /* used by dist interface - see below */ } @@ -463,7 +446,7 @@ attach(char *draft_file_name) } } if (has_body && non_ascii) { - break; /* that's been already enough information +/ + break; /* that's been already enough information */ } } @@ -648,16 +631,16 @@ static int sendaux(char **vec, int vecp, char *drft, struct stat *st) { pid_t child_id; - int i, status, fd, fd2; + int i, status, fd; char backup[BUFSIZ]; + /* + ** fd collects the output of postproc, and is used for the + ** failure notice if we need to send one in alert(). + */ fd = pushsw ? tmp_fd() : NOTOK; - fd2 = NOTOK; vec[vecp++] = drft; - if (annotext && (fd2 = tmp_fd()) == NOTOK) { - admonish(NULL, "unable to create file for annotation list"); - } if (distfile && distout(drft, distfile, backup) == NOTOK) { done(1); } @@ -666,7 +649,6 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) { sleep(5); } - switch (child_id) { case -1: /* oops -- fork error */ @@ -694,8 +676,9 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) default: /* parent process -- wait for it */ if ((status = pidwait(child_id, NOTOK)) == OK) { - if (annotext && fd2 != NOTOK) - anno(fd2, st); + if (annotext) { + anno(st); + } } else { /* ** If postproc failed, and we have good fd (which @@ -708,9 +691,6 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) } else { advise(NULL, "message not delivered to anyone"); } - if (annotext && fd2 != NOTOK) { - close(fd2); - } if (distfile) { unlink(drft); if (rename(backup, drft) == NOTOK) { @@ -812,12 +792,11 @@ tmp_fd(void) static void -anno(int fd, struct stat *st) +anno(struct stat *st) { - pid_t child_id; - sigset_t set, oset; - static char *cwd = NULL; struct stat st2; + char *msgs, *folder; + char buf[BUFSIZ]; if (altmsg && (stat(altmsg, &st2) == NOTOK || st->st_mtime != st2.st_mtime || @@ -829,138 +808,27 @@ anno(int fd, struct stat *st) return; } - child_id = debugsw ? NOTOK : fork(); - switch (child_id) { - case NOTOK: /* oops */ - if (!debugsw) { - advise(NULL, "unable to fork, so doing annotations by hand..."); - } - if (!cwd) { - cwd = getcpy(pwd()); - } - /* fall */ - - case OK: - /* block a few signals */ - sigemptyset(&set); - sigaddset(&set, SIGHUP); - sigaddset(&set, SIGINT); - sigaddset(&set, SIGQUIT); - sigaddset(&set, SIGTERM); - SIGPROCMASK(SIG_BLOCK, &set, &oset); - - annoaux(fd); - if (child_id == OK) { - _exit(0); - } - - /* reset the signal mask */ - SIGPROCMASK(SIG_SETMASK, &oset, &set); - - chdir(cwd); - break; - - default: /* no waiting... */ - close(fd); - break; - } -} - - -static void -annoaux(int fd) -{ - int fd2, fd3, msgnum; - char *cp, *folder, *maildir; - char buffer[BUFSIZ], **ap; - FILE *fp; - struct msgs *mp; - if (!(folder = getenv("mhfolder")) || !*folder) { if (debugsw) { admonish(NULL, "$mhfolder not set"); } return; } - maildir = toabsdir(folder); - if (chdir(maildir) == NOTOK) { - if (debugsw) { - admonish(maildir, "unable to change directory to"); - } - return; - } - if (!(mp = folder_read(folder))) { - if (debugsw) { - admonish(NULL, "unable to read folder %s", folder); - } - return; - } - - if (mp->nummsg == 0) { - if (debugsw) { - admonish(NULL, "no messages in %s", folder); - } - goto oops; - } - if ((cp = getenv("mhmessages")) == NULL || *cp == 0) { + if (!(msgs = getenv("mhmessages")) || !*msgs) { if (debugsw) { admonish(NULL, "$mhmessages not set"); } - goto oops; - } - if (!debugsw /* MOBY HACK... */ - && pushsw - && (fd3 = open("/dev/null", O_RDWR)) != NOTOK - && (fd2 = dup(fileno(stderr))) != NOTOK) { - dup2(fd3, fileno(stderr)); - close(fd3); - } else { - fd2 = NOTOK; - } - for (ap = brkstring(cp = getcpy(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"); - } - goto oops; - } - - lseek(fd, (off_t) 0, SEEK_SET); - if ((fp = fdopen(fd, "r")) == NULL) { - if (debugsw) { - admonish(NULL, "unable to fdopen annotation list"); - } - goto oops; - } - cp = NULL; - while (fgets(buffer, sizeof(buffer), fp) != NULL) { - cp = add(buffer, cp); + return; } - fclose(fp); - if (debugsw) { - advise(NULL, "annotate%s with %s: \"%s\"", - inplace ? " inplace" : "", annotext, cp); + advise(NULL, "annotate as `%s': %s %s", annotext, + folder, msgs); } - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - if (debugsw) { - advise(NULL, "annotate message %d", msgnum); - } - annotate(m_name(msgnum), annotext, cp, inplace, - 1, -2, 0); - } + snprintf(buf, sizeof buf, "anno -comp '%s' '+%s' %s", + annotext, folder, msgs); + if (system(buf) != 0) { + advise(NULL, "unable to annotate"); } - free(cp); - -oops: - folder_free(mp); }