changeset 100:867ec80dbf42 HEAD

Custom flags are now shown in FLAGS and PERMANENTFLAGS lists after SELECT. It also warns if there's for some reason a duplicate index number in custom flags file.
author Timo Sirainen <tss@iki.fi>
date Thu, 29 Aug 2002 22:21:51 +0300
parents 352c2567ba11
children edc37d046b08
files src/imap/cmd-select.c src/lib-storage/flags-file/flags-file.c src/lib-storage/index/index-status.c src/lib-storage/mail-storage.h
diffstat 4 files changed, 73 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/cmd-select.c	Thu Aug 29 21:44:16 2002 +0300
+++ b/src/imap/cmd-select.c	Thu Aug 29 22:21:51 2002 +0300
@@ -1,13 +1,43 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "common.h"
+#include "temp-string.h"
 #include "commands.h"
 
+#define SYSTEM_PERMANENT_FLAGS \
+	"\\Answered \\Flagged \\Deleted \\Seen \\Draft"
+#define SYSTEM_FLAGS SYSTEM_PERMANENT_FLAGS " \\Recent"
+
+static const char *
+get_custom_flags_string(const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT])
+{
+	TempString *str;
+	int i;
+
+	/* first see if there even is custom flags */
+	for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
+		if (custom_flags[i] != NULL)
+			break;
+	}
+
+	if (i == MAIL_CUSTOM_FLAGS_COUNT)
+		return "";
+
+	str = t_string_new(256);
+	for (; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
+		if (custom_flags[i] != NULL) {
+			t_string_append_c(str, ' ');
+			t_string_append(str, custom_flags[i]);
+		}
+	}
+	return str->str;
+}
+
 int cmd_select_full(Client *client, int readonly)
 {
 	Mailbox *box;
 	MailboxStatus status;
-	const char *mailbox;
+	const char *mailbox, *custom_flags;
 
 	/* <mailbox> */
 	if (!client_read_string_args(client, 1, &mailbox))
@@ -25,21 +55,24 @@
 
 	box = client->mailbox;
 	if (!box->get_status(box, STATUS_MESSAGES | STATUS_RECENT |
-			     STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY,
-			     &status)) {
+			     STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
+			     STATUS_CUSTOM_FLAGS, &status)) {
 		client_send_storage_error(client);
 		return TRUE;
 	}
 
-	client_send_line(client, "* FLAGS (\\Answered \\Flagged "
-			 "\\Deleted \\Seen \\Draft \\Recent)");
+	custom_flags = get_custom_flags_string(status.custom_flags);
+
+	client_send_line(client, t_strconcat("* FLAGS ("SYSTEM_FLAGS,
+					     custom_flags, ")", NULL));
 	if (box->readonly) {
 		client_send_line(client, "* OK [PERMANENTFLAGS ()] "
 				 "Read-only mailbox.");
 	} else {
-		client_send_line(client, "* OK [PERMANENTFLAGS (\\Answered "
-				 "\\Flagged \\Deleted \\Seen \\Draft)] "
-				 "Flags permitted.");
+		client_send_line(client, t_strconcat("* OK [PERMANENTFLAGS ("
+						     SYSTEM_PERMANENT_FLAGS,
+						     custom_flags, ")] "
+						     "Flags permitted.", NULL));
 	}
 
 	client_send_line(client,
--- a/src/lib-storage/flags-file/flags-file.c	Thu Aug 29 21:44:16 2002 +0300
+++ b/src/lib-storage/flags-file/flags-file.c	Thu Aug 29 22:21:51 2002 +0300
@@ -10,6 +10,10 @@
 #include <fcntl.h>
 #include <ctype.h>
 
+/* Header is simply a counter which is increased every time the file is
+   updated. This allows other processes to easily notice if there's been
+   any changes. */
+
 #define COUNTER_SIZE 4
 #define HEADER_SIZE (COUNTER_SIZE + 1) /* 0000\n */
 
@@ -125,6 +129,12 @@
 			while (data != data_end && *data != '\n')
 				data++;
 
+			if (ff->custom_flags[num] != NULL) {
+				i_warning("Error in custom flags file %s: "
+					  "Duplicated ID %u", ff->path, num);
+				i_free(ff->custom_flags[num]);
+			}
+
 			ff->custom_flags[num] = i_strdup_until(line, data);
 		}
 	}
--- a/src/lib-storage/index/index-status.c	Thu Aug 29 21:44:16 2002 +0300
+++ b/src/lib-storage/index/index-status.c	Thu Aug 29 22:21:51 2002 +0300
@@ -79,12 +79,26 @@
 	return rec == NULL ? 0 : seq;
 }
 
+static void
+get_custom_flags(FlagsFile *ff, const char *result[MAIL_CUSTOM_FLAGS_COUNT])
+{
+	const char **flags;
+	int i;
+
+	flags = flags_file_list_get(ff);
+	for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++)
+		result[i] = t_strdup(flags[i]);
+	flags_file_list_unref(ff);
+}
+
 int index_storage_get_status(Mailbox *box, MailboxStatusItems items,
 			     MailboxStatus *status)
 {
 	IndexMailbox *ibox = (IndexMailbox *) box;
 	MailIndexHeader *hdr;
 
+	memset(status, 0, sizeof(MailboxStatus));
+
 	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED))
 		return mail_storage_set_index_error(ibox);
 
@@ -103,6 +117,9 @@
 	if (items & STATUS_RECENT)
 		status->recent = get_recent_count(ibox->index);
 
+	if (items & STATUS_CUSTOM_FLAGS)
+		get_custom_flags(ibox->flagsfile, status->custom_flags);
+
 	/* STATUS sends EXISTS, so we've synced it */
 	ibox->synced_messages_count = hdr->messages_count;
 
--- a/src/lib-storage/mail-storage.h	Thu Aug 29 21:44:16 2002 +0300
+++ b/src/lib-storage/mail-storage.h	Thu Aug 29 22:21:51 2002 +0300
@@ -21,7 +21,8 @@
 	STATUS_UIDNEXT		= 0x04,
 	STATUS_UIDVALIDITY	= 0x08,
 	STATUS_UNSEEN		= 0x10,
-	STATUS_FIRST_UNSEEN_SEQ	= 0x20
+	STATUS_FIRST_UNSEEN_SEQ	= 0x20,
+	STATUS_CUSTOM_FLAGS	= 0x40
 } MailboxStatusItems;
 
 typedef enum {
@@ -184,6 +185,9 @@
 	unsigned int uidnext;
 
 	unsigned int first_unseen_seq;
+
+	/* may be allocated from temp pool */
+	const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT];
 };
 
 struct _MailFetchData {