[dovecot-cvs] dovecot/src/imap client.c,1.24,1.25 client.h,1.11,1.12 cmd-append.c,1.23,1.24 cmd-select.c,1.14,1.15 cmd-store.c,1.10,1.11 commands-util.c,1.21,1.22 commands-util.h,1.9,1.10 common.h,1.3,1.4 mail-storage-callbacks.c,1.5,1.6 main.c,1.25,1.26
cras at procontrol.fi
cras at procontrol.fi
Fri Feb 14 10:00:54 EET 2003
Update of /home/cvs/dovecot/src/imap
In directory danu:/tmp/cvs-serv13828/src/imap
Modified Files:
client.c client.h cmd-append.c cmd-select.c cmd-store.c
commands-util.c commands-util.h common.h
mail-storage-callbacks.c main.c
Log Message:
Added setting to limit length of custom flag names.
Index: client.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/client.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- client.c 27 Jan 2003 01:44:34 -0000 1.24
+++ client.c 14 Feb 2003 08:00:52 -0000 1.25
@@ -73,6 +73,8 @@
MAX_IMAP_ARG_ELEMENTS);
client->last_input = ioloop_time;
+ client->mailbox_flags.pool =
+ pool_alloconly_create("mailbox_custom_flags", 512);
client->storage = storage;
storage->set_callbacks(storage, &mail_storage_callbacks, client);
@@ -95,6 +97,7 @@
i_stream_unref(client->input);
o_stream_unref(client->output);
+ pool_unref(client->mailbox_flags.pool);
i_free(client);
/* quit the program */
Index: client.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/client.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- client.h 27 Jan 2003 04:23:45 -0000 1.11
+++ client.h 14 Feb 2003 08:00:52 -0000 1.12
@@ -8,6 +8,13 @@
typedef int client_command_func_t(struct client *client);
+struct mailbox_custom_flags {
+ pool_t pool; /* will be p_clear()ed when changed */
+
+ char **custom_flags;
+ unsigned int custom_flags_count;
+};
+
struct client {
int socket;
struct io *io;
@@ -16,6 +23,7 @@
struct mail_storage *storage;
struct mailbox *mailbox;
+ struct mailbox_custom_flags mailbox_flags;
unsigned int select_counter; /* increased when mailbox is changed */
time_t last_input;
Index: cmd-append.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-append.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- cmd-append.c 27 Jan 2003 04:23:45 -0000 1.23
+++ cmd-append.c 14 Feb 2003 08:00:52 -0000 1.24
@@ -46,10 +46,12 @@
int cmd_append(struct client *client)
{
struct mailbox *box;
+ struct mailbox_status status;
struct mail_save_context *ctx;
struct imap_parser *save_parser;
struct imap_arg *args;
struct imap_arg_list *flags_list;
+ struct mailbox_custom_flags old_flags;
struct mail_full_flags flags;
time_t internal_date;
const char *mailbox, *internal_date_str, *error;
@@ -71,6 +73,16 @@
return TRUE;
}
+ if (!box->get_status(box, STATUS_CUSTOM_FLAGS, &status)) {
+ client_send_storage_error(client);
+ box->close(box);
+ return TRUE;
+ }
+ memset(&old_flags, 0, sizeof(old_flags));
+ old_flags.pool = data_stack_pool;
+ client_save_custom_flags(&old_flags, status.custom_flags,
+ status.custom_flags_count);
+
ctx = box->save_init(box, TRUE);
if (ctx == NULL) {
client_send_storage_error(client);
@@ -141,7 +153,7 @@
if (flags_list != NULL) {
if (!client_parse_mail_flags(client, flags_list->args,
- &flags))
+ &old_flags, &flags))
break;
} else {
memset(&flags, 0, sizeof(flags));
Index: cmd-select.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-select.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cmd-select.c 22 Jan 2003 20:46:36 -0000 1.14
+++ cmd-select.c 14 Feb 2003 08:00:52 -0000 1.15
@@ -34,6 +34,9 @@
return TRUE;
}
+ client_save_custom_flags(&client->mailbox_flags, status.custom_flags,
+ status.custom_flags_count);
+
/* set client's mailbox only after getting status to make sure
we're not sending any expunge/exists replies too early to client */
client->mailbox = box;
Index: cmd-store.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-store.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cmd-store.c 21 Jan 2003 11:24:06 -0000 1.10
+++ cmd-store.c 14 Feb 2003 08:00:52 -0000 1.11
@@ -61,10 +61,11 @@
if (args[2].type == IMAP_ARG_LIST) {
if (!client_parse_mail_flags(client,
IMAP_ARG_LIST(&args[2])->args,
- &flags))
+ &client->mailbox_flags, &flags))
return TRUE;
} else {
- if (!client_parse_mail_flags(client, args+2, &flags))
+ if (!client_parse_mail_flags(client, args+2,
+ &client->mailbox_flags, &flags))
return TRUE;
}
Index: commands-util.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/commands-util.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- commands-util.c 12 Feb 2003 18:22:11 -0000 1.21
+++ commands-util.c 14 Feb 2003 08:00:52 -0000 1.22
@@ -131,7 +131,32 @@
t_strconcat(syntax ? "* BAD " : "* NO ", error, NULL));
}
+static int is_valid_custom_flag(struct client *client,
+ const struct mailbox_custom_flags *old_flags,
+ const char *flag)
+{
+ size_t i;
+
+ /* if it already exists, skip validity checks */
+ for (i = 0; i < old_flags->custom_flags_count; i++) {
+ if (old_flags->custom_flags[i] != NULL &&
+ strcasecmp(old_flags->custom_flags[i], flag) == 0)
+ return TRUE;
+ }
+
+ if (strlen(flag) > max_custom_flag_length) {
+ client_send_tagline(client,
+ t_strdup_printf("BAD Invalid flag name '%s': "
+ "Maximum length is %u characters",
+ flag, max_custom_flag_length));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
int client_parse_mail_flags(struct client *client, struct imap_arg *args,
+ const struct mailbox_custom_flags *old_flags,
struct mail_full_flags *flags)
{
/* @UNSAFE */
@@ -187,6 +212,9 @@
}
if (i == flags->custom_flags_count) {
+ if (!is_valid_custom_flag(client, old_flags,
+ atom))
+ return FALSE;
flags->flags |= 1 << (flag_pos +
MAIL_CUSTOM_FLAG_1_BIT);
flags->custom_flags[flag_pos++] = atom;
@@ -246,4 +274,20 @@
box->allow_custom_flags ? " \\*" : "",
")] Flags permitted.", NULL));
}
+}
+
+void client_save_custom_flags(struct mailbox_custom_flags *dest,
+ const char *custom_flags[],
+ unsigned int custom_flags_count)
+{
+ unsigned int i;
+
+ p_clear(dest->pool);
+
+ dest->custom_flags =
+ p_new(dest->pool, char *, custom_flags_count);
+ dest->custom_flags_count = custom_flags_count;
+
+ for (i = 0; i < custom_flags_count; i++)
+ dest->custom_flags[i] = p_strdup(dest->pool, custom_flags[i]);
}
Index: commands-util.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/commands-util.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- commands-util.h 27 Jan 2003 04:23:45 -0000 1.9
+++ commands-util.h 14 Feb 2003 08:00:52 -0000 1.10
@@ -33,11 +33,17 @@
/* Parse flags. Returns TRUE if successful, if not sends an error message to
client. */
int client_parse_mail_flags(struct client *client, struct imap_arg *args,
+ const struct mailbox_custom_flags *old_flags,
struct mail_full_flags *flags);
/* Send FLAGS + PERMANENTFLAGS to client. */
void client_send_mailbox_flags(struct client *client, struct mailbox *box,
const char *custom_flags[],
unsigned int custom_flags_count);
+
+/* Copy custom flags into dest. dest must have been initialized. */
+void client_save_custom_flags(struct mailbox_custom_flags *dest,
+ const char *custom_flags[],
+ unsigned int custom_flags_count);
#endif
Index: common.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/common.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- common.h 22 Jan 2003 19:23:28 -0000 1.3
+++ common.h 14 Feb 2003 08:00:52 -0000 1.4
@@ -8,6 +8,9 @@
for command from user is around MAX_INBUF_SIZE * MAX_IMAP_ARG_ELEMENTS */
#define MAX_IMAP_ARG_ELEMENTS 128
+#define DEFAULT_MAX_CUSTOM_FLAG_LENGTH 50
+
extern struct ioloop *ioloop;
+extern unsigned int max_custom_flag_length;
#endif
Index: mail-storage-callbacks.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/mail-storage-callbacks.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mail-storage-callbacks.c 27 Jan 2003 04:23:45 -0000 1.5
+++ mail-storage-callbacks.c 14 Feb 2003 08:00:52 -0000 1.6
@@ -95,6 +95,9 @@
if (client->mailbox != mailbox)
return;
+ client_save_custom_flags(&client->mailbox_flags, custom_flags,
+ custom_flags_count);
+
client_send_mailbox_flags(client, mailbox, custom_flags,
custom_flags_count);
}
Index: main.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/main.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- main.c 11 Feb 2003 10:30:29 -0000 1.25
+++ main.c 14 Feb 2003 08:00:52 -0000 1.26
@@ -16,6 +16,8 @@
(getenv("LOGGED_IN") == NULL)
struct ioloop *ioloop;
+unsigned int max_custom_flag_length;
+
static char log_prefix[128]; /* syslog() needs this to be permanent */
static void sig_quit(int signo __attr_unused__)
@@ -61,7 +63,7 @@
{
struct client *client;
struct mail_storage *storage;
- const char *mail;
+ const char *mail, *str;
int hin, hout;
lib_init_signals(sig_quit);
@@ -99,6 +101,11 @@
"autodetection failed (home %s)", home);
}
}
+
+ str = getenv("MAIL_MAX_FLAG_LENGTH");
+ max_custom_flag_length = str != NULL ?
+ (unsigned int)strtoul(str, NULL, 10) :
+ DEFAULT_MAX_CUSTOM_FLAG_LENGTH;
client = client_create(hin, hout, storage);
More information about the dovecot-cvs
mailing list