From: Art Cancro Date: Thu, 14 Dec 2023 16:30:52 +0000 (-0500) Subject: upload.c: completed the code to reload attachments. X-Git-Tag: v997~71 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=8491e712ec23bda39709193af166789a272e8a53 upload.c: completed the code to reload attachments. Now we have an API call to load attachments from existing messages instead of from the browser. This is the server side API. Still need to integrate it into the client. --- 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); }