Added a system of weighted preferences to the
authorArt Cancro <ajc@citadel.org>
Tue, 24 Oct 2006 03:05:21 +0000 (03:05 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 24 Oct 2006 03:05:21 +0000 (03:05 +0000)
choose_preferred() callback.  This will ensure that when we parse a
multipart/alternative message, the MIME types we've declared earlier in
our preference list will always be chosen ahead of the ones we've
declared later.  This will eliminate the need for the text client to
parse HTML messages when there's a perfectly good text/plain available.

citadel/msgbase.c
citadel/msgbase.h

index a098a5cb879c90a5ae9b9e4d82e70bf882427cf3..3361b0c440c26faacf5aa9b155659fb42f38984d 100644 (file)
@@ -1209,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,
@@ -1223,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;
+                               }
                        }
                }
        }
@@ -1766,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);
index 88c58ecaccf319ab46d7876400d27e8d07fb97fd..6cfa6e481cdbea75ce3207aa0e28583238d76679 100644 (file)
@@ -38,6 +38,7 @@ struct ma_info {
                                 * digging through a subsection */
        int did_print;          /* One alternative has been displayed */
        char chosen_part[128];  /* Which part of a m/a did we choose? */
+       int chosen_pref;        /* Chosen part preference level (lower is better) */
        int use_fo_hooks;       /* Use fixed output hooks */
 };