[Commits] Makefile.am NONE 1.1.2.1 clamav_plugin.c NONE 1.1.2.1 clamav_plugin.h NONE 1.1.2.1 clamav_plugin_gtk.c NONE 1.1.2.1 placeholder.txt 1.1.2.1 NONE

colin at claws-mail.org colin at claws-mail.org
Sun Feb 17 22:21:59 CET 2013


Update of /home/claws-mail/claws/src/plugins/clamd
In directory srv:/tmp/cvs-serv7104/src/plugins/clamd

Added Files:
      Tag: gtk2
	Makefile.am clamav_plugin.c clamav_plugin.h 
	clamav_plugin_gtk.c 
Removed Files:
      Tag: gtk2
	placeholder.txt 
Log Message:
2013-02-17 [colin]	3.9.0cvs75

	* src/plugins/Makefile.am
	* src/plugins/archive/Makefile.am
	* src/plugins/clamd/Makefile.am
	* src/plugins/clamd/clamav_plugin.c
	* src/plugins/clamd/clamav_plugin.h
	* src/plugins/clamd/clamav_plugin_gtk.c
	* src/plugins/clamd/placeholder.txt
	* src/plugins/clamd/libclamd/Makefile.am
	* src/plugins/clamd/libclamd/clamd-plugin.c
	* src/plugins/clamd/libclamd/clamd-plugin.h
	* src/plugins/fetchinfo/Makefile.am
	* src/plugins/fetchinfo/fetchinfo_plugin.c
	* src/plugins/fetchinfo/fetchinfo_plugin.h
	* src/plugins/fetchinfo/fetchinfo_plugin_gtk.c
	* src/plugins/fetchinfo/placeholder.txt
	* src/plugins/gdata/Makefile.am
	* src/plugins/gdata/cm_gdata_contacts.c
	* src/plugins/gdata/cm_gdata_contacts.h
	* src/plugins/gdata/cm_gdata_prefs.c
	* src/plugins/gdata/cm_gdata_prefs.h
	* src/plugins/gdata/gdata_plugin.c
	* src/plugins/gdata/gdata_plugin.h
	* src/plugins/gdata/placeholder.txt
	* src/plugins/geolocation/placeholder.txt
	* src/plugins/gtkhtml2_viewer/placeholder.txt
	* src/plugins/mailmbox/Makefile.am
	* src/plugins/mailmbox/carray.c
	* src/plugins/mailmbox/carray.h
	* src/plugins/mailmbox/chash.c
	* src/plugins/mailmbox/chash.h
	* src/plugins/mailmbox/clist.c
	* src/plugins/mailmbox/clist.h
	* src/plugins/mailmbox/mailimf.c
	* src/plugins/mailmbox/mailimf.h
	* src/plugins/mailmbox/mailimf_types.c
	* src/plugins/mailmbox/mailimf_types.h
	* src/plugins/mailmbox/mailimf_types_helper.c
	* src/plugins/mailmbox/mailimf_types_helper.h
	* src/plugins/mailmbox/mailimf_write.c
	* src/plugins/mailmbox/mailimf_write.h
	* src/plugins/mailmbox/maillock.c
	* src/plugins/mailmbox/maillock.h
	* src/plugins/mailmbox/mailmbox.c
	* src/plugins/mailmbox/mailmbox.h
	* src/plugins/mailmbox/mailmbox_folder.c
	* src/plugins/mailmbox/mailmbox_folder.h
	* src/plugins/mailmbox/mailmbox_gtk.deps
	* src/plugins/mailmbox/mailmbox_parse.c
	* src/plugins/mailmbox/mailmbox_parse.h
	* src/plugins/mailmbox/mailmbox_types.c
	* src/plugins/mailmbox/mailmbox_types.h
	* src/plugins/mailmbox/mmapstring.c
	* src/plugins/mailmbox/mmapstring.h
	* src/plugins/mailmbox/placeholder.txt
	* src/plugins/mailmbox/plugin.c
	* src/plugins/mailmbox/plugin_gtk.c
	* src/plugins/mailmbox/plugin_gtk.h
	* src/plugins/newmail/Makefile.am
	* src/plugins/newmail/newmail.c
	* src/plugins/newmail/placeholder.txt
	* src/plugins/notification/Makefile.am
	* src/plugins/notification/claws.def
	* src/plugins/notification/notification_banner.c
	* src/plugins/notification/notification_banner.h
	* src/plugins/notification/notification_command.c
	* src/plugins/notification/notification_command.h
	* src/plugins/notification/notification_core.c
	* src/plugins/notification/notification_core.h
	* src/plugins/notification/notification_foldercheck.c
	* src/plugins/notification/notification_foldercheck.h
	* src/plugins/notification/notification_hotkeys.c
	* src/plugins/notification/notification_hotkeys.h
	* src/plugins/notification/notification_indicator.c
	* src/plugins/notification/notification_indicator.h
	* src/plugins/notification/notification_lcdproc.c
	* src/plugins/notification/notification_lcdproc.h
	* src/plugins/notification/notification_pixbuf.c
	* src/plugins/notification/notification_pixbuf.h
	* src/plugins/notification/notification_plugin.c
	* src/plugins/notification/notification_plugin.h
	* src/plugins/notification/notification_popup.c
	* src/plugins/notification/notification_popup.h
	* src/plugins/notification/notification_prefs.c
	* src/plugins/notification/notification_prefs.h
	* src/plugins/notification/notification_trayicon.c
	* src/plugins/notification/notification_trayicon.h
	* src/plugins/notification/placeholder.txt
	* src/plugins/notification/plugin.def
	* src/plugins/notification/raw_claws_mail_logo_64x64.h
	* src/plugins/notification/version.rc
	* src/plugins/pdf_viewer/Makefile.am
	* src/plugins/pdf_viewer/doc_index.xpm
	* src/plugins/pdf_viewer/doc_index_close.xpm
	* src/plugins/pdf_viewer/doc_info.xpm
	* src/plugins/pdf_viewer/first_arrow.xpm
	* src/plugins/pdf_viewer/last_arrow.xpm
	* src/plugins/pdf_viewer/left_arrow.xpm
	* src/plugins/pdf_viewer/placeholder.txt
	* src/plugins/pdf_viewer/poppler_viewer.c
	* src/plugins/pdf_viewer/poppler_viewer.h
	* src/plugins/pdf_viewer/right_arrow.xpm
	* src/plugins/pdf_viewer/rotate_left.xpm
	* src/plugins/pdf_viewer/rotate_right.xpm
	* src/plugins/pdf_viewer/zoom_fit.xpm
	* src/plugins/pdf_viewer/zoom_in.xpm
	* src/plugins/pdf_viewer/zoom_out.xpm
	* src/plugins/pdf_viewer/zoom_width.xpm
	* src/plugins/perl/Makefile.am
	* src/plugins/perl/perl_gtk.c
	* src/plugins/perl/perl_gtk.h
	* src/plugins/perl/perl_plugin.c
	* src/plugins/perl/perl_plugin.h
	* src/plugins/perl/placeholder.txt
	* src/plugins/python/Makefile.am
	* src/plugins/python/clawsmailmodule.c
	* src/plugins/python/clawsmailmodule.h
	* src/plugins/python/composewindowtype.c
	* src/plugins/python/composewindowtype.h
	* src/plugins/python/foldertype.c
	* src/plugins/python/foldertype.h
	* src/plugins/python/messageinfotype.c
	* src/plugins/python/messageinfotype.h
	* src/plugins/python/nodetype.c
	* src/plugins/python/nodetype.h
	* src/plugins/python/placeholder.txt
	* src/plugins/python/python-hooks.c
	* src/plugins/python/python-hooks.h
	* src/plugins/python/python-shell.c
	* src/plugins/python/python-shell.h
	* src/plugins/python/python_plugin.c
	* src/plugins/vcalendar/Makefile.in
		Add some plugins (clamd, fetchinfo, gdata, mailmbox, newmail,
		notification, pdf_viewer, perl, python). Notification not yet
		enabled because it has too much autoconf switches for my taste.

