[dovecot-cvs] dovecot/src/lib-storage/index index-mail.c, 1.66, 1.67 index-mail.h, 1.24, 1.25 index-search.c, 1.97, 1.98 index-status.c, 1.34, 1.35 index-storage.c, 1.65, 1.66 index-storage.h, 1.84, 1.85 index-sync.c, 1.44, 1.45

cras at dovecot.org cras at dovecot.org
Sun Dec 26 11:12:44 EET 2004


Update of /var/lib/cvs/dovecot/src/lib-storage/index
In directory talvi:/tmp/cvs-serv26125/lib-storage/index

Modified Files:
	index-mail.c index-mail.h index-search.c index-status.c 
	index-storage.c index-storage.h index-sync.c 
Log Message:
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.



Index: index-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- index-mail.c	19 Dec 2004 06:36:12 -0000	1.66
+++ index-mail.c	26 Dec 2004 09:12:41 -0000	1.67
@@ -155,20 +155,34 @@
 	}
 }
 
-const struct mail_full_flags *index_mail_get_flags(struct mail *_mail)
+enum mail_flags index_mail_get_flags(struct mail *_mail)
 {
 	struct index_mail *mail = (struct index_mail *) _mail;
 	struct index_mail_data *data = &mail->data;
 
-	data->flags.flags = data->rec->flags & MAIL_FLAGS_MASK;
+	data->flags = data->rec->flags & MAIL_FLAGS_MASK;
 	if (index_mailbox_is_recent(mail->ibox, data->seq))
-		data->flags.flags |= MAIL_RECENT;
+		data->flags |= MAIL_RECENT;
 
-	/*FIXME:data->flags.keywords =
-		mail_keywords_list_get(mail->ibox->index->keywords);
-	data->flags.keywords_count = MAIL_KEYWORDS_COUNT;*/
+	return data->flags;
+}
 
-	return &data->flags;
+const char *const *index_mail_get_keywords(struct mail *_mail)
+{
+	struct index_mail *mail = (struct index_mail *) _mail;
+	struct index_mail_data *data = &mail->data;
+	const char *const *keywords;
+
+	if (data->keywords_buf == NULL)
+		data->keywords_buf = buffer_create_dynamic(mail->pool, 128);
+
+	if (mail_index_lookup_keywords(mail->ibox->view, mail->data.seq,
+				       data->keywords_buf, &keywords) < 0) {
+		mail_storage_set_index_error(mail->ibox);
+		return NULL;
+	}
+
+	return keywords;
 }
 
 const struct message_part *index_mail_get_parts(struct mail *_mail)
@@ -736,31 +750,23 @@
 	memset(mail, 0, sizeof(*mail));
 }
 
-int index_mail_update_flags(struct mail *mail,
-			    const struct mail_full_flags *flags,
-			    enum modify_type modify_type)
+int index_mail_update_flags(struct mail *mail, enum modify_type modify_type,
+			    enum mail_flags flags)
 {
 	struct index_mail *imail = (struct index_mail *)mail;
-	enum mail_flags modify_flags;
-	keywords_mask_t keywords;
-
-	modify_flags = flags->flags & MAIL_FLAGS_MASK;
 
-	/*if (!index_mailbox_fix_keywords(ibox, &modify_flags,
-					    flags->keywords,
-					    flags->keywords_count))
-		return FALSE;*/
-
-	memset(keywords, 0, sizeof(keywords));
 	mail_index_update_flags(imail->trans->trans, mail->seq, modify_type,
-				flags->flags, keywords);
+				flags & MAIL_FLAGS_MASK);
+	return 0;
+}
 
-	/*if (mail_keywords_has_changes(ibox->index->keywords)) {
-		storage->callbacks->new_keywords(&ibox->box,
-			mail_keywords_list_get(ibox->index->keywords),
-			MAIL_KEYWORDS_COUNT, storage->callback_context);
-	}*/
+int index_mail_update_keywords(struct mail *mail, enum modify_type modify_type,
+			       const struct mail_keywords *keywords)
+{
+	struct index_mail *imail = (struct index_mail *)mail;
 
+	mail_index_update_keywords(imail->trans->trans, mail->seq, modify_type,
+				   keywords);
 	return 0;
 }
 

