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.
16 void do_room(int sock, char *roomname, char *salearnargs)
25 if (verbose) printf("%s: ", roomname);
27 sock_printf(sock, "GOTO %s\n", roomname);
28 sock_getln(sock, buf, sizeof buf);
30 if (verbose) printf("%s\n", &buf[4]);
34 /* Only fetch enough message pointers to fill our buffer.
35 * Since we're going to delete them, if there are more we will get them on the next run.
37 sock_printf(sock, "MSGS LAST|%d\n", MAXMSGS);
38 sock_getln(sock, buf, sizeof buf);
40 if (verbose) printf("%s\n", &buf[4]);
43 while (sock_getln(sock, buf, sizeof buf), strcmp(buf, "000")) {
44 msgs[num_msgs++] = atol(buf);
46 if (verbose) printf("%d messages\n", num_msgs);
48 if (num_msgs == 0) return;
49 for (i=0; i<num_msgs; ++i) {
50 snprintf(buf, sizeof buf, "sa-learn %s", salearnargs);
51 if (!verbose) strcat(buf, " >/dev/null");
53 if (fp == NULL) return;
54 if (verbose) printf("Submitting message %ld\n", msgs[i]);
55 sock_printf(sock, "MSG2 %ld\n", msgs[i]);
56 sock_getln(sock, buf, sizeof buf);
58 while (sock_getln(sock, buf, sizeof buf), strcmp(buf, "000")) {
59 fprintf(fp, "%s\n", buf);
62 if (pclose(fp) == 0) {
63 sock_printf(sock, "DELE %ld\n", msgs[i]);
64 sock_getln(sock, buf, sizeof buf);
65 if (verbose) printf("%s\n", &buf[4]);
71 int main(int argc, char **argv)
73 int server_socket = 0;
75 int ipgm_secret = (-1);
80 if ( (argc >= 2) && (!strcmp(argv[1], "-v")) ) {
85 printf("\nAuto-submit spam and ham to sa-learn for Citadel " PACKAGE_VERSION "\n");
86 printf("(c) 2009-2011 citadel.org GPLv3\n");
89 char *socket_locations[] = {
90 "/usr/local/citadel/citadel-admin.socket",
91 "/appl/citadel/citadel-admin.socket",
92 "/root/citadel/citadel/citadel-admin.socket"
97 for (i=0; i<(sizeof socket_locations / sizeof(char *)); ++i) {
98 if (server_socket < 0) {
99 if (verbose) printf("Trying %s...\n", socket_locations[i]);
100 server_socket = uds_connectsock(socket_locations[i]);
104 if (server_socket < 0) {
108 sock_getln(server_socket, buf, sizeof buf);
109 if (verbose) printf("%s\n", &buf[4]);
112 do_room(server_socket, "0000000001.spam", "--spam");
113 do_room(server_socket, "0000000001.ham", "--ham");
116 sock_puts(server_socket, "QUIT");
117 sock_getln(server_socket, buf, sizeof buf);
118 if (verbose) printf("%s\n", &buf[4]);
119 close(server_socket);