--- NEW FILE: Makefile.am ---
SUBDIRS = libclamd
plugindir = $(pkglibdir)/plugins

plugin_LTLIBRARIES = clamd.la

clamd_la_SOURCES = \
	clamav_plugin.c \
	clamav_plugin_gtk.c \
	clamav_plugin.h

clamd_la_LDFLAGS = \
	-avoid-version -module \
	$(GTK_LIBS) \
	-L$(top_builddir)/src/plugins/clamd/libclamd

clamd_la_LIBADD = \
	-lclamd-plugin

INCLUDES = \
	-I$(top_srcdir)/src/plugins/clamd/libclamd \
	-I$(top_srcdir)/src \
	-I$(top_srcdir)/src/common \
	-I$(top_srcdir)/src/gtk

AM_CPPFLAGS = \
	-Wall \
	$(CLAWS_MAIL_CFLAGS) \
	$(GLIB_CFLAGS) \
	$(GTK_CFLAGS) \
	-DLOCALEDIR=\""$(localedir)"\"

--- NEW FILE: clamav_plugin_gtk.c ---
/*
 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
 * Copyright (C) 2003-2010 the Claws Mail Team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */


#ifdef HAVE_CONFIG_H
#  include "config.h"
#  include "claws-features.h"
#endif

#include <glib.h>
#include <glib/gi18n.h>

#include "defs.h"

#include <gtk/gtk.h>
#include <gtk/gtkutils.h>

#include "common/claws.h"
#include "common/version.h"
#include "plugin.h"
#include "utils.h"
#include "prefs.h"
#include "folder.h"
#include "prefs_gtk.h"
#include "foldersel.h"
#include "clamav_plugin.h"
#include "statusbar.h"
#include "alertpanel.h"
#include "clamd-plugin.h"

struct ClamAvPage
{
	PrefsPage page;
	
	GtkWidget *enable_clamav;
/*	GtkWidget *enable_arc;*/
	GtkWidget *max_size;
	GtkWidget *recv_infected;
	GtkWidget *save_folder;
	GtkWidget *config_type;
	GtkWidget *config_folder;
	GtkWidget *config_host;
	GtkWidget *config_port;
};

static GtkWidget *hbox_auto1, *hbox_auto2, *hbox_manual1, *hbox_manual2;

