Added MaxMessages patch from Eivind Eklund <eivind@FreeBSD.org>.

config_defaults() can just use memcpy() instead of assigning each struct
member individually.

config_defaults() can be declared static
This commit is contained in:
Michael Elkins 2001-11-15 23:59:27 +00:00
parent 06a5edb452
commit e02975e888
6 changed files with 76 additions and 39 deletions

5
NEWS
View File

@ -1,3 +1,8 @@
[0.7]
Added `MaxMessages' configuration option to allow tracking of only the most
recently added message in the local mailbox.
[0.6] [0.6]
Added `Delete' configuration option to correspond to the -d command line Added `Delete' configuration option to correspond to the -d command line

View File

@ -33,28 +33,10 @@
config_t *boxes = 0; config_t *boxes = 0;
/* set defaults from the global configuration section */ /* set defaults from the global configuration section */
void static void
config_defaults (config_t * conf) config_defaults (config_t * conf)
{ {
conf->user = global.user; memcpy (conf, &global, sizeof (config_t));
conf->pass = global.pass;
conf->port = global.port;
conf->box = global.box;
conf->host = global.host;
conf->max_size = global.max_size;
conf->copy_deleted_to = global.copy_deleted_to;
conf->use_namespace = global.use_namespace;
conf->expunge = global.expunge;
conf->delete = global.delete;
conf->poll = global.poll;
#if HAVE_LIBSSL
conf->require_ssl = global.require_ssl;
conf->use_imaps = global.use_imaps;
conf->cert_file = global.cert_file;
conf->use_sslv2 = global.use_sslv2;
conf->use_sslv3 = global.use_sslv3;
conf->use_tlsv1 = global.use_tlsv1;
#endif
} }
#ifndef HAVE_STRNDUP #ifndef HAVE_STRNDUP
@ -231,6 +213,13 @@ load_config (const char *where)
else else
global.max_size = atol (val); global.max_size = atol (val);
} }
else if (!strcasecmp ("MaxMessages", cmd))
{
if (*cur)
(*cur)->max_messages = atol (val);
else
global.max_messages = atol (val);
}
else if (!strcasecmp ("UseNamespace", cmd)) else if (!strcasecmp ("UseNamespace", cmd))
{ {
if (*cur) if (*cur)
@ -259,15 +248,6 @@ load_config (const char *where)
else else
global.delete = (strcasecmp (val, "yes") == 0); global.delete = (strcasecmp (val, "yes") == 0);
} }
#if 0
else if (!strcasecmp ("Poll", cmd))
{
if (*cur)
(*cur)->poll = atoi (val);
else
global.poll = atoi (val);
}
#endif
#if HAVE_LIBSSL #if HAVE_LIBSSL
else if (!strcasecmp ("CertificateFile", cmd)) else if (!strcasecmp ("CertificateFile", cmd))
{ {
@ -313,7 +293,7 @@ load_config (const char *where)
} }
#endif #endif
else if (buf[0]) else if (buf[0])
printf ("%s:%d:unknown command:%s\n", path, line, cmd); printf ("%s:%d:unknown keyword:%s\n", path, line, cmd);
} }
fclose (fp); fclose (fp);
} }

20
isync.1
View File

@ -189,6 +189,26 @@ This directive is only meaningful the in
section (see below). section (see below).
.. ..
.TP .TP
\fBMaxMessages\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.)
The messages that were the first to arrive in the mailbox (independent of the
actual date of the message) will automatically be deleted if you tell
pass
.B isync
the delete (-d, --delete) flag.
Messages that are flagged (marked as important) will not be automatically
deleted.
If
.I count
is 0, the maximum number of messages is
.B unlimited (Default: 0).
..
.TP
\fBMaxSize\fR \fIbytes\fR \fBMaxSize\fR \fIbytes\fR
Sets a threshold for the maximum message size (in bytes) for which Sets a threshold for the maximum message size (in bytes) for which
.B isync .B isync

View File

