From fd23674a5829d5092c99a07110086f02f0b4a238 Mon Sep 17 00:00:00 2001 From: Lyndon Nerenberg Date: Thu, 3 Jul 2014 16:40:37 -0700 Subject: [PATCH 01/16] Default to enabling (Cyrus) SASL, if available. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 846466f8..341e2771 100644 --- a/configure.ac +++ b/configure.ac @@ -38,7 +38,7 @@ AS_IF([test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"],[ AS_IF([test x"$with_cyrus_sasl" != xyes],[ AC_MSG_WARN([Arguments to --with-cyrus-sasl now ignored]) AC_MSG_WARN([Please pass the appropriate arguments to CPPFLAGS/LDFLAGS])]) - sasl_support=yes], [sasl_support=no]) + sasl_support=no], [sasl_support=yes]) dnl Do you want client-side support for encryption with TLS? AC_ARG_WITH([tls], AS_HELP_STRING([--with-tls], [Enable TLS support])) -- 2.48.1 From 7e6d0b76b1869b4fecc2412ac68f9739ee5916ea Mon Sep 17 00:00:00 2001 From: Lyndon Nerenberg Date: Thu, 3 Jul 2014 17:49:31 -0700 Subject: [PATCH 02/16] Comments should say why a chance matters ... --- configure.ac | 2 -- 1 file changed, 2 deletions(-) diff --git a/configure.ac b/configure.ac index 341e2771..923a0fea 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,6 @@ dnl dnl configure.ac -- autoconf template for nmh dnl - -dnl Move this up a bit AC_PREREQ([2.68]) AC_INIT([nmh], m4_normalize(m4_include([VERSION])), [nmh-workers@nongnu.org]) -- 2.48.1 From 4adc55188d1d3adaaed502a215ed33fe140ec9e1 Mon Sep 17 00:00:00 2001 From: Lyndon Nerenberg Date: Thu, 3 Jul 2014 19:31:44 -0700 Subject: [PATCH 03/16] Turn back the sasl test. Everything broke as a result. Not surprising. Revert "Comments should say why a chance matters ..." This reverts commit 7e6d0b76b1869b4fecc2412ac68f9739ee5916ea. --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index 923a0fea..341e2771 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,8 @@ dnl dnl configure.ac -- autoconf template for nmh dnl + +dnl Move this up a bit AC_PREREQ([2.68]) AC_INIT([nmh], m4_normalize(m4_include([VERSION])), [nmh-workers@nongnu.org]) -- 2.48.1 From e56a4e39d6306b23fde3194b11a1c09dddbcd65f Mon Sep 17 00:00:00 2001 From: Lyndon Nerenberg Date: Fri, 4 Jul 2014 13:24:37 -0700 Subject: [PATCH 04/16] Revert "Default to enabling (Cyrus) SASL, if available." This reverts commit fd23674a5829d5092c99a07110086f02f0b4a238. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 341e2771..846466f8 100644 --- a/configure.ac +++ b/configure.ac @@ -38,7 +38,7 @@ AS_IF([test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"],[ AS_IF([test x"$with_cyrus_sasl" != xyes],[ AC_MSG_WARN([Arguments to --with-cyrus-sasl now ignored]) AC_MSG_WARN([Please pass the appropriate arguments to CPPFLAGS/LDFLAGS])]) - sasl_support=no], [sasl_support=yes]) + sasl_support=yes], [sasl_support=no]) dnl Do you want client-side support for encryption with TLS? AC_ARG_WITH([tls], AS_HELP_STRING([--with-tls], [Enable TLS support])) -- 2.48.1 From a138850f50ffe0620298c0c364e1f3a0f184482c Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 6 Jul 2014 16:46:12 -0500 Subject: [PATCH 05/16] Fix to commit 03e76aecdf671ca13b5912af8206e9bdcb6c0919 to enable TLS by default. Boolean logic is our friend. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 846466f8..7fb50025 100644 --- a/configure.ac +++ b/configure.ac @@ -42,9 +42,9 @@ AS_IF([test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"],[ dnl Do you want client-side support for encryption with TLS? AC_ARG_WITH([tls], AS_HELP_STRING([--with-tls], [Enable TLS support])) -AS_IF([test x"$with_tls" != x -a x"$with_tls" != x"no"],[ +AS_IF([test x"$with_tls" = x -o x"$with_tls" != x"no"],[ AC_DEFINE([TLS_SUPPORT], [1], [Support TLS for session encryption.])dnl - tls_support=no],[tls_support=yes]) + tls_support=yes],[tls_support=no]) dnl Set the backup prefix AC_ARG_WITH([hash-backup], -- 2.48.1 From f1f778e727253c88411d312eb5d6b9db07af6ee3 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 6 Jul 2014 22:22:38 -0500 Subject: [PATCH 06/16] Here's an even simpler fix to enable TLS by default. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7fb50025..62d8cbbe 100644 --- a/configure.ac +++ b/configure.ac @@ -42,7 +42,7 @@ AS_IF([test x"$with_cyrus_sasl" != x -a x"$with_cyrus_sasl" != x"no"],[ dnl Do you want client-side support for encryption with TLS? AC_ARG_WITH([tls], AS_HELP_STRING([--with-tls], [Enable TLS support])) -AS_IF([test x"$with_tls" = x -o x"$with_tls" != x"no"],[ +AS_IF([test x"$with_tls" != x"no"],[ AC_DEFINE([TLS_SUPPORT], [1], [Support TLS for session encryption.])dnl tls_support=yes],[tls_support=no]) -- 2.48.1 From 19238e87f359e78f6c28f9d9f5ecd23a023135f6 Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 8 Jul 2014 19:58:12 -0500 Subject: [PATCH 07/16] If the user didn't specify any of the tls switches to post(8), try to help them by implying -initialtls if they're using port 465 (smtps, until IANA revoked that registration in 1998). --- man/post.man | 8 +++++++- man/send.man | 8 +++++++- uip/post.c | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/man/post.man b/man/post.man index 8ea92332..a1fb3160 100644 --- a/man/post.man +++ b/man/post.man @@ -1,4 +1,4 @@ -.TH POST %manext8% "April 14, 2013" "%nmhversion%" +.TH POST %manext8% "July 8, 2014" "%nmhversion%" .\" .\" %nmhwarning% .\" @@ -249,6 +249,12 @@ switch. The .B \-notls switch will disable all attempts to negotiate TLS. +.PP +If port 465 is specified and none of the TLS switches were enabled, +.B \-initialtls +will be implied if TLS support was compiled in. Though port 465 for +SMTPS (SMTP over SSL) was deregistered by IANA in 1998, it is still +used for that service. .SH FILES .fc ^ ~ .nf diff --git a/man/send.man b/man/send.man index c8346c34..6e22bba2 100644 --- a/man/send.man +++ b/man/send.man @@ -1,7 +1,7 @@ .\" .\" %nmhwarning% .\" -.TH SEND %manext1% "January 23, 2014" "%nmhversion%" +.TH SEND %manext1% "July 8, 2014" "%nmhversion%" .SH NAME send \- send a message .SH SYNOPSIS @@ -436,6 +436,12 @@ The .B \-notls switch will disable all attempts to negotiate TLS. .PP +If port 465 is specified and none of the TLS switches were enabled, +.B \-initialtls +will be implied if TLS support was compiled in. Though port 465 for +SMTPS (SMTP over SSL) was deregistered by IANA in 1998, it is still +used for that service. +.PP The files specified by the profile entry \*(lqAliasfile:\*(rq and any additional alias files given by the .B \-alias diff --git a/uip/post.c b/uip/post.c index ef9c8803..16121359 100644 --- a/uip/post.c +++ b/uip/post.c @@ -201,7 +201,7 @@ static int saslssf=-1; /* Our maximum SSF for SASL */ static char *saslmech=NULL; /* Force use of particular SASL mech */ static char *user=NULL; /* Authenticate as this user */ static char *port="submission"; /* Name of server port for SMTP submission */ -static int tls=0; /* Use TLS for encryption */ +static int tls=-1; /* Use TLS for encryption */ static int fromcount=0; /* Count of addresses on From: header */ static int seensender=0; /* Have we seen a Sender: header? */ @@ -602,6 +602,21 @@ main (int argc, char **argv) envelope = from; } + if (tls == -1) { +#ifdef TLS_SUPPORT + /* + * The user didn't specify any of the tls switches. Try to + * help them by implying -initialtls if they're using port 465 + * (smtps, until IANA revoked that registration in 1998). + */ + tls = ! strcmp (port, "465") || ! strcasecmp (port, "smtps") + ? 2 + : 0; +#else /* ! TLS_SUPPORT */ + tls = 0; +#endif /* ! TLS_SUPPORT */ + } + /* If we are doing a "whom" check */ if (whomsw) { /* This won't work with MTS_SENDMAIL_PIPE. */ -- 2.48.1 From 2c1d16910a0262878f7c63ad1228c71afb8b12ea Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Wed, 9 Jul 2014 12:05:49 -0400 Subject: [PATCH 08/16] Fix bug #42718; ali(1) still refers to removed options -normalize and -nonormalize. --- man/ali.man | 7 ------- 1 file changed, 7 deletions(-) diff --git a/man/ali.man b/man/ali.man index 7adcfffb..b50e4446 100644 --- a/man/ali.man +++ b/man/ali.man @@ -92,10 +92,3 @@ aliasfile .PD .SH CONTEXT None -.SH BUGS -The -.B \-user -option with -.B \-nonormalize -is not entirely accurate, as it -does not replace local nicknames for hosts with their official site names. -- 2.48.1 From 67506f8a343d03fae9f5a98e89cbd431426347cc Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 22 Jul 2014 20:46:04 -0500 Subject: [PATCH 09/16] Note in mh-folders(5) man page that spoollocking can be overridden in mts.conf as well as with configure. --- man/mh-folders.man | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/man/mh-folders.man b/man/mh-folders.man index 52cde277..0fbdddd0 100644 --- a/man/mh-folders.man +++ b/man/mh-folders.man @@ -1,4 +1,4 @@ -.TH MH-FOLDERS %manext5% "February 26, 2014" "%nmhversion%" +.TH MH-FOLDERS %manext5% "July 22, 2014" "%nmhversion%" .\" .\" %nmhwarning% .\" @@ -141,10 +141,12 @@ A second, possibly different, locking method is used by .BR inc (1) when accessing the user's mail spool file or by .B nmh -programs that open any mbox file. This locking method is selected +programs that open any mbox file. This locking method can be overridden when .B nmh -is configured and can be accessed as a string using +is configured, or in the +.B nmh +mts configuration file, and can be accessed as a string using .BR "mhparam spoollocking" . By default, kernel-level locking is used if appropriate for the platform, and it is for popular platforms. That default should also @@ -165,9 +167,10 @@ program, if provided on the platform. .IR folder (1), .IR mail (1), .IR mark (1), -.IR mh\-param (1), -.IR mh\-path (1), +.IR mhparam (1), +.IR mhpath (1), .IR mh\-profile (5), .IR mh\-sequence (5), +.IR mh\-tailor (5), .IR pick (1), .IR rcvstore (1) -- 2.48.1 From 9cf2ce257838765e082fb0e6260110d7f87e4666 Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 22 Jul 2014 21:17:54 -0500 Subject: [PATCH 10/16] Updated test-spoollocking to restore mts.conf when it's finished (successfully) so as to not upset subsequent tests. Also fixed removal of existing spoollocking option each time through. --- test/locking/test-spoollocking | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/locking/test-spoollocking b/test/locking/test-spoollocking index c795ce3d..c5a420ea 100755 --- a/test/locking/test-spoollocking +++ b/test/locking/test-spoollocking @@ -32,11 +32,11 @@ EOM # invoke "inc" for each locking algorithm # +mv -f ${MHMTSCONF} ${MHMTSCONF}.backup + for locktype in $supported_locks do - mv -f ${MHMTSCONF} ${MHMTSCONF}.backup - sed -e '/^datalocking:/d' < ${MHMTSCONF}.backup > ${MHMTSCONF} - rm -f ${MHMTSCONF}.backup + sed -e '/^spoollocking:/d' < ${MHMTSCONF}.backup > ${MHMTSCONF} echo "spoollocking: $locktype" >> ${MHMTSCONF} @@ -47,9 +47,11 @@ do $testmessage not zero'd" rmm 11 - done +#### Restore mts.conf so subsequent tests use expected spoollocking. +mv -f ${MHMTSCONF}.backup ${MHMTSCONF} + rm -f "$testmessage" exit ${failed:-0} -- 2.48.1 From ff01465b392751abf86ad95f672e460f59a2ad10 Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 22 Jul 2014 21:50:30 -0500 Subject: [PATCH 11/16] When mhparam(1) is going to output the value for spoollocking, call mts_init() first in case it was set in mts.conf. --- uip/mhparam.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/uip/mhparam.c b/uip/mhparam.c index bb2f7d2f..bd22470c 100644 --- a/uip/mhparam.c +++ b/uip/mhparam.c @@ -189,16 +189,20 @@ main(int argc, char **argv) advise(NULL, "-%scomponents ignored with -all", components ? "" : "no"); - /* print all entries in context/profile list */ + /* Print all entries in context/profile list. That does not + include entries in mts.conf, such as spoollocking. */ for (np = m_defs; np; np = np->n_next) printf("%s: %s\n", np->n_name, np->n_field); } else if (debug) { struct proc *ps; - /* Need to see if datalocking was set in profile. */ + /* In case datalocking was set in profile. */ if ((cp = context_find("datalocking"))) { datalocking = cp; } + /* In case spoollocking was set in mts.conf. */ + mts_init(invo_name); + /* Also set localmbox here */ if (! localmbox_primed) { localmbox = getlocalmbox(); @@ -220,6 +224,11 @@ main(int argc, char **argv) for (i = 0; i < compp; i++) { register char *value; + if (! strcmp ("spoollocking", comps[i])) { + /* In case spoollocking was set in mts.conf. */ + mts_init(invo_name); + } + value = context_find (comps[i]); if (!value) value = p_find (comps[i]); -- 2.48.1 From 351f6ba380cba11a1301015ea37b6e6db742c0ca Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 23 Jul 2014 21:10:47 -0500 Subject: [PATCH 12/16] Apply flex fixup to dtimep.c with flex 2.5.37 as well as 2.5.36. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 62d8cbbe..57ff08df 100644 --- a/configure.ac +++ b/configure.ac @@ -496,13 +496,13 @@ dnl ---------------- dnl CHECK FLEX FIXUP dnl ---------------- dnl Use LFLAGS make variable setting to work around bugs in flex -dnl 2.5.36 that cause signed/unsigned mismatch, +dnl 2.5.36-37 that cause signed/unsigned mismatch, dnl http://sourceforge.net/p/flex/bugs/140/ AS_IF([test "$LEX" = flex], [AS_CASE([`$LEX -V`], [flex\ 2.5.35], [LFLAGS=\ '; sed -e "s/ int n;/ size_t n;/" $@ >$@.tmp && mv -f $@.tmp $@; true'], - [flex\ 2.5.36], [LFLAGS=\ + [flex\ 2.5.3[[67]]], [LFLAGS=\ '; sed -s "s/\( \)int i;/\1yy_size_t i;/" $@ >$@.tmp && mv -f $@.tmp $@; true']) AC_SUBST([LFLAGS])]) -- 2.48.1 From cce1fc3879071125169f43ce5e82465d2fda3da0 Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 23 Jul 2014 21:20:34 -0500 Subject: [PATCH 13/16] Removed "true" from end of flex fixups. I don't know why it was there. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 57ff08df..30afee83 100644 --- a/configure.ac +++ b/configure.ac @@ -501,9 +501,9 @@ dnl http://sourceforge.net/p/flex/bugs/140/ AS_IF([test "$LEX" = flex], [AS_CASE([`$LEX -V`], [flex\ 2.5.35], [LFLAGS=\ -'; sed -e "s/ int n;/ size_t n;/" $@ >$@.tmp && mv -f $@.tmp $@; true'], +'; sed -e "s/ int n;/ size_t n;/" $@ >$@.tmp && mv -f $@.tmp $@'], [flex\ 2.5.3[[67]]], [LFLAGS=\ -'; sed -s "s/\( \)int i;/\1yy_size_t i;/" $@ >$@.tmp && mv -f $@.tmp $@; true']) +'; sed -s "s/\( \)int i;/\1yy_size_t i;/" $@ >$@.tmp && mv -f $@.tmp $@']) AC_SUBST([LFLAGS])]) dnl ---------------- -- 2.48.1 From 63aa290b4202ee837a5afeca9bdd093b5505c5e2 Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 24 Jul 2014 13:10:23 -0500 Subject: [PATCH 14/16] Fixed sed usage in flex fixup to not use -s (or -e, because even that's not needed). --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 30afee83..df70c7ab 100644 --- a/configure.ac +++ b/configure.ac @@ -501,9 +501,9 @@ dnl http://sourceforge.net/p/flex/bugs/140/ AS_IF([test "$LEX" = flex], [AS_CASE([`$LEX -V`], [flex\ 2.5.35], [LFLAGS=\ -'; sed -e "s/ int n;/ size_t n;/" $@ >$@.tmp && mv -f $@.tmp $@'], +'; sed "s/ int n;/ size_t n;/" $@ >$@.tmp && mv -f $@.tmp $@'], [flex\ 2.5.3[[67]]], [LFLAGS=\ -'; sed -s "s/\( \)int i;/\1yy_size_t i;/" $@ >$@.tmp && mv -f $@.tmp $@']) +'; sed "s/\( \)int i;/\1yy_size_t i;/" $@ >$@.tmp && mv -f $@.tmp $@']) AC_SUBST([LFLAGS])]) dnl ---------------- -- 2.48.1 From c602746d5836bdd43bd423092019947c2e4bce88 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 27 Jul 2014 08:32:13 -0500 Subject: [PATCH 15/16] Separated out list of programs that are required to build from a source code snapshot from those that are required to build from a distribution. --- MACHINES | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/MACHINES b/MACHINES index 4ff55253..fd45fe66 100644 --- a/MACHINES +++ b/MACHINES @@ -7,7 +7,7 @@ platforms: Cygwin (32- and 64-bit) FreeBSD 9 FreeBSD 10 - Linux (Fedora and Ubuntu distributions) + Linux (Fedora, Ubuntu, and CentOS distributions) Mac OS X 10.9 OpenBSD 5.4 Solaris 11 @@ -20,6 +20,13 @@ the exceptions noted below), using an ANSI C compiler, such as gcc: Solaris 7 and 8 (sparc,x86) SunOS 4.1 +On all platforms, the following programs are required to build nmh from a +snapshot of the source code repository: + autoconf + automake + flex +They are not required if building from an nmh distribution (.tar.gz) file. + Platform-specific notes follow. ------------------------------------------------------------------------------ @@ -34,17 +41,12 @@ Run-time package requirements: openssl-libs / libssl (if configured with --with-tls) Additional build-time package requirements: - flex ncurses-devel / libncurses5-devel gdbm-devel, db4-devel or libdb-devel/libdb-dev (only needed for slocal(1)) readline-devel (if you want readline support) cyrus-sasl-devel / libsasl2-dev (if configuring with --with-cyrus-sasl) openssl-devel / libssl-dev (if configuring with --with-tls) -Packages required to regenerate the configure script: - autoconf - automake - ------------------------------------------------------------------------------ Mac OS X ------------------------------------------------------------------------------ @@ -84,7 +86,6 @@ Run-time package requirements: openssl (if configured with --with-tls) Additional build-time package requirements: - flex libncurses-devel or libncursesw-devel libgdbm4-devel (only needed for slocal(1)) libiconv-devel (if you want iconv support) @@ -98,15 +99,11 @@ Additional build-time package requirements: subdirectory, or build with: make DEFAULT_INCLUDES='-I. -I/usr/include/ncurses' -Packages required to regenerate the configure script: - autoconf - automake - When running the nmh test suite ("make check"), it helps to have /usr/bin/ ahead of any Windows directories on your PATH. -Note that the -link switch to refile cannot be used on FAT32 and similar -filesystems. +Note that the -link switch to refile cannot be used on FAT32 and other +filesystems that do not support hard links. ------------------------------------------------------------------------------ HPUX -- 2.48.1 From 40a17f8f191deee9f27fd3dd394eda9a641e6f1c Mon Sep 17 00:00:00 2001 From: David Levine Date: Sat, 2 Aug 2014 21:37:34 -0500 Subject: [PATCH 16/16] Fixed refile(1) -retainsequences when the source and destination folders are the same. --- test/refile/test-refile | 9 ++++++++ uip/refile.c | 49 ++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/test/refile/test-refile b/test/refile/test-refile index 645f4f1c..71b2baab 100755 --- a/test/refile/test-refile +++ b/test/refile/test-refile @@ -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 diff --git a/uip/refile.c b/uip/refile.c index cbe61cdb..cd352a40 100644 --- a/uip/refile.c +++ b/uip/refile.c @@ -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); } -- 2.48.1