static void foldersel_cb(GtkWidget *widget, gpointer data)
{
	struct ClamAvPage *page = (struct ClamAvPage *) data;
	FolderItem *item;
	gchar *item_id;
	gint newpos = 0;
	
	item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL, FALSE);
	if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
		gtk_editable_delete_text(GTK_EDITABLE(page->save_folder), 0, -1);
		gtk_editable_insert_text(GTK_EDITABLE(page->save_folder), item_id, strlen(item_id), &newpos);
		g_free(item_id);
	}
}

static void clamd_folder_cb(GtkWidget *widget, gpointer data)
{
	GtkWidget *dialog;
	gchar* file;
	gint newpos = 0;
	struct ClamAvPage *page = (struct ClamAvPage *) data;

	dialog = gtk_file_chooser_dialog_new(
					"Select file with clamd configuration [clamd.conf]",
					NULL,
					GTK_FILE_CHOOSER_ACTION_OPEN,
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
					NULL);
	gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "/etc");
	if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_APPLY) {
		file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
		debug_print("New clamd.conf: %s\n", file);
		if (file) {
			gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
			gtk_editable_insert_text(GTK_EDITABLE(page->config_folder), file, strlen(file), &newpos);
			g_free(file);
		}
	}
	gtk_widget_destroy(dialog);
}

static void check_permission(gchar* folder) {
	struct stat info;

	g_stat(folder, &info);
	mode_t perm = info.st_mode & ~(S_IFMT);
	debug_print("%s: Old file permission: %05o\n", folder, perm);
	if ((perm & S_IXOTH) != S_IXOTH) {
		perm = perm | S_IXOTH;
		g_chmod(folder, perm);
	}
	debug_print("%s: New file permission: %05o\n", folder, perm);
}

static void folder_permission_cb(GtkWidget *widget, gpointer data) {
	static gchar* folders[] = {
			".claws-mail",
			".claws-mail/mimetmp",
			".claws-mail/tmp",
			NULL};
	const gchar* home = g_get_home_dir();
	int i;

	check_permission((gchar *) home);
	for (i = 0; folders[i]; i++) {
		gchar* file = g_strdup_printf("%s/%s", home, folders[i]);
		check_permission(file);
		g_free(file);
	}
}

static void clamav_show_config(Config* config) {
	if (config) {
		if (config->ConfigType == MANUAL) {
			gtk_widget_hide(hbox_auto1);
			gtk_widget_hide(hbox_auto2);
			gtk_widget_show(hbox_manual1);
			gtk_widget_show(hbox_manual2);
		}
		else {
			gtk_widget_hide(hbox_manual1);
			gtk_widget_hide(hbox_manual2);
			gtk_widget_show(hbox_auto1);
			gtk_widget_show(hbox_auto2);
		}
	}
}

static void setting_type_cb(GtkWidget *widget, gpointer data) {
	gboolean state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
	struct ClamAvPage *page = (struct ClamAvPage *) data;
	Config* c;
	gint newpos = 0;
	gboolean tmp_conf = FALSE;

	if (page && page->page.widget) {
		/* Reset configuration */
		debug_print("Resetting configuration\n");
		gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
		gtk_editable_delete_text(GTK_EDITABLE(page->config_host), 0, -1);
		gtk_editable_delete_text(GTK_EDITABLE(page->config_port), 0, -1);
		clamav_save_config();
	
		c = clamd_get_config();
		if (!c) {
			c = clamd_config_new();
			tmp_conf = TRUE;
		}
		if (state) {
			/* Automatic configuration */
			debug_print("Setting clamd to automatic configuration\n");
			if (clamd_find_socket()) {
				if (tmp_conf) {
					Config* clamd_conf = clamd_get_config();
					if (clamd_conf->automatic.folder)
						c->automatic.folder = g_strdup(clamd_conf->automatic.folder);
					else
						c->automatic.folder = g_strdup("");
				}
				if (c->ConfigType == AUTOMATIC) {
					gtk_editable_insert_text(GTK_EDITABLE(page->config_folder),
						c->automatic.folder, strlen(c->automatic.folder), &newpos);
					clamav_save_config();
				}
			}
			c->ConfigType = AUTOMATIC;
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), TRUE);
		}
		else {
			/* Manual configuration */
			debug_print("Setting clamd to manual configuration\n");
			c->ConfigType = MANUAL;
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), FALSE);
		}
		clamav_show_config(c);
		if (tmp_conf)
			clamd_config_free(c);
	}
}

