#include <errno.h>
#include <stdarg.h>
#include <sys/stat.h>
+#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
-#include "serv_extensions.h"
#include "database.h"
#include "msgbase.h"
#include "support.h"
#include "file_ops.h"
#include "config.h"
#include "control.h"
-#include "tools.h"
#include "euidindex.h"
/*
*/
+
+/*
+ * Return nonzero if the supplied room is one which should have
+ * an EUID index.
+ */
+int DoesThisRoomNeedEuidIndexing(struct ctdlroom *qrbuf) {
+
+ switch(qrbuf->QRdefaultview) {
+ case VIEW_BBS: return(0);
+ case VIEW_MAILBOX: return(0);
+ case VIEW_ADDRESSBOOK: return(1);
+ case VIEW_CALENDAR: return(1);
+ case VIEW_TASKS: return(1);
+ case VIEW_NOTES: return(1);
+ case VIEW_WIKI: return(1);
+ }
+
+ return(0);
+}
+
+
+
+
+
+
/*
* Locate a message in a given room with a given euid, and return
* its message number.
* Called by rebuild_euid_index_for_room() to index one message.
*/
void rebuild_euid_index_for_msg(long msgnum, void *userdata) {
- struct CtdlMessage *msg;
+ struct CtdlMessage *msg = NULL;
msg = CtdlFetchMessage(msgnum, 0);
if (msg == NULL) return;
while (rplist != NULL) {
if (getroom(&qr, rplist->name) == 0) {
- lprintf(CTDL_DEBUG, "Rebuilding EUID index for <%s>\n", rplist->name);
- usergoto(rplist->name, 0, 0, NULL, NULL);
- CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, rebuild_euid_index_for_msg, NULL);
+ if (DoesThisRoomNeedEuidIndexing(&qr)) {
+ lprintf(CTDL_DEBUG,
+ "Rebuilding EUID index for <%s>\n",
+ rplist->name);
+ usergoto(rplist->name, 0, 0, NULL, NULL);
+ CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
+ rebuild_euid_index_for_msg, NULL);
+ }
}
ptr = rplist;
rplist = rplist->next;
* Globally rebuild the EUID indices in every room.
*/
void rebuild_euid_index(void) {
- cdb_trunc(CDB_EUIDINDEX); /* delete the old indices */
- ForEachRoom(rebuild_euid_index_for_room, NULL); /* enumerate the room names */
- rebuild_euid_index_for_room(NULL, NULL); /* now do indexing on them */
+ cdb_trunc(CDB_EUIDINDEX); /* delete the old indices */
+ ForEachRoom(rebuild_euid_index_for_room, NULL); /* enumerate rm names */
+ rebuild_euid_index_for_room(NULL, NULL); /* and index them */
}
void cmd_euid(char *cmdbuf) {
char euid[256];
long msgnum;
+ struct cdbdata *cdbfr;
+ long *msglist = NULL;
+ int num_msgs = 0;
+ int i;
if (CtdlAccessCheck(ac_logged_in)) return;
extract_token(euid, cmdbuf, 0, '|', sizeof euid);
msgnum = locate_message_by_euid(euid, &CC->room);
-
- if (msgnum > 0L) {
- cprintf("%d %ld\n", CIT_OK, msgnum);
- }
- else {
+ if (msgnum <= 0L) {
cprintf("%d not found\n", ERROR + MESSAGE_NOT_FOUND);
+ return;
+ }
+
+ cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
+ if (cdbfr != NULL) {
+ num_msgs = cdbfr->len / sizeof(long);
+ msglist = (long *) cdbfr->ptr;
+ for (i = 0; i < num_msgs; ++i) {
+ if (msglist[i] == msgnum) {
+ cdb_free(cdbfr);
+ cprintf("%d %ld\n", CIT_OK, msgnum);
+ return;
+ }
+ }
+ cdb_free(cdbfr);
}
+
+ cprintf("%d not found\n", ERROR + MESSAGE_NOT_FOUND);
}
+
+