// 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.
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"))) {
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"))) {