From 80eeca1af5bc5120d9aeef933c2e162c382c9d29 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Sun, 12 Feb 2012 16:45:26 +0100 Subject: [PATCH] Changed the Fcc handling code in spost. Both, the new as well as the old approach have their limitations. I'm far from confident with the new approach. At least it's simpler. It should be good enough for now. --- uip/spost.c | 127 ++++++++++++++++++++++++----------------------------------- 1 file changed, 51 insertions(+), 76 deletions(-) diff --git a/uip/spost.c b/uip/spost.c index 8b4b830..7b74dcc 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -128,8 +128,7 @@ static char tmpfil[] = "/tmp/spost-XXXXXX"; static char bccfil[] = "/tmp/spost-bcc-XXXXXX"; static char *subject = NULL; /* the subject field for BCC'ing */ -static char *fccfold[FCCS]; /* foldernames for FCC'ing */ -static short fccind = 0; /* index into fccfold[] */ +static char fccs[BUFSIZ] = ""; struct mailname *bccs = NULL; static struct headers *hdrtab; /* table for the message we're doing */ @@ -145,7 +144,6 @@ static void finish_headers(FILE *); static int get_header(char *, struct headers *); static void putadr(char *, struct mailname *); static int putone(char *, int, int); -static void insert_fcc(char *, unsigned char *); static void fcc(char *, char *); static void make_bcc_draft(char *); @@ -322,8 +320,8 @@ main(int argc, char **argv) fclose(out); /* process Fcc */ - for (i=0; iflags & HFCC) { - if ((cp = strrchr(str, '\n'))) { - *cp = '\0'; + if (strlen(str)+strlen(fccs) > sizeof fccs /2) { + adios(NULL, "Too much Fcc data"); } - for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) { - *cp++ = '\0'; - insert_fcc(hdr->value, pp); + /* todo: better have three states: SEPARATOR, PLUS, WORD */ + int state = 0; + for (cp=pp=str; *cp; cp++) { + switch (*cp) { + case ' ': + case '\t': + case '\n': + case ',': + if (state != 0) { + state = 0; + *cp = '\0'; + if (*pp=='+' || *pp=='@') { + strcat(fccs, " "); + } else { + strcat(fccs, " +"); + } + strcat(fccs, pp); + } + break; + default: + if (state == 0) { + state = 1; + pp = cp; + } + break; + } } - insert_fcc(hdr->value, pp); return; } @@ -642,76 +662,31 @@ putone(char *adr, int pos, int indent) } -/* -** Insert the normalized value from pp into fccfold[]. -*/ -static void -insert_fcc(char *name, unsigned char *pp) -{ - unsigned char *cp; - - for (cp = pp; isspace(*cp); cp++) - continue; - for (pp += strlen(pp) - 1; pp > cp && isspace(*pp); pp--) - continue; - if (pp >= cp) - *++pp = '\0'; - if (!*cp) - return; - - if (fccind >= FCCS) - adios(NULL, "too many %ss", name); - fccfold[fccind++] = getcpy(cp); -} - - static void -fcc(char *file, char *folder) +fcc(char *file, char *folders) { - pid_t child_id; - int i, status; - char fold[BUFSIZ]; + int status; + char cmd[BUFSIZ]; - if (verbose) + if (verbose) { printf("%sFcc: %s\n", msgstate == resent ? "Resent-" : "", - folder); - fflush(stdout); - - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep(5); - switch (child_id) { - case NOTOK: - if (verbose) { - printf("Sorry man, but we had no more forks.\n"); - } else { - fprintf(stderr, "Skipped %sFcc %s: unable to fork.\n", - msgstate == resent ? "Resent-" : "", - folder); - } - break; - - case OK: - snprintf(fold, sizeof(fold), "%s%s", - *folder == '+' || *folder == '@' ? "" : "+", - folder); - execlp(fileproc, mhbasename(fileproc), - "-link", "-file", file, fold, NULL); - _exit(-1); - - default: - if ((status = pidwait(child_id, OK))) { - if (verbose) { - printf(" errored (0%o)\n", status); - } else { - fprintf(stderr, " %sFcc %s: errored (0%o)\n", - msgstate == resent ? - "Resent-" : "", folder, - status); - } - } + folders); + fflush(stdout); + } + if (strlen(fileproc)+strlen(file)+strlen(folders)+100 > sizeof cmd) { + adios(NULL, "Too much Fcc data"); + } + /* hack: read from /dev/null and refile(1) won't question us */ + snprintf(cmd, sizeof cmd, "