Commit 7b42d158 7b42d1582103e31485d6ded16c797f351d8544b7 by Sergey Poznyakoff

Implemented -header. Several fixes.

1 parent c53ccfe9
Showing 1 changed file with 69 additions and 23 deletions
...@@ -222,20 +222,23 @@ _scan (const char *name, int depth) ...@@ -222,20 +222,23 @@ _scan (const char *name, int depth)
222 struct stat st; 222 struct stat st;
223 size_t uid; 223 size_t uid;
224 224
225 if (fast_mode && !recurse && depth > 0) 225 if (!recurse)
226 { 226 {
227 memset (&info, 0, sizeof (info)); 227 if (fast_mode && depth > 0)
228 info.name = strdup (name); 228 {
229 install_folder_info (name, &info); 229 memset (&info, 0, sizeof (info));
230 return; 230 info.name = strdup (name);
231 install_folder_info (name, &info);
232 return;
233 }
234
235 if (depth > 1)
236 return;
231 } 237 }
232
233 if (depth > 1 && !recurse)
234 return;
235 238
236 dir = opendir (name); 239 dir = opendir (name);
237 240
238 if (!dir && errno == ENOENT) 241 if (!dir && errno == ENOENT && create_flag)
239 { 242 {
240 mh_check_folder (name, 0); 243 mh_check_folder (name, 0);
241 dir = opendir (name); 244 dir = opendir (name);
...@@ -271,7 +274,7 @@ _scan (const char *name, int depth) ...@@ -271,7 +274,7 @@ _scan (const char *name, int depth)
271 info.message_count++; 274 info.message_count++;
272 if (info.min == 0 || uid < info.min) 275 if (info.min == 0 || uid < info.min)
273 info.min = uid; 276 info.min = uid;
274 else if (uid > info.max) 277 if (uid > info.max)
275 info.max = uid; 278 info.max = uid;
276 } 279 }
277 break; 280 break;
...@@ -305,8 +308,17 @@ print_all () ...@@ -305,8 +308,17 @@ print_all ()
305 308
306 for (info = folder_info; info < end; info++) 309 for (info = folder_info; info < end; info++)
307 { 310 {
308 printf ("%19.19s%c", info->name, 311 int len = strlen (info->name);
309 (strcmp (info->name, current_folder) == 0) ? '+' : ' '); 312 printf ("%s", info->name);
313 if (strcmp (info->name, current_folder) == 0)
314 {
315 printf ("+");
316 len++;
317 }
318
319 for (; len < 20; len++)
320 putchar (' ');
321
310 if (info->message_count) 322 if (info->message_count)
311 { 323 {
312 printf (" has %4lu messages (%4lu-%4lu)", 324 printf (" has %4lu messages (%4lu-%4lu)",
...@@ -319,7 +331,7 @@ print_all () ...@@ -319,7 +331,7 @@ print_all ()
319 if (info->others) 331 if (info->others)
320 { 332 {
321 if (!info->cur) 333 if (!info->cur)
322 printf ("; "); 334 printf ("; ");
323 else 335 else
324 printf ("; "); 336 printf ("; ");
325 printf ("(others)"); 337 printf ("(others)");
...@@ -379,14 +391,18 @@ action_print () ...@@ -379,14 +391,18 @@ action_print ()
379 if (fast_mode) 391 if (fast_mode)
380 print_fast (); 392 print_fast ();
381 else 393 else
382 print_all (); 394 {
383 395 if (print_header)
384 if (print_total) 396 printf ("Folder # of messages ( range ) cur msg (other files)\n");
385 printf ("%24.24s=%4lu messages in %4lu folders\n", 397
386 "TOTAL", 398 print_all ();
387 (unsigned long) message_count, 399
388 (unsigned long) folder_info_count); 400 if (print_total)
389 401 printf ("%24.24s=%4lu messages in %4lu folders\n",
402 "TOTAL",
403 (unsigned long) message_count,
404 (unsigned long) folder_info_count);
405 }
390 if (push_folder) 406 if (push_folder)
391 mh_global_save_state (); 407 mh_global_save_state ();
392 408
...@@ -400,7 +416,8 @@ action_list () ...@@ -400,7 +416,8 @@ action_list ()
400 416
401 printf ("%s", current_folder); 417 printf ("%s", current_folder);
402 if (stack) 418 if (stack)
403 printf (" %s\n", stack); 419 printf (" %s", stack);
420 printf ("\n");
404 return 0; 421 return 0;
405 } 422 }
406 423
...@@ -440,7 +457,19 @@ static int ...@@ -440,7 +457,19 @@ static int
440 action_pop () 457 action_pop ()
441 { 458 {
442 char *stack = mh_global_context_get ("Folder-Stack", NULL); 459 char *stack = mh_global_context_get ("Folder-Stack", NULL);
443 char *s, *p = strtok_r (stack, " ", &s); 460 char *s, *p;
461
462 if (stack)
463 {
464 p = strtok_r (stack, " ", &s);
465 if (s[0] == 0)
466 s = NULL;
467 }
468 else
469 {
470 p = current_folder;
471 s = NULL;
472 }
444 mh_global_context_set ("Folder-Stack", s); 473 mh_global_context_set ("Folder-Stack", s);
445 current_folder = p; 474 current_folder = p;
446 action_list (); 475 action_list ();
...@@ -452,6 +481,8 @@ int ...@@ -452,6 +481,8 @@ int
452 main (int argc, char **argv) 481 main (int argc, char **argv)
453 { 482 {
454 int index = 0; 483 int index = 0;
484 mh_msgset_t msgset;
485
455 mh_argp_parse (argc, argv, options, mh_option, args_doc, doc, 486 mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
456 opt_handler, NULL, &index); 487 opt_handler, NULL, &index);
457 488
...@@ -460,6 +491,21 @@ main (int argc, char **argv) ...@@ -460,6 +491,21 @@ main (int argc, char **argv)
460 if (program_invocation_short_name[strlen (program_invocation_short_name) - 1] == 's') 491 if (program_invocation_short_name[strlen (program_invocation_short_name) - 1] == 's')
461 show_all++; 492 show_all++;
462 493
494 if (argc - index == 1)
495 {
496 mailbox_t mbox = mh_open_folder (current_folder, 0);
497 mh_msgset_parse (mbox, &msgset, argc - index, argv + index);
498 current_message = msgset.list[0];
499 mh_global_save_state ();
500 mailbox_close (mbox);
501 mailbox_destroy (&mbox);
502 }
503 else if (argc - index > 1)
504 {
505 mh_error ("too many arguments");
506 exit (1);
507 }
508
463 if (show_all) 509 if (show_all)
464 print_header = print_total = 1; 510 print_header = print_total = 1;
465 511
......