Grammar change in the license declaration.
[citadel.git] / webcit-ng / server / forum_view.c
index ef16e4eeb54089dcc41cfe49a623317f9215bbe8..188f2e8cc509ccfb02529f755beb99a9e901cac5 100644 (file)
@@ -1,10 +1,10 @@
 // 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.
+// disclosure is subject to the GNU General Public License v3.
 
 #include "webcit.h"
 
@@ -54,7 +54,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,8 +90,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 {
+                       // 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"))) {