+void output_text_plain(char *partbuf, int total_length) {
+ wprintf("<PRE>\n");
+ write(WC->http_sock, partbuf, total_length);
+ wprintf("</PRE><BR>\n");
+}
+
+
+
+
+/*
+ * Output the chosen part of a MIME message. This might be chosen from
+ * a multipart/alternative or it might be chosen because it's the only one
+ * present. We care not why it was chosen; it is our job to be a servile
+ * little function and do what we are told.
+ */
+void output_chosen_part(long msgnum, char *multipart_chosen) {
+ char buf[SIZ];
+ char *partbuf;
+ int total_length = 0;
+ int downloaded_length = 0;
+ int block_length = 0;
+ char content_type[SIZ];
+
+ serv_printf("OPNA %ld|%s", msgnum, multipart_chosen);
+ serv_gets(buf);
+ if (buf[0] != '2') {
+ wprintf("<I>Error reading msg %ld part %s</I><BR><BR>",
+ msgnum, multipart_chosen);
+ return;
+ }
+
+ total_length = extract_int(&buf[4], 0);
+ extract(content_type, &buf[4], 3);
+
+ if ( (strlen(content_type) ==0)
+ ||(!strcasecmp(content_type, "text"))
+ ||(!strcasecmp(content_type, "text/english"))
+ ) {
+ strcpy(content_type, "text/plain");
+ }
+
+ partbuf = malloc(total_length);
+ if (partbuf == NULL) {
+ wprintf("<I>Memory allocation error</I><BR><BR>");
+ return;
+ }
+
+ while (downloaded_length < total_length) {
+ if ((total_length - downloaded_length) < 4096) {
+ block_length = total_length - downloaded_length;
+ }
+ else {
+ block_length = 4096;
+ }
+ serv_printf("READ %d|%d", downloaded_length, block_length);
+ serv_gets(buf);
+ if (buf[0] == '6') {
+ block_length = extract_int(&buf[4], 0);
+ serv_read(partbuf, block_length);
+ downloaded_length += block_length;
+ }
+ }
+
+ serv_puts("CLOS");
+ serv_gets(buf);
+
+ if (!strcasecmp(content_type, "text/plain")) {
+ output_text_plain(partbuf, total_length);
+ }
+ else {
+ wprintf("<I>Unknown content type %s</I><BR><BR>\n",
+ content_type);
+ }
+
+ free(partbuf);
+}