Spamassassin plug-in: add support for compression (server must have
authorwwp <wwp@free.fr>
Thu, 12 Apr 2018 19:37:21 +0000 (21:37 +0200)
committerwwp <wwp@free.fr>
Thu, 12 Apr 2018 19:37:21 +0000 (21:37 +0200)
compression enabled, local spamc too).

configure.ac
src/plugins/spamassassin/Makefile.am
src/plugins/spamassassin/spamassassin.c
src/plugins/spamassassin/spamassassin.h
src/plugins/spamassassin/spamassassin_gtk.c

index 791a2dd3a0eca597e6ed129dc6b607787b8cfa98..50d68662ed66ea04d6aad8699f9176657c0efad4 100644 (file)
@@ -1853,6 +1853,28 @@ if test x"$enable_spamassassin_plugin" != xno; then
        PLUGINS="$PLUGINS spamassassin"
        AC_MSG_RESULT(yes)
        AC_SPAMASSASSIN
+
+       dnl check for zlib (optional)
+       spamassassin_zlib=0
+       SPAMASSASSIN_CFLAGS=""
+       SPAMASSASSIN_LIBS=""
+       AC_CHECK_HEADER([zlib.h],
+                       [AC_DEFINE(HAVE_ZLIB_H,1,[optional zlib support for spamassassin plugin])]
+                       [spamassassin_zlib=1],
+                       [spamassassin_zlib=0])
+       if test $spamassassin_zlib -eq 1; then
+               AC_CHECK_LIB(z, deflate, [spamassassin_zlib=1], [spamassassin_zlib=0])
+               AC_MSG_CHECKING([whether to build spamassassin plugin with zlib support])
+               if test $spamassassin_zlib -eq 1; then
+                       AC_MSG_RESULT(yes)
+                       SPAMASSASSIN_CFLAGS="-DHAVE_LIBZ"
+                       SPAMASSASSIN_LIBS="-lz"
+               else
+                       AC_MSG_RESULT(no)
+               fi
+       fi
+       AC_SUBST(SPAMASSASSIN_CFLAGS)
+       AC_SUBST(SPAMASSASSIN_LIBS)
 else
        DISABLED_PLUGINS="$DISABLED_PLUGINS spamassassin"
        AC_MSG_RESULT(no)
index 92712f08437f22f485347a60f6555abb08a1b967..71e6c061ffec2c8826e28e8d4a01927812a35f3e 100644 (file)
@@ -16,7 +16,8 @@ spamassassin_la_SOURCES = \
        utils.c utils.h
 
 spamassassin_la_LDFLAGS = \
-       -avoid-version -module
+       -avoid-version -module \
+       $(SPAMASSASSIN_LIBS)
 
 if CYGWIN
 cygwin_export_lib = -L$(top_builddir)/src -lclaws-mail
@@ -33,6 +34,7 @@ spamassassin_la_CPPFLAGS = \
        -I$(top_srcdir)/src/gtk \
        $(ENCHANT_CFLAGS) \
        $(GLIB_CFLAGS) \
-       $(GTK_CFLAGS)
+       $(GTK_CFLAGS) \
+       $(SPAMASSASSIN_CFLAGS)
 
 EXTRA_DIST = README NOTICE
index f01bd92b2f8e728940a0677b05548c4ea5bfbe62..c33307b96ecb10c412f63b80168493518e67ed99 100644 (file)
@@ -116,6 +116,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"whitelist_ab_folder", N_("Any"), &config.whitelist_ab_folder, P_STRING,
         NULL, NULL, NULL},
+       {"compress", "FALSE", &config.compress, P_BOOL,
+        NULL, NULL, NULL},
 
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
@@ -137,6 +139,15 @@ typedef enum {
        MSG_FILTERING_ERROR = 2
 } MsgStatus;
 
