off the top of my head, can't you first check for a ctime older than 30
days..and then of those, to check whether it was read,
check that the atime is newer than the ctime?
ctime being creation time
atime being last access time


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

#define MAILSPOOL       "/var/spool/mail"
#define DAYS_OLD        30

int main(void) {
char filename[256];
time_t tm;
struct stat fileinfo;
struct dirent *dp;
DIR *dirp;


dirp=opendir(MAILSPOOL);
if (dirp == NULL) {
        printf("Can't open MAILSPOOL!\n");
        exit(0);
        }
while ((dp = readdir(dirp)) != NULL) {
        if (dp->d_name[0]=='.') continue;
        snprintf(filename,256,"%s/%s",MAILSPOOL,dp->d_name);
        if (stat(filename,&fileinfo) == -1) continue;
        if (!S_ISREG(fileinfo.st_mode)) continue;
        time(&tm);
        if ( ((tm-(86400*DAYS_OLD)) >= fileinfo.st_ctime) && 
             (fileinfo.st_atime > fileinfo.st_ctime)) {
                unlink(filename);
        }
} /* while */
closedir(dirp);
return 1;
}


-Tony
.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-.
Anthony J. Biacco                       Network Administrator/Engineer
[EMAIL PROTECTED]       Intergrafix Internet Services

    "Dream as if you'll live forever, live as if you'll die today"
http://www.asteroid-b612.org                http://www.intergrafix.net
.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-.

On Thu, 28 Jun 2001, Tim Olson wrote:

> Boy do I ever 2nd this motion. ;)
> Maybe we should add it to Qpoppers wish list?
> I suppose someone's going to tell us next that it's a procmail issue.
> 
> Tim Olson
> 
> Daniel Senie wrote:
> > 
> > I'd like to find some tools to go through mailboxes (mbox format, in
> > /var/spool/mail) and delete anything that's been read, and which is more
> > than 30 days old. I've got some users who just won't set the "delete from
> > server" switch, and it's time to take action. I really don't want to do
> > quotas enforcement at this point, though.
> > 
> > Anyone know of tools to do this? I'd love it if Qpopper had an option for
> > this and would just perform the trim while it was doing its processing, but
> > the only switch I find there is auto-delete.
> > 
> > An alternative would be to add auto-delete on a per-user basis, targetting
> > the abusive users only.
> > 
> > Any thoughts or pointers to tools would be greatly appreciated.
> > 
> > Dan
> > -----------------------------------------------------------------
> > Daniel Senie                                        [EMAIL PROTECTED]
> > Amaranth Networks Inc.                    http://www.amaranth.com
> 

Reply via email to