.B sortm
.RI [ +folder ]
.RI [ msgs ]
-.RB [ \-all | \-noall ]
+.RB [ \-all " | " \-noall ]
.RB [ \-datefield
.IR field ]
.RB [ \-textfield
.RB [ \-limit
.IR days ]
.RB [ \-nolimit ]
+.RB [ \-check " | " \-nocheck ]
.RB [ \-verbose " | " \-noverbose ]
.RB [ \-version ]
.RB [ \-help ]
.RS 5
sortm -textfield subject +folder
.RE
+.PP
+.B sortm
+always issues a warning for each message that is missing a
+\*(lqDate:\*(rq field, has a \*(lqDate:\*(rq field that cannot be
+parsed, or has a format error in any header field. With the
+.B \-check
+switch,
+.B sortm
+inhibits all modifications to the folder if there any such messages,
+and exits with non-zero status. With the default of
+.BR \-nocheck ,
+.B sortm
+sorts messages with a missing or invalid
+\*(lqDate:\*(rq field using their file modification times.
.SH FILES
.fc ^ ~
.nf
.RB ` \-notextfield '
.RB ` \-noverbose '
.RB ` \-nolimit '
+.RB ` \-nocheck '
.fi
.SH CONTEXT
If a folder is given, it will become the current folder. If the current
.RB \*(lq "folder\ \-pack" \*(rq
as always.
.SH BUGS
-If
-.B sortm
-encounters a message without a date\-field, or if the
-message has a date\-field that
-.B sortm
-cannot parse, then
-.B sortm
-attempts to keep the message in the same relative position. This does
-not always work. For instance, if the first message encountered lacks
-a date which can be parsed, then it will usually be placed at the end
-of the messages being sorted.
-.PP
When
.B sortm
complains about a message which it can't temporally
set -e
-if test -z "${MH_OBJ_DIR}"; then
+if test -z "$MH_OBJ_DIR"; then
srcdir=`dirname $0`/../..
MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi
-nolimit
-[no]verbose
-[no]all
+ -[no]check
-version
-help
EOF
scan >"$actual"
check "$expected" "$actual"
+# check -check
+cat >"$expected" <<EOF
+sortm: can't parse date field in message 14, continuing...
+sortm: errors found, no messages sorted
+EOF
+
+sed -e 's/Sep//' $MH_TEST_DIR/Mail/inbox/7 > $MH_TEST_DIR/Mail/inbox/14
+set +e
+sortm -check >"$actual" 2>&1
+set -e
+check "$expected" "$actual"
+
+cat >"$expected" <<EOF
+ 1 09/28 Test12 common subject<<This is message number 12 >>
+ 2+ 09/29 Test10 Testing message 10<<This is message number 10 >>
+ 3 09/29 Test5 Testing message 5<<This is message number 5 >>
+ 4 09/29 Test6 Testing message 6<<This is message number 6 >>
+ 5 09/29 Test7 Testing message 7<<This is message number 7 >>
+ 6 09/29 Test8 Testing message 8<<This is message number 8 >>
+ 7 09/29 Test9 Testing message 9<<This is message number 9 >>
+ 8 09/29 Test1 Testing message 1<<This is message number 1 >>
+ 9 09/29 Test2 Testing message 2<<This is message number 2 >>
+ 10 09/29 Test3 Testing message 3<<This is message number 3 >>
+ 11 09/29 Test4 Testing message 4<<This is message number 4 >>
+ 12 09/29 Test11 Re: common subject<<This is message number 11 >>
+ 13 10/31 Test13 Re: common subject<<This is message number 13 >>
+ 14 01/00 Test9 Testing message 9<<This is message number 9 >>
+EOF
+scan >"$actual"
+check "$expected" "$actual"
+
+# check -nocheck
+cat >"$expected" <<EOF
+ 1 09/28 Test12 common subject<<This is message number 12 >>
+ 2+ 09/29 Test10 Testing message 10<<This is message number 10 >>
+ 3 09/29 Test5 Testing message 5<<This is message number 5 >>
+ 4 09/29 Test6 Testing message 6<<This is message number 6 >>
+ 5 09/29 Test7 Testing message 7<<This is message number 7 >>
+ 6 09/29 Test8 Testing message 8<<This is message number 8 >>
+ 7 09/29 Test9 Testing message 9<<This is message number 9 >>
+ 8 09/29 Test1 Testing message 1<<This is message number 1 >>
+ 9 09/29 Test2 Testing message 2<<This is message number 2 >>
+ 10 09/29 Test3 Testing message 3<<This is message number 3 >>
+ 11 09/29 Test4 Testing message 4<<This is message number 4 >>
+ 12 09/29 Test11 Re: common subject<<This is message number 11 >>
+ 13 10/31 Test13 Re: common subject<<This is message number 13 >>
+ 14 01/00 Test9 Testing message 9<<This is message number 9 >>
+EOF
+
+sed -e 's/Sep//' $MH_TEST_DIR/Mail/inbox/7 > $MH_TEST_DIR/Mail/inbox/14
+run_test 'sortm -check -nocheck' \
+ "sortm: can't parse date field in message 14, continuing..."
+scan >"$actual"
+check "$expected" "$actual"
+
exit ${failed:-0}
{ "all", 0 },
#define NALLMSGS 9
{ "noall", 0 },
-#define VERSIONSW 10
+#define CHECKSW 10
+ { "check", 0 },
+#define NCHECKSW 11
+ { "nocheck", 0 },
+#define VERSIONSW 12
{ "version", 0 },
-#define HELPSW 11
+#define HELPSW 13
{ "help", 0 },
{ NULL, 0 }
};
int submajor = 0; /* if true, sort on subject-major */
int verbose;
int allmsgs = 1;
+int check_failed = 0;
/* This keeps compiler happy on calls to qsort */
typedef int (*qsort_comp) (const void *, const void *);
struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
struct smsg **dlist;
+ int checksw = 0;
#ifdef LOCALE
setlocale(LC_ALL, "");
case NALLMSGS:
allmsgs = 0;
continue;
+
+ case CHECKSW:
+ checksw = 1;
+ continue;
+ case NCHECKSW:
+ checksw = 0;
+ continue;
}
}
if (*cp == '+' || *cp == '@') {
if ((nmsgs = read_hdrs (mp, datesw)) <= 0)
adios (NULL, "no messages to sort");
+ if (checksw && check_failed) {
+ adios (NULL, "errors found, no messages sorted");
+ }
+
/*
* sort a list of pointers to our "messages to be sorted".
*/
case LENERR:
case FMTERR:
- if (state == LENERR || state == FMTERR)
+ if (state == LENERR || state == FMTERR) {
admonish (NULL, "format error in message %d (header #%d)",
msg, compnum);
+ check_failed = 1;
+ }
if (datecomp)
free (datecomp);
if (subjcomp)
admonish (NULL, "can't parse %s field in message %d", datesw, msg);
fstat (fileno (in), &st);
smsg->s_clock = st.st_mtime;
+ check_failed = 1;
} else {
smsg->s_clock = dmktime (tw);
}