[dovecot-cvs] dovecot/src/imap cmd-sort.c,NONE,1.1 Makefile.am,1.8,1.9 cmd-search.c,1.5,1.6 commands.c,1.2,1.3 commands.h,1.2,1.3
cras at procontrol.fi
cras at procontrol.fi
Wed Dec 4 20:28:39 EET 2002
- Previous message: [dovecot-cvs] dovecot configure.in,1.70,1.71
- Next message: [dovecot-cvs] dovecot/src/lib-storage mail-sort.c,NONE,1.1 mail-sort.h,NONE,1.1 .cvsignore,1.2,1.3 Makefile.am,1.3,1.4 mail-storage.h,1.20,1.21
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/dovecot/src/imap
In directory danu:/tmp/cvs-serv16863/src/imap
Modified Files:
Makefile.am cmd-search.c commands.c commands.h
Added Files:
cmd-sort.c
Log Message:
First implementation of SORT extension. String comparing still not up to
spec, so we don't advertise it in capability string yet. The code supports
getting the data partially pre-sorted to reduce memory usage and make it
faster. So, in future we could use this by creating sorted binary trees.
Also moved mail-storage-register.c into it's own .a lib to fix circular
dependencies.
--- NEW FILE: cmd-sort.c ---
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "commands.h"
#include "mail-search.h"
#include "mail-sort.h"
typedef struct {
MailSortType type;
const char *name;
} SortName;
static SortName sort_names[] = {
{ MAIL_SORT_ARRIVAL, "arrival" },
{ MAIL_SORT_CC, "cc" },
{ MAIL_SORT_DATE, "date" },
{ MAIL_SORT_FROM, "from" },
{ MAIL_SORT_SIZE, "size" },
{ MAIL_SORT_SUBJECT, "subject" },
{ MAIL_SORT_TO, "to" },
{ MAIL_SORT_REVERSE, "reverse" },
{ MAIL_SORT_END, NULL }
};
static MailSortType *get_sort_program(Client *client, ImapArg *args)
{
MailSortType *program, *temp_prog;
size_t program_alloc, program_size;
int i;
program_alloc = 32; program_size = 0;
program = t_new(MailSortType, program_alloc+1);
while (args->type == IMAP_ARG_ATOM || args->type == IMAP_ARG_STRING) {
const char *arg = args->data.str;
for (i = 0; sort_names[i].type != MAIL_SORT_END; i++) {
if (strcasecmp(arg, sort_names[i].name) == 0)
break;
}
if (sort_names[i].type == MAIL_SORT_END) {
client_send_command_error(client, t_strconcat(
"Unknown sort argument: ", arg, NULL));
return NULL;
}
if (program_size == program_alloc) {
program_alloc *= 2;
if (!t_try_realloc(program, program_alloc+1)) {
temp_prog = t_new(MailSortType, program_alloc);
memcpy(temp_prog, program,
sizeof(MailSortType) * program_size);
program = temp_prog;
}
}
program[program_size++] = sort_names[i].type;
args++;
}
program[program_size] = MAIL_SORT_END;
if (args->type != IMAP_ARG_EOL) {
client_send_command_error(client,
"Invalid sort list argument.");
return NULL;
}
return program;
}
int cmd_sort(Client *client)
{
MailSearchArg *sargs;
MailSortType *sorting;
ImapArg *args;
int args_count;
Pool pool;
const char *error, *charset;
args_count = imap_parser_read_args(client->parser, 0, 0, &args);
if (args_count == -2)
return FALSE;
if (args_count < 3) {
client_send_command_error(client,
"Missing or invalid arguments.");
return TRUE;
}
if (!client_verify_open_mailbox(client))
return TRUE;
/* sort program */
if (args->type != IMAP_ARG_LIST) {
client_send_command_error(client, "Invalid sort argument.");
return TRUE;
}
sorting = get_sort_program(client, args->data.list->args);
if (sorting == NULL)
return TRUE;
args++;
/* charset */
if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) {
client_send_command_error(client,
"Invalid charset argument.");
}
charset = args->data.str;
args++;
pool = pool_create("MailSortArgs", 2048, FALSE);
sargs = mail_search_args_build(pool, args, &error);
if (sargs == NULL) {
/* error in search arguments */
client_send_tagline(client, t_strconcat("NO ", error, NULL));
} else {
if (client->mailbox->search(client->mailbox, charset,
sargs, sorting,
client->outbuf, client->cmd_uid)) {
/* NOTE: syncing is allowed when returning UIDs */
if (client->cmd_uid)
client_sync_full(client);
else
client_sync_without_expunges(client);
client_send_tagline(client, "OK Search completed.");
} else {
client_send_storage_error(client);
}
}
pool_unref(pool);
return TRUE;
}
Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/imap/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Makefile.am 25 Nov 2002 19:02:49 -0000 1.8
+++ Makefile.am 4 Dec 2002 18:28:37 -0000 1.9
@@ -9,10 +9,11 @@
-I$(top_srcdir)/src/lib-storage
imap_LDADD = \
- ../lib-storage/libstorage.a \
+ ../lib-storage/register/libstorage-register.a \
../lib-storage/index/maildir/libstorage_maildir.a \
../lib-storage/index/mbox/libstorage_mbox.a \
../lib-storage/index/libstorage_index.a \
+ ../lib-storage/libstorage.a \
../lib-index/maildir/libstorage_index_maildir.a \
../lib-index/mbox/libstorage_index_mbox.a \
../lib-index/libstorage_index.a \
@@ -42,6 +43,7 @@
cmd-rename.c \
cmd-search.c \
cmd-select.c \
+ cmd-sort.c \
cmd-status.c \
cmd-store.c \
cmd-subscribe.c \
Index: cmd-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-search.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cmd-search.c 3 Nov 2002 08:39:43 -0000 1.5
+++ cmd-search.c 4 Dec 2002 18:28:37 -0000 1.6
@@ -49,7 +49,8 @@
/* error in search arguments */
client_send_tagline(client, t_strconcat("NO ", error, NULL));
} else {
- if (client->mailbox->search(client->mailbox, charset, sargs,
+ if (client->mailbox->search(client->mailbox, charset,
+ sargs, NULL,
client->outbuf, client->cmd_uid)) {
/* NOTE: syncing isn't allowed here */
client_sync_without_expunges(client);
Index: commands.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/commands.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- commands.c 28 Aug 2002 04:54:23 -0000 1.2
+++ commands.c 4 Dec 2002 18:28:37 -0000 1.3
@@ -64,6 +64,8 @@
return cmd_store;
if (strcmp(name, "SEARCH") == 0)
return cmd_search;
+ if (strcmp(name, "SORT") == 0)
+ return cmd_sort;
if (strcmp(name, "SELECT") == 0)
return cmd_select;
if (strcmp(name, "STATUS") == 0)
Index: commands.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/commands.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- commands.h 26 Nov 2002 20:04:08 -0000 1.2
+++ commands.h 4 Dec 2002 18:28:37 -0000 1.3
@@ -36,6 +36,7 @@
int cmd_close(Client *client);
int cmd_expunge(Client *client);
int cmd_search(Client *client);
+int cmd_sort(Client *client);
int cmd_fetch(Client *client);
int cmd_store(Client *client);
int cmd_copy(Client *client);
- Previous message: [dovecot-cvs] dovecot configure.in,1.70,1.71
- Next message: [dovecot-cvs] dovecot/src/lib-storage mail-sort.c,NONE,1.1 mail-sort.h,NONE,1.1 .cvsignore,1.2,1.3 Makefile.am,1.3,1.4 mail-storage.h,1.20,1.21
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list