home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Mail / appnmail-1.8-Solaris / mailapp-utilities / listmail.m < prev    next >
Encoding:
Text File  |  1997-04-19  |  4.3 KB  |  164 lines

  1. /* -*-C-*-
  2. *******************************************************************************
  3. *
  4. * File:         listmail.m
  5. * RCS:          /usr/local/sources/CVS/mailapp-utilities/listmail.m,v 1.4 1997/04/19 17:37:20 tom Exp
  6. * Description:  List the contents of a Mail.app table_of_contents
  7. * Author:       Carl Edman
  8. * Created:      Fri Mar 12 18:21:23 1993
  9. * Modified:     Sat Nov 30 23:29:31 1996 Tom Hageman <tom@basil.icce.rug.nl>
  10. * Language:     Objective C
  11. * Package:      mailapp-utilities
  12. * Status:       First release.
  13. *
  14. * (C) Copyright 1993, but otherwise this file is perfect freeware.
  15. *
  16. *******************************************************************************
  17. */
  18.  
  19. #import <libc.h>
  20. #import <errno.h>
  21. //#import <stdlib.h>
  22. //#import <stdio.h>
  23. //#import <string.h>
  24. //#import <time.h>
  25. #import <regex.h>
  26. //#import <sys/file.h>
  27. //#import <sys/param.h>
  28. //#import <sys/types.h>
  29. //#import <sys/stat.h>
  30. #import <defaults/defaults.h>
  31. #import "mailutil.h"
  32. #import "mailtoc.h"
  33. #import "optutil.h"
  34.  
  35. #define USAGE "\
  36. Usage: %s [-nv][-t][-H|-V] mbox...\n"
  37.  
  38. #define HELP "\
  39.  -n           ignore mailbox locks, list regardless\n\
  40.  -v           talkative mode\n\
  41.  -t           show total number of messages\n\
  42.  -V           show version\n\
  43.  -H           this help\n\
  44. "
  45.  
  46. char line[LINELEN];
  47.  
  48. int main(int ac,char *av[])
  49. {
  50.    int c,width;
  51.    int verboseflg=0,nowaitflg=0,countonlyflg=0,lockedflg;
  52.    FILE *tocf;
  53.    char *p;
  54.    struct table_of_contents_header *toch=0;
  55.    struct message_index *mi=0;
  56.    int status=EXIT_SUCCESS;
  57.  
  58.    set_progname(av[0]);
  59.  
  60.    while((c=getopt(ac,av,"nvtVH"))!=EOF) switch(c)
  61.    {
  62.     case 'v':
  63.       verboseflg++;
  64.       break;
  65.     case 'n':
  66.       nowaitflg++;
  67.       break;
  68.     case 't':
  69.       countonlyflg++;
  70.       break;
  71.     case 'V':
  72.       status=EXIT_VERSION;
  73.       break;
  74.     case 'H':
  75.       status=EXIT_HELP;
  76.       break;
  77.     case '?':
  78.     default:
  79.       status=EXIT_USAGE;
  80.    }
  81.    if (status==EXIT_SUCCESS && optind>=ac) status=EXIT_USAGE;
  82.    handle_usage_help_version(status, USAGE, HELP);
  83.  
  84.    for(;optind<ac;optind++)
  85.    {
  86.       int priority;
  87.       time_t s,t;
  88.       
  89.       if (verboseflg) fprintf(stderr,"Entering %s...\n",av[optind]);
  90.       if (cd_mbox(av[optind],0)) goto next;
  91.       lockedflg=lock_mbox(nowaitflg);
  92.  
  93.       if ((tocf=fopen("table_of_contents","rb"))==NULL)
  94.       {
  95.          fprintf(stderr,"%s: %s: opening: %s\n",progname(),av[optind],strerror(errno));
  96.          goto unlock;
  97.       }
  98.  
  99.       toch=get_table_of_contents_header(tocf,0);
  100.       if (!toch)
  101.       {
  102.          fprintf(stderr,"%s: %s: invalid table_of_contents\n",progname(),av[optind]);
  103.          goto unlock;
  104.       }
  105.  
  106.       if (countonlyflg)
  107.       {
  108.          printf("%d\n",toch->num_msgs);
  109.          goto unlock;
  110.       }
  111.       // XXX wishlist: countall -- message count per category.
  112.  
  113.       printf("Table of contents (magic=%d):\n",toch->magic);
  114.       printf("Number of messages:%5d   Modification Time:%25s",toch->num_msgs,
  115.              ctime(&toch->mbox_time));
  116.       if (toch->mbox_time!=mtime("mbox"))
  117.       {
  118.          s=mtime("mbox");
  119.          printf("(!=%25s)",ctime(&s));
  120.       }
  121.       
  122.       printf("\nAt (%.2f,%.2f) %.2fx%.2f(%.2f)\n",toch->window.origin.x,
  123.              toch->window.origin.y,toch->window.size.width,toch->window.size.height,
  124.              toch->list);
  125.  
  126.       for(c=toch->num_msgs,width=0;c>0;) { width++; c/=10; }
  127.       for(c=0;c<toch->num_msgs;c++)
  128.       {
  129.          if ((mi=get_message_index(tocf))==0)
  130.      {
  131.             fprintf(stderr,"%s: %s: reading mbox entries: %s\n",progname(),av[optind],(errno?strerror(errno):"invalid"));
  132.             goto unlock;
  133.      }
  134.  
  135.          printf("%c%c%c%c%*d %8d %5d/%7d %s:%s",mi->status,mi->msgtype,mi->encrypted,mi->sync,width,c+1,mi->mes_date,mi->mes_length,mi->mes_offset,message_from(mi),message_subject(mi));
  136.          if (*(p=message_reference(mi)))
  137.      {
  138.             t=message_attachtime(mi);
  139.             s=mtime(p);
  140.         printf("(%s:%d@%25s", p, message_attachsize(mi),ctime(&t));
  141.             if (t!=s) printf("!= %25s",ctime(&s));
  142.             printf(")");
  143.      }
  144.  
  145.          if ((priority=message_priority(mi))>0)
  146.      {
  147.             printf("(pri=%d)",priority);
  148.      }
  149.          
  150.          printf("\n");
  151.          free(mi); mi=0;
  152.       }
  153.  
  154.     unlock:
  155.       if (tocf!=NULL) fclose(tocf);
  156.       if (!lockedflg) unlock_mbox();
  157.     next:
  158.       if (toch) { free(toch); toch=0; }
  159.       if (mi) { free(mi); mi=0; }
  160.       uncd_mbox();
  161.    }
  162.    exit(EXIT_SUCCESS);
  163. }
  164.