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.
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);
78 char *ctdldir = "/usr/local/citadel" ;
80 while ((a = getopt(argc, argv, "vh:")) != EOF) switch(a) {
85 ctdldir = strdup(optarg);
88 fprintf(stderr, "%s: usage: %s [-v]\n", argv[0], argv[0]);
93 printf("\nAuto-submit spam and ham to sa-learn for Citadel " PACKAGE_VERSION "\n");
94 printf("(c) 2009-2011 citadel.org GPLv3\n");
97 if (chdir(ctdldir) != 0) {
98 fprintf(stderr, "%s: cannot change directory to %s: %s\n", argv[0], ctdldir, strerror(errno));
102 fprintf(stderr, "Changed directory to %s\n", ctdldir);
105 server_socket = (-1);
107 if (verbose) fprintf(stderr, "Connecting to server...\n");
108 server_socket = uds_connectsock("citadel-admin.socket");
110 if (server_socket < 0) {
111 if (verbose) fprintf(stderr, "Could not connect to Citadel server.\n");
115 sock_getln(server_socket, buf, sizeof buf);
116 if (verbose) printf("%s\n", &buf[4]);
119 do_room(server_socket, "0000000001.spam", "--dbpath /home/spam/.spamassassin --spam");
120 do_room(server_socket, "0000000001.ham", "--dbpath /home/spam/.spamassassin --ham");
123 sock_puts(server_socket, "QUIT");
124 sock_getln(server_socket, buf, sizeof buf);
125 if (verbose) printf("%s\n", &buf[4]);
126 close(server_socket);