Commit fedafd6e fedafd6edc4b5b8fabb483d8beca1b3be117d15a by Sergey Poznyakoff

New option --copy.

Properly handle trailing folder names. As a side-effect
it accepts messages and folders given in any order. Good!
1 parent 815d03f2
...@@ -36,8 +36,9 @@ static struct argp_option options[] = { ...@@ -36,8 +36,9 @@ static struct argp_option options[] = {
36 N_("Specify folder to operate upon")}, 36 N_("Specify folder to operate upon")},
37 {"draft", ARG_DRAFT, NULL, 0, 37 {"draft", ARG_DRAFT, NULL, 0,
38 N_("Use <mh-dir>/draft as the source message")}, 38 N_("Use <mh-dir>/draft as the source message")},
39 {"link", ARG_LINK, N_("BOOL"), OPTION_ARG_OPTIONAL, 39 {"copy", ARG_LINK, N_("BOOL"), OPTION_ARG_OPTIONAL,
40 N_("* Preserve the source folder copy")}, 40 N_("Preserve the source folder copy.")},
41 {"link", 0, NULL, OPTION_ALIAS, NULL},
41 {"preserve", ARG_PRESERVE, N_("BOOL"), OPTION_ARG_OPTIONAL, 42 {"preserve", ARG_PRESERVE, N_("BOOL"), OPTION_ARG_OPTIONAL,
42 N_("* Try to preserve message sequence numbers")}, 43 N_("* Try to preserve message sequence numbers")},
43 {"source", ARG_SOURCE, N_("FOLDER"), 0, 44 {"source", ARG_SOURCE, N_("FOLDER"), 0,
...@@ -57,7 +58,7 @@ struct mh_option mh_option[] = { ...@@ -57,7 +58,7 @@ struct mh_option mh_option[] = {
57 { 0 } 58 { 0 }
58 }; 59 };
59 60
60 int link_flag = 1; 61 int link_flag = 0;
61 int preserve_flag = 0; 62 int preserve_flag = 0;
62 char *source_file = NULL; 63 char *source_file = NULL;
63 list_t folder_name_list = NULL; 64 list_t folder_name_list = NULL;
...@@ -149,7 +150,6 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) ...@@ -149,7 +150,6 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
149 { 150 {
150 switch (key) 151 switch (key)
151 { 152 {
152 case '+':
153 case ARG_FOLDER: 153 case ARG_FOLDER:
154 add_folder (arg); 154 add_folder (arg);
155 break; 155 break;
...@@ -218,7 +218,7 @@ main (int argc, char **argv) ...@@ -218,7 +218,7 @@ main (int argc, char **argv)
218 int index; 218 int index;
219 mh_msgset_t msgset; 219 mh_msgset_t msgset;
220 mailbox_t mbox; 220 mailbox_t mbox;
221 int status; 221 int status, i, j;
222 222
223 /* Native Language Support */ 223 /* Native Language Support */
224 mu_init_nls (); 224 mu_init_nls ();
...@@ -226,13 +226,27 @@ main (int argc, char **argv) ...@@ -226,13 +226,27 @@ main (int argc, char **argv)
226 mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc, 226 mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
227 opt_handler, NULL, &index); 227 opt_handler, NULL, &index);
228 228
229 argc -= index;
230 argv += index;
231
232 /* Collect any surplus folders */
233 for (i = j = 0; i < argc; i++)
234 {
235 if (argv[i][0] == '+')
236 add_folder (argv[i]);
237 else
238 argv[j++] = argv[i];
239 }
240 argv[j] = NULL;
241 argc = j;
242
229 open_folders (); 243 open_folders ();
230 244
231 if (source_file) 245 if (source_file)
232 { 246 {
233 message_t msg; 247 message_t msg;
234 248
235 if (index < argc) 249 if (argc > 0)
236 { 250 {
237 mh_error (_("both message set and source file given")); 251 mh_error (_("both message set and source file given"));
238 exit (1); 252 exit (1);
...@@ -246,7 +260,7 @@ main (int argc, char **argv) ...@@ -246,7 +260,7 @@ main (int argc, char **argv)
246 else 260 else
247 { 261 {
248 mbox = mh_open_folder (current_folder, 0); 262 mbox = mh_open_folder (current_folder, 0);
249 mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); 263 mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
250 264
251 status = mh_iterate (mbox, &msgset, refile_iterator, NULL); 265 status = mh_iterate (mbox, &msgset, refile_iterator, NULL);
252 266
......