static void clamav_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
{
	struct ClamAvPage *page = (struct ClamAvPage *) _page;
	ClamAvConfig *config;
	Config		 *clamd_config;
 	 
	GtkWidget *vbox1, *vbox2;
	GtkWidget *enable_clamav;
  	GtkWidget *label1;
/*  	GtkWidget *enable_arc;*/
  	GtkWidget *label2;
  	GtkObject *max_size_adj;
  	GtkWidget *max_size;
	GtkWidget *hbox1;
  	GtkWidget *recv_infected;
  	GtkWidget *save_folder;
  	GtkWidget *save_folder_select;
	GtkWidget *clamd_conf_label;
	GtkWidget *config_folder;
	GtkWidget *config_host;
	GtkWidget *config_port;
	GtkWidget *config_folder_select;
	GtkWidget *blank;
	GtkWidget *permission_label;
	GtkWidget *permission_select;
	GtkWidget *host_label;
	GtkWidget *port_label;
	GtkWidget *setting_type;
	GtkTooltips *tooltips;

	tooltips = gtk_tooltips_new();
	enable_clamav = page->enable_clamav;

	vbox1 = gtk_vbox_new (FALSE, VSPACING);
	gtk_widget_show (vbox1);
	gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);

	vbox2 = gtk_vbox_new (FALSE, 4);
	gtk_widget_show (vbox2);
	gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);

	PACK_CHECK_BUTTON (vbox2, enable_clamav, _("Enable virus scanning"));
/*	PACK_CHECK_BUTTON (vbox2, enable_arc, _("Scan archive contents"));

 	SET_TOGGLE_SENSITIVITY (enable_clamav, enable_arc);*/

 	hbox1 = gtk_hbox_new (FALSE, 8);
	gtk_widget_show (hbox1);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
