home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / MailTOC_Dump / MailTOC_Dump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-02  |  3.4 KB  |  106 lines

  1. /* MailTOC_Dump.c - Program to dump Mailbox table_of_contents to stdout.
  2.     Based on info provided by Chris Paris cap+@cmu.edu.
  3.     Get file "mailforward*.tar.Z" from the archive and see
  4.     index_files.rtf in it.
  5.  
  6.    This should be run in a ~/Mailboxes/*.mbox directory where file
  7.    table_of_contents is in the current directory.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <sys/time.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15.  
  16.  
  17. typedef struct table_of_contents_header {
  18.     long magic;        /* magic number: 0xd9758 */
  19.     long num_msgs;        /* number of messages in mbox */
  20.     long mbox_time;        /* the m_time of mbox */
  21.     float listview_height;    /* height of upper section of split view containing list */
  22.     float llx;        /* lower left X coordinate of window */
  23.     float lly;        /* lower left Y coordinate */
  24.     float width;        /* width of window */
  25.     float height;        /* height of window */
  26.     } MailTocHeader;
  27.  
  28. typedef struct message_index {
  29.     long record_length;        /* the length of this record, including this word */
  30.     long message_offset;        /* offset in mbox where this message begins */
  31.     long message_length;        /* length in bytes of this message in mbox */
  32.     long message_date;        /* the date of this message */
  33.     char status;            /* read, unread, deleted */
  34.     char msgtype;            /* regular or NeXT mail */
  35.     char mystery[2];        /* I don't know what these are */
  36.     } MailMsgIndex;
  37.  
  38.  
  39. main()
  40. {
  41. FILE *fp;
  42. MailTocHeader header;
  43. MailMsgIndex mindex;
  44. int nread, i, c;
  45. unsigned long year, month, day;
  46.  
  47.     fp = fopen("table_of_contents", "r");
  48.     if(fp == NULL)
  49.     {
  50.     fprintf(stderr, "Can't open table_of_contents file.\n");
  51.        fprintf(stderr, "Run within a ~/Mailboxes/*.mbox directory.\n");
  52.     exit(1);
  53.     }
  54.  
  55.     nread = fread(&header, (size_t)sizeof(MailTocHeader), 1, fp);
  56.     if(nread==0)
  57.     {
  58.     fprintf(stderr,"No header could be read.\n");
  59.     exit(2);
  60.     }
  61.     /* dump header info */
  62.     printf("Magic (should be 0xd9758): 0x%lx\n", header.magic);
  63.     printf("# of messages: %ld\n", header.num_msgs);
  64.     printf("Modification time of mbox: %s", ctime(&header.mbox_time));
  65.     printf("Height of message list view: %.1f\n",header.listview_height);
  66.     printf("Window Origin(x,y)=(%.f, %.f),  Size(w,h)=(%.f, %.f)\n",
  67.         header.llx, header.lly, header.width, header.height);
  68.  
  69.     /* Now, dump records for each message */
  70.     for(i=0; i<header.num_msgs; i++)
  71.     {
  72.     nread = fread(&mindex, (size_t)sizeof(MailMsgIndex), 1, fp);
  73.         if(nread == 0)
  74.     {
  75.         fprintf(stderr,"Premature EOF\n");
  76.         exit(3);
  77.     }
  78.  
  79.     printf("---[%d]---\n", i+1);
  80.     printf("Record Length: %ld\n", mindex.record_length);
  81.     printf("Message Offset into mbox: %ld\n", mindex.message_offset);
  82.     printf("Message Length (bytes): %ld\n", mindex.message_length);
  83.     day = month = year = mindex.message_date;
  84.     year >>= 9;
  85.     month >>= 5; month &= 0xf;
  86.     day &= 0x1f;
  87.     printf("Message Date (Y-M-D): %d-%d-%d\n", year, month, day);
  88.     printf("Status: Read( ), Last-Read(>), Unread(*), Deleted(d): [%c]\n", mindex.status);
  89.     printf("NeXTmail(r) or regular ( ): [%c]\n",mindex.msgtype);
  90.     printf("Mystery byte-1: %d (dec), [%c]\n", (int)(mindex.mystery[0]), mindex.mystery[0]);
  91.     printf("Mystery byte-2: %d (dec), [%c]\n", (int)(mindex.mystery[1]), mindex.mystery[1]);
  92.     printf("From: ");
  93.     while((c=fgetc(fp)) != (int)'\0')
  94.         putchar(c);
  95.     printf("\nSubject: ");
  96.     while((c=fgetc(fp)) != (int)'\0')
  97.         putchar(c);
  98.     printf("\nAttachment Dir: ");
  99.     while((c=fgetc(fp)) != (int)'\0')
  100.         putchar(c);
  101.     printf("\n");
  102.     }
  103.     printf("---End of TOC---\n");
  104.     fclose(fp);
  105. }
  106.