From: David Levine Date: Sat, 27 Oct 2012 17:14:01 +0000 (-0500) Subject: Added -check/-nocheck switches to sortm(1). Also removed obsolete X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=68cb35c28d5d050867d9442c177019f0c1fcbdc7 Added -check/-nocheck switches to sortm(1). Also removed obsolete note in the BUGS portion of its man page about how it sorts messages that are missing or have an invalid Date: field. It actually sorts them using their file modification times. --- diff --git a/man/sortm.man b/man/sortm.man index 4d03446..aa08f82 100644 --- a/man/sortm.man +++ b/man/sortm.man @@ -10,7 +10,7 @@ sortm \- sort messages .B sortm .RI [ +folder ] .RI [ msgs ] -.RB [ \-all | \-noall ] +.RB [ \-all " | " \-noall ] .RB [ \-datefield .IR field ] .RB [ \-textfield @@ -19,6 +19,7 @@ sortm \- sort messages .RB [ \-limit .IR days ] .RB [ \-nolimit ] +.RB [ \-check " | " \-nocheck ] .RB [ \-verbose " | " \-noverbose ] .RB [ \-version ] .RB [ \-help ] @@ -97,6 +98,20 @@ the same subject on the same date together, use: .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 @@ -122,6 +137,7 @@ sortm -textfield subject +folder .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 @@ -142,18 +158,6 @@ numbering in a folder, use .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 diff --git a/test/folder/test-sortm b/test/folder/test-sortm index 0e33154..7ef656c 100755 --- a/test/folder/test-sortm +++ b/test/folder/test-sortm @@ -7,7 +7,7 @@ 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 @@ -32,6 +32,7 @@ Usage: sortm [+folder] [msgs] [switches] -nolimit -[no]verbose -[no]all + -[no]check -version -help EOF @@ -385,5 +386,60 @@ sortm -noall -all scan >"$actual" check "$expected" "$actual" +# check -check +cat >"$expected" < $MH_TEST_DIR/Mail/inbox/14 +set +e +sortm -check >"$actual" 2>&1 +set -e +check "$expected" "$actual" + +cat >"$expected" <> + 2+ 09/29 Test10 Testing message 10<> + 3 09/29 Test5 Testing message 5<> + 4 09/29 Test6 Testing message 6<> + 5 09/29 Test7 Testing message 7<> + 6 09/29 Test8 Testing message 8<> + 7 09/29 Test9 Testing message 9<> + 8 09/29 Test1 Testing message 1<> + 9 09/29 Test2 Testing message 2<> + 10 09/29 Test3 Testing message 3<> + 11 09/29 Test4 Testing message 4<> + 12 09/29 Test11 Re: common subject<> + 13 10/31 Test13 Re: common subject<> + 14 01/00 Test9 Testing message 9<> +EOF +scan >"$actual" +check "$expected" "$actual" + +# check -nocheck +cat >"$expected" <> + 2+ 09/29 Test10 Testing message 10<> + 3 09/29 Test5 Testing message 5<> + 4 09/29 Test6 Testing message 6<> + 5 09/29 Test7 Testing message 7<> + 6 09/29 Test8 Testing message 8<> + 7 09/29 Test9 Testing message 9<> + 8 09/29 Test1 Testing message 1<> + 9 09/29 Test2 Testing message 2<> + 10 09/29 Test3 Testing message 3<> + 11 09/29 Test4 Testing message 4<> + 12 09/29 Test11 Re: common subject<> + 13 10/31 Test13 Re: common subject<> + 14 01/00 Test9 Testing message 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} diff --git a/uip/sortm.c b/uip/sortm.c index 45e2b29..024fcf5 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -32,9 +32,13 @@ static struct swit switches[] = { { "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 } }; @@ -53,6 +57,7 @@ time_t datelimit = 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 *); @@ -80,6 +85,7 @@ main (int argc, char **argv) struct msgs_array msgs = { 0, 0, NULL }; struct msgs *mp; struct smsg **dlist; + int checksw = 0; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -165,6 +171,13 @@ main (int argc, char **argv) case NALLMSGS: allmsgs = 0; continue; + + case CHECKSW: + checksw = 1; + continue; + case NCHECKSW: + checksw = 0; + continue; } } if (*cp == '+' || *cp == '@') { @@ -211,6 +224,10 @@ main (int argc, char **argv) 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". */ @@ -389,9 +406,11 @@ get_fields (char *datesw, int msg, struct smsg *smsg) 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) @@ -415,6 +434,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg) 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); }