Mercurial > dovecot > original-hg > dovecot-1.2
changeset 2621:c6cc163344c3 HEAD
Added pop3_enable_last setting to enable deprecated LAST command.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 12 Sep 2004 17:26:58 +0300 |
parents | f4f793129402 |
children | 033d2fd1cd38 |
files | dovecot-example.conf src/master/master-settings.c src/master/master-settings.h src/pop3/client.c src/pop3/client.h src/pop3/commands.c src/pop3/common.h src/pop3/main.c |
diffstat | 8 files changed, 63 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/dovecot-example.conf Sun Sep 12 17:17:42 2004 +0300 +++ b/dovecot-example.conf Sun Sep 12 17:26:58 2004 +0300 @@ -382,6 +382,11 @@ # new/ to cur/, with mbox it doesn't write Status-header. #pop3_mails_keep_recent = no + # Support LAST command which exists in old POP3 specs, but has been removed + # from new ones. Some clients still wish to use this though. Enabling this + # makes RSET command clear all \Seen flags from messages. + #pop3_enable_last = no + # Support for dynamically loadable modules. #mail_use_modules = no #mail_modules = /usr/lib/dovecot/pop3
--- a/src/master/master-settings.c Sun Sep 12 17:17:42 2004 +0300 +++ b/src/master/master-settings.c Sun Sep 12 17:26:58 2004 +0300 @@ -120,6 +120,7 @@ /* pop3 */ DEF(SET_BOOL, pop3_mails_keep_recent), + DEF(SET_BOOL, pop3_enable_last), DEF(SET_STR, pop3_client_workarounds), { 0, NULL, 0 } @@ -285,6 +286,7 @@ /* pop3 */ MEMBER(pop3_mails_keep_recent) FALSE, + MEMBER(pop3_enable_last) FALSE, MEMBER(pop3_client_workarounds) NULL, /* .. */
--- a/src/master/master-settings.h Sun Sep 12 17:17:42 2004 +0300 +++ b/src/master/master-settings.h Sun Sep 12 17:26:58 2004 +0300 @@ -90,7 +90,8 @@ const char *imap_client_workarounds; /* pop3 */ - int pop3_mails_keep_recent; + int pop3_mails_keep_recent; + int pop3_enable_last; const char *pop3_client_workarounds; /* .. */
--- a/src/pop3/client.c Sun Sep 12 17:17:42 2004 +0300 +++ b/src/pop3/client.c Sun Sep 12 17:26:58 2004 +0300 @@ -71,7 +71,9 @@ return FALSE; } + client->last_seen = 0; client->messages_count = status.messages; + client->total_size = 0; client->deleted_size = 0; if (client->messages_count == 0) @@ -89,16 +91,20 @@ return FALSE; } - client->total_size = 0; - client->deleted_size = 0; failed = FALSE; while ((mail = mailbox_search_next(ctx)) != NULL) { uoff_t size = mail->get_virtual_size(mail); + const struct mail_full_flags *flags; - if (size == (uoff_t)-1) { + flags = mail->get_flags(mail); + + if (flags == NULL || size == (uoff_t)-1) { failed = TRUE; break; } + + if ((flags->flags & MAIL_SEEN) != 0) + client->last_seen = mail->seq; client->total_size += size; i_assert(mail->seq <= client->messages_count);
--- a/src/pop3/client.h Sun Sep 12 17:17:42 2004 +0300 +++ b/src/pop3/client.h Sun Sep 12 17:26:58 2004 +0300 @@ -26,6 +26,7 @@ uoff_t *message_sizes; uoff_t total_size; uoff_t deleted_size; + uint32_t last_seen; unsigned char *deleted_bitmask;
--- a/src/pop3/commands.c Sun Sep 12 17:17:42 2004 +0300 +++ b/src/pop3/commands.c Sun Sep 12 17:26:58 2004 +0300 @@ -166,6 +166,12 @@ return TRUE; } +static int cmd_last(struct client *client, const char *args __attr_unused__) +{ + client_send_line(client, "+OK %u", client->last_seen); + return TRUE; +} + static int cmd_noop(struct client *client, const char *args __attr_unused__) { client_send_line(client, "+OK"); @@ -380,12 +386,23 @@ if (get_msgnum(client, args, &msgnum) == NULL) return FALSE; + if (client->last_seen <= msgnum) + client->last_seen = msgnum+1; + fetch(client, msgnum, (uoff_t)-1); return TRUE; } static int cmd_rset(struct client *client, const char *args __attr_unused__) { + struct mailbox_transaction_context *t; + struct mail_search_context *search_ctx; + struct mail *mail; + struct mail_search_arg search_arg; + struct mail_full_flags seen_flag; + + client->last_seen = 0; + if (client->deleted) { client->deleted = FALSE; memset(client->deleted_bitmask, 0, MSGS_BITMASK_SIZE(client)); @@ -393,6 +410,26 @@ client->deleted_size = 0; } + if (enable_last_command) { + /* remove all \Seen flags */ + memset(&search_arg, 0, sizeof(search_arg)); + search_arg.type = SEARCH_ALL; + + memset(&seen_flag, 0, sizeof(seen_flag)); + seen_flag.flags = MAIL_SEEN; + + t = mailbox_transaction_begin(client->mailbox, FALSE); + search_ctx = mailbox_search_init(t, NULL, &search_arg, + NULL, 0, NULL); + while ((mail = mailbox_search_next(search_ctx)) != NULL) { + if (mail->update_flags(mail, &seen_flag, + MODIFY_REMOVE) < 0) + break; + } + (void)mailbox_search_deinit(search_ctx); + (void)mailbox_transaction_commit(t, 0); + } + client_send_line(client, "+OK"); return TRUE; } @@ -544,6 +581,8 @@ case 'L': if (strcmp(name, "LIST") == 0) return cmd_list(client, args); + if (strcmp(name, "LAST") == 0 && enable_last_command) + return cmd_last(client, args); break; case 'N': if (strcmp(name, "NOOP") == 0)
--- a/src/pop3/common.h Sun Sep 12 17:17:42 2004 +0300 +++ b/src/pop3/common.h Sun Sep 12 17:26:58 2004 +0300 @@ -10,6 +10,7 @@ extern struct ioloop *ioloop; extern enum client_workarounds client_workarounds; +extern int enable_last_command; extern void (*hook_mail_storage_created)(struct mail_storage **storage); extern void (*hook_client_created)(struct client **client);
--- a/src/pop3/main.c Sun Sep 12 17:17:42 2004 +0300 +++ b/src/pop3/main.c Sun Sep 12 17:26:58 2004 +0300 @@ -34,6 +34,7 @@ static struct module *modules; static char log_prefix[128]; /* syslog() needs this to be permanent */ enum client_workarounds client_workarounds = 0; +int enable_last_command = FALSE; static void sig_quit(int signo __attr_unused__) { @@ -128,7 +129,9 @@ if (mail != NULL) mail = t_strconcat("maildir:", mail, NULL); } - parse_workarounds(); + + parse_workarounds(); + enable_last_command = getenv("POP3_ENABLE_LAST") != NULL; storage = mail_storage_create_with_data(mail, getenv("USER")); if (storage == NULL) {