Index: index-mail.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- index-mail.h	4 Sep 2004 12:44:14 -0000	1.24
+++ index-mail.h	26 Dec 2004 09:12:41 -0000	1.25
@@ -53,7 +53,8 @@
 struct message_header_line;
 
 struct index_mail_data {
-	struct mail_full_flags flags;
+	enum mail_flags flags;
+	const char *const *keywords;
 	time_t date, received_date;
 	uoff_t virtual_size, physical_size;
 
@@ -73,6 +74,7 @@
 	struct message_size hdr_size, body_size;
 	struct message_parser_ctx *parser_ctx;
 	int parsing_count;
+	buffer_t *keywords_buf;
 
 	unsigned int parse_header:1;
 	unsigned int save_envelope:1;
@@ -128,7 +130,8 @@
 index_mail_get_headers(struct mail *_mail,
 		       struct mailbox_header_lookup_ctx *headers);
 
-const struct mail_full_flags *index_mail_get_flags(struct mail *_mail);
+enum mail_flags index_mail_get_flags(struct mail *_mail);
+const char *const *index_mail_get_keywords(struct mail *_mail);
 const struct message_part *index_mail_get_parts(struct mail *_mail);
 time_t index_mail_get_received_date(struct mail *_mail);
 time_t index_mail_get_date(struct mail *_mail, int *timezone);
@@ -140,9 +143,10 @@
 const char *index_mail_get_special(struct mail *_mail,
 				   enum mail_fetch_field field);
 
-int index_mail_update_flags(struct mail *mail,
-			    const struct mail_full_flags *flags,
-			    enum modify_type modify_type);
+int index_mail_update_flags(struct mail *mail, enum modify_type modify_type,
+			    enum mail_flags flags);
+int index_mail_update_keywords(struct mail *mail, enum modify_type modify_type,
+			       const struct mail_keywords *keywords);
 int index_mail_expunge(struct mail *mail);
 
 const char *index_mail_get_cached_string(struct index_mail *mail,

Index: index-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- index-search.c	25 Nov 2004 20:19:38 -0000	1.97
+++ index-search.c	26 Dec 2004 09:12:41 -0000	1.98
@@ -79,41 +79,13 @@
 	return num;
 }
 
-static int search_keyword(struct mail_index *index,
-			  const struct mail_index_record *rec,
-			  const char *value)
-{
-	const char **keywords;
-	int i;
-
-	for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
-		if (rec->keywords[i] != 0)
-			break;
-	}
-
-	if (i == INDEX_KEYWORDS_BYTE_COUNT)
-		return FALSE; /* no keywords set */
-
-	/*FIXME:keywords = mail_keywords_list_get(index->keywords);
-	for (i = 0; i < MAIL_KEYWORDS_COUNT; i++) {
-		if (keywords[i] != NULL &&
-		    strcasecmp(keywords[i], value) == 0) {
-			return rec->msg_flags &
-				(1 << (MAIL_KEYWORD_1_BIT+i));
-		}
-	}*/
-
-	return FALSE;
-}
-
 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
-static int search_arg_match_index(struct index_mailbox *ibox,
-				  struct index_mail *imail,
+static int search_arg_match_index(struct index_mail *imail,
 				  enum mail_search_arg_type type,
 				  const char *value)
 {
 	const struct mail_index_record *rec = imail->data.rec;
-	const struct mail_full_flags *full_flags;
+	const char *const *keywords;
 
 	switch (type) {
 	case SEARCH_ALL:
@@ -131,10 +103,17 @@
 	case SEARCH_SEEN:
 		return rec->flags & MAIL_SEEN;
 	case SEARCH_RECENT:
-		full_flags = imail->mail.get_flags(&imail->mail);
-		return full_flags->flags & MAIL_RECENT;
+		return imail->mail.get_flags(&imail->mail) & MAIL_RECENT;
 	case SEARCH_KEYWORD:
-		return search_keyword(ibox->index, rec, value);
+		keywords = imail->mail.get_keywords(&imail->mail);
+		if (keywords != NULL) {
+			while (*keywords != NULL) {
+				if (strcasecmp(*keywords, value) == 0)
+					return 1;
+				keywords++;
+			}
+		}
+		return 0;
 
 	default:
 		return -1;
@@ -158,8 +137,8 @@
 		return;
 	}
 
-	switch (search_arg_match_index(ctx->ibox, &ctx->imail,
-				       arg->type, arg->value.str)) {
+	switch (search_arg_match_index(&ctx->imail, arg->type,
+				       arg->value.str)) {
 	case -1:
 		/* unknown */
 		break;
@@ -430,7 +409,7 @@
 	}
 }
 
-static void search_header(struct message_part *part,
+static void search_header(struct message_part *part __attr_unused__,
                           struct message_header_line *hdr, void *context)
 {
 	struct search_header_context *ctx = context;

Index: index-status.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-status.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- index-status.c	24 Nov 2004 18:39:58 -0000	1.34
+++ index-status.c	26 Dec 2004 09:12:42 -0000	1.35
@@ -3,20 +3,6 @@
 #include "lib.h"
 #include "index-storage.h"
 
-/*static void
-get_keywords(struct mail_keywords *mcf, struct mailbox_status *status)
-{
-	const char **flags;
-	unsigned int i;
-
-	status->keywords_count = MAIL_KEYWORDS_COUNT;
-	status->keywords = t_new(const char *, MAIL_KEYWORDS_COUNT);
-
-	flags = mail_keywords_list_get(mcf);
-	for (i = 0; i < MAIL_KEYWORDS_COUNT; i++)
-		status->keywords[i] = t_strdup(flags[i]);
-}*/
-
 int index_storage_get_status_locked(struct index_mailbox *ibox,
 				    enum mailbox_status_items items,
 				    struct mailbox_status *status_r)
@@ -43,8 +29,10 @@
 		}
 	}
 
-	/*FIXME:if (items & STATUS_KEYWORDS)
-		get_keywords(ibox, status_r);*/
+	if (items & STATUS_KEYWORDS) {
+		status_r->keywords = mail_index_get_keywords(ibox->index);
+		status_r->keywords_count = strarray_length(status_r->keywords);
+	}
 	return 0;
 }
 

Index: index-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- index-storage.c	10 Oct 2004 17:25:44 -0000	1.65
+++ index-storage.c	26 Dec 2004 09:12:42 -0000	1.66
@@ -414,23 +414,12 @@
 	return FALSE;
 }
 