/*	SET_TOGGLE_SENSITIVITY (enable_arc, hbox1);*/

  	label1 = gtk_label_new(_("Maximum attachment size"));
  	gtk_widget_show (label1);
  	gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, label1);

  	max_size_adj = gtk_adjustment_new (1, 1, 1024, 1, 10, 0);
  	max_size = gtk_spin_button_new (GTK_ADJUSTMENT (max_size_adj), 1, 0);
	gtk_widget_show (max_size);
  	gtk_box_pack_start (GTK_BOX (hbox1), max_size, FALSE, FALSE, 0);
	gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (max_size), TRUE);
	gtk_tooltips_set_tip(tooltips, max_size,
			     _("Message attachments larger than this will not be scanned"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, max_size);

  	label2 = gtk_label_new(_("MB"));
	gtk_widget_show (label2);
  	gtk_box_pack_start (GTK_BOX (hbox1), label2, FALSE, FALSE, 0);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, label2);

  	hbox1 = gtk_hbox_new (FALSE, 8);
	gtk_widget_show (hbox1);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);

 	recv_infected = gtk_check_button_new_with_label(_("Save infected mail in"));
	gtk_widget_show (recv_infected);
	gtk_box_pack_start (GTK_BOX (hbox1), recv_infected, FALSE, FALSE, 0);
	gtk_tooltips_set_tip(tooltips, recv_infected,
			     _("Save mail that contains viruses"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, recv_infected);

  	save_folder = gtk_entry_new ();
	gtk_widget_show (save_folder);
	gtk_box_pack_start (GTK_BOX (hbox1), save_folder, TRUE, TRUE, 0);
	gtk_tooltips_set_tip(tooltips, save_folder,
			     _("Folder for storing infected mail. Leave empty to use the default trash folder"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, save_folder);

	save_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
	gtk_widget_show (save_folder_select);
  	gtk_box_pack_start (GTK_BOX (hbox1), save_folder_select, FALSE, FALSE, 0);
	gtk_tooltips_set_tip(tooltips, save_folder_select,
			     _("Click this button to select a folder for storing infected mail"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, save_folder_select);

	hbox1 = gtk_hbox_new (FALSE, 8);
	gtk_widget_show (hbox1);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);

 	setting_type = gtk_check_button_new_with_label(_("Automatic configuration"));
 	/*gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), TRUE);*/
	gtk_widget_show (setting_type);
	gtk_box_pack_start (GTK_BOX (hbox1), setting_type, FALSE, FALSE, 0);
	gtk_tooltips_set_tip(tooltips, setting_type,
			     _("Should configuration be done automatic or manual"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, setting_type);
	
  	hbox_auto1 = gtk_hbox_new (FALSE, 8);
	gtk_widget_show (hbox_auto1);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_auto1, FALSE, FALSE, 0);

 	clamd_conf_label = gtk_label_new(_("Where is clamd.conf"));
	gtk_widget_show (clamd_conf_label);
	gtk_box_pack_start (GTK_BOX (hbox_auto1), clamd_conf_label, FALSE, FALSE, 0);

	config_folder = gtk_entry_new ();
	gtk_widget_show (config_folder);
	gtk_box_pack_start (GTK_BOX (hbox_auto1), config_folder, TRUE, TRUE, 0);
	gtk_tooltips_set_tip(tooltips, config_folder,
			     _("Full path to clamd.conf. If this field is not empty then the plugin has been able to locate the file automatically"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, config_folder);

	config_folder_select = gtkut_get_browse_directory_btn(_("Br_owse"));
	gtk_widget_show (config_folder_select);
  	gtk_box_pack_start (GTK_BOX (hbox_auto1), config_folder_select, FALSE, FALSE, 0);
	gtk_tooltips_set_tip(tooltips, config_folder_select,
			     _("Click this button to select full path to clamd.conf"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, config_folder_select);

  	hbox_auto2 = gtk_hbox_new (FALSE, 8);
	gtk_widget_show (hbox_auto2);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_auto2, FALSE, FALSE, 0);

 	permission_label = gtk_label_new(_("Check permission for folders and adjust if necessary"));
	gtk_widget_show (permission_label);
	gtk_box_pack_start (GTK_BOX (hbox_auto2), permission_label, FALSE, FALSE, 0);

	blank = gtk_label_new("");
	gtk_widget_show (blank);
	gtk_box_pack_start (GTK_BOX (hbox_auto2), blank, TRUE, TRUE, 0);

	permission_select = gtk_button_new_from_stock(GTK_STOCK_FIND_AND_REPLACE);
			/*gtk_button_new_with_mnemonic(_("_Check Permission"));*/
	gtk_widget_show (permission_select);
  	gtk_box_pack_start (GTK_BOX (hbox_auto2), permission_select, FALSE, FALSE, 0);
	gtk_tooltips_set_tip(tooltips, permission_select,
			     _("Click this button to check and adjust folder permissions"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, permission_select);

  	hbox_manual1 = gtk_hbox_new (FALSE, 8);
	gtk_widget_show (hbox_manual1);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_manual1, FALSE, FALSE, 0);

 	host_label = gtk_label_new(_("Remote Host"));
	gtk_widget_show (host_label);
	gtk_box_pack_start (GTK_BOX (hbox_manual1), host_label, FALSE, FALSE, 0);

	config_host = gtk_entry_new ();
	gtk_widget_show (config_host);
	gtk_box_pack_start (GTK_BOX (hbox_manual1), config_host, FALSE, FALSE, 0);
	gtk_tooltips_set_tip(tooltips, config_host,
			     _("Hostname or IP for remote host running clamav daemon"),
			     NULL);
 	SET_TOGGLE_SENSITIVITY (enable_clamav, config_host);

	blank = gtk_label_new("");
	gtk_widget_show (blank);
	gtk_box_pack_start (GTK_BOX (hbox_manual1), blank, TRUE, TRUE, 0);

  	hbox_manual2 = gtk_hbox_new (FALSE, 8);
	gtk_widget_show (hbox_manual2);
	gtk_box_pack_start (GTK_BOX (vbox2), hbox_manual2, FALSE, FALSE, 0);

 	port_label = gtk_label_new(_("Port"));
	gtk_widget_show (port_label);
	gtk_box_pack_start (GTK_BOX (hbox_manual2), port_label, FALSE, FALSE, 0);

	config_port = gtk_entry_new ();
	gtk_entry_set_width_chars(GTK_ENTRY(config_port), 5);
	gtk_entry_set_max_length(GTK_ENTRY(config_port), 5);
	gtk_widget_show (config_port);
	gtk_box_pack_start (GTK_BOX (hbox_manual2), config_port, FALSE, FALSE, 0);
	gtk_tooltips_set_tip(tooltips, config_port,
			     _("Port number where clamav daemon is listening"),
			     NULL);

	blank = gtk_label_new("");
	gtk_widget_show (blank);
	gtk_box_pack_start (GTK_BOX (hbox_manual2), blank, TRUE, TRUE, 0);

 	SET_TOGGLE_SENSITIVITY (enable_clamav, config_port);

	g_signal_connect(G_OBJECT(save_folder_select), "clicked", 
			 G_CALLBACK(foldersel_cb), page);
	g_signal_connect(G_OBJECT(config_folder_select), "clicked",
			 G_CALLBACK(clamd_folder_cb), page);
	g_signal_connect(G_OBJECT(permission_select), "clicked",
			 G_CALLBACK(folder_permission_cb), page);
	g_signal_connect(G_OBJECT(setting_type), "clicked",
			 G_CALLBACK(setting_type_cb), page);

	config = clamav_get_config();

	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_clamav), config->clamav_enable);
/*	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_arc), config->clamav_enable_arc);*/
	gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->clamav_max_size);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(recv_infected), config->clamav_recv_infected);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), config->clamd_config_type);

	clamd_config = clamd_get_config();
		
	if (config->clamav_save_folder != NULL)
		gtk_entry_set_text(GTK_ENTRY(save_folder), config->clamav_save_folder);
	if (!config->clamd_config_type) {
	/*if (config->clamd_host && strlen(config->clamd_host) > 0 && config->clamd_port > 0) {*/
		gtk_entry_set_text(GTK_ENTRY(config_host), config->clamd_host);
		gchar* s = int2char(config->clamd_port);
		gtk_entry_set_text(GTK_ENTRY(config_port), s);
		g_free(s);
		/* activate manual checkbox and blind folder */
		debug_print("Showing manual configuration and hiding automatic configuration\n");
		if (! clamd_config) {
			clamd_config = clamd_config_new();
			clamd_config->ConfigType = MANUAL;
			clamav_show_config(clamd_config);
			clamd_config_free(clamd_config);
		}
		else
			clamav_show_config(clamd_config);
	}
	else {
	//else if (config->clamd_config_folder == NULL || strlen(config->clamd_config_folder) == 0) {
		if (clamd_find_socket()) {
			Config* c = clamd_get_config();
			if (c && c->ConfigType == AUTOMATIC) {
				config->clamd_config_folder = g_strdup(c->automatic.folder);
				/* deactivate manual checkbox and blind host and port */
				debug_print("Showing automatic configuration and hiding manual configuration\n");
				clamav_show_config(c);
				gint newpos = 0;
				gtk_editable_delete_text(GTK_EDITABLE(config_folder), 0, -1);
				gtk_editable_insert_text(GTK_EDITABLE(config_folder), 
					config->clamd_config_folder, strlen(config->clamd_config_folder), &newpos);
			}
			else if (c && c->ConfigType == MANUAL) {
				/* deactivate automatic automatic configuration */
				debug_print("Showing manual configuration and hiding automatic configuration\n");
				clamav_show_config(c);
			}
		}
	}
