Fixed -mime for forw and repl.
[mmh] / uip / forw.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);
 }