]> diplodocus.org Git - nmh/commitdiff
Fixed refile(1) -retainsequences when the source and destination
authorDavid Levine <levinedl@acm.org>
Sun, 3 Aug 2014 02:37:34 +0000 (21:37 -0500)
committerDavid Levine <levinedl@acm.org>
Sun, 3 Aug 2014 02:37:34 +0000 (21:37 -0500)
folders are the same.

test/refile/test-refile
uip/refile.c

index 645f4f1c7872d5cc158e0bdf9a962ef9c87c0f86..71b2baabf46bac24e2e1bab31166890a4df57fcf 100755 (executable)
@@ -222,9 +222,18 @@ TOTAL = 13 messages in 3 folders.'
 mark first -seq seq1
 mark last -seq seq2
 refile first last -retainsequences +other
+#### The following command changes the current folder to +other.
 run_test 'mark +other -list -sequence seq1 -sequence seq2' \
          "seq1: 16
 seq2: 17"
 
+# test -retainsequences when refiling to same folder (+other)
+# cur is set to the original message number of the last message refiled.
+mark first -seq seq1 -zero
+mark first=2 -seq seq2 -zero
+refile first:2 -retainsequences +other
+run_test 'mark -list' "cur: 2
+seq1: 18
+seq2: 19"
 
 exit $failed
index cbe61cdb5020140de5dda96a899a12784be39cf7..cd352a40939fe0a02dd78c696f13727fe8946def 100644 (file)
@@ -47,7 +47,7 @@ struct st_fold {
 /*
  * static prototypes
  */
-static void opnfolds (struct st_fold *, int);
+static void opnfolds (struct msgs *, struct st_fold *, int);
 static void clsfolds (struct st_fold *, int);
 static void remove_files (int, char **);
 static int m_file (struct msgs *, char *, int, struct st_fold *, int, int, int);
@@ -57,7 +57,7 @@ static void copy_seqs (struct msgs *, int, struct msgs *, int);
 int
 main (int argc, char **argv)
 {
-    int        linkf = 0, preserve = 0, retainseqs = 0, filep = 0;
+    int linkf = 0, preserve = 0, retainseqs = 0, filep = 0;
     int foldp = 0, isdf = 0, unlink_msgs = 0;
     int i, msgnum;
     char *cp, *folder = NULL, buf[BUFSIZ];
@@ -173,7 +173,7 @@ main (int argc, char **argv)
     if (filep > 0) {
        if (folder || msgs.size)
            adios (NULL, "use -file or some messages, not both");
-       opnfolds (folders, foldp);
+       opnfolds (NULL, folders, foldp);
        for (i = 0; i < filep; i++)
            if (m_file (0, files[i], 0, folders, foldp, preserve, 0))
                done (1);
@@ -207,7 +207,7 @@ main (int argc, char **argv)
     seq_setprev (mp);  /* set the previous-sequence */
 
     /* create folder structures for each destination folder */
-    opnfolds (folders, foldp);
+    opnfolds (mp, folders, foldp);
 
     /* Link all the selected messages into destination folders.
      *
@@ -272,7 +272,7 @@ main (int argc, char **argv)
  */
 
 static void
-opnfolds (struct st_fold *folders, int nfolders)
+opnfolds (struct msgs *src_folder, struct st_fold *folders, int nfolders)
 {
     char nmaildir[BUFSIZ];
     register struct st_fold *fp, *ep;
@@ -282,15 +282,25 @@ opnfolds (struct st_fold *folders, int nfolders)
        chdir (m_maildir (""));
        strncpy (nmaildir, m_maildir (fp->f_name), sizeof(nmaildir));
 
-    create_folder (nmaildir, 0, done);
-
-       if (chdir (nmaildir) == NOTOK)
-           adios (nmaildir, "unable to change directory to");
-       if (!(mp = folder_read (fp->f_name, 1)))
-           adios (NULL, "unable to read folder %s", fp->f_name);
-       mp->curmsg = 0;
-
-       fp->f_mp = mp;
+       /*
+        * Null src_folder indicates that we are refiling a file to
+        * the folders, in which case we don't want to short-circuit
+        * fp->f_mp to any "source folder".
+        */
+       if (! src_folder  ||  strcmp (src_folder->foldpath, nmaildir)) {
+           create_folder (nmaildir, 0, done);
+
+           if (chdir (nmaildir) == NOTOK)
+               adios (nmaildir, "unable to change directory to");
+           if (!(mp = folder_read (fp->f_name, 1)))
+               adios (NULL, "unable to read folder %s", fp->f_name);
+           mp->curmsg = 0;
+
+           fp->f_mp = mp;
+       } else {
+           /* Source and destination folders are the same. */
+           fp->f_mp = src_folder;
+       }
 
        chdir (maildir);
     }
@@ -363,7 +373,16 @@ m_file (struct msgs *mp, char *msgfile, int oldmsgnum,
     struct st_fold *fp, *ep;
 
     for (fp = folders, ep = folders + nfolders; fp < ep; fp++) {
-       if ((msgnum = folder_addmsg (&fp->f_mp, msgfile, 1, 0, preserve, nfolders == 1 && refile, maildir)) == -1)
+       /*
+        * With same source and destination folder, don't indicate that
+        * the new message is selected so that 1) folder_delmsgs() doesn't
+        * delete it later and 2) it is not reflected in mp->hghsel, and
+        * therefore won't be assigned to be the current message.
+        */
+       if ((msgnum = folder_addmsg (&fp->f_mp, msgfile,
+                                    mp == fp->f_mp ? 0 : 1,
+                                    0, preserve, nfolders == 1 && refile,
+                                    maildir)) == -1)
            return 1;
        if (oldmsgnum) copy_seqs (mp, oldmsgnum, fp->f_mp, msgnum);
     }