#include "imap-date.h"
#include "mail-search-build.h"
#include "commands.h"
+#include "imap-quote.h"
#include "imap-fetch.h"
#include "imap-util.h"
#define ENVELOPE_NIL_REPLY \
"(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)"
-const struct imap_fetch_handler default_handlers[8];
+#define IMAP_FETCH_HANDLER_COUNT 9
+const struct imap_fetch_handler default_handlers[IMAP_FETCH_HANDLER_COUNT];
static buffer_t *fetch_handlers = NULL;
static int imap_fetch_handler_cmp(const void *p1, const void *p2)
return TRUE;
}
-const struct imap_fetch_handler default_handlers[8] = {
+static int fetch_x_mailbox(struct imap_fetch_context *ctx, struct mail *mail,
+ void *context ATTR_UNUSED)
+{
+ const char *str;
+
+ if (mail_get_special(mail, MAIL_FETCH_MAILBOX_NAME, &str) < 0)
+ i_panic("mailbox name not returned");
+ str_append(ctx->cur_str, "X-MAILBOX ");
+ imap_quote_append_string(ctx->cur_str, str, FALSE);
+ return 1;
+}
+
+static bool
+fetch_x_mailbox_init(struct imap_fetch_context *ctx ATTR_UNUSED,
+ const char *name,
+ const struct imap_arg **args ATTR_UNUSED)
+{
+ imap_fetch_add_handler(ctx, TRUE, FALSE, name, NULL,
+ fetch_x_mailbox, NULL);
+ return TRUE;
+}
+
+const struct imap_fetch_handler default_handlers[IMAP_FETCH_HANDLER_COUNT] = {
{ "BODY", fetch_body_init },
{ "BODYSTRUCTURE", fetch_bodystructure_init },
{ "ENVELOPE", fetch_envelope_init },
{ "INTERNALDATE", fetch_internaldate_init },
{ "MODSEQ", fetch_modseq_init },
{ "RFC822", fetch_rfc822_init },
- { "UID", fetch_uid_init }
+ { "UID", fetch_uid_init },
+ { "X-MAILBOX", fetch_x_mailbox_init }
};
static int search_arg_match_cached(struct index_search_context *ctx,
struct mail_search_arg *arg)
{
+ const char *str;
struct tm *tm;
uoff_t virtual_size;
time_t date;
else
return virtual_size > arg->value.size;
+ case SEARCH_MAILBOX:
+ if (mail_get_special(ctx->mail, MAIL_FETCH_MAILBOX_NAME,
+ &str) < 0)
+ return -1;
+
+ if (strcasecmp(str, "INBOX") == 0)
+ return strcasecmp(arg->value.str, "INBOX") == 0;
+ return strcmp(str, arg->value.str) == 0;
default:
return -1;
}
case SEARCH_TEXT:
case SEARCH_BODY_FAST:
case SEARCH_TEXT_FAST:
+ case SEARCH_MAILBOX:
return TRUE;
}
return FALSE;
MAIL_FETCH_FROM_ENVELOPE = 0x00008000,
MAIL_FETCH_HEADER_MD5 = 0x00010000,
MAIL_FETCH_UIDL_FILE_NAME = 0x00020000,
- MAIL_FETCH_UIDL_BACKEND = 0x00040000
+ MAIL_FETCH_UIDL_BACKEND = 0x00040000,
+ MAIL_FETCH_MAILBOX_NAME = 0x00080000
};
enum mailbox_transaction_flags {