Commit 34361061 34361061098003122b0ce911a87123f012e79f88 by Sergey Poznyakoff

sortm: update current message number; add testsuite.

* mh/sortm.c (current_num): New variable.
(sort): Keep track of the current message UID.  Store it back to
mailbox if in reorder mode.
(main): Save initial current message UID.  Save global and mailbox
status before exiting.
* mh/mh.h (mh_open_folder): Change last argument name.
* mh_open_folder (mh_open_folder): Change meaning of the 2nd argument:
it contains usual stream flags now.  All uses changed.

* mh/tests/sortm.at: New file.
* mh/tests/testsuite.at: Include sortm.at
* mh/tests/Makefile.am (TESTSUITE_AT): Add sortm.at.
1 parent f5374bc2
...@@ -116,7 +116,7 @@ main (int argc, char **argv) ...@@ -116,7 +116,7 @@ main (int argc, char **argv)
116 mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, 116 mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
117 opt_handler, NULL, &index); 117 opt_handler, NULL, &index);
118 118
119 mbox = mh_open_folder (mh_current_folder (), 0); 119 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
120 120
121 if (!component) 121 if (!component)
122 { 122 {
......
...@@ -721,7 +721,7 @@ main (int argc, char **argv) ...@@ -721,7 +721,7 @@ main (int argc, char **argv)
721 argv += index; 721 argv += index;
722 722
723 VERBOSE ((_("Opening folder `%s'"), mh_current_folder ())); 723 VERBOSE ((_("Opening folder `%s'"), mh_current_folder ()));
724 mbox = mh_open_folder (mh_current_folder (), 0); 724 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
725 mh_msgset_parse (mbox, &msgset, argc, argv, "cur"); 725 mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
726 726
727 if (inplace) 727 if (inplace)
...@@ -729,7 +729,7 @@ main (int argc, char **argv) ...@@ -729,7 +729,7 @@ main (int argc, char **argv)
729 size_t i, count; 729 size_t i, count;
730 730
731 VERBOSE ((_("Opening temporary folder `%s'"), tempfolder)); 731 VERBOSE ((_("Opening temporary folder `%s'"), tempfolder));
732 tmpbox = mh_open_folder (tempfolder, 1); 732 tmpbox = mh_open_folder (tempfolder, MU_STREAM_RDWR|MU_STREAM_CREAT);
733 VERBOSE ((_("Cleaning up temporary folder"))); 733 VERBOSE ((_("Cleaning up temporary folder")));
734 mu_mailbox_messages_count (tmpbox, &count); 734 mu_mailbox_messages_count (tmpbox, &count);
735 for (i = 1; i <= count; i++) 735 for (i = 1; i <= count; i++)
......
...@@ -249,7 +249,8 @@ main (int argc, char **argv) ...@@ -249,7 +249,8 @@ main (int argc, char **argv)
249 mh_msgset_t msgset; 249 mh_msgset_t msgset;
250 mu_mailbox_t mbox; 250 mu_mailbox_t mbox;
251 251
252 mbox = mh_open_folder (draftfolder, 1); 252 mbox = mh_open_folder (draftfolder,
253 MU_STREAM_RDWR|MU_STREAM_CREAT);
253 mh_msgset_parse (mbox, &msgset, 254 mh_msgset_parse (mbox, &msgset,
254 argc - index, argv + index, 255 argc - index, argv + index,
255 use_draft ? "cur" : "new"); 256 use_draft ? "cur" : "new");
...@@ -275,7 +276,7 @@ main (int argc, char **argv) ...@@ -275,7 +276,7 @@ main (int argc, char **argv)
275 mh_msgset_t msgset; 276 mh_msgset_t msgset;
276 mu_mailbox_t mbox; 277 mu_mailbox_t mbox;
277 278
278 mbox = mh_open_folder (mh_current_folder (), 0); 279 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
279 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); 280 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
280 if (msgset.count != 1) 281 if (msgset.count != 1)
281 { 282 {
......
...@@ -839,7 +839,7 @@ int ...@@ -839,7 +839,7 @@ int
839 action_pack () 839 action_pack ()
840 { 840 {
841 const char *folder_dir = mh_expand_name (NULL, mh_current_folder (), 0); 841 const char *folder_dir = mh_expand_name (NULL, mh_current_folder (), 0);
842 mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), 0); 842 mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
843 struct pack_tab *pack_tab; 843 struct pack_tab *pack_tab;
844 size_t i, count, start; 844 size_t i, count, start;
845 int status; 845 int status;
...@@ -917,7 +917,7 @@ action_pack () ...@@ -917,7 +917,7 @@ action_pack ()
917 /* Fix-up sequences */ 917 /* Fix-up sequences */
918 if (!dry_run) 918 if (!dry_run)
919 { 919 {
920 mbox = mh_open_folder (mh_current_folder (), 0); 920 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
921 fd.mbox = mbox; 921 fd.mbox = mbox;
922 fd.folder_dir = folder_dir; 922 fd.folder_dir = folder_dir;
923 fd.pack_tab = pack_tab; 923 fd.pack_tab = pack_tab;
...@@ -967,7 +967,7 @@ main (int argc, char **argv) ...@@ -967,7 +967,7 @@ main (int argc, char **argv)
967 967
968 if (argc - index == 1) 968 if (argc - index == 1)
969 { 969 {
970 mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), 0); 970 mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
971 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); 971 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
972 mh_msgset_current (mbox, &msgset, 0); 972 mh_msgset_current (mbox, &msgset, 0);
973 mh_global_save_state (); 973 mh_global_save_state ();
......
...@@ -503,7 +503,7 @@ main (int argc, char **argv) ...@@ -503,7 +503,7 @@ main (int argc, char **argv)
503 } 503 }
504 else 504 else
505 { 505 {
506 mbox = mh_open_folder (mh_current_folder (), 0); 506 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
507 mh_msgset_parse (mbox, &msgset, argc, argv, "cur"); 507 mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
508 } 508 }
509 509
......
...@@ -219,7 +219,7 @@ main (int argc, char **argv) ...@@ -219,7 +219,7 @@ main (int argc, char **argv)
219 exit (1); 219 exit (1);
220 } 220 }
221 221
222 output = mh_open_folder (append_folder, 1); 222 output = mh_open_folder (append_folder, MU_STREAM_RDWR|MU_STREAM_CREAT);
223 if ((rc = mu_mailbox_messages_count (output, &lastmsg)) != 0) 223 if ((rc = mu_mailbox_messages_count (output, &lastmsg)) != 0)
224 { 224 {
225 mu_error (_("cannot read output mailbox: %s"), 225 mu_error (_("cannot read output mailbox: %s"),
......
...@@ -201,7 +201,7 @@ main (int argc, char **argv) ...@@ -201,7 +201,7 @@ main (int argc, char **argv)
201 mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, 201 mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
202 opt_handler, NULL, &index); 202 opt_handler, NULL, &index);
203 203
204 mbox = mh_open_folder (mh_current_folder (), 0); 204 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
205 mu_mailbox_get_url (mbox, &url); 205 mu_mailbox_get_url (mbox, &url);
206 mbox_dir = mu_url_to_string (url); 206 mbox_dir = mu_url_to_string (url);
207 if (memcmp (mbox_dir, "mh:", 3) == 0) 207 if (memcmp (mbox_dir, "mh:", 3) == 0)
......
...@@ -302,7 +302,7 @@ void mh_audit_close (FILE *fp); ...@@ -302,7 +302,7 @@ void mh_audit_close (FILE *fp);
302 302
303 int mh_message_number (mu_message_t msg, size_t *pnum); 303 int mh_message_number (mu_message_t msg, size_t *pnum);
304 304
305 mu_mailbox_t mh_open_folder (const char *folder, int create); 305 mu_mailbox_t mh_open_folder (const char *folder, int flags);
306 306
307 void mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset, 307 void mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset,
308 int argc, char **argv, char *def); 308 int argc, char **argv, char *def);
......
...@@ -443,14 +443,13 @@ mh_message_number (mu_message_t msg, size_t *pnum) ...@@ -443,14 +443,13 @@ mh_message_number (mu_message_t msg, size_t *pnum)
443 } 443 }
444 444
445 mu_mailbox_t 445 mu_mailbox_t
446 mh_open_folder (const char *folder, int create) 446 mh_open_folder (const char *folder, int flags)
447 { 447 {
448 mu_mailbox_t mbox = NULL; 448 mu_mailbox_t mbox = NULL;
449 char *name; 449 char *name;
450 int flags = MU_STREAM_RDWR;
451 450
452 name = mh_expand_name (NULL, folder, 1); 451 name = mh_expand_name (NULL, folder, 1);
453 if (create && mh_check_folder (name, 1)) 452 if ((flags & MU_STREAM_CREAT) && mh_check_folder (name, 1))
454 exit (0); 453 exit (0);
455 454
456 if (mu_mailbox_create_default (&mbox, name)) 455 if (mu_mailbox_create_default (&mbox, name))
...@@ -460,9 +459,6 @@ mh_open_folder (const char *folder, int create) ...@@ -460,9 +459,6 @@ mh_open_folder (const char *folder, int create)
460 exit (1); 459 exit (1);
461 } 460 }
462 461
463 if (create)
464 flags |= MU_STREAM_CREAT;
465
466 if (mu_mailbox_open (mbox, flags)) 462 if (mu_mailbox_open (mbox, flags))
467 { 463 {
468 mu_error (_("cannot open mailbox %s: %s"), name, strerror (errno)); 464 mu_error (_("cannot open mailbox %s: %s"), name, strerror (errno));
...@@ -1045,7 +1041,7 @@ mh_draft_message (const char *name, const char *msgspec, char **pname) ...@@ -1045,7 +1041,7 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
1045 mu_mailbox_t mbox; 1041 mu_mailbox_t mbox;
1046 const char *path; 1042 const char *path;
1047 1043
1048 mbox = mh_open_folder (name, 0); 1044 mbox = mh_open_folder (name, MU_STREAM_RDWR);
1049 if (!mbox) 1045 if (!mbox)
1050 return 1; 1046 return 1;
1051 1047
......
...@@ -1684,7 +1684,8 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding, ...@@ -1684,7 +1684,8 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
1684 case store_to_folder_msg: 1684 case store_to_folder_msg:
1685 case store_to_folder: 1685 case store_to_folder:
1686 { 1686 {
1687 mu_mailbox_t mbox = mh_open_folder (name, 1); 1687 mu_mailbox_t mbox = mh_open_folder (name,
1688 MU_STREAM_RDWR|MU_STREAM_CREAT);
1688 size_t uid; 1689 size_t uid;
1689 1690
1690 mu_mailbox_uidnext (mbox, &uid); 1691 mu_mailbox_uidnext (mbox, &uid);
...@@ -2284,12 +2285,12 @@ edit_forw (char *cmd, struct compose_env *env, mu_message_t *pmsg, int level) ...@@ -2284,12 +2285,12 @@ edit_forw (char *cmd, struct compose_env *env, mu_message_t *pmsg, int level)
2284 2285
2285 if (ws.ws_wordv[0][0] == '+') 2286 if (ws.ws_wordv[0][0] == '+')
2286 { 2287 {
2287 mbox = mh_open_folder (ws.ws_wordv[0], 0); 2288 mbox = mh_open_folder (ws.ws_wordv[0], MU_STREAM_RDWR);
2288 i = 1; 2289 i = 1;
2289 } 2290 }
2290 else 2291 else
2291 { 2292 {
2292 mbox = mh_open_folder (mh_current_folder (), 0); 2293 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
2293 i = 0; 2294 i = 0;
2294 } 2295 }
2295 2296
...@@ -2930,7 +2931,7 @@ main (int argc, char **argv) ...@@ -2930,7 +2931,7 @@ main (int argc, char **argv)
2930 } 2931 }
2931 else 2932 else
2932 { 2933 {
2933 mbox = mh_open_folder (mh_current_folder (), 0); 2934 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
2934 mh_msgset_parse (mbox, &msgset, argc, argv, "cur"); 2935 mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
2935 } 2936 }
2936 2937
......
...@@ -87,7 +87,7 @@ main (int argc, char **argv) ...@@ -87,7 +87,7 @@ main (int argc, char **argv)
87 exit (0); 87 exit (0);
88 } 88 }
89 89
90 mbox = mh_open_folder (current_folder, 0); 90 mbox = mh_open_folder (current_folder, MU_STREAM_RDWR);
91 91
92 mu_mailbox_messages_count (mbox, &total); 92 mu_mailbox_messages_count (mbox, &total);
93 mu_mailbox_get_url (mbox, &url); 93 mu_mailbox_get_url (mbox, &url);
......
...@@ -80,7 +80,7 @@ main (int argc, char **argv) ...@@ -80,7 +80,7 @@ main (int argc, char **argv)
80 80
81 argc -= index; 81 argc -= index;
82 argv += index; 82 argv += index;
83 mbox = mh_open_folder (mh_current_folder (), 0); 83 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
84 84
85 mh_msgset_parse (mbox, &msgset, argc, argv, "cur"); 85 mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
86 if (uid_option) 86 if (uid_option)
......
...@@ -390,7 +390,7 @@ main (int argc, char **argv) ...@@ -390,7 +390,7 @@ main (int argc, char **argv)
390 if (pick_parse (lexlist)) 390 if (pick_parse (lexlist))
391 return 1; 391 return 1;
392 392
393 mbox = mh_open_folder (mh_current_folder (), 0); 393 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
394 394
395 argc -= index; 395 argc -= index;
396 argv += index; 396 argv += index;
......
...@@ -104,7 +104,7 @@ open_folders () ...@@ -104,7 +104,7 @@ open_folders ()
104 mu_mailbox_t mbox; 104 mu_mailbox_t mbox;
105 105
106 mu_iterator_current (itr, (void **)&name); 106 mu_iterator_current (itr, (void **)&name);
107 mbox = mh_open_folder (name, 1); 107 mbox = mh_open_folder (name, MU_STREAM_RDWR|MU_STREAM_CREAT);
108 mu_list_append (folder_mbox_list, mbox); 108 mu_list_append (folder_mbox_list, mbox);
109 free (name); 109 free (name);
110 } 110 }
...@@ -261,7 +261,7 @@ main (int argc, char **argv) ...@@ -261,7 +261,7 @@ main (int argc, char **argv)
261 } 261 }
262 else 262 else
263 { 263 {
264 mbox = mh_open_folder (mh_current_folder (), 0); 264 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
265 mh_msgset_parse (mbox, &msgset, argc, argv, "cur"); 265 mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
266 266
267 status = mh_iterate (mbox, &msgset, refile_iterator, NULL); 267 status = mh_iterate (mbox, &msgset, refile_iterator, NULL);
......
...@@ -407,7 +407,7 @@ main (int argc, char **argv) ...@@ -407,7 +407,7 @@ main (int argc, char **argv)
407 exit (1); 407 exit (1);
408 } 408 }
409 409
410 mbox = mh_open_folder (mh_current_folder (), 0); 410 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
411 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); 411 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
412 if (msgset.count != 1) 412 if (msgset.count != 1)
413 { 413 {
......
...@@ -94,7 +94,7 @@ opt_handler (int key, char *arg, struct argp_state *state) ...@@ -94,7 +94,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
94 static char * 94 static char *
95 current_folder_path () 95 current_folder_path ()
96 { 96 {
97 mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), 0); 97 mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
98 mu_url_t url; 98 mu_url_t url;
99 char *p; 99 char *p;
100 mu_mailbox_get_url (mbox, &url); 100 mu_mailbox_get_url (mbox, &url);
......
...@@ -73,7 +73,7 @@ main (int argc, char **argv) ...@@ -73,7 +73,7 @@ main (int argc, char **argv)
73 mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, 73 mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
74 opt_handler, NULL, &index); 74 opt_handler, NULL, &index);
75 75
76 mbox = mh_open_folder (mh_current_folder (), 0); 76 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
77 77
78 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); 78 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
79 79
......
...@@ -179,7 +179,7 @@ main (int argc, char **argv) ...@@ -179,7 +179,7 @@ main (int argc, char **argv)
179 exit (1); 179 exit (1);
180 } 180 }
181 181
182 mbox = mh_open_folder (mh_current_folder (), 0); 182 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
183 183
184 argc -= index; 184 argc -= index;
185 argv += index; 185 argv += index;
......
...@@ -765,7 +765,7 @@ main (int argc, char **argv) ...@@ -765,7 +765,7 @@ main (int argc, char **argv)
765 const char *path; 765 const char *path;
766 size_t i; 766 size_t i;
767 767
768 mbox = mh_open_folder (draftfolder, 1); 768 mbox = mh_open_folder (draftfolder, MU_STREAM_RDWR|MU_STREAM_CREAT);
769 mh_msgset_parse (mbox, &msgset, argc, argv, draftmessage); 769 mh_msgset_parse (mbox, &msgset, argc, argv, draftmessage);
770 mu_mailbox_get_url (mbox, &url); 770 mu_mailbox_get_url (mbox, &url);
771 mu_url_sget_path (url, &path); 771 mu_url_sget_path (url, &path);
......
...@@ -93,6 +93,7 @@ static int verbose; ...@@ -93,6 +93,7 @@ static int verbose;
93 static mu_mailbox_t mbox; 93 static mu_mailbox_t mbox;
94 static const char *mbox_path; 94 static const char *mbox_path;
95 static mh_msgset_t msgset; 95 static mh_msgset_t msgset;
96 static size_t current_num;
96 97
97 #define ACTION_REORDER 0 98 #define ACTION_REORDER 0
98 #define ACTION_DRY_RUN 1 99 #define ACTION_DRY_RUN 1
...@@ -193,7 +194,8 @@ opt_handler (int key, char *arg, struct argp_state *state) ...@@ -193,7 +194,8 @@ opt_handler (int key, char *arg, struct argp_state *state)
193 194
194 195
195 /* *********************** Comparison functions **************************** */ 196 /* *********************** Comparison functions **************************** */
196 struct comp_op { 197 struct comp_op
198 {
197 char *field; 199 char *field;
198 compfun comp; 200 compfun comp;
199 }; 201 };
...@@ -219,7 +221,8 @@ addop (char *field, compfun comp) ...@@ -219,7 +221,8 @@ addop (char *field, compfun comp)
219 mu_list_append (oplist, op); 221 mu_list_append (oplist, op);
220 } 222 }
221 223
222 struct rem_data { 224 struct rem_data
225 {
223 struct comp_op *op; 226 struct comp_op *op;
224 compfun comp; 227 compfun comp;
225 }; 228 };
...@@ -244,7 +247,8 @@ remop (compfun comp) ...@@ -244,7 +247,8 @@ remop (compfun comp)
244 mu_list_remove (oplist, d.op); 247 mu_list_remove (oplist, d.op);
245 } 248 }
246 249
247 struct comp_data { 250 struct comp_data
251 {
248 int r; 252 int r;
249 mu_message_t m[2]; 253 mu_message_t m[2];
250 }; 254 };
...@@ -491,7 +495,7 @@ sort () ...@@ -491,7 +495,7 @@ sort ()
491 switch (algorithm) 495 switch (algorithm)
492 { 496 {
493 case ARG_QUICKSORT: 497 case ARG_QUICKSORT:
494 qsort(msgset.list, msgset.count, sizeof(msgset.list[0]), 498 qsort(msgset.list, msgset.count, sizeof (msgset.list[0]),
495 comp); 499 comp);
496 break; 500 break;
497 501
...@@ -528,14 +532,36 @@ sort () ...@@ -528,14 +532,36 @@ sort ()
528 mh_message_number (msg, &new_num); 532 mh_message_number (msg, &new_num);
529 transpose (i, oldlist[i]); 533 transpose (i, oldlist[i]);
530 if (verbose) 534 if (verbose)
531 fprintf (stderr, "{%s, %s}\n", 535 {
536 fprintf (stderr, "{%s, %s}",
532 mu_umaxtostr (0, old_num), 537 mu_umaxtostr (0, old_num),
533 mu_umaxtostr (1, new_num)); 538 mu_umaxtostr (1, new_num));
539 }
540 if (old_num == current_num)
541 {
542 if (verbose)
543 fputc ('*', stderr);
544 current_num = new_num;
545 }
546 else if (new_num == current_num)
547 {
548 if (verbose)
549 fputc ('*', stderr);
550 current_num = old_num;
551 }
552 if (verbose)
553 fputc ('\n', stderr);
534 if (action == ACTION_REORDER) 554 if (action == ACTION_REORDER)
535 swap_message (old_num, new_num); 555 swap_message (old_num, new_num);
536 } 556 }
537 } 557 }
538 } 558 }
559 if (action == ACTION_REORDER)
560 {
561 mu_mailbox_close (mbox);
562 mu_mailbox_open (mbox, MU_STREAM_RDWR);
563 mh_mailbox_set_cur (mbox, current_num);
564 }
539 } 565 }
540 566
541 567
...@@ -560,7 +586,7 @@ main (int argc, char **argv) ...@@ -560,7 +586,7 @@ main (int argc, char **argv)
560 exit (1); 586 exit (1);
561 } 587 }
562 588
563 mbox = mh_open_folder (mh_current_folder (), 0); 589 mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
564 mu_mailbox_get_url (mbox, &url); 590 mu_mailbox_get_url (mbox, &url);
565 mbox_path = mu_url_to_string (url); 591 mbox_path = mu_url_to_string (url);
566 if (memcmp (mbox_path, "mh:", 3) == 0) 592 if (memcmp (mbox_path, "mh:", 3) == 0)
...@@ -569,7 +595,12 @@ main (int argc, char **argv) ...@@ -569,7 +595,12 @@ main (int argc, char **argv)
569 argc -= index; 595 argc -= index;
570 argv += index; 596 argv += index;
571 597
598 mh_mailbox_get_cur (mbox, &current_num);
599
572 mh_msgset_parse (mbox, &msgset, argc, argv, "all"); 600 mh_msgset_parse (mbox, &msgset, argc, argv, "all");
573 sort (mbox, msgset); 601 sort ();
602 mh_global_save_state ();
603 mu_mailbox_destroy (&mbox);
604
574 return 0; 605 return 0;
575 } 606 }
......
...@@ -56,6 +56,7 @@ TESTSUITE_AT = \ ...@@ -56,6 +56,7 @@ TESTSUITE_AT = \
56 pick.at\ 56 pick.at\
57 scan.at\ 57 scan.at\
58 send.at\ 58 send.at\
59 sortm.at\
59 refile.at\ 60 refile.at\
60 repl.at\ 61 repl.at\
61 rmf.at\ 62 rmf.at\
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2010 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 m4_pushdef([MH_KEYWORDS],[sortm])
18 m4_pushdef([scancmd],[scan -format '%4(msg)%<(cur)+%| %> %02(mon{date})/%02(mday{date}) %24(friendly{from}) %{subject}'])
19
20 MH_CHECK([sortm -textfield],[sortm00 sortm-textfield],[
21 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
22 echo "cur: 11" > Mail/teaparty/.mh_sequences
23 sortm -text From -nodate +teaparty || exit $?
24 scancmd
25 ],
26 [0],
27 [ 1 07/29 Alice Re: Invitation
28 2 07/29 Alice Re: Invitation
29 3 07/29 Alice Re: Invitation
30 4 07/29 Alice Re: Personal remark
31 5 07/29 Alice Re: Riddle
32 6 07/29 Alice Re: Riddle
33 7 07/29 Alice Re: Be specific
34 8 07/29 Alice Re: Watch
35 9 07/29 Alice Funny watch (was Re: Watch)
36 10 07/29 Alice Re: Funny watch
37 11 07/29 Alice Re: Funny watch
38 12 07/29 Alice Re: Riddle
39 13 07/29 Alice Re: Riddle
40 14 07/29 Alice Re: Discussing Time
41 15 07/29 Alice Re: Discussing Time
42 16 07/29 Alice Re: Discussing Time
43 17 07/29 Alice Re: Discussing Time
44 18 07/29 Alice Re: Discussing Time
45 19 07/29 Alice Re: Discussing Time
46 20 07/29 Alice A guess (was Re: Discussing Time)
47 21 07/29 Alice Re: A guess
48 22 07/29 Alice Re: A guess
49 23 07/29 Alice Re: Request for a story
50 24 07/29 Alice Re: Request for a story
51 25 07/29 Alice Re: Story
52 26 07/29 Alice Re: Story
53 27 07/29 Alice Re: Story
54 28 07/29 Alice Re: Remark
55 29 07/29 Alice Personal remark
56 30 07/29 Alice Re: Story
57 31 07/29 Alice Re: Story
58 32 07/29 Alice Re: Story
59 33 07/29 Alice Re: Story
60 34 07/29 Alice Re: Story
61 35 07/29 Alice Re: Story
62 36 07/29 Alice Re: Story
63 37 07/29 Alice Re: Story
64 38 07/29 Alice Thoughts
65 39 07/29 Dormouse Re: Be specific
66 40 07/29 Dormouse Re: Remark
67 41 07/29 Dormouse Re: Discussing Time
68 42 07/29 Dormouse Re: Request for a story
69 43 07/29 Dormouse Story (was Re: Request for a story)
70 44 07/29 Dormouse Re: Story
71 45 07/29 Dormouse Re: Story
72 46 07/29 Dormouse Re: Story
73 47 07/29 Dormouse Re: Story
74 48 07/29 Dormouse Re: Story
75 49 07/29 Dormouse Re: Story
76 50 07/29 Dormouse Re: Story
77 51 07/29 Dormouse Re: Story
78 52 07/29 Dormouse Re: Story
79 53 07/29 Dormouse Re: Story
80 54 07/29 Hatter Re: Be specific
81 55 07/29 Hatter Re: Be specific
82 56 07/29 Hatter Watch
83 57 07/29 Hatter Re: Watch
84 58 07/29 Hatter Re: Watch
85 59 07/29 Hatter Re: Funny watch
86 60 07/29 Hatter Re: Funny watch
87 61 07/29 Hatter Remark
88 62 07/29 Hatter Re: Riddle
89 63 07/29 Hatter Re: Riddle
90 64 07/29 Hatter Discussing Time
91 65 07/29 Hatter Re: Discussing Time
92 66 07/29 Hatter Re: Discussing Time
93 67 07/29 Hatter Re: Discussing Time
94 68 07/29 Hatter Re: Discussing Time
95 69 07/29 Hatter Re: Discussing Time
96 70 07/29 Hatter Re: Discussing Time
97 71 07/29 Hatter Re: Discussing Time
98 72 07/29 Hatter Re: A guess
99 73 07/29 Hatter Re: A guess
100 74 07/29 Hatter Re: Request for a story
101 75 07/29 Hatter Re: Request for a story
102 76 07/29 Hatter Re: Remark
103 77 07/29 Hatter Re: Personal remark
104 78 07/29 Hatter Let's move
105 79 07/29 Hatter Re: Story
106 80 07/29 Hatter Rude remark
107 81 07/29 March Hare Invitation
108 82 07/29 March Hare Re: Invitation
109 83 07/29 March Hare Re: Invitation
110 84 07/29 March Hare Personal remark
111 85 07/29 March Hare Riddle (was Re: Personal remark)
112 86+ 07/29 March Hare Re: Riddle
113 87 07/29 March Hare Be specific (was Re: Riddle)
114 88 07/29 March Hare Re: Be specific
115 89 07/29 March Hare Re: Watch
116 90 07/29 March Hare Re: Watch
117 91 07/29 March Hare Re: Riddle
118 92 07/29 March Hare Thought apart Re: Discussing Time
119 93 07/29 March Hare Request for a story (was Re: A guess)
120 94 07/29 March Hare Re: Request for a story
121 95 07/29 March Hare Remark
122 ])
123
124 MH_CHECK([sortm -datefield],[sortm01 sortm-datefield],[
125 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
126 echo "cur: 11" > Mail/teaparty/.mh_sequences
127 sortm -text From -nodate +teaparty || exit $?
128 scancmd
129 sortm
130 scancmd
131 ],
132 [0],
133 [ 1 07/29 Alice Re: Invitation
134 2 07/29 Alice Re: Invitation
135 3 07/29 Alice Re: Invitation
136 4 07/29 Alice Re: Personal remark
137 5 07/29 Alice Re: Riddle
138 6 07/29 Alice Re: Riddle
139 7 07/29 Alice Re: Be specific
140 8 07/29 Alice Re: Watch
141 9 07/29 Alice Funny watch (was Re: Watch)
142 10 07/29 Alice Re: Funny watch
143 11 07/29 Alice Re: Funny watch
144 12 07/29 Alice Re: Riddle
145 13 07/29 Alice Re: Riddle
146 14 07/29 Alice Re: Discussing Time
147 15 07/29 Alice Re: Discussing Time
148 16 07/29 Alice Re: Discussing Time
149 17 07/29 Alice Re: Discussing Time
150 18 07/29 Alice Re: Discussing Time
151 19 07/29 Alice Re: Discussing Time
152 20 07/29 Alice A guess (was Re: Discussing Time)
153 21 07/29 Alice Re: A guess
154 22 07/29 Alice Re: A guess
155 23 07/29 Alice Re: Request for a story
156 24 07/29 Alice Re: Request for a story
157 25 07/29 Alice Re: Story
158 26 07/29 Alice Re: Story
159 27 07/29 Alice Re: Story
160 28 07/29 Alice Re: Remark
161 29 07/29 Alice Personal remark
162 30 07/29 Alice Re: Story
163 31 07/29 Alice Re: Story
164 32 07/29 Alice Re: Story
165 33 07/29 Alice Re: Story
166 34 07/29 Alice Re: Story
167 35 07/29 Alice Re: Story
168 36 07/29 Alice Re: Story
169 37 07/29 Alice Re: Story
170 38 07/29 Alice Thoughts
171 39 07/29 Dormouse Re: Be specific
172 40 07/29 Dormouse Re: Remark
173 41 07/29 Dormouse Re: Discussing Time
174 42 07/29 Dormouse Re: Request for a story
175 43 07/29 Dormouse Story (was Re: Request for a story)
176 44 07/29 Dormouse Re: Story
177 45 07/29 Dormouse Re: Story
178 46 07/29 Dormouse Re: Story
179 47 07/29 Dormouse Re: Story
180 48 07/29 Dormouse Re: Story
181 49 07/29 Dormouse Re: Story
182 50 07/29 Dormouse Re: Story
183 51 07/29 Dormouse Re: Story
184 52 07/29 Dormouse Re: Story
185 53 07/29 Dormouse Re: Story
186 54 07/29 Hatter Re: Be specific
187 55 07/29 Hatter Re: Be specific
188 56 07/29 Hatter Watch
189 57 07/29 Hatter Re: Watch
190 58 07/29 Hatter Re: Watch
191 59 07/29 Hatter Re: Funny watch
192 60 07/29 Hatter Re: Funny watch
193 61 07/29 Hatter Remark
194 62 07/29 Hatter Re: Riddle
195 63 07/29 Hatter Re: Riddle
196 64 07/29 Hatter Discussing Time
197 65 07/29 Hatter Re: Discussing Time
198 66 07/29 Hatter Re: Discussing Time
199 67 07/29 Hatter Re: Discussing Time
200 68 07/29 Hatter Re: Discussing Time
201 69 07/29 Hatter Re: Discussing Time
202 70 07/29 Hatter Re: Discussing Time
203 71 07/29 Hatter Re: Discussing Time
204 72 07/29 Hatter Re: A guess
205 73 07/29 Hatter Re: A guess
206 74 07/29 Hatter Re: Request for a story
207 75 07/29 Hatter Re: Request for a story
208 76 07/29 Hatter Re: Remark
209 77 07/29 Hatter Re: Personal remark
210 78 07/29 Hatter Let's move
211 79 07/29 Hatter Re: Story
212 80 07/29 Hatter Rude remark
213 81 07/29 March Hare Invitation
214 82 07/29 March Hare Re: Invitation
215 83 07/29 March Hare Re: Invitation
216 84 07/29 March Hare Personal remark
217 85 07/29 March Hare Riddle (was Re: Personal remark)
218 86+ 07/29 March Hare Re: Riddle
219 87 07/29 March Hare Be specific (was Re: Riddle)
220 88 07/29 March Hare Re: Be specific
221 89 07/29 March Hare Re: Watch
222 90 07/29 March Hare Re: Watch
223 91 07/29 March Hare Re: Riddle
224 92 07/29 March Hare Thought apart Re: Discussing Time
225 93 07/29 March Hare Request for a story (was Re: A guess)
226 94 07/29 March Hare Re: Request for a story
227 95 07/29 March Hare Remark
228 1 07/29 March Hare Invitation
229 2 07/29 Alice Re: Invitation
230 3 07/29 March Hare Re: Invitation
231 4 07/29 Alice Re: Invitation
232 5 07/29 March Hare Re: Invitation
233 6 07/29 Alice Re: Invitation
234 7 07/29 March Hare Personal remark
235 8 07/29 Alice Re: Personal remark
236 9 07/29 March Hare Riddle (was Re: Personal remark)
237 10 07/29 Alice Re: Riddle
238 11+ 07/29 March Hare Re: Riddle
239 12 07/29 Alice Re: Riddle
240 13 07/29 March Hare Be specific (was Re: Riddle)
241 14 07/29 Alice Re: Be specific
242 15 07/29 Hatter Re: Be specific
243 16 07/29 March Hare Re: Be specific
244 17 07/29 Dormouse Re: Be specific
245 18 07/29 Hatter Re: Be specific
246 19 07/29 Hatter Watch
247 20 07/29 Alice Re: Watch
248 21 07/29 Hatter Re: Watch
249 22 07/29 March Hare Re: Watch
250 23 07/29 Hatter Re: Watch
251 24 07/29 March Hare Re: Watch
252 25 07/29 Alice Funny watch (was Re: Watch)
253 26 07/29 Hatter Re: Funny watch
254 27 07/29 Alice Re: Funny watch
255 28 07/29 Hatter Re: Funny watch
256 29 07/29 Alice Re: Funny watch
257 30 07/29 Hatter Remark
258 31 07/29 Dormouse Re: Remark
259 32 07/29 Hatter Re: Riddle
260 33 07/29 Alice Re: Riddle
261 34 07/29 Hatter Re: Riddle
262 35 07/29 March Hare Re: Riddle
263 36 07/29 Alice Re: Riddle
264 37 07/29 Hatter Discussing Time
265 38 07/29 Alice Re: Discussing Time
266 39 07/29 Hatter Re: Discussing Time
267 40 07/29 Alice Re: Discussing Time
268 41 07/29 Hatter Re: Discussing Time
269 42 07/29 March Hare Thought apart Re: Discussing Time
270 43 07/29 Alice Re: Discussing Time
271 44 07/29 Hatter Re: Discussing Time
272 45 07/29 Alice Re: Discussing Time
273 46 07/29 Hatter Re: Discussing Time
274 47 07/29 Alice Re: Discussing Time
275 48 07/29 Hatter Re: Discussing Time
276 49 07/29 Dormouse Re: Discussing Time
277 50 07/29 Hatter Re: Discussing Time
278 51 07/29 Alice Re: Discussing Time
279 52 07/29 Hatter Re: Discussing Time
280 53 07/29 Alice A guess (was Re: Discussing Time)
281 54 07/29 Hatter Re: A guess
282 55 07/29 Alice Re: A guess
283 56 07/29 Hatter Re: A guess
284 57 07/29 Alice Re: A guess
285 58 07/29 March Hare Request for a story (was Re: A guess)
286 59 07/29 Alice Re: Request for a story
287 60 07/29 Hatter Re: Request for a story
288 61 07/29 Dormouse Re: Request for a story
289 62 07/29 March Hare Re: Request for a story
290 63 07/29 Alice Re: Request for a story
291 64 07/29 Hatter Re: Request for a story
292 65 07/29 Dormouse Story (was Re: Request for a story)
293 66 07/29 Alice Re: Story
294 67 07/29 Dormouse Re: Story
295 68 07/29 Alice Re: Story
296 69 07/29 Dormouse Re: Story
297 70 07/29 Alice Re: Story
298 71 07/29 March Hare Remark
299 72 07/29 Alice Re: Remark
300 73 07/29 Hatter Re: Remark
301 74 07/29 Alice Personal remark
302 75 07/29 Hatter Re: Personal remark
303 76 07/29 Alice Re: Story
304 77 07/29 Dormouse Re: Story
305 78 07/29 Alice Re: Story
306 79 07/29 Dormouse Re: Story
307 80 07/29 Alice Re: Story
308 81 07/29 Dormouse Re: Story
309 82 07/29 Alice Re: Story
310 83 07/29 Dormouse Re: Story
311 84 07/29 Hatter Let's move
312 85 07/29 Alice Re: Story
313 86 07/29 Hatter Re: Story
314 87 07/29 Alice Re: Story
315 88 07/29 Dormouse Re: Story
316 89 07/29 Dormouse Re: Story
317 90 07/29 Alice Re: Story
318 91 07/29 Dormouse Re: Story
319 92 07/29 Dormouse Re: Story
320 93 07/29 Alice Re: Story
321 94 07/29 Hatter Rude remark
322 95 07/29 Alice Thoughts
323 ])
324
325 m4_popdef([scancmd])
326 m4_popdef([MH_KEYWORDS])
327
328 # End of sortm.at
...@@ -81,3 +81,4 @@ m4_include([forw.at]) ...@@ -81,3 +81,4 @@ m4_include([forw.at])
81 m4_include([repl.at]) 81 m4_include([repl.at])
82 m4_include([mhn.at]) 82 m4_include([mhn.at])
83 m4_include([send.at]) 83 m4_include([send.at])
84 m4_include([sortm.at])
......
...@@ -42,7 +42,7 @@ mh_whatnow_env_from_environ (struct mh_whatnow_env *wh) ...@@ -42,7 +42,7 @@ mh_whatnow_env_from_environ (struct mh_whatnow_env *wh)
42 size_t i; 42 size_t i;
43 struct mu_wordsplit ws; 43 struct mu_wordsplit ws;
44 mh_msgset_t msgset; 44 mh_msgset_t msgset;
45 mu_mailbox_t mbox = mh_open_folder (folder, 0); 45 mu_mailbox_t mbox = mh_open_folder (folder, MU_STREAM_RDWR);
46 46
47 if (mu_wordsplit (p, &ws, 47 if (mu_wordsplit (p, &ws,
48 MU_WRDSF_DEFFLAGS & ~MU_WRDSF_CESCAPES)) 48 MU_WRDSF_DEFFLAGS & ~MU_WRDSF_CESCAPES))
......