]> code.citadel.org Git - citadel.git/commitdiff
* First cut at downloading attachments throught the browser.
authorArt Cancro <ajc@citadel.org>
Thu, 7 Jun 2001 04:36:07 +0000 (04:36 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 7 Jun 2001 04:36:07 +0000 (04:36 +0000)
webcit/messages.c
webcit/static/attachment.gif [new file with mode: 0644]
webcit/webcit.c

index 6c36c3e006a7996fd27165b9b24f9894dcd01a13..ebb9e8ffca125c531e255748abcf5cdf65f45752 100644 (file)
@@ -83,6 +83,12 @@ char buf[];
 
 void read_message(long msgnum, int is_summary) {
        char buf[256];
+       char mime_partnum[256];
+       char mime_filename[256];
+       char mime_content_type[256];
+       char mime_disposition[256];
+       int mime_length;
+       char *mime_http = NULL;
        char m_subject[256];
        char from[256];
        char node[256];
@@ -156,6 +162,39 @@ void read_message(long msgnum, int is_summary) {
                        fmt_date(now, atol(&buf[5]));
                        wprintf("%s ", now);
                }
+
+               if (!strncasecmp(buf, "part=", 5)) {
+                       extract(mime_filename, &buf[5], 1);
+                       extract(mime_partnum, &buf[5], 2);
+                       extract(mime_disposition, &buf[5], 3);
+                       extract(mime_content_type, &buf[5], 4);
+                       mime_length = extract_int(&buf[5], 5);
+
+                       if (!strcasecmp(mime_disposition, "attachment")) {
+
+                               if (mime_http == NULL) {
+                                       mime_http = malloc(512);
+                                       strcpy(mime_http, "");
+                               }
+                               else {
+                                       mime_http = realloc(mime_http,
+                                               strlen(mime_http) + 512);
+                               }
+       
+                               sprintf(&mime_http[strlen(mime_http)],
+                                       "<A HREF=\"/output_mimepart?"
+                                       "msgnum=%ld&partnum=%s\" "
+                                       "TARGET=\"wc.%ld.%s\">"
+                                       "<IMG SRC=\"/static/attachment.gif\" "
+                                       "BORDER=0 ALIGN=MIDDLE>\n"
+                                       "Part %s: %s (%s, %d bytes)</A><BR>\n",
+                                       msgnum, mime_partnum,
+                                       msgnum, mime_partnum,
+                                       mime_partnum, mime_filename,
+                                       mime_content_type, mime_length);
+                       }
+               }
+
        }
 
 
@@ -250,6 +289,11 @@ void read_message(long msgnum, int is_summary) {
                }
        }
        wprintf("</I><BR>");
+
+       if (mime_http != NULL) {
+               wprintf("%s", mime_http);
+               free(mime_http);
+       }
 }
 
 
diff --git a/webcit/static/attachment.gif b/webcit/static/attachment.gif
new file mode 100644 (file)
index 0000000..6cac77c
Binary files /dev/null and b/webcit/static/attachment.gif differ
index 5758f708a44f82de7e3ed6a758dd72bf0c4cdf4f..6ee8e0847eba18b9e7285bdd0a9e76d39e181200 100644 (file)
@@ -437,6 +437,7 @@ void output_static(char *what)
        }
 }
 
+
 /*
  * When the browser requests an image file from the Citadel server,
  * this function is called to transmit it.
@@ -480,11 +481,62 @@ void output_image()
                serv_puts("CLOS");
                serv_gets(buf);
        } else {
-               wprintf("HTTP/1.0 404 %s\n", strerror(errno));
+               wprintf("HTTP/1.0 404 %s\n", &buf[4]);
+               output_headers(0);
+               wprintf("Content-Type: text/plain\n");
+               wprintf("\n");
+               wprintf("Error retrieving image: %s\n", &buf[4]);
+       }
+
+}
+
+/*
+ */
+void output_mimepart()
+{
+       char buf[256];
+       char xferbuf[4096];
+       off_t bytes;
+       off_t thisblock;
+       off_t accomplished = 0L;
+       char content_type[256];
+       
+       serv_printf("OPNA %s|%s", bstr("msgnum"), bstr("partnum"));
+       serv_gets(buf);
+       if (buf[0] == '2') {
+               bytes = extract_long(&buf[4], 0);
+               extract(content_type, &buf[4], 3);
+               output_headers(0);
+               wprintf("Content-type: %s\n", content_type);
+               wprintf("Content-length: %ld\n", (long) bytes);
+               wprintf("\n");
+
+               while (bytes > (off_t) 0) {
+                       thisblock = (off_t) sizeof(xferbuf);
+                       if (thisblock > bytes) {
+                               thisblock = bytes;
+                       }
+                       serv_printf("READ %ld|%ld", accomplished, thisblock);
+                       serv_gets(buf);
+                       if (buf[0] == '6') {
+                               thisblock = extract_long(&buf[4], 0);
+                               serv_read(xferbuf, (int) thisblock);
+                       }
+                       else {
+                               memset(xferbuf, 0, thisblock);
+                       }
+                       write(WC->http_sock, xferbuf, thisblock);
+                       bytes = bytes - thisblock;
+                       accomplished = accomplished + thisblock;
+               }
+               serv_puts("CLOS");
+               serv_gets(buf);
+       } else {
+               wprintf("HTTP/1.0 404 %s\n", &buf[4]);
                output_headers(0);
                wprintf("Content-Type: text/plain\n");
                wprintf("\n");
-               wprintf("Error retrieving image\n");
+               wprintf("Error retrieving part: %s\n", &buf[4]);
        }
 
 }
@@ -914,6 +966,8 @@ void session_loop(struct httprequest *req)
                do_generic();
        } else if (!strcasecmp(action, "display_menubar")) {
                display_menubar(1);
+       } else if (!strcasecmp(action, "output_mimepart")) {
+               output_mimepart();
        } else if (!strcasecmp(action, "diagnostics")) {
                output_headers(1);