]> code.citadel.org Git - citadel.git/blobdiff - citadel/msgbase.c
* IMAP date strings. More stupidity.
[citadel.git] / citadel / msgbase.c
index 1b819f8e833fcc05bb95fe08d4da7a61574864c0..2ef26071149cd0a162bebd24d2f2440b9f9c591e 100644 (file)
@@ -1,4 +1,9 @@
-/* $Id$ */
+/* 
+ * $Id$
+ *
+ * Implements the message store.
+ *
+ */
 
 #include "sysdep.h"
 #include <stdlib.h>
@@ -80,17 +85,18 @@ void remove_any_whitespace_to_the_left_or_right_of_at_symbol(char *name)
 {
        int i;
 
-       for (i = 0; i < strlen(name); ++i)
+stov:  for (i = 0; i < strlen(name); ++i) {
                if (name[i] == '@') {
                        if (i > 0)
                                if (isspace(name[i - 1])) {
                                        strcpy(&name[i - 1], &name[i]);
-                                       i = 0;
+                                       goto stov; /* start over */
                                }
                        while (isspace(name[i + 1])) {
                                strcpy(&name[i + 1], &name[i + 2]);
                        }
                }
+       }
 }
 
 
@@ -225,7 +231,7 @@ void get_mm(void)
 
 
 
-void simple_listing(long msgnum)
+void simple_listing(long msgnum, void *userdata)
 {
        cprintf("%ld\n", msgnum);
 }
@@ -265,13 +271,14 @@ int CtdlMsgCmp(struct CtdlMessage *msg, struct CtdlMessage *template) {
 
 /*
  * API function to perform an operation for each qualifying message in the
- * current room.
+ * current room.  (Returns the number of messages processed.)
  */
-void CtdlForEachMessage(int mode, long ref,
+int CtdlForEachMessage(int mode, long ref,
                        int moderation_level,
                        char *content_type,
                        struct CtdlMessage *compare,
-                       void (*CallBack) (long msgnum))
+                       void (*CallBack) (long, void *),
+                       void *userdata)
 {
 
        int a;
@@ -279,6 +286,7 @@ void CtdlForEachMessage(int mode, long ref,
        struct cdbdata *cdbfr;
        long *msglist = NULL;
        int num_msgs = 0;
+       int num_processed = 0;
        long thismsg;
        struct SuppMsgInfo smi;
        struct CtdlMessage *msg;
@@ -296,7 +304,7 @@ void CtdlForEachMessage(int mode, long ref,
                num_msgs = cdbfr->len / sizeof(long);
                cdb_free(cdbfr);
        } else {
-               return;         /* No messages at all?  No further action. */
+               return 0;       /* No messages at all?  No further action. */
        }
 
 
@@ -358,12 +366,15 @@ void CtdlForEachMessage(int mode, long ref,
                                       || ((mode == MSGS_LAST) && (a >= (num_msgs - ref)))
                                   || ((mode == MSGS_FIRST) && (a < ref))
                                || ((mode == MSGS_GT) && (thismsg > ref))
+                               || ((mode == MSGS_EQ) && (thismsg == ref))
                            )
                            ) {
-                               CallBack(thismsg);
+                               if (CallBack) CallBack(thismsg, userdata);
+                               ++num_processed;
                        }
                }
        phree(msglist);         /* Clean up */
+       return num_processed;
 }
 
 
@@ -429,7 +440,7 @@ void cmd_msgs(char *cmdbuf)
 
        CtdlForEachMessage(mode, cm_ref,
                CC->usersupp.moderation_filter,
-               NULL, template, simple_listing);
+               NULL, template, simple_listing, NULL);
        if (template != NULL) CtdlFreeMessage(template);
        cprintf("000\n");
 }
@@ -956,8 +967,8 @@ int CtdlOutputMsg(long msg_num,             /* message number (local) to fetch */
                                else if (i == 'R')
                                        cprintf("To: %s%s", mptr, nl);
                                else if (i == 'T') {
-                                       generate_rfc822_datestamp(datestamp,
-                                                               atol(mptr) );
+                                       datestring(datestamp, atol(mptr),
+                                               DATESTRING_RFC822 );
                                        cprintf("Date: %s%s", datestamp, nl);
                                }
                        }
@@ -1181,7 +1192,7 @@ void cmd_opna(char *cmdbuf)
 {
        long msgid;
 
-       CtdlAllocUserData(SYM_DESIRED_SECTION, 64);
+       CtdlAllocUserData(SYM_DESIRED_SECTION, 256);
 
        msgid = extract_long(cmdbuf, 0);
        extract(desired_section, cmdbuf, 1);
@@ -1423,7 +1434,7 @@ void serialize_message(struct ser_ret *ret,               /* return values */
 /*
  * Back end for the ReplicationChecks() function
  */
-void check_repl(long msgnum) {
+void check_repl(long msgnum, void *userdata) {
        struct CtdlMessage *msg;
        time_t timestamp = (-1L);
 
@@ -1473,7 +1484,8 @@ int ReplicationChecks(struct CtdlMessage *msg) {
        memset(template, 0, sizeof(struct CtdlMessage));
        template->cm_fields['E'] = strdoop(msg->cm_fields['E']);
 
-       CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, template, check_repl);
+       CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, template,
+               check_repl, NULL);
 
        /* If a newer message exists with the same Extended ID, abort
         * this save.
@@ -2526,7 +2538,7 @@ void CtdlWriteObject(char *req_room,              /* Room to stuff it in */
 
 
 
-void CtdlGetSysConfigBackend(long msgnum) {
+void CtdlGetSysConfigBackend(long msgnum, void *userdata) {
        config_msgnum = msgnum;
 }
 
@@ -2549,7 +2561,7 @@ char *CtdlGetSysConfig(char *sysconfname) {
        begin_critical_section(S_CONFIG);
        config_msgnum = (-1L);
        CtdlForEachMessage(MSGS_LAST, 1, (-127), sysconfname, NULL,
-               CtdlGetSysConfigBackend);
+               CtdlGetSysConfigBackend, NULL);
        msgnum = config_msgnum;
        end_critical_section(S_CONFIG);