Commit cd424fdc cd424fdc46326df66ee71d875fa64a834fa7fee4 by Sergey Poznyakoff

New option --exec (-E)

(mail_cmdline): Invalidate the page when a new mail arrives
(main): Fix handling of modes.
1 parent 0aed411c
Showing 1 changed file with 19 additions and 10 deletions
...@@ -49,6 +49,8 @@ static struct argp_option options[] = { ...@@ -49,6 +49,8 @@ static struct argp_option options[] = {
49 {"user", 'u', N_("USER"), 0, N_("Operate on USER's mailbox"), 0}, 49 {"user", 'u', N_("USER"), 0, N_("Operate on USER's mailbox"), 0},
50 {"append", 'a', N_("HEADER: VALUE"), 0, 50 {"append", 'a', N_("HEADER: VALUE"), 0,
51 N_("Append given header to the message being sent"), 0}, 51 N_("Append given header to the message being sent"), 0},
52 {"exec", 'E', N_("COMMAND"), 0,
53 N_("Execute COMMAND"), 0 },
52 { NULL, 0, NULL, 0, NULL, 0 } 54 { NULL, 0, NULL, 0, NULL, 0 }
53 }; 55 };
54 56
...@@ -129,6 +131,10 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -129,6 +131,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
129 case 'u': 131 case 'u':
130 args->user = arg; 132 args->user = arg;
131 break; 133 break;
134
135 case 'E':
136 util_cache_command (&command_list, arg);
137 break;
132 138
133 case 'F': 139 case 'F':
134 util_cache_command (&command_list, "set byname"); 140 util_cache_command (&command_list, "set byname");
...@@ -195,6 +201,7 @@ mail_cmdline(void *closure, int cont ARG_UNUSED) ...@@ -195,6 +201,7 @@ mail_cmdline(void *closure, int cont ARG_UNUSED)
195 && !mu_mailbox_is_updated (mbox)) 201 && !mu_mailbox_is_updated (mbox))
196 { 202 {
197 mu_mailbox_messages_count (mbox, &total); 203 mu_mailbox_messages_count (mbox, &total);
204 page_invalidate (0);
198 fprintf (ofile, _("New mail has arrived.\n")); 205 fprintf (ofile, _("New mail has arrived.\n"));
199 } 206 }
200 207
...@@ -281,7 +288,6 @@ int ...@@ -281,7 +288,6 @@ int
281 main (int argc, char **argv) 288 main (int argc, char **argv)
282 { 289 {
283 char *mode = NULL, *prompt = NULL; 290 char *mode = NULL, *prompt = NULL;
284 size_t modelen = 0;
285 struct arguments args; 291 struct arguments args;
286 int i, rc; 292 int i, rc;
287 293
...@@ -360,7 +366,7 @@ main (int argc, char **argv) ...@@ -360,7 +366,7 @@ main (int argc, char **argv)
360 util_do_command ("source %s", getenv ("MAILRC")); 366 util_do_command ("source %s", getenv ("MAILRC"));
361 367
362 util_run_cached_commands (&command_list); 368 util_run_cached_commands (&command_list);
363 369
364 if (!interactive) 370 if (!interactive)
365 { 371 {
366 util_do_command ("set nocrt"); 372 util_do_command ("set nocrt");
...@@ -372,7 +378,6 @@ main (int argc, char **argv) ...@@ -372,7 +378,6 @@ main (int argc, char **argv)
372 /* how should we be running? */ 378 /* how should we be running? */
373 if (util_getenv (&mode, "mode", Mail_env_string, 1)) 379 if (util_getenv (&mode, "mode", Mail_env_string, 1))
374 exit (EXIT_FAILURE); 380 exit (EXIT_FAILURE);
375 modelen = strlen (mode);
376 381
377 /* Interactive mode */ 382 /* Interactive mode */
378 383
...@@ -380,7 +385,7 @@ main (int argc, char **argv) ...@@ -380,7 +385,7 @@ main (int argc, char **argv)
380 mail_set_my_name(args.user); 385 mail_set_my_name(args.user);
381 386
382 /* Mode is just sending */ 387 /* Mode is just sending */
383 if (strlen ("send") == modelen && !strcmp ("send", mode)) 388 if (strcmp (mode, "send") == 0)
384 { 389 {
385 /* FIXME: set cmd to "mail [add1...]" */ 390 /* FIXME: set cmd to "mail [add1...]" */
386 char *buf = NULL; 391 char *buf = NULL;
...@@ -394,7 +399,7 @@ main (int argc, char **argv) ...@@ -394,7 +399,7 @@ main (int argc, char **argv)
394 return util_getenv (NULL, "mailx", Mail_env_boolean, 0) ? rc : 0; 399 return util_getenv (NULL, "mailx", Mail_env_boolean, 0) ? rc : 0;
395 } 400 }
396 /* Or acting as a normal reader */ 401 /* Or acting as a normal reader */
397 else 402 else
398 { 403 {
399 /* open the mailbox */ 404 /* open the mailbox */
400 if (args.file == NULL) 405 if (args.file == NULL)
...@@ -454,14 +459,18 @@ main (int argc, char **argv) ...@@ -454,14 +459,18 @@ main (int argc, char **argv)
454 exit (EXIT_FAILURE); 459 exit (EXIT_FAILURE);
455 } 460 }
456 461
457 if (strlen ("exist") == modelen && !strcmp ("exist", mode)) 462 if (strcmp (mode, "exist") == 0)
458 return (total < 1) ? 1 : 0; 463 return (total < 1) ? 1 : 0;
459 else if (strlen ("print") == modelen 464 else if (strcmp (mode, "print") == 0)
460 && !strcmp ("print", mode))
461 return util_do_command ("print *"); 465 return util_do_command ("print *");
462 else if (strlen ("headers") == modelen 466 else if (strcmp (mode, "headers") == 0)
463 && !strcmp ("headers", mode))
464 return util_do_command ("from *"); 467 return util_do_command ("from *");
468 else if (strcmp (mode, "read"))
469 {
470 util_error(_("Unknown mode `%s'"), mode);
471 util_do_command ("quit");
472 return 1;
473 }
465 } 474 }
466 475
467 if (total == 0 476 if (total == 0
......