summaryrefslogtreecommitdiff
path: root/frm
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2004-01-13 21:31:15 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2004-01-13 21:31:15 +0000
commitcea51c0b459f2b6e0752cb87daa03efafcaaf91a (patch)
tree3bf3ad5cc8dd40efab6787075bf0aea0784374b0 /frm
parentb951d4cb74d4389e157872ab4087a3820ba125c8 (diff)
downloadmailutils-cea51c0b459f2b6e0752cb87daa03efafcaaf91a.tar.gz
mailutils-cea51c0b459f2b6e0752cb87daa03efafcaaf91a.tar.bz2
Lots of changes for compatibility with ELM.
Diffstat (limited to 'frm')
-rw-r--r--frm/frm.c302
1 files changed, 190 insertions, 112 deletions
<
diff --git a/frm/frm.c b/frm/frm.c
index b734afb23..6b3df3cd9 100644
--- a/frm/frm.c
+++ b/frm/frm.c
@@ -45,7 +45,7 @@
45#include <mailutils/mutil.h> 45#include <mailutils/mutil.h>
46#include <mailutils/mime.h> 46#include <mailutils/mime.h>
47 47
48static char* show_field; 48static char *show_field;
49static int show_to; 49static int show_to;
50static int show_from = 1; 50static int show_from = 1;
51static int show_subject = 1; 51static int show_subject = 1;
@@ -54,7 +54,6 @@ static int show_summary;
54static int be_quiet; 54static int be_quiet;
55static int align = 1; 55static int align = 1;
56static int show_query; 56static int show_query;
57static int have_new_mail;
58static int dbug; 57static int dbug;
59 58
60#define IS_READ 0x001 59#define IS_READ 0x001
@@ -327,12 +326,18 @@ get_personal (header_t hdr, const char *field, char *personal, size_t buflen)
327 return status; 326 return status;
328} 327}
329 328
329static struct {
330 size_t index;
331 size_t new;
332 size_t read;
333 size_t unread;
334} counter;
335
330/* Observable action is being called on discovery of each message. */ 336/* Observable action is being called on discovery of each message. */
331/* FIXME: The format of the display is poorly done, please correct. */ 337/* FIXME: The format of the display is poorly done, please correct. */
332static int 338static int
333action (observer_t o, size_t type) 339action (observer_t o, size_t type)
334{ 340{
335 static int counter;
336 int status; 341 int status;
337 342
338 switch (type) 343 switch (type)
@@ -344,26 +349,33 @@ action (observer_t o, size_t type)
344 header_t hdr = NULL; 349 header_t hdr = NULL;
345 attribute_t attr = NULL; 350 attribute_t attr = NULL;
346 351
347 counter++; 352 counter.index++;
348 353
349 mailbox_get_message (mbox, counter, &msg); 354 mailbox_get_message (mbox, counter.index, &msg);
350 355
351 message_get_attribute (msg, &attr); 356 message_get_attribute (msg, &attr);
352 message_get_header (msg, &hdr); 357 message_get_header (msg, &hdr);
353 358
359 if (attribute_is_read (attr))
360 counter.read++;
361 else if (attribute_is_seen (attr))
362 counter.unread++;
363 else if (attribute_is_recent (attr))
364 counter.new++;
365
354 if (((select_attribute & IS_READ) && (!attribute_is_read (attr))) 366 if (((select_attribute & IS_READ) && (!attribute_is_read (attr)))
355 || ((select_attribute & IS_NEW) && (!attribute_is_recent (attr))) 367 || ((select_attribute & IS_NEW) && (!attribute_is_recent (attr)))
356 || ((select_attribute & IS_OLD) && (!attribute_is_seen (attr)))) 368 || ((select_attribute & IS_OLD) && (!attribute_is_seen (attr))))
357 break; 369 break;
358 370
359 if (attribute_is_recent (attr))
360 have_new_mail = 1;
361
362 if (select_attribute) 371 if (select_attribute)
363 selected = 1; 372 selected = 1;
364 373
374 if (be_quiet)
375 break;
376
365 if (show_number) 377 if (show_number)
366 printf ("%d: ", counter); 378 printf ("%4lu: ", (u_long) counter.index);
367 379
368 if (show_field) 380 if (show_field)
369 { 381 {
@@ -419,6 +431,24 @@ action (observer_t o, size_t type)
419 return 0; 431 return 0;
420} 432}
421 433
434static void
435frm_abort (mailbox_t *mbox)
436{
437 int status;
438
439 if ((status = mailbox_close (*mbox)) != 0)
440 {
441 url_t url;
442
443 mu_error (_("Couldn't close <%s>: %s."),
444 url_to_string (url), mu_strerror (status));
445 exit (3);
446 }
447
448 mailbox_destroy (mbox);
449 exit (3);
450}
451
422/* This is a clone of the elm program call "frm". It is a good example on 452/* This is a clone of the elm program call "frm". It is a good example on
423 how to use the observable(callback) of libmailbox. "frm" has to 453 how to use the observable(callback) of libmailbox. "frm" has to
424 be very interactive, it is not possible to call mailbox_messages_count() 454 be very interactive, it is not possible to call mailbox_messages_count()
@@ -427,123 +457,136 @@ action (observer_t o, size_t type)
427 an observable type MU_MAILBOX_MSG_ADD. The rest is formatting code. */ 457 an observable type MU_MAILBOX_MSG_ADD. The rest is formatting code. */
428 458
429int 459int
430main (int argc, char **argv) 460frm (char *mailbox_name)
431{ 461{
432 char *mailbox_name = NULL; 462 int status;
463 mailbox_t mbox;
464 url_t url = NULL;
433 size_t total = 0; 465 size_t total = 0;
434 int c;
435 int status = 0;
436
437 /* Native Language Support */
438 mu_init_nls ();
439
440 prepare_attrs ();
441
442 mu_argp_init (program_version, NULL);
443#ifdef WITH_TLS
444 mu_tls_init_client_argp ();
445#endif
446 mu_argp_parse (&argp, &argc, &argv, 0, frm_argp_capa, &c, NULL);
447
448 /* have an argument */
449 argc -= c;
450 argv += c;
451 466
452 if (argc) 467 status = mailbox_create_default (&mbox, mailbox_name);
453 mailbox_name = argv[0]; 468 if (status != 0)
454 469 {
455 /* register the formats. */ 470 mu_error (_("Couldn't create mailbox <%s>: %s."),
456 mu_register_all_mbox_formats (); 471 mailbox_name ? mailbox_name : _("default"),
457 472 mu_strerror (status));
458 /* Construct the mailbox_t, attach a notification and destroy */ 473 exit (3);
459 { 474 }
460 mailbox_t mbox;
461 observer_t observer;
462 observable_t observable;
463 url_t url = NULL;
464
465 status = mailbox_create_default (&mbox, mailbox_name);
466 if (status != 0)
467 {
468 mu_error (_("Couldn't create mailbox <%s>: %s."),
469 mailbox_name ? mailbox_name : _("default"),
470 mu_strerror (status));
471 exit (3);
472 }
473
474 if (dbug)
475 {
476 mu_debug_t debug;
477 mailbox_get_debug (mbox, &debug);
478 mu_debug_set_level (debug, MU_DEBUG_TRACE|MU_DEBUG_PROT);
479 }
480
481 mailbox_get_url (mbox, &url);
482
483 status = mailbox_open (mbox, MU_STREAM_READ);
484 if (status != 0)
485 {
486 if (status == ENOENT)
487 goto cleanup1;
488 else
489 {
490 mu_error (_("Couldn't open mailbox <%s>: %s."),
491 url_to_string (url), mu_strerror (status));
492 goto cleanup;
493 }
494 }
495
496 if (! be_quiet)
497 {
498 observer_create (&observer, mbox);
499 observer_set_action (observer, action, mbox);
500 mailbox_get_observable (mbox, &observable);
501 observable_attach (observable, MU_EVT_MESSAGE_ADD, observer);
502 }
503
504 status = mailbox_scan (mbox, 1, &total);
505 if (status != 0)
506 {
507 mu_error (_("Couldn't scan mailbox <%s>: %s."),
508 url_to_string (url), mu_strerror (status));
509 goto cleanup;
510 }
511
512 if (! be_quiet)
513 {
514 observable_detach (observable, observer);
515 observer_destroy (&observer, mbox);
516 }
517 475
518cleanup: 476 if (dbug)
519 if (mailbox_close (mbox) != 0) 477 {
520 { 478 mu_debug_t debug;
521 mu_error (_("Couldn't close <%s>: %s."), 479 mailbox_get_debug (mbox, &debug);
522 url_to_string (url), mu_strerror (status)); 480 mu_debug_set_level (debug, MU_DEBUG_TRACE|MU_DEBUG_PROT);
523 return -1; 481 }
524 }
525 482
526 mailbox_destroy (&mbox); 483 mailbox_get_url (mbox, &url);
527 484
528 if (status != 0) 485