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];
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);
+ }
+ }
+
}
}
}
wprintf("</I><BR>");
+
+ if (mime_http != NULL) {
+ wprintf("%s", mime_http);
+ free(mime_http);
+ }
}
}
}
+
/*
* When the browser requests an image file from the Citadel server,
* this function is called to transmit it.
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]);
}
}
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);