]> code.citadel.org Git - citadel.git/blobdiff - citadel/msgbase.c
* Changed the comments at the beginning of each file to a consistent format
[citadel.git] / citadel / msgbase.c
index 1b819f8e833fcc05bb95fe08d4da7a61574864c0..086ca77e63b2aeaaf4d4fd49757677e714b630d6 100644 (file)
@@ -1,4 +1,9 @@
-/* $Id$ */
+/* 
+ * $Id$
+ *
+ * Implements the message store.
+ *
+ */
 
 #include "sysdep.h"
 #include <stdlib.h>
@@ -104,13 +109,16 @@ int alias(char *name)
        int a, b;
        char aaa[300], bbb[300];
 
+       TRACE;
        remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
+       TRACE;
 
        fp = fopen("network/mail.aliases", "r");
        if (fp == NULL)
                fp = fopen("/dev/null", "r");
        if (fp == NULL)
                return (MES_ERROR);
+       TRACE;
        strcpy(aaa, "");
        strcpy(bbb, "");
        while (fgets(aaa, sizeof aaa, fp) != NULL) {
@@ -127,6 +135,7 @@ int alias(char *name)
                if (!strcasecmp(name, aaa))
                        strcpy(name, bbb);
        }
+       TRACE;
        fclose(fp);
        lprintf(7, "Mail is being forwarded to %s\n", name);
 
@@ -141,15 +150,18 @@ int alias(char *name)
        }
 
        /* determine local or remote type, see citadel.h */
+       TRACE;
        for (a = 0; a < strlen(name); ++a)
                if (name[a] == '!')
                        return (MES_INTERNET);
+       TRACE;
        for (a = 0; a < strlen(name); ++a)
                if (name[a] == '@')
                        for (b = a; b < strlen(name); ++b)
                                if (name[b] == '.')
                                        return (MES_INTERNET);
        b = 0;
+       TRACE;
        for (a = 0; a < strlen(name); ++a)
                if (name[a] == '@')
                        ++b;
@@ -169,6 +181,7 @@ int alias(char *name)
 GETSN:         do {
                        a = getstring(fp, aaa);
                } while ((a >= 0) && (strcasecmp(aaa, bbb)));
+               TRACE;
                a = getstring(fp, aaa);
                if (!strncmp(aaa, "use ", 4)) {
                        strcpy(bbb, &aaa[4]);
@@ -176,6 +189,7 @@ GETSN:              do {
                        goto GETSN;
                }
                fclose(fp);
+               TRACE;
                if (!strncmp(aaa, "uum", 3)) {
                        strcpy(bbb, name);
                        for (a = 0; a < strlen(bbb); ++a) {
@@ -209,6 +223,7 @@ GETSN:              do {
                }
                return (MES_ERROR);
        }
+       TRACE;
        lprintf(9, "returning MES_LOCAL\n");
        return (MES_LOCAL);
 }
@@ -265,9 +280,9 @@ 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,
@@ -279,6 +294,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 +312,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 +374,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);
+                               ++num_processed;
                        }
                }
        phree(msglist);         /* Clean up */
+       return num_processed;
 }