X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit-ng%2Fserver%2Fforum_view.c;h=89303256aa0a83bbacd8c1925099bd4a0bf83abb;hb=6f4c0c2ce695e96011b2a61815e25d16ebbffa85;hp=737fa955e5717e65fe14e7aff00206c8c61b7bb1;hpb=19ff43ec1b087e796cdff1dd1b9dfc27ddd02ce6;p=citadel.git diff --git a/webcit-ng/server/forum_view.c b/webcit-ng/server/forum_view.c index 737fa955e..89303256a 100644 --- a/webcit-ng/server/forum_view.c +++ b/webcit-ng/server/forum_view.c @@ -1,10 +1,9 @@ // The code in here feeds messages out as JSON to the client browser. It is currently being used // for the forum view, but as we implement other views we'll probably reuse a lot of what's here. // -// Copyright (c) 1996-2022 by the citadel.org team +// Copyright (c) 1996-2023 by the citadel.org team // -// This program is open source software. Use, duplication, or -// disclosure are subject to the GNU General Public License v3. +// This program is open source software. Use, duplication, or disclosure is subject to the GNU General Public License v3. #include "webcit.h" @@ -54,7 +53,9 @@ void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, return; } - JsonValue *j = NewJsonObject(HKEY("message")); + JsonValue *attachments = NULL; + + JsonValue *j = NewJsonObject(HKEY("")); JsonObjectAppend(j, NewJsonNumber(HKEY("msgnum"), msgnum)); while ((ctdl_readline(c, buf, sizeof(buf)) >= 0) && (strcmp(buf, "text")) && (strcmp(buf, "000"))) { @@ -88,11 +89,37 @@ void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, else if (!strncasecmp(buf, "cccc=", 5)) { JsonObjectAppend(j, json_tokenize_recipients(HKEY("cccc"), &buf[5])); } + else if (!strncasecmp(buf, "part=", 5)) { + if (attachments == NULL) { + attachments = NewJsonArray(HKEY("part")); + } + JsonValue *part = NewJsonObject(HKEY("")); + char tokbuf[1024]; + extract_token(tokbuf, &buf[5], 0, '|', sizeof tokbuf); + JsonObjectAppend(part, NewJsonPlainString(HKEY("name"), tokbuf, -1)); + extract_token(tokbuf, &buf[5], 1, '|', sizeof tokbuf); + JsonObjectAppend(part, NewJsonPlainString(HKEY("filename"), tokbuf, -1)); + extract_token(tokbuf, &buf[5], 2, '|', sizeof tokbuf); + JsonObjectAppend(part, NewJsonPlainString(HKEY("partnum"), tokbuf, -1)); + extract_token(tokbuf, &buf[5], 3, '|', sizeof tokbuf); + JsonObjectAppend(part, NewJsonPlainString(HKEY("disp"), tokbuf, -1)); + extract_token(tokbuf, &buf[5], 4, '|', sizeof tokbuf); + JsonObjectAppend(part, NewJsonPlainString(HKEY("type"), tokbuf, -1)); + JsonObjectAppend(part, NewJsonNumber(HKEY("len"), extract_long(&buf[5], 5))); + extract_token(tokbuf, &buf[5], 6, '|', sizeof tokbuf); + JsonObjectAppend(part, NewJsonPlainString(HKEY("id"), tokbuf, -1)); + extract_token(tokbuf, &buf[5], 7, '|', sizeof tokbuf); + JsonObjectAppend(part, NewJsonPlainString(HKEY("charset"), tokbuf, -1)); + JsonArrayAppend(attachments, part); + } else { - syslog(LOG_DEBUG, "unhandled header: %s", buf); + // unhandled header } } JsonObjectAppend(j, NewJsonNumber(HKEY("locl"), message_originated_locally)); + if (attachments != NULL) { + JsonObjectAppend(j, attachments); + } if (!strcmp(buf, "text")) { while ((ctdl_readline(c, buf, sizeof(buf)) >= 0) && (strcmp(buf, "")) && (strcmp(buf, "000"))) {