X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Freplsbr.c;h=852becd0896998c029777fadde5606a96a8a0333;hp=8e60a526a3f90a092b03cf8338908152c9cedb5d;hb=88d0e7601d67f8212791482433dcda4cb9d3eaac;hpb=ced6090a330d3d83d0bce709f756aa3d7d65fea4 diff --git a/uip/replsbr.c b/uip/replsbr.c index 8e60a52..852becd 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -61,13 +61,13 @@ static char *addrcomps[] = { /* ** static prototypes */ -static int insert (struct mailname *); -static void replfilter (FILE *, FILE *, char *); +static int insert(struct mailname *); +static void replfilter(FILE *, FILE *, char *); void -replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, - int mime, char *form, char *filter, char *fcc) +replout(FILE *inb, char *msg, char *drft, struct msgs *mp, + int mime, char *form, char *filter) { register int state, i; register struct comp *cptr; @@ -81,24 +81,24 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, FILE *out; mask = umask(~m_gmprot()); - if ((out = fopen (drft, "w")) == NULL) - adios (drft, "unable to create"); + if ((out = fopen(drft, "w")) == NULL) + adios(drft, "unable to create"); umask(mask); /* get new format string */ - cp = new_fs (form, NULL, NULL); - format_len = strlen (cp); + cp = new_fs(form, NULL, NULL); + format_len = strlen(cp); /* compile format string */ - ncomps = fmt_compile (cp, &fmt) + 1; + ncomps = fmt_compile(cp, &fmt) + 1; if (!(nxtbuf = compbuffers = (char **) calloc((size_t) ncomps, sizeof(char *)))) - adios (NULL, "unable to allocate component buffers"); + adios(NULL, "unable to allocate component buffers"); if (!(savecomp = used_buf = (struct comp **) calloc((size_t) (ncomps+1), sizeof(struct comp *)))) - adios (NULL, "unable to allocate component buffer stack"); + adios(NULL, "unable to allocate component buffer stack"); savecomp += ncomps + 1; *--savecomp = NULL; /* point at zero'd end minus 1 */ @@ -109,7 +109,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, tmpbuf = *nxtbuf++; for (ap = addrcomps; *ap; ap++) { - FINDCOMP (cptr, *ap); + FINDCOMP(cptr, *ap); if (cptr) cptr->c_type |= CT_ADDR; } @@ -118,89 +118,83 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, ** ignore any components killed by command line switches */ if (!ccto) { - FINDCOMP (cptr, "to"); + FINDCOMP(cptr, "to"); if (cptr) cptr->c_name = ""; } if (!cccc) { - FINDCOMP (cptr, "cc"); + FINDCOMP(cptr, "cc"); if (cptr) cptr->c_name = ""; } - /* set up the "fcc" pseudo-component */ - if (fcc) { - FINDCOMP (cptr, "fcc"); - if (cptr) - cptr->c_text = getcpy (fcc); - } if ((cp = getenv("USER"))) { - FINDCOMP (cptr, "user"); + FINDCOMP(cptr, "user"); if (cptr) cptr->c_text = getcpy(cp); } if (!ccme) - ismymbox (NULL); + ismymbox(NULL); /* ** pick any interesting stuff out of msg "inb" */ for (state = FLD;;) { - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb); switch (state) { - case FLD: - case FLDPLUS: - /* - ** if we're interested in this component, - ** save a pointer to the component text, - ** then start using our next free buffer - ** as the component temp buffer (buffer - ** switching saves an extra copy of the - ** component text). - */ - if ((cptr = wantcomp[CHASH(name)])) - do { - if (!mh_strcasecmp(name, cptr->c_name)) { - char_read += msg_count; - if (! cptr->c_text) { - i = strlen(cptr->c_text = tmpbuf) - 1; - if (tmpbuf[i] == '\n') - tmpbuf[i] = '\0'; - *--savecomp = cptr; - tmpbuf = *nxtbuf++; - } else { - i = strlen (cp = cptr->c_text) - 1; - if (cp[i] == '\n') { - if (cptr->c_type & CT_ADDR) { - cp[i] = '\0'; - cp = add (",\n\t", cp); - } else { - cp = add ("\t", cp); - } + case FLD: + case FLDPLUS: + /* + ** if we're interested in this component, save + ** a pointer to the component text, then start + ** using our next free buffer as the component + ** temp buffer (buffer switching saves an extra + ** copy of the component text). + */ + if ((cptr = wantcomp[CHASH(name)])) + do { + if (!mh_strcasecmp(name, cptr->c_name)) { + char_read += msg_count; + if (! cptr->c_text) { + i = strlen(cptr->c_text = tmpbuf) - 1; + if (tmpbuf[i] == '\n') + tmpbuf[i] = '\0'; + *--savecomp = cptr; + tmpbuf = *nxtbuf++; + } else { + i = strlen(cp = cptr->c_text) - 1; + if (cp[i] == '\n') { + if (cptr->c_type & CT_ADDR) { + cp[i] = '\0'; + cp = add(",\n\t", cp); + } else { + cp = add("\t", cp); } - cptr->c_text = add (tmpbuf, cp); } - while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, - SBUFSIZ, inb); - cptr->c_text = add (tmpbuf, cptr->c_text); - char_read += msg_count; - } - break; + cptr->c_text = add(tmpbuf, cp); + } + while (state == FLDPLUS) { + state = m_getfld(state, name, tmpbuf, + SBUFSIZ, inb); + cptr->c_text = add(tmpbuf, cptr->c_text); + char_read += msg_count; } - } while ((cptr = cptr->c_next)); + break; + } + } while ((cptr = cptr->c_next)); - while (state == FLDPLUS) - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); - break; + while (state == FLDPLUS) + state = m_getfld(state, name, tmpbuf, + SBUFSIZ, inb); + break; - case LENERR: - case FMTERR: - case BODY: - case FILEEOF: - goto finished; + case LENERR: + case FMTERR: + case BODY: + case FILEEOF: + goto finished; - default: - adios (NULL, "m_getfld() returned %d", state); + default: + adios(NULL, "m_getfld() returned %d", state); } } @@ -212,7 +206,7 @@ finished: /* ** if there's a "Subject" component, strip any "Re:"s off it */ - FINDCOMP (cptr, "subject") + FINDCOMP(cptr, "subject") if (cptr && (cp = cptr->c_text)) { register char *sp = cp; @@ -227,53 +221,56 @@ finished: } if (sp != cptr->c_text) { cp = cptr->c_text; - cptr->c_text = getcpy (sp); - free (cp); + cptr->c_text = getcpy(sp); + free(cp); } } i = format_len + char_read + 256; - scanl = mh_xmalloc ((size_t) i + 2); + scanl = mh_xmalloc((size_t) i + 2); dat[0] = 0; dat[1] = 0; dat[2] = 0; - dat[3] = outputlinelen; + dat[3] = OUTPUTLINELEN; dat[4] = 0; - fmt_scan (fmt, scanl, i, dat); - fputs (scanl, out); + fmt_scan(fmt, scanl, i, dat); + fputs(scanl, out); if (badaddrs) { - fputs ("\nrepl: bad addresses:\n", out); - fputs ( badaddrs, out); + fputs("\nrepl: bad addresses:\n", out); + fputs( badaddrs, out); } - /* - ** Check if we should filter the message - ** or add mhbuild directives - */ + /* Check if we should filter the message */ if (filter) { fflush(out); - if (ferror (out)) - adios (drft, "error writing"); + if (ferror(out)) + adios(drft, "error writing"); - replfilter (inb, out, filter); - } else if (mime && mp) { - fprintf (out, "#forw [original message] +%s %s\n", - mp->foldpath, m_name (mp->lowsel)); + replfilter(inb, out, filter); } fflush(out); - if (ferror (out)) - adios (drft, "error writing"); - fclose (out); + if (ferror(out)) + adios(drft, "error writing"); + fclose(out); + + /* if we want mime, then add an attachment header */ + if (!filter && mime && mp) { + char buffer[BUFSIZ]; + + snprintf(buffer, sizeof buffer, "+%s %s", + mp->foldpath, m_name(mp->lowsel)); + annotate(drft, attach_hdr, buffer, 0, -2, 1); + } /* return dynamically allocated buffers */ - free (scanl); + free(scanl); for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++); nxtbuf++, i--) - free (cptr->c_text); /* if not nxtbuf, nxtbuf already freed */ + free(cptr->c_text); /* if not nxtbuf, nxtbuf already freed */ while ( i-- > 0) - free (*nxtbuf++); /* free unused nxtbufs */ - free ((char *) compbuffers); - free ((char *) used_buf); + free(*nxtbuf++); /* free unused nxtbufs */ + free((char *) compbuffers); + free((char *) used_buf); } static char *buf; /* our current working buffer */ @@ -290,11 +287,11 @@ static unsigned int bufsiz=0; /* current size of buf */ ** add more mem if needed */ #define CHECKMEM(str) \ - if ((len = strlen (str)) >= bufend - dst) {\ + if ((len = strlen(str)) >= bufend - dst) {\ int i = dst - buf;\ int n = last_dst - buf;\ bufsiz += ((dst + len - bufend) / BUFINCR + 1) * BUFINCR;\ - buf = mh_xrealloc (buf, bufsiz);\ + buf = mh_xrealloc(buf, bufsiz);\ dst = buf + i;\ last_dst = buf + n;\ bufend = buf + bufsiz;\ @@ -313,7 +310,7 @@ static unsigned int bufsiz=0; /* current size of buf */ ** length of the result string. */ char * -formataddr (char *orig, char *str) +formataddr(char *orig, char *str) { register int len; char baddr[BUFSIZ], error[BUFSIZ]; @@ -325,7 +322,7 @@ formataddr (char *orig, char *str) /* if we don't have a buffer yet, get one */ if (bufsiz == 0) { - buf = mh_xmalloc (BUFINCR); + buf = mh_xmalloc(BUFINCR); last_dst = buf; /* XXX */ bufsiz = BUFINCR - 6; /* leave some slop */ bufend = buf + bufsiz; @@ -341,36 +338,36 @@ formataddr (char *orig, char *str) *dst = '\0'; } else { dst = last_dst; /* XXX */ - CHECKMEM (orig); - CPY (orig); + CHECKMEM(orig); + CPY(orig); } /* concatenate all the new addresses onto 'buf' */ - for (isgroup = 0; (cp = getname (str)); ) { - if ((mp = getm (cp, dfhost, dftype, AD_NAME, error)) == NULL) { - snprintf (baddr, sizeof(baddr), "\t%s -- %s\n", + for (isgroup = 0; (cp = getname(str)); ) { + if ((mp = getm(cp, dfhost, dftype, AD_NAME, error)) == NULL) { + snprintf(baddr, sizeof(baddr), "\t%s -- %s\n", cp, error); - badaddrs = add (baddr, badaddrs); + badaddrs = add(baddr, badaddrs); continue; } if (isgroup && (mp->m_gname || !mp->m_ingrp)) { *dst++ = ';'; isgroup = 0; } - if (insert (mp)) { + if (insert(mp)) { /* if we get here we're going to add an address */ if (dst != buf) { *dst++ = ','; *dst++ = ' '; } if (mp->m_gname) { - CHECKMEM (mp->m_gname); - CPY (mp->m_gname); + CHECKMEM(mp->m_gname); + CPY(mp->m_gname); isgroup++; } - sp = adrformat (mp); - CHECKMEM (sp); - CPY (sp); + sp = adrformat(mp); + CHECKMEM(sp); + CPY(sp); } } @@ -384,7 +381,7 @@ formataddr (char *orig, char *str) static int -insert (struct mailname *np) +insert(struct mailname *np) { char buffer[BUFSIZ]; register struct mailname *mp; @@ -393,24 +390,23 @@ insert (struct mailname *np) return 0; for (mp = &mq; mp->m_next; mp = mp->m_next) { - if (!mh_strcasecmp (np->m_host, mp->m_next->m_host) - && !mh_strcasecmp (np->m_mbox, - mp->m_next->m_mbox)) + if (!mh_strcasecmp(np->m_host, mp->m_next->m_host) && + !mh_strcasecmp(np->m_mbox, mp->m_next->m_mbox)) return 0; } - if (!ccme && ismymbox (np)) + if (!ccme && ismymbox(np)) return 0; if (querysw) { - snprintf (buffer, sizeof(buffer), "Reply to %s? ", - adrformat (np)); - if (!gans (buffer, anoyes)) + snprintf(buffer, sizeof(buffer), "Reply to %s? ", + adrformat(np)); + if (!gans(buffer, anoyes)) return 0; } mp->m_next = np; #ifdef ISI - if (ismymbox (np)) + if (ismymbox(np)) ccme = 0; #endif @@ -425,7 +421,7 @@ insert (struct mailname *np) */ static void -replfilter (FILE *in, FILE *out, char *filter) +replfilter(FILE *in, FILE *out, char *filter) { int pid; char *mhl; @@ -434,37 +430,36 @@ replfilter (FILE *in, FILE *out, char *filter) if (filter == NULL) return; - if (access (filter, R_OK) == NOTOK) - adios (filter, "unable to read"); - - mhl = r1bindex (mhlproc, '/'); - - rewind (in); - lseek (fileno(in), (off_t) 0, SEEK_SET); - - switch (pid = vfork ()) { - case NOTOK: - adios ("fork", "unable to"); - - case OK: - dup2 (fileno (in), fileno (stdin)); - dup2 (fileno (out), fileno (stdout)); - closefds (3); - - execlp (mhlproc, mhl, "-form", filter, "-noclear", - NULL); - errstr = strerror(errno); - write(2, "unable to exec ", 15); - write(2, mhlproc, strlen(mhlproc)); - write(2, ": ", 2); - write(2, errstr, strlen(errstr)); - write(2, "\n", 1); - _exit (-1); - - default: - if (pidXwait (pid, mhl)) - done (1); - fseek (out, 0L, SEEK_END); - break; + if (access(filter, R_OK) == NOTOK) + adios(filter, "unable to read"); + + mhl = mhbasename(mhlproc); + + rewind(in); + lseek(fileno(in), (off_t) 0, SEEK_SET); + + switch (pid = fork()) { + case NOTOK: + adios("fork", "unable to"); + + case OK: + dup2(fileno(in), fileno(stdin)); + dup2(fileno(out), fileno(stdout)); + closefds(3); + + execlp(mhlproc, mhl, "-form", filter, "-noclear", NULL); + errstr = strerror(errno); + write(2, "unable to exec ", 15); + write(2, mhlproc, strlen(mhlproc)); + write(2, ": ", 2); + write(2, errstr, strlen(errstr)); + write(2, "\n", 1); + _exit(-1); + + default: + if (pidXwait(pid, mhl)) + done(1); + fseek(out, 0L, SEEK_END); + break; } }