]> diplodocus.org Git - nmh/blobdiff - uip/mhfixmsg.c
Finished replacing mh_strcasecmp() with strcasecmp(). Removed
[nmh] / uip / mhfixmsg.c
index 150600a891f2dff90a90bbf38826f5b5ddcb7fb4..8abb96dee69508280b01a8c128c5cac90c713a41 100644 (file)
@@ -13,6 +13,7 @@
 #include <h/signals.h>
 #include <signal.h>
 #include <sys/stat.h>
 #include <h/signals.h>
 #include <signal.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
 #include <fcntl.h>
 #ifdef HAVE_ICONV
 #   include <iconv.h>
 #include <fcntl.h>
 #ifdef HAVE_ICONV
 #   include <iconv.h>
@@ -352,19 +353,10 @@ main (int argc, char **argv) {
             }
         }
 
             }
         }
 
-        /*
-         * This is a hack.  If we are using an external rmmproc,
-         * then save the current folder to the context file,
-         * so the external rmmproc will remove files from the correct
-         * directory.  This should be moved to folder_delmsgs().
-         */
-        if (rmmproc) {
-            context_replace (pfolder, folder);/* update current folder  */
-            seq_setcur (mp, mp->hghsel);      /* update current message */
-            seq_save (mp);                    /* synchronize sequences  */
-            context_save ();                  /* save the context file  */
-            fflush (stdout);
-        }
+        seq_setcur (mp, mp->hghsel);      /* update current message */
+        seq_save (mp);                    /* synchronize sequences  */
+        context_replace (pfolder, folder);/* update current folder  */
+        context_save ();                  /* save the context file  */
     }
 
     if (*cts) {
     }
 
     if (*cts) {
@@ -933,28 +925,30 @@ ensure_text_plain (CT *ct, CT parent, int *message_mods) {
         } else {
             /* Slip new text/plain part into a new multipart/alternative. */
             CT tp_part = build_text_plain_part (*ct);
         } else {
             /* Slip new text/plain part into a new multipart/alternative. */
             CT tp_part = build_text_plain_part (*ct);
-            CT mp_alt = build_multipart_alt (*ct, tp_part, CT_MULTIPART,
-                                             MULTI_ALTERNATE);
-            struct multipart *mp = (struct multipart *) mp_alt->c_ctparams;
-
-            if (mp  &&  mp->mp_parts  &&  (mp->mp_parts->mp_part = tp_part)) {
-                /* Make the new multipart/alternative the parent. */
-                *ct = mp_alt;
-
-                ++*message_mods;
-                if (verbosw) {
-                    report ((*ct)->c_partno, (*ct)->c_file,
-                            "insert text/plain part");
-                }
-            } else {
-                free_content (tp_part);
 
 
-                /* Undo enough of what build_multipart_alt() did so
-                   that free_content() can be called on mp_alt. */
-                mp->mp_parts->mp_part = NULL;
-                mp->mp_parts->mp_next->mp_part = NULL;
-                free_content (mp_alt);
-                status = NOTOK;
+            if (tp_part) {
+                CT mp_alt = build_multipart_alt (*ct, tp_part, CT_MULTIPART,
+                                                 MULTI_ALTERNATE);
+                if (mp_alt) {
+                    struct multipart *mp =
+                        (struct multipart *) mp_alt->c_ctparams;
+
+                    if (mp  &&  mp->mp_parts) {
+                        mp->mp_parts->mp_part = tp_part;
+                        /* Make the new multipart/alternative the parent. */
+                        *ct = mp_alt;
+
+                        ++*message_mods;
+                        if (verbosw) {
+                            report ((*ct)->c_partno, (*ct)->c_file,
+                                    "insert text/plain part");
+                        }
+                    } else {
+                        free_content (tp_part);
+                        free_content (mp_alt);
+                        status = NOTOK;
+                    }
+                }
             }
         }
         break;
             }
         }
         break;
@@ -1784,14 +1778,39 @@ write_content (CT ct, char *input_filename, char *outfile, int modify_inplace,
 
                 if (remove_file (infile) == OK) {
                     if (rename (outfile, infile)) {
 
                 if (remove_file (infile) == OK) {
                     if (rename (outfile, infile)) {
-                        /* The -file argument processing used path() to
-                           expand filename to absolute path. */
-                        int file = ct->c_file  &&  ct->c_file[0] == '/';
-
-                        admonish (NULL, "unable to rename %s %s to %s",
-                                  file ? "file" : "message", outfile, infile);
+                        /* Rename didn't work, possibly because of an
+                           attempt to rename across filesystems.  Try
+                           brute force copy. */
+                        int old = open (outfile, O_RDONLY);
+                        int new =
+                            open (infile, O_WRONLY | O_CREAT, m_gmprot ());
+                        int i = -1;
+
+                        if (old != -1  &&  new != -1) {
+                            char buffer[BUFSIZ];
+
+                            while ((i = read (old, buffer, sizeof buffer)) >
+                                   0) {
+                                if (write (new, buffer, i) != i) {
+                                    i = -1;
+                                    break;
+                                }
+                            }
+                        }
+                        if (new != -1) close (new);
+                        if (old != -1) close (old);
                         unlink (outfile);
                         unlink (outfile);
-                        status = NOTOK;
+
+                        if (i < 0) {
+                            /* The -file argument processing used path() to
+                               expand filename to absolute path. */
+                            int file = ct->c_file  &&  ct->c_file[0] == '/';
+
+                            admonish (NULL, "unable to rename %s %s to %s",
+                                      file ? "file" : "message", outfile,
+                                      infile);
+                            status = NOTOK;
+                        }
                     }
                 } else {
                     admonish (NULL, "unable to remove input file %s, "
                     }
                 } else {
                     admonish (NULL, "unable to remove input file %s, "