]> diplodocus.org Git - nmh/commitdiff
Added -[no]retainsequences switches to refile(1).
authorDavid Levine <levinedl@acm.org>
Fri, 15 Mar 2013 01:58:31 +0000 (20:58 -0500)
committerDavid Levine <levinedl@acm.org>
Fri, 15 Mar 2013 01:58:31 +0000 (20:58 -0500)
docs/pending-release-notes
man/refile.man
test/refile/test-refile
uip/refile.c

index 94a62af35fc54ff58a07218ca2a7dd10b19ceda8..1192e7e31cad2e37ebb594a3872054d69784cb1f 100644 (file)
@@ -44,6 +44,7 @@ NEW FEATURES
 - A new program, fmttest(1) is included to help debug format files
 - mhshow/mhstore now have support for RFC-2017 (access-type=url) for
   external message bodies.
 - A new program, fmttest(1) is included to help debug format files
 - mhshow/mhstore now have support for RFC-2017 (access-type=url) for
   external message bodies.
+- Added -retainsequences switch to refile(1).
 
 ----------------------------
 OBSOLETE/DEPRECATED FEATURES
 
 ----------------------------
 OBSOLETE/DEPRECATED FEATURES
index a111046de26f724469c7c09e8ce291f1955871f5..484188650515473f0bf0fff41d5599957db5b2d3 100644 (file)
@@ -12,6 +12,7 @@ refile \- file message in other folders
 .RB [ \-draft ]
 .RB [ \-link " | " \-nolink ]
 .RB [ \-preserve " | " \-nopreserve ]
 .RB [ \-draft ]
 .RB [ \-link " | " \-nolink ]
 .RB [ \-preserve " | " \-nopreserve ]
+.RB [ \-retainsequences " | " \-noretainsequences ]
 .RB [ \-unlink " | " \-nounlink ]
 .RB [ \-src
 .IR +folder ]
 .RB [ \-unlink " | " \-nounlink ]
 .RB [ \-src
 .IR +folder ]
@@ -113,6 +114,11 @@ switch, then
 will use the next available message number
 which is above the message number you wish to preserve.
 .PP
 will use the next available message number
 which is above the message number you wish to preserve.
 .PP
