On Thu, 14 Dec 2006 11:20:57 -0700, "Matthew B. Brookover"
<[EMAIL PROTECTED]> wrote:
>Please post it. Does it use the uw-imap c-client library?
>I need to hack something similar that will work with mix.
Since it uses c-client, it works with any uw-imap mailbox format.
#
# At the same level as the c-client directory, create a "mailpurge"
# directory, copy Makefile and mailpurge.c into it, and from there,
# run make.
#
C = ../c-client
CCLIENTLIB = $C/c-client.a
CC = `cat $C/CCTYPE`
CFLAGS = -I$C `cat $C/CFLAGS` -Wall
LDFLAGS = $(CCLIENTLIB) `cat $C/LDFLAGS`
mailpurge: $(CCLIENTLIB) mailpurge.o
$(CC) $(CFLAGS) -o mailpurge mailpurge.o $(LDFLAGS)
mailpurge.o: $C/mail.h $C/misc.h $C/osdep.h
$(CCLIENTLIB):
cd $C; make
clean:
rm -f *.o mailpurge
/*
* Expire and purge old messages
*
* Usage: [program] mailbox days
*
* The days parameter means how many days of mail to keep, in whole days,
* i.e., a value of 1 will keep today's mail and yesterday's too, because
* today can never be a whole day. At least not until tomorrow, and then
* it's gone.
*
* Copyright 2001-2006 John Kelly
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
#include "mail.h"
#include "osdep.h"
#include "misc.h"
#include "linkage.h"
int debug = NIL;
int verbose = NIL;
int critical = NIL;
int main (int argc, char *argv[]) {
char *pgm;
time_t ts;
struct tm tl;
long int days_to_keep;
unsigned long int ic, ix, pc;
MAILSTREAM *ms;
SEARCHPGM *sp;
char tmp[MAILTMPLEN];
pc = 0;
ms = NULL;
sp = NULL;
#include "linkage.c"
if (argc != 3) {
pgm = strrchr (argv[0], '/');
if (pgm == NULL) pgm = argv[0]; else pgm++;
printf ("Usage: %s mailbox days\n", pgm);
return (1);
}
ic = sscanf (argv[2], "%ld", &days_to_keep);
if (ic != 1 || days_to_keep < 1 || days_to_keep > 7000) {
printf ("Input: days must range from 1 to 7000\n");
return (1);
}
if (!(ms = mail_open (NULL, argv[1], NIL)))
return (1);
if (!ms->nmsgs) {
if (verbose)
printf ("%s is empty\n", ms->mailbox);
mail_close (ms);
return (0);
}
sp = mail_newsearchpgm ();
if (sp == NULL) {
printf ("Not enough memory for search program\n");
mail_close (ms);
return (1);
}
if (verbose)
printf ("%s has %lu message(s)\n", ms->mailbox, ms->nmsgs);
ts = time (NULL);
ts -= days_to_keep * 86400;
tl = *(localtime (&ts));
sp->before = ((((tl.tm_year + 1900) - BASEYEAR) << 9) | ((tl.tm_mon +
1) << 5) | tl.tm_mday);
mail_search_full (ms, NULL, sp, SE_NOPREFETCH);
mail_free_searchpgm (&sp);
for (ix = 1; ix <= ms->nmsgs; ix++) {
if (mail_elt (ms, ix)->searched) {
pc++;
snprintf (tmp, sizeof tmp, "%lu", ix);
mail_setflag (ms, tmp, "\\Deleted");
}
}
if (verbose)
printf ("%s has %lu message(s) to expunge\n", ms->mailbox, pc);
mail_expunge (ms);
mail_close (ms);
return (0);
}
void mm_searched (MAILSTREAM *stream, unsigned long number)
{
if (verbose && debug)
printf ("Message %lu flagged for delete\n", number);
}
void mm_exists (MAILSTREAM *stream, unsigned long number)
{
}
void mm_expunged (MAILSTREAM *stream, unsigned long number)
{
}
void mm_flags (MAILSTREAM *stream, unsigned long number)
{
}
void mm_notify (MAILSTREAM *stream, char *string, long errflg)
{
mm_log (string, errflg);
}
void mm_list (MAILSTREAM *stream, int delimiter, char *mailbox, long attributes)
{
}
void mm_lsub (MAILSTREAM *stream, int delimiter, char *mailbox, long attributes)
{
}
void mm_status (MAILSTREAM *stream, char *mailbox, MAILSTATUS *status)
{
}
void mm_log (char *string, long errflg)
{
switch ((short) errflg) {
case BYE:
case NIL:
if (verbose) printf ("[%s]\n", string);
break;
case PARSE:
break;
case WARN:
fprintf (stderr, "%%%s\n", string);
break;
case ERROR:
default:
fprintf (stderr, "?%s\n", string);
break;
}
}
void mm_dlog (char *string)
{
fprintf (stderr, "%s\n",string);
}
void mm_critical (MAILSTREAM *stream)
{
critical = T;
}
void mm_nocritical (MAILSTREAM *stream)
{
critical = NIL;
}
long mm_diskerror (MAILSTREAM *stream, long errcode, long serious)
{
kill (getpid (), SIGSTOP);
return (1);
}
void mm_fatal (char *string)
{
fprintf (stderr,"?%s\n", string);
}
void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
{
}
_______________________________________________
Imap-uw mailing list
[email protected]
https://mailman1.u.washington.edu/mailman/listinfo/imap-uw