imap-fetch.c revision 2412873209ff658bc4bd20123af2d6162464c4ff
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Copyright (c) 2002-2007 Dovecot authors, see the included COPYING file */
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen "\"text\" \"plain\" NIL NIL NIL \"7bit\" 0 0 NIL NIL NIL"
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainenconst struct imap_fetch_handler default_handlers[7];
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainenstatic int imap_fetch_handler_cmp(const void *p1, const void *p2)
0a00890f8ec34ee08d0d391441fca36ed42d7a0cTimo Sirainen const struct imap_fetch_handler *h1 = p1, *h2 = p2;
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainenvoid imap_fetch_handlers_register(const struct imap_fetch_handler *handlers,
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen fetch_handlers = buffer_create_dynamic(default_pool, 128);
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen buffer_append(fetch_handlers, handlers, sizeof(*handlers) * count);
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen data = buffer_get_modifiable_data(fetch_handlers, &size);
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen qsort(data, size / sizeof(*handlers), sizeof(*handlers),
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainenstatic int imap_fetch_handler_bsearch(const void *name_p, const void *handler_p)
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen const struct imap_fetch_handler *h = handler_p;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen return name[i] < 'A' || name[i] >= 'Z' ? 0 : -1;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainenbool imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name,
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainenstruct imap_fetch_context *imap_fetch_init(struct client_command_context *cmd)
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen imap_fetch_handlers_register(default_handlers,
0727e38ac12efb8963a339daf56255e2be1f29fcTimo Sirainen ctx = p_new(cmd->pool, struct imap_fetch_context, 1);
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen ctx->all_headers_buf = buffer_create_dynamic(cmd->pool, 128);
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainenvoid imap_fetch_add_handler(struct imap_fetch_context *ctx,
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen /* partially because of broken clients, but also partially because
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen it potentially can make client implementations faster, we have a
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen buffered parameter which basically means that the handler promises
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen to write the output in ctx->cur_str. The cur_str is then sent to
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen client before calling any non-buffered handlers.
70cb37c37e4dce8f57cd3f882f7444e76b918befTimo Sirainen We try to keep the handler registration order the same as the
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen client requested them. This is especially useful to get UID
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen returned first, which some clients rely on..
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen const struct imap_fetch_context_handler *handlers;
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen unsigned int i, size;
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen /* don't allow duplicate handlers */
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen for (i = 0; i < size; i++) {
98a711be68ba64e1cabf8cacc150af44421e2ac9Timo Sirainen memset(&h, 0, sizeof(h));
if (!buffered)
const void *data;
MAIL_FETCH_STREAM_BODY)) == 0)) {
const unsigned char *data;
if (len == 0)
len--;
unsigned int count;
int ret;
if (ret == 0)
if (ret < 0) {
if (ret <= 0) {
return ret;
t_push();
t_pop();
if (ret == 0) {
if (ret < 0) {
unsigned int i, count;
for (i = 0; i < count; i++) {
const char *body;
return TRUE;
const char *bodystructure;
&bodystructure) < 0)
return TRUE;
const char *envelope;
return TRUE;
const char *const *keywords;
return TRUE;
return TRUE;
return TRUE;