/*	else {
		gtk_entry_set_text(GTK_ENTRY(config_folder), config->clamd_config_folder);
		// deactivate manual checkbox and blind host and port
		debug_print("Showing automatic configuration and hiding manual configuration\n");
		if (! clamd_config) {
			clamd_config = clamd_config_new();
			clamd_config->ConfigType = AUTOMATIC;
			clamav_show_config(clamd_config);
			clamd_config_free(clamd_config);
		}
		else
			clamav_show_config(clamd_config);
	}*/

	page->enable_clamav = enable_clamav;
/*	page->enable_arc = enable_arc;*/
	page->max_size = max_size;
	page->recv_infected = recv_infected;
	page->save_folder = save_folder;
	page->config_type = setting_type;
	page->config_folder = config_folder;
	page->config_host = config_host;
	page->config_port = config_port;
	page->page.widget = vbox1;
	
	clamav_save_config();
}

static void clamav_destroy_widget_func(PrefsPage *_page)
{
	debug_print("Destroying Clamd widget\n");
}

static void clamav_save_func(PrefsPage *_page)
{
	struct ClamAvPage *page = (struct ClamAvPage *) _page;
	ClamAvConfig *config;

	debug_print("Saving Clamd Page\n");

	config = clamav_get_config();

	config->clamav_enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_clamav));
/*	config->clamav_enable_arc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_arc));*/

	config->clamav_max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
	config->clamav_recv_infected = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->recv_infected));
	g_free(config->clamav_save_folder);
	config->clamav_save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
	config->clamd_config_type = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->config_type));
	g_free(config->clamd_config_folder);
	config->clamd_config_folder = gtk_editable_get_chars(GTK_EDITABLE(page->config_folder), 0, -1);
	g_free(config->clamd_host);
	config->clamd_host = gtk_editable_get_chars(GTK_EDITABLE(page->config_host), 0, -1);
	config->clamd_port = atoi(gtk_entry_get_text(GTK_ENTRY(page->config_port)));

	if (config->clamav_enable) {
		Clamd_Stat status = clamd_prepare();
		switch (status) {
			case NO_SOCKET: 
				g_warning("[New config] No socket information");
				alertpanel_error(_("New config\nNo socket information.\nAntivirus disabled."));
				break;
			case NO_CONNECTION:
				g_warning("[New config] Clamd does not respond to ping");
				alertpanel_warning(_("New config\nClamd does not respond to ping.\nIs clamd running?"));
				break;
			default:
				break;
		}
	}
	clamav_save_config();
}

static struct ClamAvPage clamav_page;

static void gtk_message_callback(gchar *message)
{
	statusbar_print_all("%s", message);
}

gint clamav_gtk_init(void)
{
	static gchar *path[3];

	path[0] = _("Plugins");
	path[1] = _("Clam AntiVirus");
	path[2] = NULL;

	clamav_page.page.path = path;
	clamav_page.page.create_widget = clamav_create_widget_func;
	clamav_page.page.destroy_widget = clamav_destroy_widget_func;
	clamav_page.page.save_page = clamav_save_func;
	clamav_page.page.weight = 35.0;
	
	prefs_gtk_register_page((PrefsPage *) &clamav_page);
	clamav_set_message_callback(gtk_message_callback);

	debug_print("Clamd GTK plugin loaded\n");
	return 0;	
}

void clamav_gtk_done(void)
{
        prefs_gtk_unregister_page((PrefsPage *) &clamav_page);
}

--- NEW FILE: clamav_plugin.c ---
/*
 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
 * Copyright (C) 2003-2010 Michael Rasmussen and the Claws Mail Team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#  include "claws-features.h"
#endif

#include <glib.h>
#include <glib/gi18n.h>

#include "defs.h"

#include "common/claws.h"
#include "common/version.h"
#include "plugin.h"
#include "utils.h"
#include "hooks.h"
#include "inc.h"
#include "mimeview.h"
#include "folder.h"
#include "prefs.h"
#include "prefs_gtk.h"
#include "alertpanel.h"

#include "clamav_plugin.h"
#include "clamd-plugin.h"

#define PLUGIN_NAME (_("Clam AntiVirus"))

static guint hook_id;
static MessageCallback message_callback;

static ClamAvConfig config;

static PrefParam param[] = {
	{"clamav_enable", "FALSE", &config.clamav_enable, P_BOOL,
	 NULL, NULL, NULL},
/*	{"clamav_enable_arc", "FALSE", &config.clamav_enable_arc, P_BOOL,
	 NULL, NULL, NULL},*/
	{"clamav_max_size", "1", &config.clamav_max_size, P_USHORT,
	 NULL, NULL, NULL},
	{"clamav_recv_infected", "TRUE", &config.clamav_recv_infected, P_BOOL,
	 NULL, NULL, NULL},
	{"clamav_save_folder", NULL, &config.clamav_save_folder, P_STRING,
	 NULL, NULL, NULL},
	{"clamad_config_type", "TRUE", &config.clamd_config_type, P_BOOL,
	 NULL, NULL, NULL},
	{"clamd_config_folder", NULL, &config.clamd_config_folder, P_STRING,
	 NULL, NULL, NULL},
	{"clamd_host", NULL, &config.clamd_host, P_STRING,
	 NULL, NULL, NULL},
	{"clamd_port", NULL, &config.clamd_port, P_INT,
	 NULL, NULL, NULL},

	{NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
};

