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 */
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 *);
fclose(out);
/* process Fcc */
- for (i=0; i<fccind; i++) {
- fcc(tmpfil, fccfold[i]);
+ if (*fccs) {
+ fcc(tmpfil, fccs);
}
/* process Bcc */
}
if (hdr->flags & 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;
}
}
-/*
-** 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, "</dev/null %s -link -file %s %s",
+ fileproc, file, folders);
+ status = system(cmd);
+ if (status == -1) {
+ fprintf(stderr, "Skipped %sFcc %s: unable to system().\n",
+ msgstate == resent ? "Resent-" : "", folders);
+ } else if (status != 0) {
+ fprintf(stderr, "%sFcc %s: Problems occured.\n",
+ msgstate == resent ? "Resent-" : "", folders);
}
-
- fflush(stdout);
}