Mercurial > dovecot > original-hg > dovecot-1.2
changeset 9348:3eacb6bbd227 HEAD
Added pop3_save_uidl setting.
When UIDLs are sent to client, save them to dovecot-uidlist. This allows
changing pop3_uidl_format without messages getting re-downloaded. It's also
useful with virtual POP3 INBOX when UIDLs are based on IMAP UIDs that may
not be as stable as in non-virtual INBOX.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 31 Aug 2009 18:53:17 -0400 |
parents | a37fa30b0072 |
children | a5d530edfafe |
files | dovecot-example.conf src/lib-storage/index/cydir/cydir-mail.c src/lib-storage/index/dbox/dbox-mail.c src/lib-storage/index/maildir/maildir-mail.c src/lib-storage/index/mbox/mbox-mail.c src/lib-storage/index/raw/raw-mail.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.h src/lib-storage/mail.c src/master/mail-process.c src/master/master-settings-defs.c src/master/master-settings.c src/master/master-settings.h src/plugins/virtual/virtual-mail.c src/pop3/commands.c src/pop3/common.h src/pop3/main.c |
diffstat | 17 files changed, 60 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/dovecot-example.conf Fri Aug 28 16:50:20 2009 -0400 +++ b/dovecot-example.conf Mon Aug 31 18:53:17 2009 -0400 @@ -659,6 +659,10 @@ # #pop3_uidl_format = %08Xu%08Xv + # Permanently save UIDLs sent to POP3 clients, so pop3_uidl_format changes + # won't change those UIDLs. Currently this works only with Maildir. + #pop3_save_uidl = no + # POP3 logout format string: # %i - total number of bytes read from client # %o - total number of bytes sent to client
--- a/src/lib-storage/index/cydir/cydir-mail.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/lib-storage/index/cydir/cydir-mail.c Mon Aug 31 18:53:17 2009 -0400 @@ -142,6 +142,7 @@ index_mail_get_special, index_mail_update_flags, index_mail_update_keywords, + NULL, index_mail_expunge, index_mail_set_cache_corrupted, index_mail_get_index_mail
--- a/src/lib-storage/index/dbox/dbox-mail.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/lib-storage/index/dbox/dbox-mail.c Mon Aug 31 18:53:17 2009 -0400 @@ -304,6 +304,7 @@ dbox_mail_get_special, index_mail_update_flags, index_mail_update_keywords, + NULL, index_mail_expunge, index_mail_set_cache_corrupted, index_mail_get_index_mail
--- a/src/lib-storage/index/maildir/maildir-mail.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/lib-storage/index/maildir/maildir-mail.c Mon Aug 31 18:53:17 2009 -0400 @@ -491,6 +491,23 @@ return index_mail_init_stream(mail, hdr_size, body_size, stream_r); } +static void maildir_update_pop3_uidl(struct mail *_mail, const char *uidl) +{ + struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box; + const char *fname; + + if (maildir_mail_get_special(_mail, MAIL_FETCH_UIDL_FILE_NAME, + &fname) == 0 && + strcmp(uidl, fname) == 0) { + /* special case optimization: empty UIDL means the same + as base filename */ + uidl = ""; + } + + maildir_uidlist_set_ext(mbox->uidlist, _mail->uid, + MAILDIR_UIDLIST_REC_EXT_POP3_UIDL, uidl); +} + static void maildir_mail_set_cache_corrupted(struct mail *_mail, enum mail_fetch_field field) { @@ -549,6 +566,7 @@ maildir_mail_get_special, index_mail_update_flags, index_mail_update_keywords, + maildir_update_pop3_uidl, index_mail_expunge, maildir_mail_set_cache_corrupted, index_mail_get_index_mail
--- a/src/lib-storage/index/mbox/mbox-mail.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/lib-storage/index/mbox/mbox-mail.c Mon Aug 31 18:53:17 2009 -0400 @@ -363,6 +363,7 @@ mbox_mail_get_special, index_mail_update_flags, index_mail_update_keywords, + NULL, index_mail_expunge, index_mail_set_cache_corrupted, index_mail_get_index_mail
--- a/src/lib-storage/index/raw/raw-mail.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/lib-storage/index/raw/raw-mail.c Mon Aug 31 18:53:17 2009 -0400 @@ -134,6 +134,7 @@ raw_mail_get_special, index_mail_update_flags, index_mail_update_keywords, + NULL, index_mail_expunge, index_mail_set_cache_corrupted, index_mail_get_index_mail
--- a/src/lib-storage/mail-storage-private.h Fri Aug 28 16:50:20 2009 -0400 +++ b/src/lib-storage/mail-storage-private.h Mon Aug 31 18:53:17 2009 -0400 @@ -264,6 +264,7 @@ enum mail_flags flags); void (*update_keywords)(struct mail *mail, enum modify_type modify_type, struct mail_keywords *keywords); + void (*update_pop3_uidl)(struct mail *mail, const char *uidl); void (*expunge)(struct mail *mail); void (*set_cache_corrupted)(struct mail *mail, enum mail_fetch_field field);
--- a/src/lib-storage/mail-storage.h Fri Aug 28 16:50:20 2009 -0400 +++ b/src/lib-storage/mail-storage.h Mon Aug 31 18:53:17 2009 -0400 @@ -623,6 +623,7 @@ /* Update message keywords. */ void mail_update_keywords(struct mail *mail, enum modify_type modify_type, struct mail_keywords *keywords); +void mail_update_pop3_uidl(struct mail *mail, const char *uidl); /* Expunge this message. Sequence numbers don't change until commit. */ void mail_expunge(struct mail *mail);
--- a/src/lib-storage/mail.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/lib-storage/mail.c Mon Aug 31 18:53:17 2009 -0400 @@ -192,6 +192,14 @@ p->v.update_keywords(mail, modify_type, keywords); } +void mail_update_pop3_uidl(struct mail *mail, const char *uidl) +{ + struct mail_private *p = (struct mail_private *)mail; + + if (p->v.update_pop3_uidl != NULL) + p->v.update_pop3_uidl(mail, uidl); +} + void mail_expunge(struct mail *mail) { struct mail_private *p = (struct mail_private *)mail;
--- a/src/master/mail-process.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/master/mail-process.c Mon Aug 31 18:53:17 2009 -0400 @@ -359,6 +359,8 @@ env_put("POP3_NO_FLAG_UPDATES=1"); if (set->pop3_reuse_xuidl) env_put("POP3_REUSE_XUIDL=1"); + if (set->pop3_save_uidl) + env_put("POP3_SAVE_UIDL=1"); if (set->pop3_enable_last) env_put("POP3_ENABLE_LAST=1"); if (set->pop3_lock_session)
--- a/src/master/master-settings-defs.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/master/master-settings-defs.c Mon Aug 31 18:53:17 2009 -0400 @@ -121,6 +121,7 @@ DEF_BOOL(pop3_no_flag_updates), DEF_BOOL(pop3_enable_last), DEF_BOOL(pop3_reuse_xuidl), + DEF_BOOL(pop3_save_uidl), DEF_BOOL(pop3_lock_session), DEF_STR(pop3_uidl_format), DEF_STR(pop3_client_workarounds),
--- a/src/master/master-settings.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/master/master-settings.c Mon Aug 31 18:53:17 2009 -0400 @@ -287,6 +287,7 @@ MEMBER(pop3_no_flag_updates) FALSE, MEMBER(pop3_enable_last) FALSE, MEMBER(pop3_reuse_xuidl) FALSE, + MEMBER(pop3_save_uidl) FALSE, MEMBER(pop3_lock_session) FALSE, MEMBER(pop3_uidl_format) "%08Xu%08Xv", MEMBER(pop3_client_workarounds) "",
--- a/src/master/master-settings.h Fri Aug 28 16:50:20 2009 -0400 +++ b/src/master/master-settings.h Mon Aug 31 18:53:17 2009 -0400 @@ -133,6 +133,7 @@ bool pop3_no_flag_updates; bool pop3_enable_last; bool pop3_reuse_xuidl; + bool pop3_save_uidl; bool pop3_lock_session; const char *pop3_uidl_format; const char *pop3_client_workarounds;
--- a/src/plugins/virtual/virtual-mail.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/plugins/virtual/virtual-mail.c Mon Aug 31 18:53:17 2009 -0400 @@ -343,6 +343,13 @@ return 0; } +static void virtual_mail_update_pop3_uidl(struct mail *mail, const char *uidl) +{ + struct virtual_mail *vmail = (struct virtual_mail *)mail; + + mail_update_pop3_uidl(vmail->backend_mail, uidl); +} + static void virtual_mail_expunge(struct mail *mail) { struct virtual_mail *vmail = (struct virtual_mail *)mail; @@ -392,6 +399,7 @@ virtual_mail_get_special, index_mail_update_flags, index_mail_update_keywords, + virtual_mail_update_pop3_uidl, virtual_mail_expunge, virtual_mail_set_cache_corrupted, virtual_mail_get_index_mail
--- a/src/pop3/commands.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/pop3/commands.c Mon Aug 31 18:53:17 2009 -0400 @@ -519,7 +519,7 @@ unsigned int message; }; -static void pop3_get_uid(struct cmd_uidl_context *ctx, +static bool pop3_get_uid(struct cmd_uidl_context *ctx, struct var_expand_table *tab, string_t *str) { char uid_str[MAX_INT_STRLEN]; @@ -528,13 +528,13 @@ if (mail_get_special(ctx->mail, MAIL_FETCH_UIDL_BACKEND, &uidl) == 0 && *uidl != '\0') { str_append(str, uidl); - return; + return TRUE; } if (reuse_xuidl && mail_get_first_header(ctx->mail, "X-UIDL", &uidl) > 0) { str_append(str, uidl); - return; + return FALSE; } if ((uidl_keymask & UIDL_UID) != 0) { @@ -560,6 +560,7 @@ } } var_expand(str, uidl_format, tab); + return FALSE; } static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx) @@ -574,6 +575,7 @@ struct var_expand_table *tab; string_t *str; int ret; + unsigned int uidl_pos; bool found = FALSE; tab = t_malloc(sizeof(static_tab)); @@ -593,7 +595,9 @@ str_truncate(str, 0); str_printfa(str, ctx->message == 0 ? "%u " : "+OK %u ", ctx->mail->seq); - pop3_get_uid(ctx, tab, str); + uidl_pos = str_len(str); + if (!pop3_get_uid(ctx, tab, str) && save_uidl) + mail_update_pop3_uidl(ctx->mail, str_c(str) + uidl_pos); ret = client_send_line(client, "%s", str_c(str)); if (ret < 0)
--- a/src/pop3/common.h Fri Aug 28 16:50:20 2009 -0400 +++ b/src/pop3/common.h Mon Aug 31 18:53:17 2009 -0400 @@ -19,6 +19,7 @@ extern struct ioloop *ioloop; extern enum client_workarounds client_workarounds; extern bool enable_last_command, no_flag_updates, reuse_xuidl, lock_session; +extern bool save_uidl; extern const char *uidl_format, *logout_format; extern enum uidl_keys uidl_keymask;
--- a/src/pop3/main.c Fri Aug 28 16:50:20 2009 -0400 +++ b/src/pop3/main.c Mon Aug 31 18:53:17 2009 -0400 @@ -48,6 +48,7 @@ bool enable_last_command = FALSE; bool no_flag_updates = FALSE; bool reuse_xuidl = FALSE; +bool save_uidl = FALSE; bool lock_session = FALSE; const char *uidl_format, *logout_format; enum uidl_keys uidl_keymask; @@ -235,6 +236,7 @@ enable_last_command = getenv("POP3_ENABLE_LAST") != NULL; no_flag_updates = getenv("POP3_NO_FLAG_UPDATES") != NULL; reuse_xuidl = getenv("POP3_REUSE_XUIDL") != NULL; + save_uidl = getenv("POP3_SAVE_UIDL") != NULL; lock_session = getenv("POP3_LOCK_SESSION") != NULL; uidl_format = getenv("POP3_UIDL_FORMAT");