struct clamd_result {
	Clamd_Stat status;
};

static gboolean scan_func(GNode *node, gpointer data)
{
	struct clamd_result *result = (struct clamd_result *) data;
	MimeInfo *mimeinfo = (MimeInfo *) node->data;
	gchar *outfile;
	response buf;
	int max;
	struct stat info;

	outfile = procmime_get_tmp_file_name(mimeinfo);
	if (procmime_get_part(outfile, mimeinfo) < 0)
		g_warning("Can't get the part of multipart message.");
	else {
    	max = config.clamav_max_size * 1048576; /* maximum file size */
		if (stat(outfile, &info) == -1)
			g_warning("Can't determine file size");
		else {
			if (info.st_size <= max) {
				debug_print("Scanning %s\n", outfile);
				result->status = clamd_verify_email(outfile, &buf);
				debug_print("status: %d\n", result->status);
				switch (result->status) {
					case NO_SOCKET: 
						g_warning("[scanning] No socket information");
						alertpanel_error(_("Scanning\nNo socket information.\nAntivirus disabled."));
						break;
					case NO_CONNECTION:
						g_warning("[scanning] Clamd does not respond to ping");
						alertpanel_warning(_("Scanning\nClamd does not respond to ping.\nIs clamd running?"));
						break;
					case VIRUS: 
						g_warning("Detected %s virus.\n", clamd_get_virus_name(buf.msg));
						alertpanel_warning(_("Detected %s virus."), clamd_get_virus_name(buf.msg));
						break;
					case SCAN_ERROR:
						debug_print("Error: %s\n", buf.msg);
						alertpanel_error(_("Scanning error:\n%s"), buf.msg);
						break;
					case OK:
						debug_print("No virus detected.\n");
						break;
				}
			}
			else {
				debug_print("File: %s. Size (%d) greater than limit (%d)\n",
							outfile, (int) info.st_size, max);
			}
		}
		g_unlink(outfile);
	}

	return (result->status == OK) ? FALSE : TRUE;
}

static gboolean mail_filtering_hook(gpointer source, gpointer data)
{
	MailFilteringData *mail_filtering_data = (MailFilteringData *) source;
	MsgInfo *msginfo = mail_filtering_data->msginfo;
	MimeInfo *mimeinfo;

	struct clamd_result result;

	if (!config.clamav_enable)
		return FALSE;

	mimeinfo = procmime_scan_message(msginfo);
	if (!mimeinfo) return FALSE;

	debug_print("Scanning message %d for viruses\n", msginfo->msgnum);
	if (message_callback != NULL)
		message_callback(_("ClamAV: scanning message..."));

	debug_print("status: %d\n", result.status);
	g_node_traverse(mimeinfo->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, scan_func, &result);

	if (result.status == VIRUS) {
		if (config.clamav_recv_infected) {
			FolderItem *clamav_save_folder;

			if ((!config.clamav_save_folder) ||
			    (config.clamav_save_folder[0] == '\0') ||
			    ((clamav_save_folder = folder_find_item_from_identifier(config.clamav_save_folder)) == NULL))
				    clamav_save_folder = folder_get_default_trash();

			procmsg_msginfo_unset_flags(msginfo, ~0, 0);
			msginfo->filter_op = IS_MOVE;
			msginfo->to_filter_folder = clamav_save_folder;
		} else {
			folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
		}
	}
	
	procmime_mimeinfo_free_all(mimeinfo);
	
	return (result.status == OK) ? FALSE : TRUE;
}

Clamd_Stat clamd_prepare(void) {
	debug_print("Creating socket\n");
	if (!config.clamd_config_type || (config.clamd_host != NULL && config.clamd_port > 0)) {
		if (config.clamd_host == NULL || config.clamd_port < 1) {
			/* error */
			return NO_SOCKET;
		}
		/* Manual configuration has highest priority */
		debug_print("Using user input: %s:%d\n",
			config.clamd_host, config.clamd_port);
		clamd_create_config_manual(config.clamd_host, config.clamd_port);
	}
	else if (config.clamd_config_type || config.clamd_config_folder != NULL) {
		if (config.clamd_config_folder == NULL) {
			/* error */
			return NO_SOCKET;
		}
		debug_print("Using clamd.conf: %s\n", config.clamd_config_folder);
		clamd_create_config_automatic(config.clamd_config_folder);
	}
	else {
		/* Fall back. Try enable anyway */
		if (! clamd_find_socket())
			return NO_SOCKET;
	}

	return clamd_init(NULL);
}

