-/*
- * When the browser requests an image file from the Citadel server,
- * this function is called to transmit it.
- */
-void output_image()
-{
- struct wcsession *WCC = WC;
- char buf[SIZ];
- off_t bytes;
- const char *MimeType;
-
- serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
- serv_getln(buf, sizeof buf);
- if (buf[0] == '2') {
- bytes = extract_long(&buf[4], 0);
-
- /** Read it from the server */
-
- if (read_server_binary(WCC->WBuf, bytes) > 0) {
- serv_puts("CLOS");
- serv_getln(buf, sizeof buf);
-
- MimeType = GuessMimeType (ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
- /** Write it to the browser */
- if (!IsEmptyStr(MimeType))
- {
- http_transmit_thing(MimeType, 0);
- return;
- }
- }
- /* hm... unknown mimetype? fallback to blank gif */
- }
-
-
- /*
- * Instead of an ugly 404, send a 1x1 transparent GIF
- * when there's no such image on the server.
- */
- char blank_gif[SIZ];
- snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
- output_static(blank_gif);
-}
-
-/*
- * Extract an embedded photo from a vCard for display on the client
- */
-void display_vcard_photo_img(void)
-{
- long msgnum = 0L;
- char *vcard;
- struct vCard *v;
- char *photosrc;
- const char *contentType;
- struct wcsession *WCC = WC;
-
- msgnum = StrTol(WCC->UrlFragment2);
-
- vcard = load_mimepart(msgnum,"1");
- v = vcard_load(vcard);
-
- photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
- FlushStrBuf(WCC->WBuf);
- StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
- if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
- FlushStrBuf(WCC->WBuf);
-
- hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
- output_headers(0, 0, 0, 0, 0, 0);
- hprintf("Content-Type: text/plain\r\n");
- wprintf(_("Could Not decode vcard photo\n"));
- end_burst();
- return;
- }
- contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
- http_transmit_thing(contentType, 0);
- free(v);
- free(photosrc);
-}
-
-/*
- * Generic function to output an arbitrary MIME attachment from
- * message being composed
- *
- * partnum The MIME part to be output
- * filename Fake filename to give
- * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
- */
-void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
-{
- void *vPart;
- StrBuf *content_type;
- wc_mime_attachment *part;
-
- if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
- (vPart != NULL)) {
- part = (wc_mime_attachment*) vPart;
- if (force_download) {
- content_type = NewStrBufPlain(HKEY("application/octet-stream"));
- }
- else {
- content_type = NewStrBufDup(part->ContentType);
- }
- output_headers(0, 0, 0, 0, 0, 0);
- StrBufAppendBuf(WC->WBuf, part->Data, 0);
- http_transmit_thing(ChrPtr(content_type), 0);
- } else {
- hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
- output_headers(0, 0, 0, 0, 0, 0);
- hprintf("Content-Type: text/plain\r\n");
- wprintf(_("An error occurred while retrieving this part: %s/%s\n"),
- ChrPtr(partnum), ChrPtr(filename));
- end_burst();
- }
- FreeStrBuf(&content_type);
-}
-
-
-/*
- * Generic function to output an arbitrary MIME part from an arbitrary
- * message number on the server.
- *
- * msgnum Number of the item on the citadel server
- * partnum The MIME part to be output
- * force_download Nonzero to force set the Content-Type: header to "application/octet-stream"
- */
-void mimepart(const char *msgnum, const char *partnum, int force_download)
-{
- char buf[256];
- off_t bytes;
- char content_type[256];
-
- serv_printf("OPNA %s|%s", msgnum, partnum);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '2') {
- bytes = extract_long(&buf[4], 0);
- if (force_download) {
- strcpy(content_type, "application/octet-stream");
- }
- else {
- extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
- }
- output_headers(0, 0, 0, 0, 0, 0);
-
- read_server_binary(WC->WBuf, bytes);
- serv_puts("CLOS");
- serv_getln(buf, sizeof buf);
- http_transmit_thing(content_type, 0);
- } else {
- hprintf("HTTP/1.1 404 %s\n", &buf[4]);
- output_headers(0, 0, 0, 0, 0, 0);
- hprintf("Content-Type: text/plain\r\n");
- wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
- end_burst();
- }
-}
-
-
-/*
- * Read any MIME part of a message, from the server, into memory.
- */
-char *load_mimepart(long msgnum, char *partnum)
-{
- char buf[SIZ];
- off_t bytes;
- char content_type[SIZ];
- char *content;
-
- serv_printf("DLAT %ld|%s", msgnum, partnum);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '6') {
- bytes = extract_long(&buf[4], 0);
- extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
-
- content = malloc(bytes + 2);
- serv_read(content, bytes);
-
- content[bytes] = 0; /* null terminate for good measure */
- return(content);
- }
- else {
- return(NULL);
- }
-}
-
-/*
- * Read any MIME part of a message, from the server, into memory.
- */
-void MimeLoadData(wc_mime_attachment *Mime)
-{
- char buf[SIZ];
- off_t bytes;
-//// TODO: is there a chance the contenttype is different to the one we know?
- serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
- serv_getln(buf, sizeof buf);
- if (buf[0] == '6') {
- bytes = extract_long(&buf[4], 0);
-
- if (Mime->Data == NULL)
- Mime->Data = NewStrBufPlain(NULL, bytes);
- StrBuf_ServGetBLOB(Mime->Data, bytes);
-
- }
- else {
- FlushStrBuf(Mime->Data);
- /// TODO XImportant message
- }
-}
-