-int index_mailbox_fix_keywords(struct index_mailbox *ibox,
-			       enum mail_flags *flags,
-			       const char *keywords[],
-			       unsigned int keywords_count)
+struct mail_keywords *
+index_keywords_create(struct mailbox_transaction_context *_t,
+		      const char *const keywords[])
 {
-	/*FIXME:int ret;
+	struct index_transaction_context *t =
+		(struct index_transaction_context *)_t;
 
-	ret = mail_keywords_fix_list(ibox->index, flags, keywords,
-				     keywords_count);
-	switch (ret) {
-	case 1:
-		return TRUE;
-	case 0:
-		mail_storage_set_error(ibox->box.storage,
-			"Maximum number of different keywords exceeded");
-		return FALSE;
-	default:
-		return mail_storage_set_index_error(ibox);
-	}*/
+	return mail_index_keywords_create(t->trans, keywords);
 }

Index: index-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- index-storage.h	17 Dec 2004 11:08:58 -0000	1.84
+++ index-storage.h	26 Dec 2004 09:12:42 -0000	1.85
@@ -145,10 +145,9 @@
 int index_storage_allow_new_keywords(struct mailbox *box);
 int index_storage_is_inconsistent(struct mailbox *box);
 
-int index_mailbox_fix_keywords(struct index_mailbox *ibox,
-			       enum mail_flags *flags,
-			       const char *keywords[],
-			       unsigned int keywords_count);
+struct mail_keywords *
+index_keywords_create(struct mailbox_transaction_context *t,
+		      const char *const keywords[]);
 
 void index_mailbox_set_recent(struct index_mailbox *ibox, uint32_t seq);
 int index_mailbox_is_recent(struct index_mailbox *ibox, uint32_t seq);

Index: index-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-sync.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- index-sync.c	28 Nov 2004 23:19:54 -0000	1.44
+++ index-sync.c	26 Dec 2004 09:12:42 -0000	1.45
@@ -185,6 +185,7 @@
 			/* later */
 			break;
 		case MAIL_INDEX_SYNC_TYPE_FLAGS:
+		case MAIL_INDEX_SYNC_TYPE_KEYWORDS:
 			/* FIXME: hide the flag updates for expunged messages */
 			if (mail_index_lookup_uid_range(ctx->ibox->view,
 						sync.uid1, sync.uid2,
@@ -197,7 +198,10 @@
 			if (sync_rec_r->seq1 == 0)
 				break;
 
-			sync_rec_r->type = MAILBOX_SYNC_TYPE_FLAGS;
+			sync_rec_r->type =
+				sync.type == MAIL_INDEX_SYNC_TYPE_FLAGS ?
+				MAILBOX_SYNC_TYPE_FLAGS :
+				MAILBOX_SYNC_TYPE_KEYWORDS;
 			return 1;
 		}
 	}



More information about the dovecot-cvs mailing list