sync 098claws
[claws.git] / src / plugins / spamassassin / spamassassin.c
index 195dfe5300392a0d745aea3e710985afabfac758..2284a6ea1e93908eb40dbc2e27e95bef5e86a9da 100644 (file)
@@ -80,12 +80,14 @@ static gchar *username = NULL;
 static SpamAssassinConfig config;
 
 static PrefParam param[] = {
-       {"enable", "FALSE", &config.enable, P_BOOL,
+       {"transport", "0", &config.transport, P_INT,
         NULL, NULL, NULL},
        {"hostname", "localhost", &config.hostname, P_STRING,
         NULL, NULL, NULL},
        {"port", "783", &config.port, P_INT,
         NULL, NULL, NULL},
+       {"socket", "", &config.socket, P_STRING,
+        NULL, NULL, NULL},
        {"receive_spam", "TRUE", &config.receive_spam, P_BOOL,
         NULL, NULL, NULL},
        {"save_folder", NULL, &config.save_folder, P_STRING,
@@ -111,12 +113,31 @@ gboolean timeout_func(gpointer data)
 
 static gboolean msg_is_spam(FILE *fp)
 {
-       struct sockaddr addr;
+       struct transport trans;
        struct message m;
        gboolean is_spam = FALSE;
 
-       if (lookup_host(config.hostname, config.port, &addr) != EX_OK) {
-               debug_print("failed to look up spamd host\n");
+       transport_init(&trans);
+       switch (config.transport) {
+       case SPAMASSASSIN_TRANSPORT_LOCALHOST:
+               trans.type = TRANSPORT_LOCALHOST;
+               trans.port = config.port;
+               break;
+       case SPAMASSASSIN_TRANSPORT_TCP:
+               trans.type = TRANSPORT_TCP;
+               trans.hostname = config.hostname;
+               trans.port = config.port;
+               break;
+       case SPAMASSASSIN_TRANSPORT_UNIX:
+               trans.type = TRANSPORT_UNIX;
+               trans.socketpath = config.socket;
+               break;
+       default:
+               return FALSE;
+       }
+
+       if (transport_setup(&trans, flags) != EX_OK) {
+               debug_print("failed to setup transport\n");
                return FALSE;
        }
 
@@ -130,7 +151,7 @@ static gboolean msg_is_spam(FILE *fp)
                return FALSE;
        }
 
-       if (message_filter(&addr, username, flags, &m) != EX_OK) {
+       if (message_filter(&trans, username, flags, &m) != EX_OK) {
                debug_print("filtering the message failed\n");
                message_cleanup(&m);
                return FALSE;
@@ -153,7 +174,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
        int pid = 0;
        int status;
 
-       if (!config.enable)
+       if (config.transport == SPAMASSASSIN_DISABLED)
                return FALSE;
 
        debug_print("Filtering message %d\n", msginfo->msgnum);
@@ -290,9 +311,10 @@ const gchar *plugin_name(void)
 
 const gchar *plugin_desc(void)
 {
-       return _("This plugin checks all messages that are received from a POP "
-                "account for spam using a SpamAssassin server. You will need "
-                "a SpamAssassin Server (spamd) running somewhere.\n"
+       return _("This plugin checks all messages that are received from an "
+                "IMAP, LOCAL or POP account for spam using a SpamAssassin "
+                "server. You will need a SpamAssassin Server (spamd) running "
+                "somewhere.\n"
                 "\n"
                 "When a message is identified as spam it can be deleted or "
                 "saved into a special folder.\n"