Added a system of weighted preferences to the
[citadel.git] / citadel / msgbase.c
index 978b19e9d1499bc169cfa0d3725b9acc71bc994f..3361b0c440c26faacf5aa9b155659fb42f38984d 100644 (file)
 #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;
 
@@ -1205,6 +1209,12 @@ void fixed_output(char *name, char *filename, char *partnum, char *disp,
  * The client is elegant and sophisticated and wants to be choosy about
  * MIME content types, so figure out which multipart/alternative part
  * we're going to send.
+ *
+ * We use a system of weights.  When we find a part that matches one of the
+ * MIME types we've declared as preferential, we can store it in ma->chosen_part
+ * and then set ma->chosen_pref to that MIME type's position in our preference
+ * list.  If we then hit another match, we only replace the first match if
+ * the preference value is lower.
  */
 void choose_preferred(char *name, char *filename, char *partnum, char *disp,
                void *content, char *cbtype, char *cbcharset, size_t length,
@@ -1219,8 +1229,12 @@ void choose_preferred(char *name, char *filename, char *partnum, char *disp,
        if (ma->is_ma > 0) {
                for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
                        extract_token(buf, CC->preferred_formats, i, '|', sizeof buf);
+                       lprintf(CTDL_DEBUG, "Is <%s> == <%s> ??\n", buf, cbtype);
                        if ( (!strcasecmp(buf, cbtype)) && (!ma->freeze) ) {
-                               safestrncpy(ma->chosen_part, partnum, sizeof ma->chosen_part);
+                               if (i < ma->chosen_pref) {
+                                       safestrncpy(ma->chosen_part, partnum, sizeof ma->chosen_part);
+                                       ma->chosen_pref = i;
+                               }
                        }
                }
        }
@@ -1580,6 +1594,12 @@ int CtdlOutputPreLoadedMsg(
                                else if (i == 'Y') {
                                        cprintf("CC: %s%s", mptr, nl);
                                }
+                               else if (i == 'P') {
+                                       cprintf("Return-Path: %s%s", mptr, nl);
+                               }
+                               else if (i == 'V') {
+                                       cprintf("Envelope-To: %s%s", mptr, nl);
+                               }
                                else if (i == 'U') {
                                        cprintf("Subject: %s%s", mptr, nl);
                                        subject_found = 1;
@@ -1756,6 +1776,7 @@ START_TEXT:
                if (mode == MT_MIME) {
                        ma.use_fo_hooks = 0;
                        strcpy(ma.chosen_part, "1");
+                       ma.chosen_pref = 9999;
                        mime_parser(mptr, NULL,
                                *choose_preferred, *fixed_output_pre,
                                *fixed_output_post, (void *)&ma, 0);
@@ -2036,6 +2057,13 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
        /* 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 */
+
        /* Go back to the room we were in before we wandered here... */
        getroom(&CC->room, hold_rm);