* Completed the MSGP and MSG4 commands to set the client's preferred MIME
authorArt Cancro <ajc@citadel.org>
Tue, 23 Jul 2002 04:00:06 +0000 (04:00 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 23 Jul 2002 04:00:06 +0000 (04:00 +0000)
  content types, and fetch messages with MIME content types.

citadel/ChangeLog
citadel/citserver.c
citadel/msgbase.c
citadel/msgbase.h
citadel/server.h
citadel/techdoc/session.txt

index 7639848958428540f4194f5ccc2cc8579acfe62e..c7c2c9ae07c5c54c15020df94c188b72aa733b6d 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 591.73  2002/07/23 04:00:06  ajc
+ * Completed the MSGP and MSG4 commands to set the client's preferred MIME
+   content types, and fetch messages with MIME content types.
+
  Revision 591.72  2002/07/21 22:29:46  ajc
  * Added in some infrastructure to switch the client's message reading from
    conventional MSG0 to a MIME-download type thing, like WebCit does.
@@ -3831,3 +3835,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index e68a21d1284e6238c90d29b3ce84ec68812032a4..7785c73cb52bdca140d303a30bcaeb52402c0132 100644 (file)
@@ -1027,6 +1027,10 @@ void do_command_loop(void) {
                cmd_msg4(&cmdbuf[5]);
        }
 
+       else if (!strncasecmp(cmdbuf,"MSGP",4)) {
+               cmd_msgp(&cmdbuf[5]);
+       }
+
        else if (!strncasecmp(cmdbuf,"OPNA",4)) {
                cmd_opna(&cmdbuf[5]);
        }
index acbfaa7a26167379ec4c6bc85279955fb457bc98..34027331d5296957599fd73cc3914d690a57b3d7 100644 (file)
@@ -881,7 +881,7 @@ void fixed_output_pre(char *name, char *filename, char *partnum, char *disp,
 {
                lprintf(9, "fixed_output_pre() type=<%s>\n", cbtype);   
                if (!strcasecmp(cbtype, "multipart/alternative")) {
-                       ma->is_ma = 1;
+                       ++ma->is_ma;
                        ma->did_print = 0;
                        return;
                }
@@ -896,7 +896,7 @@ void fixed_output_post(char *name, char *filename, char *partnum, char *disp,
 {
                lprintf(9, "fixed_output_post() type=<%s>\n", cbtype);  
                if (!strcasecmp(cbtype, "multipart/alternative")) {
-                       ma->is_ma = 0;
+                       --ma->is_ma;
                        ma->did_print = 0;
                        return;
                }
@@ -950,6 +950,73 @@ 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.
+ */
+void choose_preferred(char *name, char *filename, char *partnum, char *disp,
+               void *content, char *cbtype, size_t length, char *encoding,
+               void *cbuserdata)
+{
+       char buf[SIZ];
+       int i;
+
+       if (ma->is_ma > 0) {
+               for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
+                       extract(buf, CC->preferred_formats, i);
+                       if (!strcasecmp(buf, cbtype)) {
+                               strcpy(ma->chosen_part, partnum);
+                       }
+               }
+       }
+}
+
+/*
+ * Now that we've chosen our preferred part, output it.
+ */
+void output_preferred(char *name, char *filename, char *partnum, char *disp,
+               void *content, char *cbtype, size_t length, char *encoding,
+               void *cbuserdata)
+{
+       int i;
+       char buf[SIZ];
+       int add_newline = 0;
+       char *text_content;
+
+       /* This is not the MIME part you're looking for... */
+       if (strcasecmp(partnum, ma->chosen_part)) return;
+
+       /* If the content-type of this part is in our preferred formats
+        * list, we can simply output it verbatim.
+        */
+       for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
+               extract(buf, CC->preferred_formats, i);
+               if (!strcasecmp(buf, cbtype)) {
+                       /* Yeah!  Go!  W00t!! */
+
+                       text_content = (char *)content;
+                       if (text_content[length-1] != '\n') {
+                               ++add_newline;
+                       }
+
+                       cprintf("Content-type: %s\n", cbtype);
+                       cprintf("Content-length: %d\n",
+                               length + add_newline);
+                       cprintf("Content-transfer-encoding: %s\n", encoding);
+                       cprintf("\n");
+                       client_write(content, length);
+                       if (add_newline) cprintf("\n");
+                       return;
+               }
+       }
+
+       /* No translations required or possible: output as text/plain */
+       cprintf("Content-type: text/plain\n\n");
+       fixed_output(name, filename, partnum, disp, content, cbtype,
+                       length, encoding, cbuserdata);
+}
+
 
 /*
  * Get a message off disk.  (returns om_* values found in msgbase.h)
@@ -1092,28 +1159,17 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
        /* now for the user-mode message reading loops */
        if (do_proto) cprintf("%d Message %ld:\n", LISTING_FOLLOWS, msg_num);
 
-       /******** (we don't do this anymore)
-        * Tell the client which format type we're using.  If this is a
-        * MIME message, *lie* about it and tell the user it's fixed-format.
-       if (mode == MT_CITADEL) {
-               if (TheMessage->cm_format_type == FMT_RFC822) {
-                       if (do_proto) cprintf("type=1\n");
-               }
-               else {
-                       if (do_proto) cprintf("type=%d\n",
-                               TheMessage->cm_format_type);
-               }
-       }
-        ***************/
-
-       /* Tell the client the truth about which format type we're using. */
+       /* Tell the client which format type we're using. */
        if ( (mode == MT_CITADEL) && (do_proto) ) {
                cprintf("type=%d\n", TheMessage->cm_format_type);
        }
 
        /* nhdr=yes means that we're only displaying headers, no body */
-       if ((TheMessage->cm_anon_type == MES_ANONONLY) && (mode == MT_CITADEL)) {
-               if (do_proto) cprintf("nhdr=yes\n");
+       if ( (TheMessage->cm_anon_type == MES_ANONONLY)
+           && (mode == MT_CITADEL)
+          && (do_proto)
+          ) {
+               cprintf("nhdr=yes\n");
        }
 
        /* begin header processing loop for Citadel message format */
@@ -1223,8 +1279,8 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
                                else if (i == 'R')
                                        cprintf("To: %s%s", mptr, nl);
                                else if (i == 'T') {
-                                       datestring(datestamp, sizeof datestamp, atol(mptr),
-                                               DATESTRING_RFC822 );
+                                       datestring(datestamp, sizeof datestamp,
+                                               atol(mptr), DATESTRING_RFC822);
                                        cprintf("Date: %s%s", datestamp, nl);
                                }
                        }
@@ -1266,21 +1322,12 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
 
        /* Tell the client about the MIME parts in this message */
        if (TheMessage->cm_format_type == FMT_RFC822) {
-               if (mode == MT_CITADEL) {
-                       mime_parser(mptr, NULL,
-                               *list_this_part,
-                               *list_this_pref,
-                               *list_this_suff,
-                               NULL, 0);
-               }
-               else if (mode == MT_MIME) {     /* list parts only */
+               if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) {
                        mime_parser(mptr, NULL,
                                *list_this_part,
                                *list_this_pref,
                                *list_this_suff,
                                NULL, 0);
-                       if (do_proto) cprintf("000\n");
-                       return(om_ok);
                }
                else if (mode == MT_RFC822) {   /* unparsed RFC822 dump */
                        /* FIXME ... we have to put some code in here to avoid
@@ -1304,8 +1351,9 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
        }
 
        /* signify start of msg text */
-       if (mode == MT_CITADEL)
+       if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) {
                if (do_proto) cprintf("text\n");
+       }
        if (mode == MT_RFC822) {
                if (TheMessage->cm_fields['U'] == NULL) {
                        cprintf("Subject: (no subject)%s", nl);
@@ -1318,6 +1366,9 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
         * what message transfer format is in use.
         */
        if (TheMessage->cm_format_type == FMT_FIXED) {
+               if (mode == MT_MIME) {
+                       cprintf("Content-type: text/plain\n\n");
+               }
                strcpy(buf, "");
                while (ch = *mptr++, ch > 0) {
                        if (ch == 13)
@@ -1342,6 +1393,9 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
         * message to the reader's screen width.
         */
        if (TheMessage->cm_format_type == FMT_CITADEL) {
+               if (mode == MT_MIME) {
+                       cprintf("Content-type: text/x-citadel-variformat\n\n");
+               }
                memfmout(80, mptr, 0, nl);
        }
 
@@ -1353,9 +1407,20 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
        if (TheMessage->cm_format_type == FMT_RFC822) {
                CtdlAllocUserData(SYM_MA_INFO, sizeof(struct ma_info));
                memset(ma, 0, sizeof(struct ma_info));
-               mime_parser(mptr, NULL,
-                       *fixed_output, *fixed_output_pre, *fixed_output_post,
-                       NULL, 0);
+
+               if (mode == MT_MIME) {
+                       strcpy(ma->chosen_part, "1");
+                       mime_parser(mptr, NULL,
+                               *choose_preferred, *fixed_output_pre,
+                               *fixed_output_post, NULL, 0);
+                       mime_parser(mptr, NULL,
+                               *output_preferred, NULL, NULL, NULL, 0);
+               }
+               else {
+                       mime_parser(mptr, NULL,
+                               *fixed_output, *fixed_output_pre,
+                               *fixed_output_post, NULL, 0);
+               }
        }
 
        /* now we're done */
@@ -1437,7 +1502,7 @@ void cmd_msg3(char *cmdbuf)
 
 
 /* 
- * display a message (mode 4 - MIME) (FIXME ... still evolving, not complete)
+ * Display a message using MIME content types
  */
 void cmd_msg4(char *cmdbuf)
 {
@@ -1447,6 +1512,19 @@ void cmd_msg4(char *cmdbuf)
        CtdlOutputMsg(msgid, MT_MIME, 0, 1, 0);
 }
 
+
+
+/* 
+ * Client tells us its preferred message format(s)
+ */
+void cmd_msgp(char *cmdbuf)
+{
+       safestrncpy(CC->preferred_formats, cmdbuf,
+                       sizeof(CC->preferred_formats));
+       cprintf("%d ok\n", CIT_OK);
+}
+
+
 /*
  * Open a component of a MIME message as a download file 
  */
index 81754118457baa33af9165eea45c5a74d76c52b0..b746ab133d90adab9b817fbc6ceee3ade8be3a97 100644 (file)
@@ -34,6 +34,7 @@ enum {
 struct ma_info {
        int is_ma;              /* Set to 1 if we are using this stuff */
        int did_print;          /* One alternative has been displayed */
+       char chosen_part[SIZ];  /* Which part of a m/a did we choose? */
 };
 
 
@@ -71,6 +72,7 @@ void cmd_msg0 (char *cmdbuf);
 void cmd_msg2 (char *cmdbuf);
 void cmd_msg3 (char *cmdbuf);
 void cmd_msg4 (char *cmdbuf);
+void cmd_msgp (char *cmdbuf);
 void cmd_opna (char *cmdbuf);
 long send_message (struct CtdlMessage *, FILE *);
 void loadtroom (void);
index 0ac21564764806b3f5e93a3d71139759c529620a..451fa64304298869bcc1613344af1e7011fc1b16 100644 (file)
@@ -147,6 +147,7 @@ struct CitContext {
 
        struct CtdlMessage *cached_msg;
        long cached_msgnum;
+       char preferred_formats[SIZ];            /* Preferred MIME formats */
 
        /* Dynamically allocated session data */
        struct CtdlSessData *FirstSessData;
index b0004693dadb2b0824856f885e10c82e2529880d..2a559f5631a621e362302cd9eca77a855e656bf4 100644 (file)
@@ -1751,12 +1751,31 @@ into the system.  It is implemented in the serv_expire module.
  
   
  
- MSG4   (read MeSsaGe, mode 4 -- enumerate MIME parts)
+ MSG4   (read MeSsaGe, mode 4 -- output in preferred MIME format)
  
-     FIXME ... do the writeup for this once it's done.
+ This is the equivalent of MSG0, except it's a bit smarter about messages in
+rich text formats.  Immediately following the "text" directive, the server
+will output RFC822-like MIME part headers such as "Content-type:" and
+"Content-length:".  MIME formats are chosen and/or converted based on the
+client's preferred format settings, which are set using the MSGP command,
+described below.
+  
  
-
+ MSGP   (set MeSsaGe Preferred MIME format)
+ Client tells the server what MIME content types it knows how to handle, and
+the order in which it prefers them.  This is similar to an HTTP "Accept:"
+header.
+ The parameters to a MSGP command are the client's acceptable MIME content
+types, in the order it prefers them (from most preferred to least preferred).
+For example:  MSGP text/html|text/plain
+ The MSGP command always returns OK.
   
+  
+   
  OPNA   (OPeN Attachment)
  
  Opens, as a download file, a component of a MIME-encoded message.  The two