]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/server/forum_view.c
"rcpt" and "cccc" fields are now delivered as json arrays
[citadel.git] / webcit-ng / server / forum_view.c
index 90ef33746c68cfbc8a9d058fe6526fd5b18dae00..9fccab60f104b8435bf8c46f8971edea486c63bd 100644 (file)
@@ -19,6 +19,22 @@ void setup_for_forum_view(struct ctdlsession *c) {
 }
 
 
+// Convenience function for json_render_one_message()
+// Converts a string of comma-separated recipients into a JSON Array
+JsonValue *json_tokenize_recipients(const char *Key, long keylen, char *recp) {
+       char tokbuf[1024];
+
+       JsonValue *j = NewJsonArray(Key, keylen);
+       int num_recp = num_tokens(recp, ',');
+       for (int i=0; i<num_recp; ++i) {
+               extract_token(tokbuf, recp, i, ',', sizeof(tokbuf));
+               striplt(tokbuf);
+               JsonArrayAppend(j, NewJsonPlainString(HKEY("r"), tokbuf, strlen(tokbuf)));
+       }
+       return(j);
+}
+
+
 // Fetch a single message and return it in JSON format for client-side rendering
 void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum) {
        StrBuf *raw_msg = NULL;
@@ -27,8 +43,6 @@ void json_render_one_message(struct http_transaction *h, struct ctdlsession *c,
        char content_transfer_encoding[1024] = { 0 };
        char content_type[1024] = { 0 };
        char datetime[128] = { 0 };
-       char author[1024] = { 0 };
-       char emailaddr[1024] = { 0 };
        int message_originated_locally = 0;
 
        setup_for_forum_view(c);
@@ -48,10 +62,10 @@ void json_render_one_message(struct http_transaction *h, struct ctdlsession *c,
 
                // citadel header parsing here
                if (!strncasecmp(buf, "from=", 5)) {
-                       safestrncpy(author, &buf[5], sizeof author);
+                       JsonObjectAppend(j, NewJsonPlainString(HKEY("from"), &buf[5], -1));
                }
                else if (!strncasecmp(buf, "rfca=", 5)) {
-                       safestrncpy(emailaddr, &buf[5], sizeof emailaddr);
+                       JsonObjectAppend(j, NewJsonPlainString(HKEY("rfca"), &buf[5], -1));
                }
                else if (!strncasecmp(buf, "time=", 5)) {
                        JsonObjectAppend(j, NewJsonNumber(HKEY("time"), atol(&buf[5])));
@@ -68,14 +82,14 @@ void json_render_one_message(struct http_transaction *h, struct ctdlsession *c,
                else if (!strncasecmp(buf, "wefw=", 5)) {
                        JsonObjectAppend(j, NewJsonPlainString(HKEY("wefw"), &buf[5], -1));
                }
+               else if (!strncasecmp(buf, "rcpt=", 5)) {
+                       JsonObjectAppend(j, json_tokenize_recipients(HKEY("rcpt"), &buf[5]));
+               }
+               else if (!strncasecmp(buf, "cccc=", 5)) {
+                       JsonObjectAppend(j, json_tokenize_recipients(HKEY("cccc"), &buf[5]));
+               }
        }
-
-       if (message_originated_locally) {
-               JsonObjectAppend(j, NewJsonPlainString(HKEY("from"), author, -1));
-       }
-       else {
-               JsonObjectAppend(j, NewJsonPlainString(HKEY("from"), emailaddr, -1));           // FIXME do compound address string
-       }
+       JsonObjectAppend(j, NewJsonNumber(HKEY("locl"), message_originated_locally));
 
        if (!strcmp(buf, "text")) {
                while ((ctdl_readline(c, buf, sizeof(buf)) >= 0) && (strcmp(buf, "")) && (strcmp(buf, "000"))) {