From: Timo Sirainen Date: Mon, 2 Jun 2008 17:01:42 +0000 (+0300) Subject: dbox: Use POP3 UIDLs from metadata if they exist. X-Git-Tag: 1.1.rc8~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbfb72bba858a2cb4d067a2f254384285372f128;p=thirdparty%2Fdovecot%2Fcore.git dbox: Use POP3 UIDLs from metadata if they exist. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox/dbox-file-maildir.c b/src/lib-storage/index/dbox/dbox-file-maildir.c index 6fe9dff3f8..6e7d6443f8 100644 --- a/src/lib-storage/index/dbox/dbox-file-maildir.c +++ b/src/lib-storage/index/dbox/dbox-file-maildir.c @@ -73,6 +73,7 @@ const char *dbox_file_maildir_metadata_get(struct dbox_file *file, &size)) value = dec2str(size); break; + case DBOX_METADATA_POP3_UIDL: case DBOX_METADATA_EXPUNGED: case DBOX_METADATA_EXT_REF: case DBOX_METADATA_SPACE: diff --git a/src/lib-storage/index/dbox/dbox-file.h b/src/lib-storage/index/dbox/dbox-file.h index 8fffa9287c..58ac4e7c0f 100644 --- a/src/lib-storage/index/dbox/dbox-file.h +++ b/src/lib-storage/index/dbox/dbox-file.h @@ -54,15 +54,17 @@ enum dbox_metadata_key { DBOX_METADATA_FLAGS = 'F', /* Space separated list of keywords */ DBOX_METADATA_KEYWORDS = 'K', - /* Pointer to external message data. Format is: - 1*( ) */ - DBOX_METADATA_EXT_REF = 'P', + /* POP3 UIDL overriding the default format */ + DBOX_METADATA_POP3_UIDL = 'P', /* Received UNIX timestamp in hex */ DBOX_METADATA_RECEIVED_TIME = 'R', /* Saved UNIX timestamp in hex */ DBOX_METADATA_SAVE_TIME = 'S', /* Virtual message size in hex (line feeds counted as CRLF) */ DBOX_METADATA_VIRTUAL_SIZE = 'V', + /* Pointer to external message data. Format is: + 1*( ) */ + DBOX_METADATA_EXT_REF = 'X', /* End of metadata block. The spaces can be used for writing more metadata. */ diff --git a/src/lib-storage/index/dbox/dbox-mail.c b/src/lib-storage/index/dbox/dbox-mail.c index 030096559a..438910a653 100644 --- a/src/lib-storage/index/dbox/dbox-mail.c +++ b/src/lib-storage/index/dbox/dbox-mail.c @@ -3,6 +3,7 @@ #include "lib.h" #include "ioloop.h" #include "istream.h" +#include "str.h" #include "index-mail.h" #include "dbox-storage.h" #include "dbox-file.h" @@ -176,6 +177,47 @@ static int dbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r) return 0; } +static int +dbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field, + const char **value_r) +{ + struct dbox_mail *mail = (struct dbox_mail *)_mail; + struct index_mail *imail = &mail->imail; + const unsigned int pop3_uidl_cache_field = + imail->ibox->cache_fields[MAIL_CACHE_POP3_UIDL].idx; + struct dbox_file *file; + const char *value; + string_t *str; + + switch (field) { + case MAIL_FETCH_UIDL_BACKEND: + /* keep the UIDL in cache file, otherwise POP3 would open all + mail files and read the metadata */ + str = str_new(imail->data_pool, 64); + if (mail_cache_lookup_field(imail->trans->cache_view, str, + _mail->seq, + pop3_uidl_cache_field) > 0) { + *value_r = str_c(str); + return 0; + } + + if (dbox_mail_metadata_seek(mail, &file) < 0) + return -1; + + value = dbox_file_metadata_get(file, DBOX_METADATA_POP3_UIDL); + if (value == NULL) + value = ""; + index_mail_cache_add_idx(imail, pop3_uidl_cache_field, + value, strlen(value)+1); + *value_r = value; + return 0; + default: + break; + } + + return index_mail_get_special(_mail, field, value_r); +} + static int dbox_mail_get_stream(struct mail *_mail, struct message_size *hdr_size, struct message_size *body_size, struct istream **stream_r) @@ -236,7 +278,7 @@ struct mail_vfuncs dbox_mail_vfuncs = { index_mail_get_headers, index_mail_get_header_stream, dbox_mail_get_stream, - index_mail_get_special, + dbox_mail_get_special, index_mail_update_flags, index_mail_update_keywords, index_mail_expunge, diff --git a/src/lib-storage/index/dbox/dbox-sync-file.c b/src/lib-storage/index/dbox/dbox-sync-file.c index c7e6ef2423..96fee5ac19 100644 --- a/src/lib-storage/index/dbox/dbox-sync-file.c +++ b/src/lib-storage/index/dbox/dbox-sync-file.c @@ -200,6 +200,7 @@ dbox_sync_file_split(struct dbox_sync_context *ctx, struct dbox_file *in_file, DBOX_METADATA_VIRTUAL_SIZE, DBOX_METADATA_RECEIVED_TIME, DBOX_METADATA_SAVE_TIME, + DBOX_METADATA_POP3_UIDL }; struct dbox_index_append_context *append_ctx; struct dbox_file *out_file;