#include "citserver.h"
#include "support.h"
#include "config.h"
-#include "serv_extensions.h"
#include "room_ops.h"
#include "user_ops.h"
#include "policy.h"
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Bcc");
- if (fieldptr != NULL) {
- if (bmstrcasestr(fieldptr, itemlist[pos+1])) {
- match = 1;
+ if (msg != NULL) {
+ fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Bcc");
+ if (fieldptr != NULL) {
+ if (bmstrcasestr(fieldptr, itemlist[pos+1])) {
+ match = 1;
+ }
+ free(fieldptr);
}
- free(fieldptr);
}
pos += 2;
}
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (msg->cm_fields['T'] != NULL) {
- if (imap_datecmp(itemlist[pos+1],
- atol(msg->cm_fields['T'])) < 0) {
- match = 1;
+ if (msg != NULL) {
+ if (msg->cm_fields['T'] != NULL) {
+ if (imap_datecmp(itemlist[pos+1],
+ atol(msg->cm_fields['T'])) < 0) {
+ match = 1;
+ }
}
}
pos += 2;
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (bmstrcasestr(msg->cm_fields['M'], itemlist[pos+1])) {
- match = 1;
+ if (msg != NULL) {
+ if (bmstrcasestr(msg->cm_fields['M'], itemlist[pos+1])) {
+ match = 1;
+ }
}
}
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- fieldptr = msg->cm_fields['Y'];
- if (fieldptr != NULL) {
- if (bmstrcasestr(fieldptr, itemlist[pos+1])) {
- match = 1;
- }
- }
- else {
- fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Cc");
+ if (msg != NULL) {
+ fieldptr = msg->cm_fields['Y'];
if (fieldptr != NULL) {
if (bmstrcasestr(fieldptr, itemlist[pos+1])) {
match = 1;
}
- free(fieldptr);
+ }
+ else {
+ fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Cc");
+ if (fieldptr != NULL) {
+ if (bmstrcasestr(fieldptr, itemlist[pos+1])) {
+ match = 1;
+ }
+ free(fieldptr);
+ }
}
}
pos += 2;
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (bmstrcasestr(msg->cm_fields['A'], itemlist[pos+1])) {
- match = 1;
- }
- if (bmstrcasestr(msg->cm_fields['F'], itemlist[pos+1])) {
- match = 1;
+ if (msg != NULL) {
+ if (bmstrcasestr(msg->cm_fields['A'], itemlist[pos+1])) {
+ match = 1;
+ }
+ if (bmstrcasestr(msg->cm_fields['F'], itemlist[pos+1])) {
+ match = 1;
+ }
}
pos += 2;
}
else if (!strcasecmp(itemlist[pos], "HEADER")) {
- /* FIXME */
+
+ /* We've got to do a slow search for this because the client
+ * might be asking for an RFC822 header field that has not been
+ * converted into a Citadel header field. That requires
+ * examining the message body.
+ */
+ if (msg == NULL) {
+ msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
+ need_to_free_msg = 1;
+ }
+
+ if (msg != NULL) {
+
+ CC->redirect_buffer = malloc(SIZ);
+ CC->redirect_len = 0;
+ CC->redirect_alloc = SIZ;
+ CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1);
+
+ fieldptr = rfc822_fetch_field(CC->redirect_buffer, itemlist[pos+1]);
+ if (fieldptr != NULL) {
+ if (bmstrcasestr(fieldptr, itemlist[pos+2])) {
+ match = 1;
+ }
+ free(fieldptr);
+ }
+
+ free(CC->redirect_buffer);
+ CC->redirect_buffer = NULL;
+ CC->redirect_len = 0;
+ CC->redirect_alloc = 0;
+ }
+
pos += 3; /* Yes, three */
}
else if (!strcasecmp(itemlist[pos], "KEYWORD")) {
- /* FIXME */
+ /* not implemented */
pos += 2;
}
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (strlen(msg->cm_fields['M']) > atoi(itemlist[pos+1])) {
- match = 1;
+ if (msg != NULL) {
+ if (strlen(msg->cm_fields['M']) > atoi(itemlist[pos+1])) {
+ match = 1;
+ }
}
pos += 2;
}
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (msg->cm_fields['T'] != NULL) {
- if (imap_datecmp(itemlist[pos+1],
- atol(msg->cm_fields['T'])) == 0) {
- match = 1;
+ if (msg != NULL) {
+ if (msg->cm_fields['T'] != NULL) {
+ if (imap_datecmp(itemlist[pos+1],
+ atol(msg->cm_fields['T'])) == 0) {
+ match = 1;
+ }
}
}
pos += 2;
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (msg->cm_fields['T'] != NULL) {
- if (imap_datecmp(itemlist[pos+1],
- atol(msg->cm_fields['T'])) < 0) {
- match = 1;
+ if (msg != NULL) {
+ if (msg->cm_fields['T'] != NULL) {
+ if (imap_datecmp(itemlist[pos+1],
+ atol(msg->cm_fields['T'])) < 0) {
+ match = 1;
+ }
}
}
pos += 2;
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (msg->cm_fields['T'] != NULL) {
- if (imap_datecmp(itemlist[pos+1],
- atol(msg->cm_fields['T'])) == 0) {
- match = 1;
+ if (msg != NULL) {
+ if (msg->cm_fields['T'] != NULL) {
+ if (imap_datecmp(itemlist[pos+1],
+ atol(msg->cm_fields['T'])) == 0) {
+ match = 1;
+ }
}
}
pos += 2;
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (msg->cm_fields['T'] != NULL) {
- if (imap_datecmp(itemlist[pos+1],
- atol(msg->cm_fields['T'])) >= 0) {
- match = 1;
+ if (msg != NULL) {
+ if (msg->cm_fields['T'] != NULL) {
+ if (imap_datecmp(itemlist[pos+1],
+ atol(msg->cm_fields['T'])) >= 0) {
+ match = 1;
+ }
}
}
pos += 2;
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (msg->cm_fields['T'] != NULL) {
- if (imap_datecmp(itemlist[pos+1],
- atol(msg->cm_fields['T'])) >= 0) {
- match = 1;
+ if (msg != NULL) {
+ if (msg->cm_fields['T'] != NULL) {
+ if (imap_datecmp(itemlist[pos+1],
+ atol(msg->cm_fields['T'])) >= 0) {
+ match = 1;
+ }
}
}
pos += 2;
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (strlen(msg->cm_fields['M']) < atoi(itemlist[pos+1])) {
- match = 1;
+ if (msg != NULL) {
+ if (strlen(msg->cm_fields['M']) < atoi(itemlist[pos+1])) {
+ match = 1;
+ }
}
pos += 2;
}
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (bmstrcasestr(msg->cm_fields['U'], itemlist[pos+1])) {
- match = 1;
+ if (msg != NULL) {
+ if (bmstrcasestr(msg->cm_fields['U'], itemlist[pos+1])) {
+ match = 1;
+ }
}
pos += 2;
}
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- for (i='A'; i<='Z'; ++i) {
- if (bmstrcasestr(msg->cm_fields[i], itemlist[pos+1])) {
- match = 1;
+ if (msg != NULL) {
+ for (i='A'; i<='Z'; ++i) {
+ if (bmstrcasestr(msg->cm_fields[i], itemlist[pos+1])) {
+ match = 1;
+ }
}
}
pos += 2;
msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1);
need_to_free_msg = 1;
}
- if (bmstrcasestr(msg->cm_fields['R'], itemlist[pos+1])) {
- match = 1;
+ if (msg != NULL) {
+ if (bmstrcasestr(msg->cm_fields['R'], itemlist[pos+1])) {
+ match = 1;
+ }
}
pos += 2;
}
+ /* FIXME this is b0rken. fix it. */
+ else if (imap_is_message_set(itemlist[pos])) {
+ if (is_msg_in_sequence_set(itemlist[pos], seq)) {
+ match = 1;
+ }
+ pos += 1;
+ }
+
+ /* FIXME this is b0rken. fix it. */
else if (!strcasecmp(itemlist[pos], "UID")) {
if (is_msg_in_sequence_set(itemlist[pos+1], IMAP->msgids[seq-1])) {
match = 1;
/* Now here come the 'UN' criteria. Why oh why do we have to
* implement *both* the 'UN' criteria *and* the 'NOT' keyword? Why
- * can't there be *one* way to do things? Answer: the design of
- * IMAP suffers from gratuitous complexity.
+ * can't there be *one* way to do things? More gratuitous complexity.
*/
else if (!strcasecmp(itemlist[pos], "UNANSWERED")) {
* text index to disqualify messages that don't have any chance of
* matching. (Only do this if the index is enabled!!)
*/
- if (config.c_enable_fulltext) for (i=0; i<(num_items-1); ++i) {
+ if (config.c_enable_fulltext) for (i=0; i<(num_items-1); ++i) {
if (!strcasecmp(itemlist[i], "BODY")) {
ft_search(&fts_num_msgs, &fts_msgs, itemlist[i+1]);
if (fts_num_msgs > 0) {
IMAP->flags[i] |= IMAP_SELECTED;
}
- for (i=1; i<num_parms; ++i) {
- if (imap_is_message_set(parms[i])) {
- imap_pick_range(parms[i], 0);
- }
- }
-
imap_do_search(num_parms-2, &parms[2], 0);
cprintf("%s OK SEARCH completed\r\n", parms[0]);
}
IMAP->flags[i] |= IMAP_SELECTED;
}
- for (i=1; i<num_parms; ++i) {
- if (imap_is_message_set(parms[i])) {
- imap_pick_range(parms[i], 1);
- }
- }
-
imap_do_search(num_parms-3, &parms[3], 1);
cprintf("%s OK UID SEARCH completed\r\n", parms[0]);
}