ClamAvConfig *clamav_get_config(void)
{
	return &config;
}

void clamav_save_config(void)
{
	PrefFile *pfile;
	gchar *rcpath;

	debug_print("Saving Clamd Page\n");

	rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
	pfile = prefs_write_open(rcpath);
	g_free(rcpath);
	if (!pfile || (prefs_set_block_label(pfile, "ClamAV") < 0))
		return;

	if (prefs_write_param(param, pfile->fp) < 0) {
		g_warning("failed to write Clamd configuration to file\n");
		prefs_file_close_revert(pfile);
		return;
	}
    if (fprintf(pfile->fp, "\n") < 0) {
		FILE_OP_ERROR(rcpath, "fprintf");
		prefs_file_close_revert(pfile);
	} else
	        prefs_file_close(pfile);
}

void clamav_set_message_callback(MessageCallback callback)
{
	message_callback = callback;
}

gint plugin_init(gchar **error)
{
	gchar *rcpath;

	if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
				VERSION_NUMERIC, PLUGIN_NAME, error))
		return -1;

	hook_id = hooks_register_hook(MAIL_FILTERING_HOOKLIST, mail_filtering_hook, NULL);
	if (hook_id == -1) {
		*error = g_strdup(_("Failed to register mail filtering hook"));
		return -1;
	}

	prefs_set_default(param);
	rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
	prefs_read_config(param, "ClamAV", rcpath, NULL);
	g_free(rcpath);

	clamav_gtk_init();

	if (config.clamav_enable) {
		debug_print("Creating socket\n");
		Clamd_Stat status = clamd_prepare();
		switch (status) {
			case NO_SOCKET: 
				g_warning("[init] No socket information");
				alertpanel_error(_("Init\nNo socket information.\nAntivirus disabled."));
				break;
			case NO_CONNECTION:
				g_warning("[init] Clamd does not respond to ping");
				alertpanel_warning(_("Init\nClamd does not respond to ping.\nIs clamd running?"));
				break;
			default:
				break;
		}
	}

	debug_print("Clamd plugin loaded\n");

	return 0;
	
}

gboolean plugin_done(void)
{
	hooks_unregister_hook(MAIL_FILTERING_HOOKLIST, hook_id);
	g_free(config.clamav_save_folder);
	clamav_gtk_done();
	clamd_free();

	debug_print("Clamd plugin unloaded\n");
	return TRUE;
}

const gchar *plugin_name(void)
{
	return PLUGIN_NAME;
}

const gchar *plugin_desc(void)
{
	return _("This plugin uses Clam AntiVirus to scan all messages that are "
	       "received from an IMAP, LOCAL or POP account.\n"
	       "\n"
	       "When a message attachment is found to contain a virus it can be "
	       "deleted or saved in a specially designated folder.\n"
	       "\n"
	       "Because this plugin communicates with clamd via a\n"
	       "socket then there are some minimum requirements to\n"
	       "the permissions for your home folder and the\n"
	       ".claws-mail folder provided the clamav-daemon is\n"
	       "configured to communicate via a unix socket. All\n"
	       "users at least need to be given execute permissions\n"
	       "on these folders.\n"
	       "\n"
	       "To avoid changing permissions you could configure\n"
	       "the clamav-daemon to communicate via a TCP socket\n"
	       "and choose manual configuration for clamd.\n" 
	       "\n"
	       "Options can be found in /Configuration/Preferences/Plugins/Clam AntiVirus");
}

const gchar *plugin_type(void)
{
	return "GTK2";
}

const gchar *plugin_licence(void)
{
	return "GPL3+";
}

const gchar *plugin_version(void)
{
	return VERSION;
}

struct PluginFeature *plugin_provides(void)
{
	static struct PluginFeature features[] = 
		{ {PLUGIN_FILTERING, N_("Virus detection")},
		  {PLUGIN_NOTHING, NULL}};
	return features;
}

--- NEW FILE: clamav_plugin.h ---
/*
 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
 * Copyright (C) 2003-2010 Michael Rasmussen and the Claws Mail Team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */

#ifndef CLAMAV_PLUGIN_H
#define CLAMAV_PLUGIN_H 1

#include <glib.h>
#include "clamd-plugin.h"

typedef struct _ClamAvConfig ClamAvConfig;

typedef void (*MessageCallback) (gchar *);

struct _ClamAvConfig
{
	gboolean	 clamav_enable;
/*	gboolean 	 clamav_enable_arc;*/
	guint 		 clamav_max_size;
	gboolean 	 clamav_recv_infected;
	gchar		*clamav_save_folder;
	gboolean	 clamd_config_type;
	gchar		*clamd_host;
	int			 clamd_port;
	gchar		*clamd_config_folder;
};

ClamAvConfig *clamav_get_config		  (void);
void	      clamav_save_config	  (void);
void 	      clamav_set_message_callback (MessageCallback callback);
Clamd_Stat	  clamd_prepare(void);
gint	      clamav_gtk_init(void);
void 	      clamav_gtk_done(void);

#endif

--- placeholder.txt DELETED ---



More information about the Commits mailing list