- * We are replying to a message.
- */
- if (!msg)
- msg = "cur";
- if (!folder)
- folder = getfolder (1);
- maildir = m_maildir (folder);
-
- if (chdir (maildir) == NOTOK)
- adios (maildir, "unable to change directory to");
-
- /* read folder and create message structure */
- if (!(mp = folder_read (folder)))
- adios (NULL, "unable to read folder %s", folder);
-
- /* check for empty folder */
- if (mp->nummsg == 0)
- adios (NULL, "no messages in %s", folder);
-
- /* parse the message range/sequence/name and set SELECTED */
- if (!m_convert (mp, msg))
- done (1);
- seq_setprev (mp); /* set the previous-sequence */
-
- if (mp->numsel > 1)
- adios (NULL, "only one message at a time!");
-
- context_replace (pfolder, folder); /* update current folder */
- seq_setcur (mp, mp->lowsel); /* update current message */
- seq_save (mp); /* synchronize sequences */
- context_save (); /* save the context file */
- }
-
- msg = file ? file : getcpy (m_name (mp->lowsel));
-
- if ((in = fopen (msg, "r")) == NULL)
- adios (msg, "unable to open");
-
- /* find form (components) file */
- if (!form) {
- if (groupreply)
- form = etcpath (replgroupcomps);
- else
- form = etcpath (replcomps);
- }
-
- replout (in, msg, drft, mp, outputlinelen, mime, form, filter, fcc);
- fclose (in);
-
- if (nwhat)
- done (0);
- what_now (ed, nedit, NOUSE, drft, msg, 0, mp,
- anot ? "Replied" : NULL, inplace, cwd);
- done (1);
- return 1;
+ ** if there's a "Subject" component, strip any "Re:"s off it
+ */
+ FINDCOMP(cptr, "subject")
+ if (cptr && (cp = cptr->c_text)) {
+ char *sp = cp;
+
+ for (;;) {
+ while (isspace(*cp))
+ cp++;
+ if(uprf(cp, "re:"))
+ cp += 3;
+ else
+ break;
+ sp = cp;
+ }
+ if (sp != cptr->c_text) {
+ cp = cptr->c_text;
+ cptr->c_text = mh_xstrdup(sp);
+ mh_free0(&cp);
+ }
+ }
+ i = format_len + char_read + 256;
+ scanl = mh_xcalloc(i + 2, sizeof(char));
+ dat[0] = 0;
+ dat[1] = 0;
+ dat[2] = 0;
+ dat[3] = OUTPUTLINELEN;
+ dat[4] = 0;
+ fmt_scan(fmt, scanl, i, dat);
+ fputs(scanl, out);
+ if (badaddrs) {
+ fputs("\nrepl: bad addresses:\n", out);
+ fputs( badaddrs, out);
+ }
+
+ /* Check if we should filter the message */
+ if (filter) {
+ fflush(out);
+ if (ferror(out))
+ adios(EX_IOERR, drft, "error writing");
+
+ replfilter(inb, out, filter);
+ }
+
+ fflush(out);
+ if (ferror(out))
+ adios(EX_IOERR, drft, "error writing");
+ fclose(out);
+
+ if (mime && mp) {
+ /* add an attachment header */
+ char buffer[BUFSIZ];
+
+ snprintf(buffer, sizeof buffer, "+%s %s",
+ mp->foldpath, m_name(mp->lowsel));
+ if (execprogl("anno", "anno", "-append", "-nodate",
+ drft, "-comp", attach_hdr, "-text", buffer,
+ (char *)NULL) != 0) {
+ advise(NULL, "unable to add attachment header");
+ }
+ }
+
+ /* return dynamically allocated buffers */
+ mh_free0(&scanl);
+}
+
+static char *buf; /* our current working buffer */
+static char *bufend; /* end of working buffer */
+static char *last_dst; /* buf ptr at end of last call */
+static unsigned int bufsiz=0; /* current size of buf */
+
+#define BUFINCR 512 /* how much to expand buf when if fills */
+
+#define CPY(s) { cp = (s); while ((*dst++ = *cp++)) ; --dst; }
+
+/*
+** check if there's enough room in buf for str.
+** add more mem if needed
+*/
+#define CHECKMEM(str) \
+ 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);\
+ dst = buf + i;\
+ last_dst = buf + n;\
+ bufend = buf + bufsiz;\
+ }
+
+
+/*
+** fmt_scan will call this routine if the user includes the function
+** "(formataddr {component})" in a format string. "orig" is the
+** original contents of the string register. "str" is the address
+** string to be formatted and concatenated onto orig. This routine
+** returns a pointer to the concatenated address string.
+**
+** We try to not do a lot of malloc/copy/free's (which is why we
+** don't call "mh_xstrdup") but still place no upper limit on the
+** length of the result string.
+**
+** This routine is an override for the equally named one in sbr/fmt_addr.c.
+** Don't delete it!
+*/
+char *
+formataddr(char *orig, char *str)
+{
+ int len;
+ char baddr[BUFSIZ], error[BUFSIZ];
+ int isgroup;
+ char *dst;
+ char *cp;
+ char *sp;
+ struct mailname *mp = NULL;
+
+ /* if we don't have a buffer yet, get one */
+ if (bufsiz == 0) {
+ buf = mh_xcalloc(BUFINCR, sizeof(char));
+ last_dst = buf; /* XXX */
+ bufsiz = BUFINCR - 6; /* leave some slop */
+ bufend = buf + bufsiz;
+ }
+ /*
+ ** If "orig" points to our buffer we can just pick up where we
+ ** left off. Otherwise we have to copy orig into our buffer.
+ */
+ if (orig == buf)
+ dst = last_dst;
+ else if (!orig || !*orig) {
+ dst = buf;
+ *dst = '\0';
+ } else {
+ dst = last_dst; /* XXX */
+ 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",
+ cp, error);
+ badaddrs = add(baddr, badaddrs);
+ continue;
+ }
+ if (isgroup && (mp->m_gname || !mp->m_ingrp)) {
+ *dst++ = ';';
+ isgroup = 0;
+ }
+ 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);
+ isgroup++;
+ }
+ sp = adrformat(mp);
+ CHECKMEM(sp);
+ CPY(sp);
+ }
+ }
+
+ if (isgroup)
+ *dst++ = ';';
+
+ *dst = '\0';
+ last_dst = dst;
+ return (buf);