]> 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 88d1484dfb1dcd682b114ba0ed4b049d591ae04c..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,10 @@ 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))
@@ -278,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;
@@ -295,22 +312,29 @@ 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. */
        }
 
 
-       /* If the caller is looking for a specific MIME type, then filter
-        * out all messages which are not of the type requested.
-        */
-       if (num_msgs > 0)
-               if (content_type != NULL)
-                       if (strlen(content_type) > 0)
-                               for (a = 0; a < num_msgs; ++a) {
-                                       GetSuppMsgInfo(&smi, msglist[a]);
-                                       if (strcasecmp(smi.smi_content_type, content_type)) {
-                                               msglist[a] = 0L;
-                                       }
-                               }
+       if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
+               GetSuppMsgInfo(&smi, msglist[a]);
+
+               /* Filter out messages that are moderated below the level
+                * currently being viewed at.
+                */
+               if (smi.smi_mod < moderation_level) {
+                       msglist[a] = 0L;
+               }
+
+               /* If the caller is looking for a specific MIME type, filter
+                * out all messages which are not of the type requested.
+                */
+               if (content_type != NULL) if (strlen(content_type) > 0) {
+                       if (strcasecmp(smi.smi_content_type, content_type)) {
+                               msglist[a] = 0L;
+                       }
+               }
+       }
 
        num_msgs = sort_msglist(msglist, num_msgs);
 
@@ -350,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;
 }
 
 
@@ -419,7 +446,9 @@ void cmd_msgs(char *cmdbuf)
                cprintf("%d Message list...\n", LISTING_FOLLOWS);
        }
 
-       CtdlForEachMessage(mode, cm_ref, NULL, template, simple_listing);
+       CtdlForEachMessage(mode, cm_ref,
+               CC->usersupp.moderation_filter,
+               NULL, template, simple_listing);
        if (template != NULL) CtdlFreeMessage(template);
        cprintf("000\n");
 }
@@ -1433,7 +1462,7 @@ void check_repl(long msgnum) {
        lprintf(9, "older!\n");
 
        /* Existing isn't newer?  Then delete the old one(s). */
-       CtdlDeleteMessages(CC->quickroom.QRname, msgnum, NULL);
+       CtdlDeleteMessages(CC->quickroom.QRname, msgnum, "");
 }
 
 
@@ -1463,7 +1492,7 @@ int ReplicationChecks(struct CtdlMessage *msg) {
        memset(template, 0, sizeof(struct CtdlMessage));
        template->cm_fields['E'] = strdoop(msg->cm_fields['E']);
 
-       CtdlForEachMessage(MSGS_ALL, 0L, NULL, template, check_repl);
+       CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, template, check_repl);
 
        /* If a newer message exists with the same Extended ID, abort
         * this save.
@@ -2178,7 +2207,7 @@ void cmd_ent3(char *entargs)
  */
 int CtdlDeleteMessages(char *room_name,                /* which room */
                       long dmsgnum,            /* or "0" for any */
-                      char *content_type       /* or NULL for any */
+                      char *content_type       /* or "" for any */
 )
 {
 
@@ -2217,7 +2246,7 @@ int CtdlDeleteMessages(char *room_name,           /* which room */
                        if ((dmsgnum == 0L) || (msglist[i] == dmsgnum)) {
                                delete_this |= 0x01;
                        }
-                       if (content_type == NULL) {
+                       if (strlen(content_type) == 0) {
                                delete_this |= 0x02;
                        } else {
                                GetSuppMsgInfo(&smi, msglist[i]);
@@ -2268,7 +2297,7 @@ void cmd_dele(char *delstr)
        }
        delnum = extract_long(delstr, 0);
 
-       num_deleted = CtdlDeleteMessages(CC->quickroom.QRname, delnum, NULL);
+       num_deleted = CtdlDeleteMessages(CC->quickroom.QRname, delnum, "");
 
        if (num_deleted) {
                cprintf("%d %d message%s deleted.\n", OK,
@@ -2319,7 +2348,7 @@ void cmd_move(char *args)
        /* Now delete the message from the source room,
         * if this is a 'move' rather than a 'copy' operation.
         */
-       if (is_copy == 0) CtdlDeleteMessages(CC->quickroom.QRname, num, NULL);
+       if (is_copy == 0) CtdlDeleteMessages(CC->quickroom.QRname, num, "");
 
        cprintf("%d Message %s.\n", OK, (is_copy ? "copied" : "moved") );
 }
@@ -2538,7 +2567,7 @@ char *CtdlGetSysConfig(char *sysconfname) {
        /* We want the last (and probably only) config in this room */
        begin_critical_section(S_CONFIG);
        config_msgnum = (-1L);
-       CtdlForEachMessage(MSGS_LAST, 1, sysconfname, NULL,
+       CtdlForEachMessage(MSGS_LAST, 1, (-127), sysconfname, NULL,
                CtdlGetSysConfigBackend);
        msgnum = config_msgnum;
        end_critical_section(S_CONFIG);