371dbc828cbf0ff47da2b663a25c5a9e4e4ca043
[citadel.git] / webcit-ng / server / ctdlfunctions.c
1 // These utility functions loosely make up a Citadel protocol client library.
2 //
3 // Copyright (c) 2016-2022 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or
6 // disclosure are subject to the GNU General Public License v3.
7
8 #include "webcit.h"
9
10 // Delete one or more messages from the connected Citadel server.
11 // This function expects the session to already be "in" the room from which the messages will be deleted.
12 void ctdl_delete_msgs(struct ctdlsession *c, long *msgnums, int num_msgs) {
13         int i = 0;
14         char buf[1024];
15
16         if ((c == NULL) || (msgnums == NULL) || (num_msgs < 1)) {
17                 return;
18         }
19
20         i = 0;
21         strcpy(buf, "DELE ");
22         do {
23                 sprintf(&buf[strlen(buf)], "%ld", msgnums[i]);
24                 if ((((i + 1) % 50) == 0) || (i == num_msgs - 1))       // delete up to 50 messages with one server command
25                 {
26                         syslog(LOG_DEBUG, "%s", buf);
27                         ctdl_printf(c, "%s", buf);
28                         ctdl_readline(c, buf, sizeof(buf));
29                         syslog(LOG_DEBUG, "%s", buf);
30                 }
31                 else {
32                         strcat(buf, ",");
33                 }
34         } while (++i < num_msgs);
35 }