Subject: Scanning filtered mail and making a summary

From: [email-masked] (Marko Hotti)
Date: 20 Aug 1994 18:21:41 GMT

I'd like to run a script in the beginning of every session which
scans specified folders in ~/Mail -directory for unread mail. I'm
using 'filter' in my .forward file to redirect incoming mail from
mailing lists to respective folders. I *do know* that I can use
'filter -s' to get a filter activity summary but the output is not
what I'm lookin for. I'd like to get information like this:

STATUS OF INCOMING FOLDERS:
===========================

Folder name:	Total:	Unread:
-------------------------------
mailing-list1	20	3
mailing-list2	35	6
mailing-list3	5	0
...etc.

You got the idea? The output does not have to be exactly like this
but the information I need should be in tiny column format since there
are about 20 mailing list folders.

I guess this could be achieved by using perl or something. I wonder
if there are ready packages for doing these kind of summaries????

	Thanx! -=Marko=-

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Marko Hotti <[email-masked]>		University of Oulu
						Faculty of Medicine

---

From: Patrick Heck <[email-masked]>
Date: Sat, 20 Aug 1994 16:59:55 +0100

> STATUS OF INCOMING FOLDERS:

A couple of months ago I wrote a quick-and-dirty C program that should 
work in most Unix environments.  I've included it and a man page as 
attachments.  It doesn't print exactly what you are looking for, but it
may be close enough.  It checks for unread mail in mail folders and 
prints out lines as in

	Unread mail in /usr/spool/mail/heck
	Unread mail in Mail/Chatter
	...

Nothing is printed out for folders that do not have any unread mail.  It
should be fairly easy to modify the code to print other relevant
information. 

Pat Heck                           University of Evansville 
[email-masked]        Office: (812) 479-2193   Home: (812) 477-9873
#include <stdio.h>
#include <string.h>
#include <pwd.h>

#define TRUE   1
#define FALSE  0

FILE *fp_curfolder;    /* current mail folder being checked */
FILE *fp_mailcheck;

char logname[100];
struct passwd *pwentry;

int main(int argc, char **argv)
{
    char logname[15];
    int i;
    int num_unread_folders = -1;
    char folder[20][50];
    char orig_name[1000];
    char curfolder[1000];
    char mailcheck[1000];      
    char line[1000];

    if (cuserid(logname)==NULL) {
	fprintf(stderr,"%s: Can't determine who you are.",argv[0]);
	return 1;
    }
    if ((pwentry=getpwnam(logname))==NULL) {
	fprintf(stderr,"%s: Can't access /etc/passwd information.",argv[0]);
	return 1;
    }

    /** create file name for .mailcheck */
    strcat(strcpy(mailcheck,pwentry->pw_dir),"/.mailcheck");
    if ((fp_mailcheck = fopen(mailcheck,"r"))==NULL) {
	fprintf(stderr,"%s: Unable to access '.mailcheck' file.\n",argv[0]);
	return 1;
    }

    while (!feof(fp_mailcheck))
    {
	curfolder[0] = '\0';
	fgets(curfolder, 100, fp_mailcheck);
	if (curfolder[0] == '\0')
	    continue;
	/* get rid of newline character (if exists) */
	for (i=0; curfolder[i] != '\0'; i++)
	{
	    if (curfolder[i] == '\n')
		curfolder[i] = '\0';
	}
	strcpy(orig_name,curfolder);  /* save name for message */
	if (curfolder[0] != '/')  /* then need to prepend home dir */
	{
	    strcpy(line,curfolder);
	    strcat(strcat(strcpy(curfolder,pwentry->pw_dir),"/"),line);
	}
/*	printf("Checking %s\n",curfolder); */
	if ((fp_curfolder = fopen(curfolder,"r")) != NULL)
	{
	    if (unreadmail(fp_curfolder))
	    {
		num_unread_folders++;
		strcpy(folder[num_unread_folders],orig_name);
	    }
	    fclose(fp_curfolder);
	}
    }
    if (num_unread_folders > -1)
    {
	for (i=0; i<=num_unread_folders; i++)
	{
	    printf("Unread mail in %s\n",folder[i]);
	}
    }
}

int unreadmail(FILE *fp_curfolder)
{
    char line[1001];
    while (!feof(fp_curfolder))
    {
	fgets(line, 1000, fp_curfolder);
	if (!strncmp(line,"From ", 5))
	{
/*	    printf("%s",line); */
	    while (1)
	    {
		fgets(line, 1000, fp_curfolder);
/*		printf("%s",line); */
		if (!strcmp(line,"\n"))
		    return TRUE;
		if (!strncmp(line,"Status: R", 9))
		    break;
		if (!strncmp(line,"Status: ", 8))
		    return TRUE;
	    }
	}
    }
    return FALSE;
}
.TH 1L "mailcheck" "6-11-1994" "U. of Evansville"
.SH NAME
mailcheck - Checks multiple folders for unread mail
.SH SYNOPSIS
.B mailcheck
.br
.SH DESCRIPTION
.I mailcheck
checks user specified mail folders for the presence of unread mail.
Unread mail does not necessarily indicate new mail. 
.I mailcheck
was designed to work with
.I pine
and is not guaranteed to work with any other mail user agent.

.I mailcheck
expects that the file
.I .mailcheck
resides in the user's home directory and contains
the name of mail folders that should be checked.  The folder names
are one to a line.  If the name of the folder does not contain
the full path (eg, /usr/spool/mail/heck), the user's home directory
will be prepended to the name of the folder (eg, Mail/stuff
will cause ~/Mail/stuff to be checked).  
.SH FILES
~/.mailcheck
.SH AUTHOR
Patrick Heck, University of Evansville
.SH SEE\ ALSO
 pine(1)
 procmail(1)
.SH BUGS
Does not understand ~/ notation.  Will not work with more than 20 folders.
Will not work when complete path to folder is more than 50 characters.
All bugs due to the quick-and-dirty nature of this program (ie, I needed
it done in 30 minutes and it took me 45 as it is).
.SH BUG REPORTS TO
[email-masked]
.SH COPYRIGHTS
.ps 18
\fB\(co\fR\s12 Ain't no stinkin' copyright