X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit-ng%2Fserver%2Fupload.c;h=961d1845748f79a10b4d3002b5fce89a0c8864ea;hb=8491e712ec23bda39709193af166789a272e8a53;hp=f917f9a495f642f38b83a8b24bb9ced3ffe0da20;hpb=ea50862e0afd4eb85c98c4b735601c0b213fa081;p=citadel.git diff --git a/webcit-ng/server/upload.c b/webcit-ng/server/upload.c index f917f9a49..961d18457 100644 --- a/webcit-ng/server/upload.c +++ b/webcit-ng/server/upload.c @@ -152,6 +152,19 @@ struct uploaded_file pop_upload(char *id) { } +// When reloading attachments already in an existing message, accept only parts that are tagged as attachments. +void attachment_filter(char *name, char *filename, char *partnum, char *disp, + void *content, char *cbtype, char *cbcharset, + size_t length, char *encoding, char *cbid, void *userdata) +{ + struct uploaded_file u; + + if (!strcasecmp(disp, "attachment")) { + upload_handler(name, filename, partnum, disp, content, cbtype, cbcharset, length, encoding, cbid, userdata); + } +} + + // Load the attachments from an existing message. This is typically used when forwarding a message, // so the attachments don't have to be sent out to the browser and back. void load_attachments_from_message(struct http_transaction *h, struct ctdlsession *c, char *name) { @@ -167,11 +180,28 @@ void load_attachments_from_message(struct http_transaction *h, struct ctdlsessio return; } + JsonValue *j_uploads = NewJsonArray(HKEY("")); + Body = NewStrBuf(); while (ctdl_readline(c, buf, sizeof buf), strcmp(buf, "000")) { - // do something + StrBufAppendPrintf(Body, "%s\n", buf); } + char *raw_message = SmashStrBuf(&Body); + mime_parser(raw_message, NULL, *attachment_filter, NULL, NULL, j_uploads, 0); + free(raw_message); - do_405(h); + // probably do something more clever here + h->response_code = 200; + h->response_string = strdup("OK"); + + // send back a JSON array of all files uploaded + StrBuf *sj = NewStrBuf(); + SerializeJson(sj, j_uploads, 1); // '1' == free the source object + add_response_header(h, strdup("Content-type"), strdup("application/json")); + h->response_code = 200; + h->response_string = strdup("OK"); + h->response_body_length = StrLength(sj); + h->response_body = SmashStrBuf(&sj); + syslog(LOG_DEBUG, "upload: %s", h->response_body); }