--- config.c.orig Wed Feb 28 02:02:50 2001 +++ config.c Sun Jul 8 14:55:06 2001 @@ -39,6 +39,7 @@ conf->box = global.box; conf->host = global.host; conf->max_size = global.max_size; + conf->max_msgs = global.max_msgs; conf->copy_deleted_to = global.copy_deleted_to; conf->use_namespace = global.use_namespace; conf->expunge = global.expunge; @@ -205,6 +206,13 @@ (*cur)->max_size = atol (val); else global.max_size = atol (val); + } + else if (!strncasecmp ("maxmsgs", cmd, 7)) + { + if (*cur) + (*cur)->max_msgs = atol (val); + else + global.max_msgs = atol (val); } else if (!strncasecmp ("UseNamespace", cmd, 12)) { --- isync.1.orig Sun Jul 8 14:55:14 2001 +++ isync.1 Sun Jul 8 14:55:19 2001 @@ -181,6 +181,23 @@ section (see below). .. .TP +\fBMaxMsgs\fR \fIcount\fR +Sets the number of messages +.B isync +should keep in a mailbox. +This is useful for mailboxes where you keep a complete archive on the +server, but want to mirror only the last messages (for instance, for mailing +lists.) +Old messages that are not flagged will automatically be deleted if you tell +pass +.B isync +the delete (-d, --delete) flag. +If +.I count +is 0, the maximum number of messages is +.B unlimited. +.. +.TP \fBMaxSize\fR \fIbytes\fR Sets a threshold for the maximum message size (in bytes) for which .B isync --- isync.h.orig Fri Jan 26 21:21:27 2001 +++ isync.h Sun Jul 8 14:55:06 2001 @@ -58,6 +58,7 @@ char *alias; char *copy_deleted_to; off_t max_size; + unsigned int max_msgs; config_t *next; #if HAVE_LIBSSL char *cert_file; @@ -92,6 +93,8 @@ #define D_RECENT (1<<4) #define D_DRAFT (1<<5) #define D_MAX 6 +/* Internal flags */ +#define D_WANTED (1<<31) struct message { @@ -162,7 +165,7 @@ char *next_arg (char **); -int sync_mailbox (mailbox_t *, imap_t *, int, unsigned int); +int sync_mailbox (mailbox_t *, imap_t *, int, unsigned int, unsigned int); void config_defaults (config_t *); void load_config (const char *); --- main.c.orig Wed Feb 14 21:46:41 2001 +++ main.c Sun Jul 8 14:55:57 2001 @@ -146,6 +146,7 @@ global.user = strdup (pw->pw_name); global.maildir = strdup (pw->pw_dir); global.max_size = 0; + global.max_msgs = 0; global.use_namespace = 1; #if HAVE_LIBSSL /* this will probably annoy people, but its the best default just in @@ -265,7 +266,7 @@ puts ("Synchronizing"); i = delete ? SYNC_DELETE : 0; i |= (expunge || box->expunge) ? SYNC_EXPUNGE : 0; - if (sync_mailbox (mail, imap, i, box->max_size)) + if (sync_mailbox (mail, imap, i, box->max_size, box->max_msgs)) exit (1); if (!fast) --- sync.c.orig Wed Feb 14 21:46:41 2001 +++ sync.c Sun Jul 8 14:58:44 2001 @@ -42,7 +42,7 @@ int sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags, - unsigned int max_size) + unsigned int max_size, unsigned int max_msgs) { message_t *cur; message_t *tmp; @@ -53,6 +53,7 @@ int fd; int ret; int fetched = 0; + unsigned int msg_count; if (mbox->uidvalidity > 0) { @@ -107,8 +108,8 @@ if (sb.st_size > imap->box->max_size) { printf - ("Warning, local message is too large (%ld), skipping...\n", - sb.st_size); + ("Warning, local message is too large (%lu), skipping...\n", + (unsigned long)sb.st_size); continue; } fd = open (path, O_RDONLY); @@ -203,9 +204,38 @@ } } + if (max_msgs == 0) { + /* No limits */ + max_msgs = ULONG_MAX; + } else { + /* expire messages in excess of the max-count for this mailbox. + * flagged mails are considered sacrosant and not deleted. + * we have already done the upload to the server, so messing with + * the flags variable do not have remote side effects. + */ + for (cur = imap->msgs, msg_count = 0; + cur && msg_count < max_msgs; + cur = cur->next, msg_count++) + { + tmp = find_msg (mbox->msgs, cur->uid); + if (tmp) + tmp->flags |= D_WANTED; + } + for (cur = mbox->msgs; cur; cur = cur->next) + { + if (!(cur->flags & D_WANTED) && !(cur->flags & D_FLAGGED)) { + cur->flags |= D_DELETED; + cur->dead = 1; + mbox->deleted++; + } + } + } + fputs ("Fetching new messages", stdout); fflush (stdout); - for (cur = imap->msgs; cur; cur = cur->next) + for (cur = imap->msgs, msg_count = 0; + cur && msg_count < max_msgs; + cur = cur->next, msg_count++) { if (!cur->processed) {