+static void update_flags(void)
+{
+       /* set the SPAMC_USE_ZLIB flag according to config */
+       if (config.compress)
+               flags |= SPAMC_USE_ZLIB;
+       else
+               flags &= ~SPAMC_USE_ZLIB;
+}
+
 static MsgStatus msg_is_spam(FILE *fp)
 {
        struct transport trans;
@@ -146,6 +157,7 @@ static MsgStatus msg_is_spam(FILE *fp)
        if (!config.enable)
                return MSG_IS_HAM;
 
+       update_flags();
        transport_init(&trans);
        switch (config.transport) {
        case SPAMASSASSIN_TRANSPORT_LOCALHOST:
@@ -371,10 +383,11 @@ gchar* spamassassin_create_tmp_spamc_wrapper(gboolean spam)
 
        if (fname != NULL) {
                contents = g_strdup_printf(
-                                               "spamc -d %s -p %u -u %s -t %u -s %u -L %s<\"$*\";exit $?",
+                                               "spamc -d %s -p %u -u %s -t %u -s %u %s -L %s<\"$*\";exit $?",
                                                config.hostname, config.port, 
                                                config.username, config.timeout,
-                                               config.max_size * 1024, spam?"spam":"ham");
+                                               config.max_size * 1024, config.compress?"-z":"",
+                                               spam?"spam":"ham");
                if (str_write_to_file(contents, fname) < 0) {
                        g_free(fname);
                        fname = NULL;
index d786da947ac97f646207dc7dac01645b5496addf..c13d4bc9057147bce98b85d45a5c80bd63816159 100644 (file)
@@ -50,6 +50,7 @@ struct _SpamAssassinConfig
        gboolean                 mark_as_read;
        gboolean                 whitelist_ab;
        gchar                   *whitelist_ab_folder;
+       gboolean                 compress;
 };
 
 SpamAssassinConfig *spamassassin_get_config          (void);
index 1c9254420aebadc0226196a055f2d70cbef2266e..3cc56d600ba3325a42d2a4e74028cbc43e15cad9 100644 (file)
@@ -60,6 +60,7 @@ struct SpamAssassinPage
        GtkWidget *save_folder_select;
        GtkWidget *max_size;
        GtkWidget *timeout;
+       GtkWidget *compress;
        GtkWidget *mark_as_read;
        GtkWidget *whitelist_ab;
        GtkWidget *whitelist_ab_folder_combo;
@@ -216,8 +217,8 @@ static void spamassassin_create_widget_func(PrefsPage * _page,
 
        GtkWidget *vbox1, *vbox2;
        GtkWidget *frame_transport, *table_transport, *vbox_transport;
-       GtkWidget *hbox_spamd, *hbox_max_size, *hbox_timeout;
-       GtkWidget *hbox_process_emails, *hbox_save_spam;
+       GtkWidget *hbox_spamd, *hbox_compress, *hbox_max_size;
+       GtkWidget *hbox_timeout, *hbox_process_emails, *hbox_save_spam;
        GtkWidget *hbox_mark_as_read, *hbox_whitelist;
        GtkWidget *whitelist_ab_checkbtn;
        GtkWidget *whitelist_ab_folder_combo;
@@ -238,6 +239,8 @@ static void spamassassin_create_widget_func(PrefsPage * _page,
        GtkWidget *spamd_port_spinbtn;
        GtkWidget *spamd_socket_entry;
 
+       GtkWidget *compress_checkbtn;
+
        GtkWidget *max_size_label;
        GtkAdjustment *max_size_spinbtn_adj;
        GtkWidget *max_size_spinbtn;
@@ -353,6 +356,17 @@ static void spamassassin_create_widget_func(PrefsPage * _page,
        gtk_box_pack_start(GTK_BOX(hbox_spamd), spamd_socket_entry, TRUE, TRUE, 0);
        CLAWS_SET_TIP(spamd_socket_entry, _("Path of Unix socket"));
 
+       hbox_compress = gtk_hbox_new(FALSE, 8);
+       gtk_widget_show(hbox_compress);
+       gtk_box_pack_start (GTK_BOX (vbox2), hbox_compress, TRUE, TRUE, 0);
+
+       compress_checkbtn = gtk_check_button_new_with_label(
+                       _("Use compression"));
+       gtk_widget_show(compress_checkbtn);
+       gtk_box_pack_start(GTK_BOX(hbox_compress), compress_checkbtn, TRUE, TRUE, 0);
+       CLAWS_SET_TIP(compress_checkbtn,
+                       _("Enable compression if spamd uses it, otherwise disable it."));
+
        hbox_max_size = gtk_hbox_new(FALSE, 8);
        gtk_widget_show(hbox_max_size);
        gtk_box_pack_start (GTK_BOX (vbox2), hbox_max_size, TRUE, TRUE, 0);
@@ -453,6 +467,7 @@ static void spamassassin_create_widget_func(PrefsPage * _page,
                        _("Click this button to select a book or folder in the address book"));
 
        SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, frame_transport);
+       SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_compress);
        SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_max_size);
        SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_timeout);
        SET_TOGGLE_SENSITIVITY(enable_sa_checkbtn, hbox_save_spam);
@@ -498,6 +513,7 @@ static void spamassassin_create_widget_func(PrefsPage * _page,
                                        config->whitelist_ab_folder);
        }
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(spamd_port_spinbtn), (float) config->port);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compress_checkbtn), config->compress);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size_spinbtn), (float) config->max_size);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(timeout_spinbtn), (float) config->timeout);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(process_emails_checkbtn), config->process_emails);
@@ -515,6 +531,7 @@ static void spamassassin_create_widget_func(PrefsPage * _page,
        page->colon = spamd_colon_label;
        page->port = spamd_port_spinbtn;
        page->socket = spamd_socket_entry;
+       page->compress = compress_checkbtn;
        page->max_size = max_size_spinbtn;
        page->timeout = timeout_spinbtn;
        page->process_emails = process_emails_checkbtn;
@@ -603,6 +620,9 @@ static void spamassassin_save_func(PrefsPage *_page)
        /* timeout */
        config->timeout = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->timeout));
 
+       /* compress */
+       config->compress = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->compress));
+
        /* mark_as_read */
        config->mark_as_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->mark_as_read));