Fixed -mime for forw and repl.
authormarkus schnalke <meillo@marmaro.de>
Tue, 24 Jan 2012 23:01:51 +0000 (00:01 +0100)
committermarkus schnalke <meillo@marmaro.de>
Tue, 24 Jan 2012 23:01:51 +0000 (00:01 +0100)
If the value of an attachment header starts with `+', then it is treated
as the specification of a message in MH style: ``+folder msg''

uip/forw.c
uip/replsbr.c
uip/sendsbr.c

index 8dc26b7..b0d4601 100644 (file)
@@ -85,7 +85,7 @@ static struct msgs *mp = NULL;  /* used a lot */
 */
 static void mhl_draft(int, char *, int, int, char *, char *, int);
 static void copy_draft(int, char *, char *, int, int, int);
-static void copy_mime_draft(int);
+static void add_forw_hdr(char *);
 static int build_form(char *, char *, int, int);
 
 
@@ -341,15 +341,18 @@ main(int argc, char **argv)
                ** If filter file is defined, then format the
                ** messages into the draft using mhlproc.
                */
-               if (filter)
+               if (filter) {
                        mhl_draft(out, digest, volume, issue, drft, filter,
                                        dashstuff);
-               else if (mime)
-                       copy_mime_draft(out);
-               else
+                       close(out);
+               } else if (mime) {
+                       close(out);
+                       add_forw_hdr(drft);
+               } else {
                        copy_draft(out, digest, drft, volume, issue,
                                        dashstuff);
-               close(out);
+                       close(out);
+               }
 
                if (digest) {
                        snprintf(buf, sizeof(buf), IFORMAT, digest);
@@ -380,7 +383,6 @@ main(int argc, char **argv)
 ** draft calling the mhlproc, and reading its output
 ** from a pipe.
 */
-
 static void
 mhl_draft(int out, char *digest, int volume, int issue,
        char *file, char *filter, int dashstuff)
@@ -469,7 +471,6 @@ mhl_draft(int out, char *digest, int volume, int issue,
 ** not filtered through the mhlproc.  Do dashstuffing if
 ** necessary.
 */
-
 static void
 copy_draft(int out, char *digest, char *file, int volume, int issue,
                int dashstuff)
@@ -552,25 +553,25 @@ copy_draft(int out, char *digest, char *file, int volume, int issue,
 
 
 /*
-** Create a mhbuild composition file for forwarding message.
+** Create an attachment header for the to be forward messages.
 */
-
 static void
-copy_mime_draft(int out)
+add_forw_hdr(char *draft)
 {
        int msgnum;
        char buffer[BUFSIZ];
 
-       snprintf(buffer, sizeof(buffer), "#forw [forwarded message%s] +%s",
-                       mp->numsel == 1 ? "" : "s", mp->foldpath);
-       write(out, buffer, strlen(buffer));
-       for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
-               if (is_selected(mp, msgnum)) {
-                       snprintf(buffer, sizeof(buffer), " %s",
-                                       m_name(msgnum));
-                       write(out, buffer, strlen(buffer));
+       snprintf(buffer, sizeof(buffer), "+%s", mp->foldpath);
+       for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
+               if (!is_selected(mp, msgnum)) {
+                       continue;
                }
-       write(out, "\n", 1);
+               /* TODO: improve the code */
+               strncat(buffer, " ", sizeof(buffer)-strlen(buffer)-1);
+               strncat(buffer, m_name(msgnum),
+                               sizeof(buffer)-strlen(buffer)-1);
+       }
+       annotate(draft, attach_hdr, buffer, 1, 0, -2, 1);
 }
 
 
index 2affe31..2cdd847 100644 (file)
@@ -245,19 +245,13 @@ finished:
                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");
 
                replfilter(inb, out, filter);
-       } else if (mime && mp) {
-               fprintf(out, "#forw [original message] +%s %s\n",
-                               mp->foldpath, m_name(mp->lowsel));
        }
 
        fflush(out);
@@ -265,6 +259,15 @@ finished:
                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, 1, 0, -2, 1);
+       }
+
        /* return dynamically allocated buffers */
        free(scanl);
        for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++);
index 150c175..9c335bd 100644 (file)
@@ -192,10 +192,7 @@ attach(char *draft_file_name)
        int length;  /* length of attachment header field name */
        char *p;  /* miscellaneous string pointer */
 
-       /*
-       ** Open up the draft file.
-       */
-
+       /* Open up the draft file. */
        if ((draft_file = fopen(draft_file_name, "r")) == (FILE *)0)
                adios(NULL, "can't open draft file `%s'.",
                                draft_file_name);
@@ -204,7 +201,6 @@ attach(char *draft_file_name)
        **  Allocate a buffer to hold the header components as they're read in.
        **  This buffer might need to be quite large, so we grow it as needed.
        */
-
        field = (char *)mh_xmalloc(field_size = 256);
 
        /*
@@ -214,7 +210,6 @@ attach(char *draft_file_name)
        ** because we're done.  Read to the end of the headers even if
        ** we have no attachments.
        */
-
        length = strlen(attach_hdr);
 
        has_attachment = 0;
@@ -231,7 +226,6 @@ attach(char *draft_file_name)
        ** Check if body contains at least one non-blank (= not empty)
        ** and if it contains any non-ASCII chars (= need MIME).
        */
-
        has_body = 0;
        non_ascii = 0;
 
@@ -319,10 +313,15 @@ attach(char *draft_file_name)
        while (get_line() != EOF && *field != '\0' && *field != '-') {
                if (strncasecmp(field, attach_hdr, length) == 0 &&
                                field[length] == ':') {
-                       for (p = field + length + 1; *p == ' ' || *p == '\t';
-                                       p++)
-                               ;
-                       make_mime_composition_file_entry(p);
+                       for (p = field+length+1; *p==' ' || *p=='\t'; p++) {
+                               continue;
+                       }
+                       if (*p == '+') {
+                               /* forwarded message */
+                               fprintf(composition_file, "#forw [forwarded message(s)] %s\n", p);
+                       } else {
+                               make_mime_composition_file_entry(p);
+                       }
                }
        }