ftp.nice.ch/pub/next/unix/mail/MailTOC_Dump.NIHS.bs.tar.gz#/MailTOC_Dump/MailTOC_Dump.c

This is MailTOC_Dump.c in view mode; [Download] [Up]

/* MailTOC_Dump.c - Program to dump Mailbox table_of_contents to stdout.
	Based on info provided by Chris Paris cap+@cmu.edu.
	Get file "mailforward*.tar.Z" from the archive and see
	index_files.rtf in it.

   This should be run in a ~/Mailboxes/*.mbox directory where file
   table_of_contents is in the current directory.
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>


typedef struct table_of_contents_header {
	long magic;		/* magic number: 0xd9758 */
	long num_msgs;		/* number of messages in mbox */
	long mbox_time;		/* the m_time of mbox */
	float listview_height;	/* height of upper section of split view containing list */
	float llx;		/* lower left X coordinate of window */
	float lly;		/* lower left Y coordinate */
	float width;		/* width of window */
	float height;		/* height of window */
    } MailTocHeader;

typedef struct message_index {
	long record_length;		/* the length of this record, including this word */
	long message_offset;		/* offset in mbox where this message begins */
	long message_length;		/* length in bytes of this message in mbox */
	long message_date;		/* the date of this message */
	char status;			/* read, unread, deleted */
	char msgtype;			/* regular or NeXT mail */
	char mystery[2];		/* I don't know what these are */
    } MailMsgIndex;


main()
{
FILE *fp;
MailTocHeader header;
MailMsgIndex mindex;
int nread, i, c;
unsigned long year, month, day;

    fp = fopen("table_of_contents", "r");
    if(fp == NULL)
    {
	fprintf(stderr, "Can't open table_of_contents file.\n");
   	fprintf(stderr, "Run within a ~/Mailboxes/*.mbox directory.\n");
	exit(1);
    }

    nread = fread(&header, (size_t)sizeof(MailTocHeader), 1, fp);
    if(nread==0)
    {
	fprintf(stderr,"No header could be read.\n");
	exit(2);
    }
    /* dump header info */
    printf("Magic (should be 0xd9758): 0x%lx\n", header.magic);
    printf("# of messages: %ld\n", header.num_msgs);
    printf("Modification time of mbox: %s", ctime(&header.mbox_time));
    printf("Height of message list view: %.1f\n",header.listview_height);
    printf("Window Origin(x,y)=(%.f, %.f),  Size(w,h)=(%.f, %.f)\n",
		header.llx, header.lly, header.width, header.height);

    /* Now, dump records for each message */
    for(i=0; i<header.num_msgs; i++)
    {
	nread = fread(&mindex, (size_t)sizeof(MailMsgIndex), 1, fp);
        if(nread == 0)
	{
	    fprintf(stderr,"Premature EOF\n");
	    exit(3);
	}

	printf("---[%d]---\n", i+1);
	printf("Record Length: %ld\n", mindex.record_length);
	printf("Message Offset into mbox: %ld\n", mindex.message_offset);
	printf("Message Length (bytes): %ld\n", mindex.message_length);
	day = month = year = mindex.message_date;
	year >>= 9;
	month >>= 5; month &= 0xf;
	day &= 0x1f;
	printf("Message Date (Y-M-D): %d-%d-%d\n", year, month, day);
	printf("Status: Read( ), Last-Read(>), Unread(*), Deleted(d): [%c]\n", mindex.status);
	printf("NeXTmail(r) or regular ( ): [%c]\n",mindex.msgtype);
	printf("Mystery byte-1: %d (dec), [%c]\n", (int)(mindex.mystery[0]), mindex.mystery[0]);
	printf("Mystery byte-2: %d (dec), [%c]\n", (int)(mindex.mystery[1]), mindex.mystery[1]);
	printf("From: ");
	while((c=fgetc(fp)) != (int)'\0')
		putchar(c);
	printf("\nSubject: ");
	while((c=fgetc(fp)) != (int)'\0')
		putchar(c);
	printf("\nAttachment Dir: ");
	while((c=fgetc(fp)) != (int)'\0')
		putchar(c);
	printf("\n");
    }
    printf("---End of TOC---\n");
    fclose(fp);
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.