+The
+.B \-retainsequences
+switch causes the memberships in sequences, except \*(lqcur\*(rq, of
+the refiled messages to be carried over to each destination folder.
+.PP
 If
 .B \-link
 is not specified (or
 If
 .B \-link
 is not specified (or
@@ -184,6 +190,7 @@ to file the <mh\-dir>/draft.
 .fi
 .SH "SEE ALSO"
 .IR folder (1),
 .fi
 .SH "SEE ALSO"
 .IR folder (1),
+.IR mh-sequence (5),
 .IR rmf (1),
 .IR rmm (1)
 .SH DEFAULTS
 .IR rmf (1),
 .IR rmm (1)
 .SH DEFAULTS
@@ -193,6 +200,7 @@ to file the <mh\-dir>/draft.
 .RB ` \-nolink '
 .RB ` \-nounlink '
 .RB ` \-nopreserve '
 .RB ` \-nolink '
 .RB ` \-nounlink '
 .RB ` \-nopreserve '
+.RB ` \-noretainsequences '
 .fi
 .SH CONTEXT
 If
 .fi
 .SH CONTEXT
 If
index 62f086df15a064dd4edbe5ab761a9213b9378e8d..da9242d2b8cfcceb5816987ce849b987adf827c1 100755 (executable)
@@ -218,5 +218,13 @@ other      has 9 messages  (1-15).
 
 TOTAL = 13 messages in 3 folders.'
 
 
 TOTAL = 13 messages in 3 folders.'
 
+# test -retainsequences
+mark first -seq seq1
+mark last -seq seq2
+refile first last -retainsequences +other
+run_test 'mark +other -list -sequence seq1 -sequence seq2' \
+         "seq1: 16
+seq2: 17"
+
 
 exit $failed
 
 exit $failed
index 54b6e5f8620aeedcd58c74e74331529acfd00357..10c9be0e9edd3e89e28249523a9f6e296ec5da22 100644 (file)
@@ -12,6 +12,7 @@
 #include <h/utils.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <h/utils.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <assert.h>
 
 #define REFILE_SWITCHES \
     X("draft", 0, DRAFTSW) \
 
 #define REFILE_SWITCHES \
     X("draft", 0, DRAFTSW) \
@@ -19,6 +20,8 @@
     X("nolink", 0, NLINKSW) \
     X("preserve", 0, PRESSW) \
     X("nopreserve", 0, NPRESSW) \
     X("nolink", 0, NLINKSW) \
     X("preserve", 0, PRESSW) \
     X("nopreserve", 0, NPRESSW) \
+    X("retainsequences", 0, RETAINSEQSSW) \
+    X("noretainsequences", 0, NRETAINSEQSSW) \
     X("unlink", 0, UNLINKSW) \
     X("nounlink", 0, NUNLINKSW) \
     X("src +folder", 0, SRCSW) \
     X("unlink", 0, UNLINKSW) \
     X("nounlink", 0, NUNLINKSW) \
     X("src +folder", 0, SRCSW) \
@@ -49,13 +52,14 @@ struct st_fold {
 static void opnfolds (struct st_fold *, int);
 static void clsfolds (struct st_fold *, int);
 static void remove_files (int, char **);
 static void opnfolds (struct st_fold *, int);
 static void clsfolds (struct st_fold *, int);
 static void remove_files (int, char **);
-static int m_file (char *, struct st_fold *, int, int, int);
+static int m_file (struct msgs *, char *, int, struct st_fold *, int, int, int);
+static void copy_seqs (struct msgs *, int, struct msgs *, int);
 
 
 int
 main (int argc, char **argv)
 {
 
 
 int
 main (int argc, char **argv)
 {
-    int        linkf = 0, preserve = 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];
     int foldp = 0, isdf = 0, unlink_msgs = 0;
     int i, msgnum;
     char *cp, *folder = NULL, buf[BUFSIZ];
@@ -83,13 +87,13 @@ main (int argc, char **argv)
     while ((cp = *argp++)) {
        if (*cp == '-') {
            switch (smatch (++cp, switches)) {
     while ((cp = *argp++)) {
        if (*cp == '-') {
            switch (smatch (++cp, switches)) {
-           case AMBIGSW: 
+           case AMBIGSW:
                ambigsw (cp, switches);
                done (1);
                ambigsw (cp, switches);
                done (1);
-           case UNKWNSW: 
+           case UNKWNSW:
                adios (NULL, "-%s unknown\n", cp);
 
                adios (NULL, "-%s unknown\n", cp);
 
-           case HELPSW: 
+           case HELPSW:
                snprintf (buf, sizeof(buf), "%s [msgs] [switches] +folder ...",
                          invo_name);
                print_help (buf, switches, 1);
                snprintf (buf, sizeof(buf), "%s [msgs] [switches] +folder ...",
                          invo_name);
                print_help (buf, switches, 1);
@@ -98,20 +102,27 @@ main (int argc, char **argv)
                print_version(invo_name);
                done (0);
 
                print_version(invo_name);
                done (0);
 
-           case LINKSW: 
+           case LINKSW:
                linkf++;
                continue;
                linkf++;
                continue;
-           case NLINKSW: 
+           case NLINKSW:
                linkf = 0;
                continue;
 
                linkf = 0;
                continue;
 
-           case PRESSW: 
+           case PRESSW:
                preserve++;
                continue;
                preserve++;
                continue;
-           case NPRESSW: 
+           case NPRESSW:
                preserve = 0;
                continue;
 
                preserve = 0;
                continue;
 
+           case RETAINSEQSSW:
+               retainseqs = 1;
+               continue;
+           case NRETAINSEQSSW:
+               retainseqs = 0;
+               continue;
+
            case UNLINKSW:
                unlink_msgs++;
                continue;
            case UNLINKSW:
                unlink_msgs++;
                continue;
@@ -119,7 +130,7 @@ main (int argc, char **argv)
                unlink_msgs = 0;
                continue;
 
                unlink_msgs = 0;
                continue;
 
-           case SRCSW: 
+           case SRCSW:
                if (folder)
                    adios (NULL, "only one source folder at a time!");
                if (!(cp = *argp++) || *cp == '-')
                if (folder)
                    adios (NULL, "only one source folder at a time!");
                if (!(cp = *argp++) || *cp == '-')
@@ -133,7 +144,7 @@ main (int argc, char **argv)
                isdf = 0;
                files[filep++] = getcpy (m_draft (NULL, NULL, 1, &isdf));
                continue;
                isdf = 0;
                files[filep++] = getcpy (m_draft (NULL, NULL, 1, &isdf));
                continue;
-           case FILESW: 
+           case FILESW:
                if (filep > NFOLDERS)
                    adios (NULL, "only %d files allowed!", NFOLDERS);
                if (!(cp = *argp++) || *cp == '-')
                if (filep > NFOLDERS)
                    adios (NULL, "only %d files allowed!", NFOLDERS);
                if (!(cp = *argp++) || *cp == '-')
@@ -141,11 +152,11 @@ main (int argc, char **argv)
                files[filep++] = path (cp, TFILE);
                continue;
 
                files[filep++] = path (cp, TFILE);
                continue;
 
-           case RPROCSW: 
+           case RPROCSW:
                if (!(rmmproc = *argp++) || *rmmproc == '-')
                    adios (NULL, "missing argument to %s", argp[-2]);
                continue;
                if (!(rmmproc = *argp++) || *rmmproc == '-')
                    adios (NULL, "missing argument to %s", argp[-2]);
                continue;
-           case NRPRCSW: 
+           case NRPRCSW:
                rmmproc = NULL;
                continue;
            }
                rmmproc = NULL;
                continue;
            }
@@ -177,7 +188,7 @@ main (int argc, char **argv)
            adios (NULL, "use -file or some messages, not both");
        opnfolds (folders, foldp);
        for (i = 0; i < filep; i++)
            adios (NULL, "use -file or some messages, not both");
        opnfolds (folders, foldp);
        for (i = 0; i < filep; i++)
-           if (m_file (files[i], folders, foldp, preserve, 0))
+           if (m_file (0, files[i], 0, folders, foldp, preserve, 0))
                done (1);
        /* If -nolink, then "remove" files */
        if (!linkf)
                done (1);
        /* If -nolink, then "remove" files */
        if (!linkf)
@@ -220,7 +231,8 @@ main (int argc, char **argv)
     for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
        if (is_selected (mp, msgnum)) {
            cp = getcpy (m_name (msgnum));
     for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
        if (is_selected (mp, msgnum)) {
            cp = getcpy (m_name (msgnum));
-           if (m_file (cp, folders, foldp, preserve, !linkf))
+           if (m_file (mp, cp, retainseqs ? msgnum : 0, folders, foldp,
+                        preserve, !linkf))
                done (1);
            free (cp);
        }
                done (1);
            free (cp);
        }
@@ -347,12 +359,13 @@ remove_files (int filep, char **files)
 
 
 /*
 
 
 /*
- * Link (or copy) the message into each of
- * the destination folders.
+ * Link (or copy) the message into each of the destination folders.
+ * If oldmsgnum is not 0, call copy_seqs().
  */
 
 static int
  */
 
 static int
-m_file (char *msgfile, struct st_fold *folders, int nfolders, int preserve, int refile)
+m_file (struct msgs *mp, char *msgfile, int oldmsgnum,
+       struct st_fold *folders, int nfolders, int preserve, int refile)
 {
     int msgnum;
     struct st_fold *fp, *ep;
 {
     int msgnum;
     struct st_fold *fp, *ep;
@@ -360,6 +373,29 @@ m_file (char *msgfile, struct st_fold *folders, int nfolders, int preserve, int
     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)
            return 1;
     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)
            return 1;
+       if (oldmsgnum) copy_seqs (mp, oldmsgnum, fp->f_mp, msgnum);
     }
     return 0;
 }
     }
     return 0;
 }
+
+
+/*
+ * Copy sequence information for a refiled message to its
+ * new folder(s).  Skip the cur sequence.
+ */
+static void
+copy_seqs (struct msgs *oldmp, int oldmsgnum, struct msgs *newmp, int newmsgnum)
+{
+    char **seq;
+    int seqnum;
+
+    for (seq = oldmp->msgattrs, seqnum = 0; *seq; ++seq, ++seqnum) {
+       if (strcmp (current, *seq)) {
+           assert (seqnum == seq_getnum (oldmp, *seq));
+           if (in_sequence (oldmp, seqnum, oldmsgnum)) {
+               seq_addmsg (newmp, *seq, newmsgnum,
+                           is_seq_private (oldmp, seqnum) ? 0 : 1, 0);
+           }
+       }
+    }
+}