Grammar change in the license declaration.
[citadel.git] / webcit-ng / server / forum_view.c
index 9fccab60f104b8435bf8c46f8971edea486c63bd..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"
 
@@ -28,7 +28,7 @@ JsonValue *json_tokenize_recipients(const char *Key, long keylen, char *recp) {
        int num_recp = num_tokens(recp, ',');
        for (int i=0; i<num_recp; ++i) {
                extract_token(tokbuf, recp, i, ',', sizeof(tokbuf));
-               striplt(tokbuf);
+               string_trim(tokbuf);
                JsonArrayAppend(j, NewJsonPlainString(HKEY("r"), tokbuf, strlen(tokbuf)));
        }
        return(j);
@@ -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,19 +90,48 @@ 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"))) {
                        // rfc822 header parsing here
                        if (!strncasecmp(buf, "Content-transfer-encoding:", 26)) {
                                strcpy(content_transfer_encoding, &buf[26]);
-                               striplt(content_transfer_encoding);
+                               string_trim(content_transfer_encoding);
                        }
                        if (!strncasecmp(buf, "Content-type:", 13)) {
                                strcpy(content_type, &buf[13]);
-                               striplt(content_type);
+                               string_trim(content_type);
                        }
                }
                if (!strcmp(buf, "000")) {              // if we have an empty message, don't try to read further