Continue phase 2 of modules stuff.
[citadel.git] / citadel / msgbase.c
index 7a1abce384b7f14d551eda54319719d2411ff252..51bf426f110b89a4c22bc57ebe3831317c2cdf8e 100644 (file)
 #include "html.h"
 #include "genstamp.h"
 #include "internet_addressing.h"
-#include "serv_fulltext.h"
+#include "serv_fulltext.h"     /* Needed for ft_search and ft_index_message */
 #include "vcard.h"
 #include "euidindex.h"
 #include "journaling.h"
 #include "citadel_dirs.h"
-#include "serv_network.h"
 
-#ifdef HAVE_LIBSIEVE
-# include "serv_sieve.h"
-#endif /* HAVE_LIBSIEVE */
 
 long config_msgnum;
 struct addresses_to_be_filed *atbf = NULL;
@@ -530,10 +526,12 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
        int num_search_msgs = 0;
        long *search_msgs = NULL;
        regex_t re;
+       int need_to_free_re = 0;
        regmatch_t pm;
 
        if (content_type) if (strlen(content_type) > 0) {
                regcomp(&re, content_type, 0);
+               need_to_free_re = 1;
        }
 
        /* Learn about the user and room in question */
@@ -548,6 +546,7 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                num_msgs = cdbfr->len / sizeof(long);
                cdb_free(cdbfr);
        } else {
+               if (need_to_free_re) regfree(&re);
                return 0;       /* No messages at all?  No further action. */
        }
 
@@ -676,6 +675,7 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                        }
                }
        free(msglist);          /* Clean up */
+       if (need_to_free_re) regfree(&re);
        return num_processed;
 }
 
@@ -992,7 +992,7 @@ void mime_spew_section(char *name, char *filename, char *partnum, char *disp,
 
        *found_it = 1;
 
-       cprintf("%d %d\n", BINARY_FOLLOWS, length);
+       cprintf("%d %d\n", BINARY_FOLLOWS, (int)length);
        client_write(content, length);
 }
 
@@ -2139,15 +2139,8 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
                lprintf(CTDL_DEBUG, "CtdlSaveMsgPointerInRoom() skips repl checks\n");
        }
 
-       /* Submit this room for net processing */
-       network_queue_room(&CC->room, NULL);
-
-#ifdef HAVE_LIBSIEVE
-       /* If this is someone's inbox, submit the room for sieve processing */
-       if (!strcasecmp(&CC->room.QRname[11], MAILROOM)) {
-               sieve_queue_room(&CC->room);
-       }
-#endif /* HAVE_LIBSIEVE */
+       /* Submit this room for processing by hooks */
+       PerformRoomHooks(&CC->room);
 
        /* Go back to the room we were in before we wandered here... */
        getroom(&CC->room, hold_rm);
@@ -2927,6 +2920,7 @@ struct CtdlMessage *CtdlMakeMessage(
        char dest_node[256];
        char buf[1024];
        struct CtdlMessage *msg;
+       int i;
 
        msg = malloc(sizeof(struct CtdlMessage));
        memset(msg, 0, sizeof(struct CtdlMessage));
@@ -2940,8 +2934,21 @@ struct CtdlMessage *CtdlMakeMessage(
        striplt(recipient);
        striplt(recp_cc);
 
-       snprintf(buf, sizeof buf, "cit%ld", author->usernum);   /* Path */
-       msg->cm_fields['P'] = strdup(buf);
+       /* Path or Return-Path */
+       if (my_email == NULL) my_email = "";
+
+       if (strlen(my_email) > 0) {
+               msg->cm_fields['P'] = strdup(my_email);
+       }
+       else {
+               snprintf(buf, sizeof buf, "%s", author->fullname);
+               msg->cm_fields['P'] = strdup(buf);
+       }
+       for (i=0; (msg->cm_fields['P'][i]!=0); ++i) {
+               if (isspace(msg->cm_fields['P'][i])) {
+                       msg->cm_fields['P'][i] = '_';
+               }
+       }
 
        snprintf(buf, sizeof buf, "%ld", (long)time(NULL));     /* timestamp */
        msg->cm_fields['T'] = strdup(buf);
@@ -3330,6 +3337,7 @@ void cmd_ent0(char *entargs)
        struct recptypes *valid_cc = NULL;
        struct recptypes *valid_bcc = NULL;
        char subject[SIZ];
+       int subject_required = 0;
        int do_confirm = 0;
        long msgnum;
        int i, j;
@@ -3512,12 +3520,22 @@ void cmd_ent0(char *entargs)
                recp[0] = 0;
        }
 
+       /* Recommend to the client that the use of a message subject is
+        * strongly recommended in this room, if either the SUBJECTREQ flag
+        * is set, or if there is one or more Internet email recipients.
+        */
+       if (CC->room.QRflags2 & QR2_SUBJECTREQ) subject_required = 1;
+       if (valid_to) if (valid_to->num_internet > 0) subject_required = 1;
+       if (valid_cc) if (valid_cc->num_internet > 0) subject_required = 1;
+       if (valid_bcc) if (valid_bcc->num_internet > 0) subject_required = 1;
+
        /* If we're only checking the validity of the request, return
         * success without creating the message.
         */
        if (post == 0) {
-               cprintf("%d %s\n", CIT_OK,
-                       ((valid_to != NULL) ? valid_to->display_recp : "") );
+               cprintf("%d %s|%d\n", CIT_OK,
+                       ((valid_to != NULL) ? valid_to->display_recp : ""), 
+                       subject_required);
                free_recipients(valid_to);
                free_recipients(valid_cc);
                free_recipients(valid_bcc);
@@ -3617,9 +3635,11 @@ int CtdlDeleteMessages(char *room_name,          /* which room */
        struct MetaData smi;
        regex_t re;
        regmatch_t pm;
+       int need_to_free_re = 0;
 
        if (content_type) if (strlen(content_type) > 0) {
                regcomp(&re, content_type, 0);
+               need_to_free_re = 1;
        }
        lprintf(CTDL_DEBUG, "CtdlDeleteMessages(%s, %d msgs, %s)\n",
                room_name, num_dmsgnums, content_type);
@@ -3628,6 +3648,7 @@ int CtdlDeleteMessages(char *room_name,           /* which room */
        if (lgetroom(&qrbuf, room_name) != 0) {
                lprintf(CTDL_ERR, "CtdlDeleteMessages(): Room <%s> not found\n",
                        room_name);
+               if (need_to_free_re) regfree(&re);
                return (0);     /* room not found */
        }
        cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf.QRnumber, sizeof(long));
@@ -3700,6 +3721,7 @@ int CtdlDeleteMessages(char *room_name,           /* which room */
        if (msglist != NULL) free(msglist);
        if (dellist != NULL) free(dellist);
        lprintf(CTDL_DEBUG, "%d message(s) deleted.\n", num_deleted);
+       if (need_to_free_re) regfree(&re);
        return (num_deleted);
 }