dovecot-2.2: imapc: Added guid-forced feature to use SHA1(messag...
dovecot at dovecot.org
dovecot at dovecot.org
Sun May 20 03:26:32 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/16ed300484c9
changeset: 14457:16ed300484c9
user: Timo Sirainen <tss at iki.fi>
date: Wed Apr 18 18:09:14 2012 +0300
description:
imapc: Added guid-forced feature to use SHA1(message) as GUID.
diffstat:
src/lib-storage/index/imapc/imapc-mail.c | 48 ++++++++++++++++++++++++---
src/lib-storage/index/imapc/imapc-settings.c | 1 +
src/lib-storage/index/imapc/imapc-settings.h | 3 +-
3 files changed, 45 insertions(+), 7 deletions(-)
diffs (103 lines):
diff -r d6376942d9a6 -r 16ed300484c9 src/lib-storage/index/imapc/imapc-mail.c
--- a/src/lib-storage/index/imapc/imapc-mail.c Tue Apr 17 13:56:00 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-mail.c Wed Apr 18 18:09:14 2012 +0300
@@ -2,6 +2,8 @@
#include "lib.h"
#include "str.h"
+#include "hex-binary.h"
+#include "sha1.h"
#include "istream.h"
#include "imap-envelope.h"
#include "imapc-msgmap.h"
@@ -307,6 +309,33 @@
buffer_free(&mail->body);
}
+static int imapc_mail_get_body_hash(struct index_mail *imail)
+{
+ struct istream *input;
+ const unsigned char *data;
+ size_t size;
+ uoff_t old_offset;
+ struct sha1_ctxt sha1_ctx;
+ unsigned char sha1_output[SHA1_RESULTLEN];
+ const char *sha1_str;
+
+ sha1_init(&sha1_ctx);
+ old_offset = imail->data.stream == NULL ? 0 :
+ imail->data.stream->v_offset;
+ if (mail_get_stream(&imail->mail.mail, NULL, NULL, &input) < 0)
+ return -1;
+ while (i_stream_read_data(input, &data, &size, 0) > 0) {
+ sha1_loop(&sha1_ctx, data, size);
+ i_stream_skip(input, size);
+ }
+ i_stream_seek(imail->data.stream, old_offset);
+ sha1_result(&sha1_ctx, sha1_output);
+
+ sha1_str = binary_to_hex(sha1_output, sizeof(sha1_output));
+ imail->data.guid = p_strdup(imail->data_pool, sha1_str);
+ return 0;
+}
+
static int imapc_mail_get_guid(struct mail *_mail, const char **value_r)
{
struct index_mail *imail = (struct index_mail *)_mail;
@@ -328,11 +357,17 @@
}
/* GUID not in cache, fetch it */
- if (imapc_mail_fetch(_mail, MAIL_FETCH_GUID) < 0)
- return -1;
- if (imail->data.guid == NULL) {
- (void)imapc_mail_failed(_mail, mbox->guid_fetch_field_name);
- return -1;
+ if (mbox->guid_fetch_field_name != NULL) {
+ if (imapc_mail_fetch(_mail, MAIL_FETCH_GUID) < 0)
+ return -1;
+ if (imail->data.guid == NULL) {
+ (void)imapc_mail_failed(_mail, mbox->guid_fetch_field_name);
+ return -1;
+ }
+ } else {
+ /* use hash of message body as the GUID */
+ if (imapc_mail_get_body_hash(imail) < 0)
+ return -1;
}
index_mail_cache_add_idx(imail, cache_idx,
@@ -349,7 +384,8 @@
switch (field) {
case MAIL_FETCH_GUID:
- if (mbox->guid_fetch_field_name == NULL) {
+ if (!IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_GUID_FORCED) &&
+ mbox->guid_fetch_field_name == NULL) {
/* GUIDs not supported by server */
break;
}
diff -r d6376942d9a6 -r 16ed300484c9 src/lib-storage/index/imapc/imapc-settings.c
--- a/src/lib-storage/index/imapc/imapc-settings.c Tue Apr 17 13:56:00 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-settings.c Wed Apr 18 18:09:14 2012 +0300
@@ -76,6 +76,7 @@
static const struct imapc_feature_list imapc_feature_list[] = {
{ "rfc822.size", IMAPC_FEATURE_RFC822_SIZE },
+ { "guid-forced", IMAPC_FEATURE_GUID_FORCED },
{ NULL, 0 }
};
diff -r d6376942d9a6 -r 16ed300484c9 src/lib-storage/index/imapc/imapc-settings.h
--- a/src/lib-storage/index/imapc/imapc-settings.h Tue Apr 17 13:56:00 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-settings.h Wed Apr 18 18:09:14 2012 +0300
@@ -3,7 +3,8 @@
/* <settings checks> */
enum imapc_features {
- IMAPC_FEATURE_RFC822_SIZE = 0x01
+ IMAPC_FEATURE_RFC822_SIZE = 0x01,
+ IMAPC_FEATURE_GUID_FORCED = 0x02
};
/* </settings checks> */
More information about the dovecot-cvs
mailing list