@ -57,7 +57,7 @@ struct config
char *box; char *box;
char *alias; char *alias;
char *copy_deleted_to; char *copy_deleted_to;
int poll; /* how often to poll (in seconds) 0 = OFF */ unsigned int max_messages;
off_t max_size; off_t max_size;
config_t *next; config_t *next;
#if HAVE_LIBSSL #if HAVE_LIBSSL
@ -72,6 +72,7 @@ struct config
unsigned int use_namespace:1; unsigned int use_namespace:1;
unsigned int expunge:1; unsigned int expunge:1;
unsigned int delete:1; unsigned int delete:1;
unsigned int wanted:1;
}; };
/* struct representing local mailbox file */ /* struct representing local mailbox file */
@ -106,6 +107,7 @@ struct message
unsigned int new:1; /* message is in the new/ subdir */ unsigned int new:1; /* message is in the new/ subdir */
unsigned int changed:1; /* flags changed */ unsigned int changed:1; /* flags changed */
unsigned int dead:1; /* message doesn't exist on the server */ unsigned int dead:1; /* message doesn't exist on the server */
unsigned int wanted:1; /* when using MaxMessages, keep this message */
}; };
/* struct used for parsing IMAP lists */ /* struct used for parsing IMAP lists */
@ -166,9 +168,8 @@ char *cram (const char *, const char *, const char *);
char *next_arg (char **); 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 *); void load_config (const char *);
char * expand_strdup (const char *s); char * expand_strdup (const char *s);
config_t *find_box (const char *); config_t *find_box (const char *);

3
main.c
View File

@ -151,6 +151,7 @@ main (int argc, char **argv)
global.user = strdup (pw->pw_name); global.user = strdup (pw->pw_name);
global.maildir = strdup (pw->pw_dir); global.maildir = strdup (pw->pw_dir);
global.max_size = 0; global.max_size = 0;
global.max_messages = 0;
global.use_namespace = 1; global.use_namespace = 1;
#if HAVE_LIBSSL #if HAVE_LIBSSL
/* this will probably annoy people, but its the best default just in /* this will probably annoy people, but its the best default just in
@ -291,7 +292,7 @@ main (int argc, char **argv)
i |= SYNC_QUIET; i |= SYNC_QUIET;
i |= (delete || box->delete) ? SYNC_DELETE : 0; i |= (delete || box->delete) ? SYNC_DELETE : 0;
i |= (expunge || box->expunge) ? SYNC_EXPUNGE : 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_messages))
exit (1); exit (1);
if (!fast) if (!fast)

38
sync.c
View File

@ -42,7 +42,7 @@ find_msg (message_t * list, unsigned int uid)
int int
sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags, 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 *cur;
message_t *tmp; message_t *tmp;
@ -54,6 +54,7 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
int ret; int ret;
int fetched = 0; int fetched = 0;
int upload = 0; int upload = 0;
unsigned int msg_count;
if (mbox->uidvalidity > 0) if (mbox->uidvalidity > 0)
{ {
@ -113,7 +114,8 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
continue; /* not fatal */ continue; /* not fatal */
} }
if (imap->box->max_size > 0 && sb.st_size > imap->box->max_size) if (imap->box->max_size > 0
&& sb.st_size > imap->box->max_size)
{ {
if ((flags & SYNC_QUIET) == 0) if ((flags & SYNC_QUIET) == 0)
printf printf
@ -214,13 +216,41 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
if (upload) if (upload)
fprintf (stdout, " %d messages.\n", upload); fprintf (stdout, " %d messages.\n", upload);
if ((flags & SYNC_QUIET) == 0) if ((flags & SYNC_QUIET) == 0)
{ {
fputs ("Fetching new messages", stdout); fputs ("Fetching new messages", stdout);
fflush (stdout); fflush (stdout);
} }
for (cur = imap->msgs; cur; cur = cur->next)
if (max_msgs == 0)
max_msgs = UINT_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->wanted = 1;
}
for (cur = mbox->msgs; cur; cur = cur->next)
{
if (!cur->wanted && !(cur->flags & D_FLAGGED))
{
cur->flags |= D_DELETED;
cur->dead = 1;
mbox->deleted++;
}
}
}
for (cur = imap->msgs, msg_count = 0;
cur && msg_count < max_msgs; cur = cur->next, msg_count++)
{ {
if (!cur->processed) if (!cur->processed)
{ {