New API "/ctdl/r/ROOMNAME/mailbox" downloads a mailbox summary of the current room...
authorArt Cancro <ajc@citadel.org>
Fri, 1 Jul 2022 16:20:30 +0000 (12:20 -0400)
committerArt Cancro <ajc@citadel.org>
Fri, 1 Jul 2022 16:20:30 +0000 (12:20 -0400)
webcit-ng/api.txt
webcit-ng/room_functions.c

index d1ba7da3dc521085caeefef683ef658eafc7209a..e46e631be8e41f0f3f7d7da501379aa6e8f0fe63 100644 (file)
@@ -10,6 +10,7 @@ GET           /ctdl/r/ROOMNAME/               Returns information about the room (name, view, etc.) in
 GET            /ctdl/r/ROOMNAME/info.txt       Returns the room info banner for this room
 GET            /ctdl/r/ROOMNAME/msgs.all       JSON array of message list in room
 GET            /ctdl/r/ROOMNAME/msgs.new       JSON array of message list in room (new messages)
+GET            /ctdl/r/ROOMNAME/mailbox        JSON dictionary of a mailbox summary in this room
 GET            /ctdl/r/ROOMNAME/MSGNUM         Retrieve the content of an individual message
 GET            /ctdl/r/ROOMNAME/MSGNUM/json    Retrieve an individual message in a room, encapsulated in JSON
 DELETE         /ctdl/r/ROOMNAME/MSGNUM         Deletes a message from a room
index 8944224e9b9271f898d7cca338aa8dacdcd57715..888a94045b973cfd5aa4e218c868aaf2251c1608 100644 (file)
@@ -73,6 +73,45 @@ int match_etags(char *taglist, long msgnum) {
 }
 
 
+// Client is requesting a mailbox summary of the current room
+void json_mailbox(struct http_transaction *h, struct ctdlsession *c) {
+       char buf[1024];
+       char field[1024];
+       JsonValue *j = NewJsonArray(HKEY("msgs"));
+
+       ctdl_printf(c, "MSGS ALL|||9");                         // "9" as the fourth parameter delivers a mailbox summary
+       ctdl_readline(c, buf, sizeof(buf));
+       if (buf[0] == '1') {
+               while (ctdl_readline(c, buf, sizeof(buf)), (strcmp(buf, "000"))) {
+                       syslog(LOG_DEBUG, "msg: %s", buf);
+                       JsonValue *jmsg = NewJsonObject(HKEY("message"));
+                       JsonObjectAppend(jmsg, NewJsonNumber(HKEY("msgnum"), extract_long(buf, 0)));
+                       JsonObjectAppend(jmsg, NewJsonNumber(HKEY("time"), extract_long(buf, 1)));
+                       extract_token(field, buf, 2, '|', sizeof field);
+                       JsonObjectAppend(jmsg, NewJsonPlainString(HKEY("author"), field, -1));
+                       extract_token(field, buf, 4, '|', sizeof field);
+                       JsonObjectAppend(jmsg, NewJsonPlainString(HKEY("addr"), field, -1));
+                       extract_token(field, buf, 5, '|', sizeof field);
+                       JsonObjectAppend(jmsg, NewJsonPlainString(HKEY("subject"), field, -1));
+                       JsonObjectAppend(jmsg, NewJsonNumber(HKEY("msgidhash"), extract_long(buf, 6)));
+                       extract_token(field, buf, 7, '|', sizeof field);
+                       JsonObjectAppend(jmsg, NewJsonPlainString(HKEY("references"), field, -1));
+                       JsonArrayAppend(j, jmsg);               // add the message to the array
+               }
+       }
+
+       StrBuf *sj = NewStrBuf();
+       SerializeJson(sj, j, 1);                                // '1' == free the source array
+
+       add_response_header(h, strdup("Content-type"), strdup("application/json"));
+       h->response_code = 200;
+       h->response_string = strdup("OK");
+       h->response_body_length = StrLength(sj);
+       h->response_body = SmashStrBuf(&sj);
+       return;
+}
+
+
 // Client is requesting a message list
 void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which) {
        int i = 0;
@@ -87,7 +126,7 @@ void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which
        }
 
        StrBuf *sj = NewStrBuf();
-       SerializeJson(sj, j, 1);        // '1' == free the source array
+       SerializeJson(sj, j, 1);                                // '1' == free the source array
 
        add_response_header(h, strdup("Content-type"), strdup("application/json"));
        h->response_code = 200;
@@ -144,6 +183,11 @@ void object_in_room(struct http_transaction *h, struct ctdlsession *c) {
 
        extract_token(buf, h->url, 4, '/', sizeof buf);
 
+       if (!strcasecmp(buf, "mailbox")) {              // Client is requesting a mailbox summary
+               json_mailbox(h, c);
+               return;
+       }
+
        if (!strncasecmp(buf, "msgs.", 5)) {            // Client is requesting a list of message numbers
                unescape_input(&buf[5]);
                json_msglist(h, c, &buf[5]);