2 * (c) 2009-2012 by Art Cancro and citadel.org
3 * This program is released under the terms of the GNU General Public License v3.
13 #include "ctdlsalearn.h"
17 void do_room(int sock, char *roomname, char *salearnargs)
26 if (verbose) printf("%s: ", roomname);
28 sock_printf(sock, "GOTO %s\n", roomname);
29 sock_getln(sock, buf, sizeof buf);
31 if (verbose) printf("%s\n", &buf[4]);
35 /* Only fetch enough message pointers to fill our buffer.
36 * Since we're going to delete them, if there are more we will get them on the next run.
38 sock_printf(sock, "MSGS LAST|%d\n", MAXMSGS);
39 sock_getln(sock, buf, sizeof buf);
41 if (verbose) printf("%s\n", &buf[4]);
44 while (sock_getln(sock, buf, sizeof buf), strcmp(buf, "000")) {
45 msgs[num_msgs++] = atol(buf);
47 if (verbose) printf("%d messages\n", num_msgs);
49 if (num_msgs == 0) return;
50 for (i=0; i<num_msgs; ++i) {
51 snprintf(buf, sizeof buf, "sa-learn %s", salearnargs);
52 if (!verbose) strcat(buf, " >/dev/null");
54 if (fp == NULL) return;
55 if (verbose) printf("Submitting message %ld\n", msgs[i]);
56 sock_printf(sock, "MSG2 %ld\n", msgs[i]);
57 sock_getln(sock, buf, sizeof buf);
59 while (sock_getln(sock, buf, sizeof buf), strcmp(buf, "000")) {
60 fprintf(fp, "%s\n", buf);
63 if (pclose(fp) == 0) {
64 sock_printf(sock, "DELE %ld\n", msgs[i]);
65 sock_getln(sock, buf, sizeof buf);
66 if (verbose) printf("%s\n", &buf[4]);
72 int main(int argc, char **argv)
74 int server_socket = 0;
76 int ipgm_secret = (-1);
81 if ( (argc >= 2) && (!strcmp(argv[1], "-v")) ) {
86 printf("\nAuto-submit spam and ham to sa-learn for Citadel " PACKAGE_VERSION "\n");
87 printf("(c) 2009-2011 citadel.org GPLv3\n");
90 char *socket_locations[] = {
91 "/usr/local/citadel/citadel-admin.socket",
92 "/appl/citadel/citadel-admin.socket",
93 "/root/citadel/citadel/citadel-admin.socket"
98 for (i=0; i<(sizeof socket_locations / sizeof(char *)); ++i) {
99 if (server_socket < 0) {
100 if (verbose) printf("Trying %s...\n", socket_locations[i]);
101 server_socket = uds_connectsock(socket_locations[i]);
105 if (server_socket < 0) {
109 sock_getln(server_socket, buf, sizeof buf);
110 if (verbose) printf("%s\n", &buf[4]);
113 do_room(server_socket, "0000000001.spam", "--spam");
114 do_room(server_socket, "0000000001.ham", "--ham");
117 sock_puts(server_socket, "QUIT");
118 sock_getln(server_socket, buf, sizeof buf);
119 if (verbose) printf("%s\n", &buf[4]);
120 close(server_socket);